diff --git a/ryzom/server/src/ai_service/ai_grp.h b/ryzom/server/src/ai_service/ai_grp.h index 0f4e84606..c2cdfc011 100644 --- a/ryzom/server/src/ai_service/ai_grp.h +++ b/ryzom/server/src/ai_service/ai_grp.h @@ -63,6 +63,7 @@ public: void aggroGain(TDataSetRow const& aggroBot) const { } virtual void spawnBots() = 0; + virtual void spawnBots(const std::string &name) = 0; virtual void despawnBots(bool immediately) = 0; virtual void update() = 0; diff --git a/ryzom/server/src/ai_service/ai_grp_fauna.cpp b/ryzom/server/src/ai_service/ai_grp_fauna.cpp index b84276b42..1a54c8c4c 100644 --- a/ryzom/server/src/ai_service/ai_grp_fauna.cpp +++ b/ryzom/server/src/ai_service/ai_grp_fauna.cpp @@ -546,6 +546,11 @@ void CSpawnGroupFauna::spawnBots() _Timer.set(getPersistent().timer(CGrpFauna::SPAWN_TIME)); } +void CSpawnGroupFauna::spawnBots(const std::string &name) +{ +} + + void CSpawnGroupFauna::despawnBots(bool immediately) { setDespawnImmediately(immediately); diff --git a/ryzom/server/src/ai_service/ai_grp_fauna.h b/ryzom/server/src/ai_service/ai_grp_fauna.h index e6363aa5d..086e7ac52 100644 --- a/ryzom/server/src/ai_service/ai_grp_fauna.h +++ b/ryzom/server/src/ai_service/ai_grp_fauna.h @@ -28,7 +28,7 @@ #include "ai_generic_fight.h" -class CGrpFauna; +class CGrpFauna; class CSpawnGroupFauna; #define GROUP_VISION_UPDATE_RADIUS (80) @@ -53,14 +53,14 @@ public: StateWandering, StateResting }; - + public: CSpawnGroupFauna(CPersistent& owner, RYAI_MAP_CRUNCH::TAStarFlag denyFlag); - + bool isSpawning(); - + void update(); - + /// @name CFightOrganizer implementation //@{ virtual void setFight(CSpawnBot* bot, CAIEntityPhysical* ennemy); @@ -69,84 +69,85 @@ public: virtual void setFlee(CSpawnBot* bot, CAIVector& fleeVect); virtual void setReturnAfterFight(CSpawnBot* bot); //@} - + virtual void spawnBots(); + virtual void spawnBots(const std::string &name); virtual void despawnBots(bool immediately); - + // overrides the init to avoid automatic bot spawn .. void spawnBotOfGroup() { } - + virtual void despawnGrp(); // critical code (despawn 'this' object). - + uint32 getLastUpdate() const { return _LastUpdate; } - + // Update Rate feature. int getUpdatePriority() const { return IsRingShard? (_UpdatePriority&7): _UpdatePriority; } // overloading to recalc the priority update rate. void recalcUpdatePriorityDeltaAndGroupPos(); - + CAIPos const& magnetPos() const; float magnetRadiusNear() const; float magnetRadiusFar() const; - + void resetTimer() { _Timer.set(0); } - + CGrpFauna& getPersistent(); - + // std::string buildDebugString(uint idx) const; - + void setPlace(int placeIndex); - + void incCurrentCycle(); - + void setCurrentCycle(uint32 cycle); - + uint32 getCurrentCycleTime(); - + CAIPlace* targetPlace() const { return _TargetPlace; } - + CPathCont& getPathCont() { return _PathCont; } - + CBotFauna* leader() const { return _Leader; } - + void setDespawnImmediately(bool immediately) { _DespawnImmediately = immediately; } - + bool despawnImmediately() { return _DespawnImmediately; } - + void setMustDespawnBots(bool toDespawnBots = true) { _MustDespawnBots=toDespawnBots; } - + bool mustDespawnBots() { return _MustDespawnBots; } - + private: uint32 getDt() const { return _DeltaTime; } - - CBotFauna* findLeader(); - + + CBotFauna* findLeader(); + // Behavior update method. void generalUpdate(TState state = StateUndefined); - + // Update method for different states. void updateSpawning(); void updateActivity(AITYPES::TProfiles activity); - + void checkTimers(); // called at each update to see if the last timer delay has expired (if true calls updateCycles) - + private: CPathCont _PathCont; - + NLMISC::CDbgPtr _TargetPlace; // a dynamic pointer to one of the above places - + bool _ArrivedInZone; // indicates that we have not reach the new zone - + NLMISC::CDbgPtr _Leader; // the individual in the group who is treated as the leader CAITimer _Timer; - + uint32 _CurrentCycle; - + int _UpdatePriority; uint32 _LastUpdate; // gamecycle at which update() last called uint32 _DeltaTime; // Dt, simply - + bool _MustDespawnBots; // if its a day group and its night for instance. bool _DespawnImmediately; // when MustdespawnBots, indicate if we must done it immedialtely or at best when no player can see it }; @@ -189,7 +190,7 @@ public: TPlaces _Place; uint32 _NextCycle; }; - + class Cycle { public: @@ -201,104 +202,104 @@ public: } std::vector _PopList; }; - + public: CGrpFauna(CMgrFauna* mgr, CAIAliasDescriptionNode* aliasTree, RYAI_MAP_CRUNCH::TAStarFlag denyFlags); - + virtual ~CGrpFauna(); - + RYZOMID::TTypeId getRyzomType() { return RYZOMID::creature; } - + CDynGrpBase* getGrpDynBase() { return this; } - - ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// // PersistentStateInstance - + CAliasTreeOwner* aliasTreeOwner() { return this; } - + CAIS::CCounter& getSpawnCounter(); - + bool timeAllowSpawn(uint32 popVersion = 12345) const; - + void stateChange(CAIState const* oldState, CAIState const* newState); - + CGroup* getGroup() { return this; } - + ////////////////////////////////////////////////////////////////////////// - + virtual void lastBotDespawned(); virtual void firstBotSpawned(); - + // debugging stuff CDebugHistory* getDebugHistory() { return this; } - + CPersistentStateInstance* getPersistentStateInstance() { return this; } - + virtual void setEvent(uint eventId); virtual void serviceEvent (const CServiceEvent &info); - + virtual std::string getFullName() const { return CGroup::getFullName(); } virtual std::string getIndexString() const { return CGroup::getIndexString(); } - + IAliasCont* getAliasCont(AITYPES::TAIType type); CAliasTreeOwner* createChild(IAliasCont* cont, CAIAliasDescriptionNode* aliasTree); - + NLMISC::CSmartPtr createSpawnGroup(); - + CSpawnGroupFauna* getSpawnObj() const { return NLMISC::type_cast(CGroup::getSpawnObj()); } - + void allocateBots(); - + // This struct is used to manage dead creatures and their corresponding respawned creature. - + // inheritted virtual interface ------------------------------------ virtual bool spawn(); bool spawnPop(uint popVersion); virtual void despawnGrp(); - + // Methods for setting up static data ------------------------------ void setType(AITYPES::TFaunaType type); void setCyles(std::string const& cycles); - + // Methods for manageing population descriptions void setPopulation(CPopulation *pop); - + // Methods for managing places void setPlace(CAIPlace*& variable, CAIPlace* place); void setupWanderPlace(); - + // Miscelaneous accessors ------------------------------------------ CMgrFauna& mgr() const; - + // reference timer value static uint32 refTimer(TTime time); uint32 timer(TTime time) const { return _Timer[time]; } void setTimer(TTime timer, uint32 time) { _Timer[timer] = time*10; } ///< we set time in seconds. - + AITYPES::TFaunaType getType() const { return _Type; } - + void setSpawnType(AITYPES::TSpawnType sp_type) { _SpawnType = sp_type; } - + void displayPlaces(CStringWriter& stringWriter) const; - + CAliasCont& places() { return _Places; } CAliasCont& populations() { return _Populations; } - + AITYPES::CPropertySet& faction() { return _Faction; } - + static const CCycleDef cycles[]; static const uint32 nbCycle; - + void setAutoSpawn(bool autoSpawn) { CGroup::setAutoSpawn(autoSpawn); if (!isAutoSpawn()) _CurrentCycle=std::numeric_limits::max(); } - + /// @name CChild implementation //@{ virtual std::string getOneLineInfoString() const; virtual std::vector getMultiLineInfoString() const; //@} - + /** Find next valid place with the wanted flags. - * If several places are valid, then one is picked randomly + * If several places are valid, then one is picked randomly * \return INVALID_PLACE if no such place exist */ sint getNextPlace(const CFaunaGenericPlace *startPlace, CAIPlaceXYRFauna::TFlag wantedFlag) const; @@ -309,35 +310,35 @@ public: public: // Dynamic data modified during normal activity -------------------- uint32 _CurPopulation; // which alternative bot population is active - + protected: - + // Static data initilised at init time ----------------------------- - + // basic data (name, id, pointer to manager, etc) AITYPES::TFaunaType _Type; // FaunaTypeHerbivore, FaunaTypePredator, ... etc - + // Definition of a vector of vectors of classes for populations ---- - + CAliasCont _Populations; CAliasCont _Places; - + AITYPES::TSpawnType _SpawnType; - + CAITimer _priorityRecalcTimer; // timer used to determine time of next recalc of _updateMask - + uint32 _Timer[LAST_TIME]; - + float _Aggro; - + /// Animat Addon double _MotivationGroupProtection; // A value between 0 an 1 giving the importance of the group protection. double _MotivationHarvestSap; // Motivation for the sap harvest. - + std::vector _Cycles; // Cycles List. uint32 _CurrentCycle; // current Cycle. sint32 _CurrentCycleIndex; // the pop index in the cycle - + AITYPES::CPropertySet _Faction; }; diff --git a/ryzom/server/src/ai_service/ai_grp_npc.cpp b/ryzom/server/src/ai_service/ai_grp_npc.cpp index 8ddfb013a..88e1c22d9 100644 --- a/ryzom/server/src/ai_service/ai_grp_npc.cpp +++ b/ryzom/server/src/ai_service/ai_grp_npc.cpp @@ -341,6 +341,57 @@ void CSpawnGroupNpc::stateChange(CAIState const* oldState, CAIState const* newSt } } +void CSpawnGroupNpc::spawnBots(const std::string &name) +{ + ucstring ucName; + ucName.fromUtf8(name); + + FOREACH(itBot, CCont, bots()) + { + CBot* bot = *itBot; + if (!bot->isSpawned()) { + bot->spawn(); + + if (!ucName.empty()) + { + CSpawnBot *spawnBot = bot->getSpawnObj(); + if (spawnBot) + { + TDataSetRow row = spawnBot->dataSetRow(); + NLNET::CMessage msgout("CHARACTER_NAME"); + msgout.serial(row); + msgout.serial(ucName); + sendMessageViaMirror("IOS", msgout); + spawnBot->getPersistent().setCustomName(ucName); + } + } + + if (_Cell < 0) { + CEntityId id = bot->getSpawnObj()->getEntityId(); + sint32 x = bot->getSpawnObj()->pos().x(); + sint32 y = bot->getSpawnObj()->pos().y(); + sint32 z = bot->getSpawnObj()->pos().h(); + float t = bot->getSpawnObj()->pos().theta().asRadians(); + uint8 cont = 0; + uint8 slide = 1; + NLMISC::TGameCycle tick = CTickEventHandler::getGameCycle() + 1; + CMessage msgout2("ENTITY_TELEPORTATION"); + msgout2.serial( id ); + msgout2.serial( x ); + msgout2.serial( y ); + msgout2.serial( z ); + msgout2.serial( t ); + msgout2.serial( tick ); + msgout2.serial( cont ); + msgout2.serial( _Cell ); + msgout2.serial( slide ); + + sendMessageViaMirror("GPMS", msgout2); + } + } + } +} + void CSpawnGroupNpc::spawnBots() { FOREACH(itBot, CCont, bots()) @@ -348,6 +399,7 @@ void CSpawnGroupNpc::spawnBots() CBot* bot = *itBot; if (!bot->isSpawned()) { bot->spawn(); + if (_Cell < 0) { CEntityId id = bot->getSpawnObj()->getEntityId(); sint32 x = bot->getSpawnObj()->pos().x(); diff --git a/ryzom/server/src/ai_service/ai_grp_npc.h b/ryzom/server/src/ai_service/ai_grp_npc.h index a90f4f5d8..382c6840e 100644 --- a/ryzom/server/src/ai_service/ai_grp_npc.h +++ b/ryzom/server/src/ai_service/ai_grp_npc.h @@ -45,6 +45,7 @@ public: CGroupNpc& getPersistent() const; virtual void spawnBots(); + virtual void spawnBots(const std::string &name); virtual void despawnBots(bool immediately); void update(); diff --git a/ryzom/server/src/ai_service/ai_grp_pet.h b/ryzom/server/src/ai_service/ai_grp_pet.h index c51c7c6cd..7d0f56ed2 100644 --- a/ryzom/server/src/ai_service/ai_grp_pet.h +++ b/ryzom/server/src/ai_service/ai_grp_pet.h @@ -33,7 +33,7 @@ class CPetOwner; class CSpawnGroupPet : public CSpawnGroup { -public: +public: CSpawnGroupPet(CPersistent& owner) : CSpawnGroup(owner) , _PathCont(NLMISC::safe_cast(&owner)->getAStarFlag()) @@ -41,18 +41,19 @@ public: _LastUpdate = CTimeInterface::gameCycle(); _IsPlayerSpawned = true; } - + CGrpPet& getPersistent() const; - + void spawnBots() { } + void spawnBots(const std::string &name) { } void despawnBots (bool immediately) { } - + void update(); - + CPathCont& getPathCont() { return _PathCont; } - + CAIVector const& getPos() const { return _PathCont.getDestination(); } - + private: CPathCont _PathCont; // this path container is share by all player pets .. (thats accelerate our computing). uint32 _LastUpdate; @@ -68,37 +69,37 @@ class CGrpPet { public: CGrpPet(CMgrPet* mgr, NLMISC::CEntityId const& owner, CAIAliasDescriptionNode* aliasTree = NULL); - + CDynGrpBase* getGrpDynBase() { return NULL; } - + RYZOMID::TTypeId getRyzomType() { return RYZOMID::pack_animal; } - + CAIS::CCounter& getSpawnCounter(); - + /// @name Service events //@{ void serviceUp(uint32 serviceId, std::string const& serviceName); void serviceDown(uint32 serviceId, std::string const& serviceName); //@} - + void init() { } - + void release() { } - + void setEvent(uint eventId); - + NLMISC::CSmartPtr createSpawnGroup(); - + CPersistentStateInstance* getPersistentStateInstance(); - + NLMISC::CEntityId const& getPetOwner() const { return _PetOwner; } - + CMgrPet& getPetManager() { return *(NLMISC::safe_cast(getOwner())); } - + CCont& bots() { return _Bots; } - + virtual std::string getOneLineInfoString() const { return std::string("Pet group '") + getName() + "'"; } - + private: NLMISC::CEntityId const _PetOwner; }; diff --git a/ryzom/server/src/ai_service/ai_instance.cpp b/ryzom/server/src/ai_service/ai_instance.cpp index 275c93b5a..8f3fce9fb 100644 --- a/ryzom/server/src/ai_service/ai_instance.cpp +++ b/ryzom/server/src/ai_service/ai_instance.cpp @@ -705,61 +705,7 @@ CGroupNpc* CAIInstance::eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const& grp->clrBotsAreNamedFlag(); - //addGroupInfo(grp, name, grp->getAlias()); - - - { - // build unnamed bot - for (uint i=0; ibots().addChild(new CBotNpc(grp, _LastSpawnAlias, name), i); // Doub: 0 instead of getAlias()+i otherwise aliases are wrong - - CBotNpc* const bot = NLMISC::safe_cast(grp->bots()[i]); - - bot->setSheet(sheet); - bot->setPrimAlias(900+_InstanceNumber); - if (!look.empty()) - bot->setClientSheet(look); - bot->equipmentInit(); - bot->initEnergy(/*groupEnergyCoef()*/0); - CAIVector rpos(pos); - if (dispersionRadius == 0) - { - nlinfo("Stucked !"); - bot->setStuck(true); - } - - float angle = 0.f; - if (orientation < (NLMISC::Pi * 2.0) && orientation > (-NLMISC::Pi * 2.0)) - angle = (float)orientation; - else - angle = randomAngle(); - - // Spawn all randomly except if only 1 bot - if (nbBots > 1 || dispersionRadius > 1) - { - bot->saveFirstPosition(pos, dispersionRadius); - RYAI_MAP_CRUNCH::CWorldMap const& worldMap = CWorldContainer::getWorldMap(); - RYAI_MAP_CRUNCH::CWorldPosition wp; - uint32 maxTries = 100; - do - { - rpos = pos; - rpos += randomPos(dispersionRadius); - --maxTries; - } - while (!worldMap.setWorldPosition(AITYPES::vp_auto, wp, rpos) && maxTries>0); - if (maxTries<=0) - rpos = pos; - - bot->setStartPos(pos.x().asDouble(), pos.y().asDouble(), angle, AITYPES::vp_auto); - } - else - bot->setStartPos(rpos.x().asDouble(),rpos.y().asDouble(), angle, AITYPES::vp_auto); - } - } + eventCreateNpcBot(grp, nbBots, false, sheetId, pos, "", orientation, dispersionRadius, look); grp->spawn(); CSpawnGroupNpc* spawnGroup = grp->getSpawnObj(); @@ -802,6 +748,71 @@ CGroupNpc* CAIInstance::eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const& return grp; } +bool CAIInstance::eventCreateNpcBot(CGroupNpc* grp, uint nbBots, bool spawnBots, NLMISC::CSheetId const& sheetId, CAIVector const& pos, const std::string &name, double orientation, double dispersionRadius, const std::string &look) +{ + uint32 offset = grp->bots().size(); + for (uint i=0; ibots().addChild(new CBotNpc(grp, _LastSpawnAlias, grp->getName()), offset+i); + + CBotNpc* const bot = NLMISC::safe_cast(grp->bots()[offset+i]); + + AISHEETS::ICreatureCPtr sheet = AISHEETS::CSheets::getInstance()->lookup(sheetId); + if (!sheet) + { + nlwarning("invalid sheet while creating event npc group"); + return false; + } + + bot->setSheet(sheet); + bot->setPrimAlias(900+_InstanceNumber); + if (!look.empty()) + bot->setClientSheet(look); + bot->equipmentInit(); + bot->initEnergy(/*groupEnergyCoef()*/0); + CAIVector rpos(pos); + if (dispersionRadius == 0) + bot->setStuck(true); + + float angle = 0.f; + if (orientation < (NLMISC::Pi * 2.0) && orientation > (-NLMISC::Pi * 2.0)) + angle = (float)orientation; + else + angle = randomAngle(); + + // Spawn all randomly except if only 1 bot + if (nbBots > 1 || dispersionRadius > 1) + { + bot->saveFirstPosition(pos, dispersionRadius); + RYAI_MAP_CRUNCH::CWorldMap const& worldMap = CWorldContainer::getWorldMap(); + RYAI_MAP_CRUNCH::CWorldPosition wp; + uint32 maxTries = 100; + do + { + rpos = pos; + rpos += randomPos(dispersionRadius); + --maxTries; + } + while (!worldMap.setWorldPosition(AITYPES::vp_auto, wp, rpos) && maxTries>0); + if (maxTries<=0) + rpos = pos; + + bot->setStartPos(pos.x().asDouble(), pos.y().asDouble(), angle, AITYPES::vp_auto); + } + else + bot->setStartPos(rpos.x().asDouble(),rpos.y().asDouble(), angle, AITYPES::vp_auto); + } + + if (spawnBots) + grp->getSpawnObj()->spawnBots(name); + + return true; +} + + + + CBotEasterEgg* CAIInstance::createEasterEgg(uint32 easterEggId, NLMISC::CSheetId const& sheetId, std::string const& botName, double x, double y, double z, double heading, const std::string& look) { if (_EasterEggManager == NULL) diff --git a/ryzom/server/src/ai_service/ai_instance.h b/ryzom/server/src/ai_service/ai_instance.h index 0d7cf647a..b2a71cd3f 100644 --- a/ryzom/server/src/ai_service/ai_instance.h +++ b/ryzom/server/src/ai_service/ai_instance.h @@ -209,6 +209,7 @@ public: } CGroupNpc* eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const& sheetId, CAIVector const& pos, double dispersionRadius, bool spawnBots, double orientation, const std::string &botsName, const std::string &look, sint32 cell=0); + bool eventCreateNpcBot(CGroupNpc* grp, uint nbBots, bool spawnBots, NLMISC::CSheetId const& sheetId, CAIVector const& pos, const std::string &name, double orientation, double dispersionRadius, const std::string &look); /// create a new easter egg CBotEasterEgg* createEasterEgg(uint32 easterEggId, NLMISC::CSheetId const& sheetId, std::string const& botName, double x, double y, double z, double heading, const std::string& look); diff --git a/ryzom/server/src/ai_service/ai_profile_npc.cpp b/ryzom/server/src/ai_service/ai_profile_npc.cpp index 6591df00a..4608bcdbf 100644 --- a/ryzom/server/src/ai_service/ai_profile_npc.cpp +++ b/ryzom/server/src/ai_service/ai_profile_npc.cpp @@ -4229,7 +4229,7 @@ void CBotProfileMoveTo::updateProfile(uint ticksSinceLastUpdate) { // get a base pointer to allow virtual call to work - nlwarning("Follow No Path : %s", _Bot->getPersistent().getOneLineInfoString().c_str()); + //nlwarning("Follow No Path : %s", _Bot->getPersistent().getOneLineInfoString().c_str()); } } } diff --git a/ryzom/server/src/ai_service/commands.cpp b/ryzom/server/src/ai_service/commands.cpp index 6e92be533..417dcab43 100644 --- a/ryzom/server/src/ai_service/commands.cpp +++ b/ryzom/server/src/ai_service/commands.cpp @@ -65,6 +65,7 @@ RYAI_TEMPLATED_COMMAND(listCellZones, "display the list of cell zones", "[]", CFamilyBehavior, buildFamilyBehaviorList, displayList) RYAI_TEMPLATED_COMMAND(listOutposts, "display the list of outposts", "[]", COutpost, buildOutpostList, displayList) RYAI_TEMPLATED_COMMAND(listManagers, "display the list of managers", "[]", CManager, buildManagerList, displayList) +RYAI_TEMPLATED_COMMAND(listNpcManagers, "display the list of managers", "[]", CManager, buildNpcManagerList, displayList) RYAI_TEMPLATED_COMMAND(listGroups, "display the list of groups", "[]", CGroup, buildGroupList, displayList) RYAI_TEMPLATED_COMMAND(listBots, "display the list of bots", "[]", CBot, buildBotList, displayList) RYAI_TEMPLATED_COMMAND(listPlayers, "display the list of players", "[]", CBotPlayer, buildPlayerList, displayList) @@ -114,77 +115,77 @@ NLMISC_COMMAND(search, "search all the data tree for a name part","") { if (args.size() != 1) return false; - + { log.displayNL("- Search results in instances ------------------------------------------------"); std::deque container; buildInstanceList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in continents -----------------------------------------------"); std::deque container; buildContinentList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in regions --------------------------------------------------"); std::deque container; buildRegionList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in cell zones -----------------------------------------------"); std::deque container; buildCellZoneList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in family behaviors -----------------------------------------"); std::deque container; buildFamilyBehaviorList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in outposts -------------------------------------------------"); std::deque container; buildOutpostList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in managers -------------------------------------------------"); std::deque container; buildManagerList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in groups ---------------------------------------------------"); std::deque container; buildGroupList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in bots -----------------------------------------------------"); std::deque container; buildBotList(container); displayList(log, container, args[0]); } - + { log.displayNL("- Search results in players --------------------------------------------------"); std::deque container; buildPlayerList(container); displayList(log, container, args[0]); } - + return true; } @@ -194,9 +195,9 @@ NLMISC_COMMAND(eventCreateNpcGroup, "create an event npc group", " { if (args.size()<5) return false; - + CLogStringWriter stringWriter(&log); - + CAIInstance* aiInstance = NULL; { uint32 aiInstanceId = NLMISC::atoui(args[0].c_str()); @@ -212,14 +213,14 @@ NLMISC_COMMAND(eventCreateNpcGroup, "create an event npc group", " return true; } } - + uint32 nbBots = NLMISC::atoui(args[1].c_str()); if (nbBots<=0) { stringWriter.append("invalid bot count"); return true; } - + NLMISC::CSheetId sheetId(args[2]); if (sheetId==NLMISC::CSheetId::Unknown) sheetId = args[2] + ".creature"; @@ -228,7 +229,7 @@ NLMISC_COMMAND(eventCreateNpcGroup, "create an event npc group", " stringWriter.append("invalid sheet id"); return true; } - + double x, y; NLMISC::fromString(args[3], x); NLMISC::fromString(args[4], y); @@ -243,7 +244,7 @@ NLMISC_COMMAND(eventCreateNpcGroup, "create an event npc group", " return true; } } - + bool spawnBots = true; if (args.size()>6) { @@ -261,7 +262,7 @@ NLMISC_COMMAND(eventCreateNpcGroup, "create an event npc group", " if (args.size()>8) botsName = args[8]; aiInstance->eventCreateNpcGroup(nbBots, sheetId, CAIVector(x, y), dispersionRadius, spawnBots, orientation, botsName, ""); - + return true; } @@ -323,7 +324,7 @@ NLMISC_COMMAND(dumpRoadCon, "dump road/cell connectivity graph"," CRegion *region = regions[i]; if (!region) continue; - + CAliasCont &cellZones = region->cellZones(); for (uint i=0; i } } - + for (uint i=0; i { nldebug("NpcZone '%s' host road '%s'", nz->getAliasTreeOwner().getName().c_str(), nz->roads()[l]->getName().c_str()); } - + } CAliasCont &roads = cell->roads(); @@ -373,17 +374,17 @@ NLMISC_COMMAND(dumpRoadCon, "dump road/cell connectivity graph"," if (!road) continue; // clear existing link; - nldebug("Road '%s' link from '%s' %s to '%s' %s", road->getName().c_str(), + nldebug("Road '%s' link from '%s' %s to '%s' %s", road->getName().c_str(), road->startZone().isNULL() ? "none" : road->startZone()->getAliasTreeOwner().getName().c_str(), road->startExternal() ? "(external)" : "", road->endZone().isNULL() ? "none" : road->endZone()->getAliasTreeOwner().getName().c_str(), road->endExternal() ? "(external)" : ""); } - + } } } - + } } @@ -431,15 +432,15 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI for (uint j=0; jregions().size(); ++j) { CRegion *region = cont->regions()[j]; - if (!region) + if (!region) { log.displayNL(" +- %u null entry", j); continue; } - log.displayNL(" +- Region '%s'%s @ %p", - region->getName().c_str(), - region->getAliasString().c_str(), + log.displayNL(" +- Region '%s'%s @ %p", + region->getName().c_str(), + region->getAliasString().c_str(), static_cast(region)); for (uint k=0; kcellZones().size(); ++k) @@ -451,11 +452,11 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI continue; } - log.displayNL(" | +- CellZone '%s'%s @ %p", - cz->getName().c_str(), - cz->getAliasString().c_str(), + log.displayNL(" | +- CellZone '%s'%s @ %p", + cz->getName().c_str(), + cz->getAliasString().c_str(), static_cast(cz)); - + for (uint l=0; lcells().size(); ++l) { CCell *cell = cz->cells()[l]; @@ -465,9 +466,9 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI continue; } - log.displayNL(" | | +- Cell '%s'%s @ %p", - cell->getName().c_str(), - cell->getAliasString().c_str(), + log.displayNL(" | | +- Cell '%s'%s @ %p", + cell->getName().c_str(), + cell->getAliasString().c_str(), static_cast(cell)); for (uint m=0; mnpcZoneCount(); ++m) @@ -480,10 +481,10 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI } // log.displayNL(" | | | +- NpcZone '%s' (alias A:%u @ %p)", nz->getName().c_str(), nz->getAlias(), static_cast(nz)); - log.displayNL(" | | | +- NpcZone '%s'%s", - nz->getAliasTreeOwner().getName().c_str(), + log.displayNL(" | | | +- NpcZone '%s'%s", + nz->getAliasTreeOwner().getName().c_str(), nz->getAliasTreeOwner().getAliasString().c_str()); - + } for (uint k=0; kroads().size(); ++k) @@ -494,12 +495,12 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI log.displayNL(" | | +- %u null entry", k); continue; } - - log.displayNL(" | | +- Road '%s'%s @ %p", - road->getName().c_str(), - road->getAliasString().c_str(), + + log.displayNL(" | | +- Road '%s'%s @ %p", + road->getName().c_str(), + road->getAliasString().c_str(), static_cast(road)); - } + } for (uint m=0; mfaunaZones().size(); ++m) { @@ -510,9 +511,9 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI continue; } - log.displayNL(" | | | +- FaunaZone '%s'%s @ %p", - fz->getName().c_str(), - fz->getAliasString().c_str(), + log.displayNL(" | | | +- FaunaZone '%s'%s @ %p", + fz->getName().c_str(), + fz->getAliasString().c_str(), static_cast(fz)); } } @@ -527,7 +528,7 @@ bool dumpContinentImp(uint instanceIndex, const std::string &continentName, NLMI log.displayNL("Can't find continent '%s' in ai instance %u", continentName.c_str(), instanceIndex); - + return true; } @@ -540,7 +541,7 @@ NLMISC_COMMAND(loadContinent, "load a continent collision map","") return false; CWorldContainer::loadContinent(args[0]); - + return true; } @@ -556,14 +557,14 @@ NLMISC_COMMAND(createDynamicAIInstance, "Create a new dynamic AIInstance","") uint32 in; NLMISC::fromString(args[0], in); if( !CAIS::instance().getAIInstance(in) ) - { + { std::string name= NLMISC::toString("ring_%d",in); const int index = CAIS::instance().createAIInstance(name, in); nlinfo("AIInstance %u created for continent '%s' (Instance Index : %u)", in, name.c_str(), index); } - + // activate the current AIInstance currentInstance = CAIS::instance().getAIInstance(in); //CAIS::instance().getAIInstance(continentInstanceId); CWorkPtr::aiInstance(currentInstance); @@ -574,7 +575,7 @@ NLMISC_COMMAND(createStaticAIInstance, "Create a new static AIInstance for a giv { if (args.size() != 1) return false; - + CUsedContinent &uc = CUsedContinent::instance(); const uint32 in = uc.getInstanceForContinent(args[0]); @@ -588,7 +589,7 @@ NLMISC_COMMAND(createStaticAIInstance, "Create a new static AIInstance for a giv if (!CAIS::instance().getAIInstance(in)) { const int index = CAIS::instance().createAIInstance(args[0], in); - nlinfo("AIInstance %u created for continent '%s' (Instance Index : %u)", + nlinfo("AIInstance %u created for continent '%s' (Instance Index : %u)", in, args[0].c_str(), index); } @@ -644,7 +645,7 @@ NLMISC_COMMAND(energy, "set or get the effective energy (affects group type)."," bool detailled=false; CLogStringWriter stringWriter(&log); - + { for (uint32 i=0;i &args, CDoOnFamily *fam) { std::string family; std::string cellZoneName; - + for (uint32 i=0;i, CAIS::instance().AIList()) { FOREACH(contIt, CCont, (*aiiIt)->continents()) @@ -783,7 +784,7 @@ bool doOnFamily (const std::vector &args, CDoOnFamily *fam) continue; fam->doOnCellZone(*czIt); - + FOREACH(fb, CCont, czIt->_Families) { if ( !family.empty() @@ -813,7 +814,7 @@ public: for (uint32 i=0;isetModifier (_value, (uint32)_index); } - + virtual void doOnCellZone(CCellZone *cz) const { if (_value==-1) _stringWriter.append(""); } -protected: +protected: private: uint32 _index; float _value; @@ -952,7 +953,7 @@ NLMISC_COMMAND(globalEnergy, "set or get the effective energy for a family.","[< string family; CLogStringWriter stringWriter(&log); - + if (args.size() > 0) { family=args[0]; @@ -1020,16 +1021,16 @@ NLMISC_COMMAND(globalEnergy, "set or get the effective energy for a family.","[< } return true; } - + //------------------------------------------------------------------------- // memory report // NLMISC_COMMAND(statMemory, "generate a memory usage statistic file","") // { // if (args.size() != 1) // return false; -// +// // CLogStringWriter stringWriter(&log); -// +// // if (args[0] == "begin") // { // stringWriter.append("Writing begin memory state in 'memory_report_begin.csv'..."); @@ -1044,7 +1045,7 @@ NLMISC_COMMAND(globalEnergy, "set or get the effective energy for a family.","[< // } // else // return false; -// +// // return true; // } @@ -1075,8 +1076,8 @@ NLMISC_COMMAND(setGroupVar,"display the logic var of the group in the given AI I return false; } } - - + + // first, try to find the group by alias uint32 alias = NLMISC::atoui(args[1].c_str()); if (alias != 0) @@ -1151,7 +1152,7 @@ NLMISC_COMMAND(displayGroupVar,"display the logic var of the group in the given } } - + CGroup *grp = NULL; // first, try to find the group by alias @@ -1223,25 +1224,25 @@ NLMISC_COMMAND(displayPlayerTeams,"display all the player teams"," [<-no_detail> CCont::iterator it=CAIS::instance().AIList().begin(), itEnd=CAIS::instance().AIList().end(); CLogStringWriter stringWriter(&log); - + while (it!=itEnd) { std::vector teamIds; CAIInstance *aiInstance=*it; aiInstance->getPlayerMgr()->getTeamIds(teamIds); - + if (teamIds.empty()) { continue; } - + std::vector::iterator first(teamIds.begin()), last(teamIds.end()); for (; first != last; ++first) { int id = *first; { stringWriter.append("Player Team "+toString(id)+" :"); - + if (!noDetail) { const std::set &team = aiInstance->getPlayerMgr()->getPlayerTeam(uint16(id)); @@ -1283,7 +1284,7 @@ NLMISC_COMMAND(setEscortId,"set the escort team id for a group in the given aIIn return false; } } - + CGroup *grp = NULL; // first, try to find the group by alias @@ -1361,7 +1362,7 @@ void execBufferedCommands() { vector retStrings; CArrayStringWriter sw(retStrings); - + FOREACHC(it, TCommandList, setEventCommands) { execSetEvent(sw, *it); @@ -1409,7 +1410,7 @@ bool execSetEvent(CStringWriter &stringWriter, const vector &args) && !( args.size() == 4 && args[1] == "-no_detail")) return false; - + CAIInstance *aiInstance=NULL; { const uint32 aiInstanceId = NLMISC::atoui(args[0].c_str()); @@ -1425,32 +1426,32 @@ bool execSetEvent(CStringWriter &stringWriter, const vector &args) return false; } } - - + + bool noDetail = false; - + if (args.size() == 4) noDetail = true; - + uint32 eventId = NLMISC::atoui(args[1].c_str()); NLMISC::clamp(eventId, 0u, 9u); - + CGroup *grp = NULL; - + // first, try to find the group by alias uint32 alias = NLMISC::atoui(args[2].c_str()); if (alias != 0) { grp = aiInstance->findGroup(alias); - + if (!grp) return false; - + stringWriter.append("Setting event "+toString(eventId)+" on groups '"+grp->aliasTreeOwner()->getName()+"' ("+toString(grp->getChildIndex())+")"); grp->setEvent(eventId); return true; } - + std::vector grps; if (!grp) { @@ -1476,12 +1477,12 @@ bool execSetEvent(CStringWriter &stringWriter, const vector &args) return false; } } - + stringWriter.append("Setting event "+toString(eventId)+" on groups '"+args[2]+"'"); - + for (uint i=0; isetEvent(eventId); - + return true; } @@ -1498,7 +1499,7 @@ bool execScript(CStringWriter& stringWriter, TCommand const& args) { if (args.size()<1) return false; - + string const& groupName = args[0]; typedef vector TGroupContainer; TGroupContainer grps; @@ -1511,17 +1512,17 @@ bool execScript(CStringWriter& stringWriter, TCommand const& args) return false; } } - + stringWriter.append("do script on groups '"+groupName+"'"); - + if (args.size()>1) { vector codeLines; for (size_t i=1; i codePtr = CCompiler::getInstance().compileCode(codeLines, "script Command"); - + FOREACHC(itGrp, TGroupContainer, grps) { CGroup* grp = *itGrp; @@ -1550,7 +1551,7 @@ bool execScript2(CStringWriter& stringWriter, TCommand const& args) { if (args.size()<1) return false; - + string const& botName = args[0]; typedef set TGroupContainer; TGroupContainer grps; @@ -1574,17 +1575,17 @@ bool execScript2(CStringWriter& stringWriter, TCommand const& args) } } } - + stringWriter.append("do script on groups containing bot '"+botName+"'"); - + if (args.size()>1) { vector codeLines; for (size_t i=1; i codePtr = CCompiler::getInstance().compileCode(codeLines, "script2 Command"); - + FOREACHC(itGrp, TGroupContainer, grps) { CGroup* grp = *itGrp; @@ -1613,7 +1614,7 @@ bool execScriptBotById(CStringWriter& stringWriter, TCommand const& args) { if (args.size()<2) return false; - + NLMISC::CEntityId botId = NLMISC::CEntityId(args[0]); if (botId==NLMISC::CEntityId::Unknown) return false; @@ -1625,15 +1626,15 @@ bool execScriptBotById(CStringWriter& stringWriter, TCommand const& args) return false; if (!bot->getPersistent().getOwner()->getPersistentStateInstance()) return false; - + vector codeLines; for (size_t i=1; i codePtr = CCompiler::getInstance().compileCode(codeLines, "script2 Command"); - + bot->getPersistent().getOwner()->getPersistentStateInstance()->interpretCode(NULL, codePtr); - + return true; } @@ -1643,7 +1644,7 @@ bool execScriptGroupByName(CStringWriter& stringWriter, TCommand const& args) { if (args.size()<2) return false; - + string const& groupName = args[0]; // NLMISC::CEntityId botId = NLMISC::CEntityId(args[0]); // if (botId==NLMISC::CEntityId::Unknown) @@ -1653,15 +1654,15 @@ bool execScriptGroupByName(CStringWriter& stringWriter, TCommand const& args) return false; if (!group->getPersistentStateInstance()) return false; - + vector codeLines; for (size_t i=1; i codePtr = CCompiler::getInstance().compileCode(codeLines, "script2 Command"); - + group->getPersistentStateInstance()->interpretCode(NULL, codePtr); - + return true; } @@ -1779,7 +1780,7 @@ bool execLoadScript(CStringWriter& stringWriter, vector const& args) { if (args.size()!=3) return false; - + CAIInstance* aiInstance = NULL; { uint32 const aiInstanceId = NLMISC::atoui(args[0].c_str()); @@ -1795,9 +1796,9 @@ bool execLoadScript(CStringWriter& stringWriter, vector const& args) return false; } } - + bool noDetail = false; - + string const& groupName = args[1]; std::vector grps; { @@ -1823,13 +1824,13 @@ bool execLoadScript(CStringWriter& stringWriter, vector const& args) return false; } } - + stringWriter.append("do script on groups '"+groupName+"'"); - + try { NLMISC::CIFile file(NLMISC::CPath::lookup(args[2])); - + vector lines; while (!file.eof()) { @@ -1840,7 +1841,7 @@ bool execLoadScript(CStringWriter& stringWriter, vector const& args) } // Compile the buffer CSmartPtr codePtr=CCompiler::getInstance().compileCode(lines, "script Command"); - + // Interpret the code for each group FOREACHC(itGrp, vector, grps) (*itGrp)->getPersistentStateInstance()->interpretCode(NULL, codePtr); @@ -1863,12 +1864,12 @@ NLMISC_COMMAND(loadScript, "execute a script from a file for a group in the give NLMISC_COMMAND(getInfo,"display returned values of buffered commands","") { CLogStringWriter stringWriter(&log); - + FOREACHC(strIt, vector, bufferedRetStrings) { stringWriter.append(*strIt); } - + return true; } @@ -1912,7 +1913,7 @@ NLMISC_COMMAND(displayTarget,"display bot target status for given bot(s) or play { if(args.size() <1) return false; - + CLogStringWriter stringWriter(&log); for (uint i=0;igetRyzomType()) { case RYZOMID::npc: case RYZOMID::creature: - case RYZOMID::pack_animal: + case RYZOMID::pack_animal: break; case RYZOMID::player: log.displayNL("=> target is a player"); @@ -1960,9 +1961,9 @@ NLMISC_COMMAND(displayTarget,"display bot target status for given bot(s) or play if (!found) { - log.displayNL("=> can't display information for the target of: %s", args[i].c_str()); + log.displayNL("=> can't display information for the target of: %s", args[i].c_str()); } - + } return true; } @@ -2059,7 +2060,7 @@ NLMISC_COMMAND(displayVisionRadius,"display roughly 'radius' cell vision centred return false; } } - + uint32 dist=100; CAICoord x, y; x=atof(args[1].c_str()); @@ -2083,7 +2084,7 @@ NLMISC_COMMAND(displayVisionRadius,"display roughly 'radius' cell vision centred const CBotPlayer* const playerPtr=dynamic_cast(&entityPtr); if (!playerPtr) continue; - + // have to implement players. #ifdef NL_DEBUG nlwarning("Not Implemented"); @@ -2129,7 +2130,7 @@ NLMISC_COMMAND(countEntitesInVisionMatrix,"scan the vision matrix for entities i return false; } } - + // build an iterator table for our scan CAIEntityMatrixIteratorTblRandom tbl; tbl.push_back(0,0); @@ -2149,7 +2150,7 @@ NLMISC_COMMAND(countEntitesInVisionMatrix,"scan the vision matrix for entities i CAIVector position(0,0); // count entities in bot matrix for (it=aiInstance->botMatrix().beginCells(&tbl,position);!it.end();++it) - { + { for (CEntityListLink *listLink=(*it)->next();listLink!=*it;listLink=listLink->next()) ++botCount; } @@ -2219,7 +2220,7 @@ NLMISC_VARIABLE(string, WATCH7, "watch string 7"); NLMISC_VARIABLE(string, WATCH8, "watch string 8"); NLMISC_VARIABLE(string, WATCH9, "watch string 9"); -// +// bool FAUNA_GRAPH_USES_DEBUG_TIME = false; NLMISC_VARIABLE(bool, FAUNA_GRAPH_USES_DEBUG_TIME, "force fauna graph to use local time (for debug)"); @@ -2229,7 +2230,7 @@ void UpdateWatches() { // if (!CAIS::initialised()) // return; - + for (uint i=0;i args,bool onOff) while (grpPtr!=NULL) { grpPtr->getDebugHistory()->setRecording(onOff); - + CBot* botPtr = grpPtr->getNextValidBotChild(); while (botPtr!=NULL) { botPtr->getDebugHistory()->setRecording(onOff); botPtr=grpPtr->getNextValidBotChild(botPtr); - } + } grpPtr=mgrPtr->getNextValidGroupChild(grpPtr); } mgrPtr=instancePtr->managers().getNextValidChild(mgrPtr); @@ -2309,7 +2310,7 @@ static bool setBotRecordHistory(std::vector args,bool onOff) { CAIInstance* instancePtr = CAIS::instance().AIList().getNextValidChild(); while (instancePtr!=NULL) - { + { CManager* mgrPtr = instancePtr->managers().getNextValidChild(); while (mgrPtr!=NULL) { @@ -2318,7 +2319,7 @@ static bool setBotRecordHistory(std::vector args,bool onOff) { if (onOff) grpPtr->getDebugHistory()->setRecording(onOff); - + CBot* botPtr = grpPtr->getNextValidBotChild(); while (botPtr!=NULL) { @@ -2328,14 +2329,14 @@ static bool setBotRecordHistory(std::vector args,bool onOff) botPtr->getDebugHistory()->setRecording(onOff); } botPtr=grpPtr->getNextValidBotChild(botPtr); - } + } grpPtr=mgrPtr->getNextValidGroupChild(grpPtr); } mgrPtr=instancePtr->managers().getNextValidChild(mgrPtr); } instancePtr=CAIS::instance().AIList().getNextValidChild(instancePtr); } - } + } return true; } @@ -2373,16 +2374,16 @@ NLMISC_COMMAND(botViewHistory,"view recorded history for named entity","getDebugHistory()->writeAsInfo(); break; // don't need to write info more than one time. } - - } + + } botPtr=grpPtr->getNextValidBotChild(botPtr); - } + } grpPtr=mgrPtr->getNextValidGroupChild(grpPtr); } mgrPtr=instancePtr->managers().getNextValidChild(mgrPtr); } instancePtr=CAIS::instance().AIList().getNextValidChild(instancePtr); - } + } return true; } @@ -2400,7 +2401,7 @@ NLMISC_COMMAND(grpHistoryRecordLog,"toggle grp history recorder 'nlinfo' logging // DISPLAYING VISION OF FAUNA GROUPS NLMISC_COMMAND(displayFaunaGrpVision,"display the vision of a fauna group","") -{ +{ return false; } @@ -2425,7 +2426,7 @@ NLMISC_COMMAND(advanceGrpState,"advance the group to the next state in its cycle else { grp->getSpawnObj()->resetTimer(); - } + } return true; } @@ -2489,19 +2490,19 @@ NLMISC_COMMAND(updateAI,"call CAIS::update() (simulate a tick off-line)","[tick] NLMISC_COMMAND(addPetsToPlayer,"Add some pets specified with a sheet to the specified player."," ") { if ( args.size() !=3 ) - return false; + return false; #ifdef NL_DEBUG nlstopex(("Not Implemented")); #endif - return true; + return true; } //------------------------------------------------------------------------- // DISPLAYING FIGHT SHEET. NLMISC_COMMAND(displayFightSheet,"display the sheet","") -{ +{ if (args.size() !=1) { log.displayNL("One argument needed"); @@ -2519,16 +2520,16 @@ NLMISC_COMMAND(displayFightSheet,"display the sheet","") std::string creatureString=args[0]+std::string(".creature"); sheet = /*const_cast(*/AISHEETS::CSheets::getInstance()->lookup(CSheetId(creatureString))/*)*/; } - + if (sheet->SheetId()==NLMISC::CSheetId::Unknown) { log.displayNL("Failed to identify sheet: %s",args[0].c_str()); return false; } - + log.displayNL("all these values are used to compute a score for a possible new target"); log.displayNL("beware the fact that in this version we used 'level' to represent relative force, it may be changed, so don't take too much time tuning courage"); - + log.displayNL("- DistModulator [0 n]: %f value=1/(1+distance*DistModulator)", sheet->DistModulator()); log.displayNL("value means the distance sensitivity of the bot, equals to zero means the bot never mind the distance"); @@ -2537,10 +2538,10 @@ NLMISC_COMMAND(displayFightSheet,"display the sheet","") log.displayNL("- ScoreModulator [0 1]: %f score>ScoreModulator", sheet->ScoreModulator()); log.displayNL("value means the minimum value (threshold) needed for the bot to attack, 0 means always, 1 never (also impossible)"); - + log.displayNL("- FearModulator [0 1]: %f score>FearModulator", sheet->FearModulator()); log.displayNL("value means the minimum value (threshold) needed for the bot to flee, 0 means always, 1 never (also impossible)"); - + log.displayNL("- LifeLevelModulator [0 1]: %f value=LifeLevelModulator*lifeCoef+(1.f-LifeLevelModulator)*levelCoef", sheet->LifeLevelModulator()); log.displayNL("value means the ratio between the life and level ratio, 1 means life is only take in count, 0 means level only take in count"); @@ -2549,10 +2550,10 @@ NLMISC_COMMAND(displayFightSheet,"display the sheet","") log.displayNL("- GroupCohesionModulator [0 1]: %f", sheet->GroupCohesionModulator()); log.displayNL("value used to make bots of a group aware of each other, 0 each bot is individual, 1 they fight in group"); - + log.displayNL("- GroupDispersion [0 1]: %f", sheet->GroupDispersion()); log.displayNL("value used to make bots of a group far or not of each other, 0 each all bots are at the same place, 1 they go everywere in the place"); - + return true; } @@ -2560,30 +2561,30 @@ NLMISC_COMMAND(displayFightSheet,"display the sheet","") // all these values are used to compute a score for a possible new target // beware the fact that in this version we used 'level' to represent relative force, it may be changed, so don't take too much time tuning courage -// +// // - DistModulator [0 n]: value=1/(1+distance*DistModulator) // value means the distance sensitivity of the bot, equals to zero means the bot never mind the distance -// +// // - TargetModulator [0 n]: value=1/(1+nbTarget*TargetModulator) // value means the number of attacker sensitivity of the bot, equals to zero means the bot never mind the number of attackers on the target -// +// // - ScoreModulator [0 1]: score>ScoreModulator // value means the minimum value (threshold) needed for the bot to attack, 0 means always, 1 never (also impossible) -// +// // - FearModulator [0 1]: score>FearModulator // value means the minimum value (threshold) needed for the bot to flee, 0 means always, 1 never (also impossible) -// +// // - LifeLevelModulator [0 1]: value=LifeLevelModulator*lifeCoef+(1.f-LifeLevelModulator)*levelCoef // value means the ratio between the life and level ratio, 1 means life is only take in count, 0 means level only take in count -// +// // - CourageModulator [-n +n]: // value used to make a bot courageous or feared, -n the bot is feared, +n its courageous -// +// // - GroupCohesionModulator [0 1]: // value used to make bots of a group aware of each other, 0 each bot is individual, 1 they fight in group /* NLMISC_COMMAND(setFightSheet,"change a value in the fight sheet"," (use name without 'modulator', ex: 'Dist')") -{ +{ if (args.size() !=3) { log.displayNL("three argument needed"); @@ -2602,9 +2603,9 @@ NLMISC_COMMAND(setFightSheet,"change a value in the fight sheet"," < log.displayNL("Failed to identify sheet: %s",args[0].c_str()); return false; } - + float value = float(atof(args[2].c_str())); - + if (NLMISC::nlstricmp(args[1].c_str(), "dist")==0) { if (value<0) @@ -2616,7 +2617,7 @@ NLMISC_COMMAND(setFightSheet,"change a value in the fight sheet"," < log.displayNL("Done, DistModulator=%f", value); return true; } - + if (NLMISC::nlstricmp(args[1].c_str(), "target")==0) { if (value<0) @@ -2671,7 +2672,7 @@ NLMISC_COMMAND(setFightSheet,"change a value in the fight sheet"," < log.displayNL("Done, CourageModulator=%f", value); return true; } - + if (NLMISC::nlstricmp(args[1].c_str(), "GroupCohesion")==0) { if (value<0 || value>1) @@ -2758,7 +2759,7 @@ NLMISC_COMMAND(botSetPosition,"set the position of one or several bots"," [ if (args.size()==4) NLMISC::fromString(args[3], z); } - + // For each bot FOREACH (itInstance, CCont, CAIS::instance().AIList()) { @@ -2806,7 +2807,7 @@ NLMISC_COMMAND(despawnEntity, "despawn an entity.","[entityId]") const TDataSetRow dataSetRow=TheDataset.getDataSetRow(entity); CAIEntityPhysical *const phys=CAIS::instance().getEntityPhysical(dataSetRow); - + if (!phys) { return true;} switch(phys->getRyzomType()) @@ -2943,7 +2944,7 @@ static void initBugSimulationTexts() bugSimulationTextInited = true; for (int i=0; i") { if (!args.empty()) return false; - const CRyzomTime &rt = CTimeInterface::getRyzomTime(); + const CRyzomTime &rt = CTimeInterface::getRyzomTime(); displayTime(rt, log); return true; } @@ -3079,7 +3080,7 @@ NLMISC_COMMAND(time, "Display current time.", "<>") NLMISC_COMMAND(localTime, "Display current local time (debug time).", "<>") { if (!args.empty()) return false; - const CRyzomTime &rt = CTimeInterface::getRyzomDebugTime(); + const CRyzomTime &rt = CTimeInterface::getRyzomDebugTime(); displayTime(rt, log); return true; } @@ -3087,8 +3088,8 @@ NLMISC_COMMAND(localTime, "Display current local time (debug time).", "<>") struct CRyzomDate { - float Time; - uint Day; + float Time; + uint Day; uint Year; }; @@ -3108,7 +3109,7 @@ static void setRyzomDebugDate(CRyzomDate &rd) NLMISC_COMMAND(setDebugHour, "set the current debug hour", "") { - if (args.size() != 1) return false; + if (args.size() != 1) return false; sint hour; if (!fromString(args[0], hour)) return false; CRyzomDate rd; @@ -3120,10 +3121,10 @@ NLMISC_COMMAND(setDebugHour, "set the current debug hour", "") NLMISC_COMMAND(setDebugDayOfYear, "set the current debug day of year (first day has index 1)", "") { - if (args.size() != 1) return false; + if (args.size() != 1) return false; sint day; if (!fromString(args[0], day)) return false; - CRyzomDate rd; + CRyzomDate rd; getRyzomDebugDate(rd); rd.Day = day - 1; // for the user, days start at '1' setRyzomDebugDate(rd); @@ -3134,7 +3135,7 @@ NLMISC_COMMAND(setDebugDayOfYear, "set the current debug day of year (first day // setPersistentVar setname:varName value // NLMISC_COMMAND(setPersistentVar, "sets an AI script persistent var", " []") -{ +{ if (args.size() == 2) { std::string varName = args[0].c_str(); @@ -3145,7 +3146,7 @@ NLMISC_COMMAND(setPersistentVar, "sets an AI script persistent var", " log.displayNL("Var '%s' set to '%s'", varName.c_str(), value.c_str()); return true; } - + return false; } @@ -3155,7 +3156,7 @@ NLMISC_COMMAND(setPersistentVar, "sets an AI script persistent var", " NLMISC_COMMAND(listPersistentVar, "display all persistent vars", "") { if (!args.empty()) return false; - + const CPersistentVariables &persistentVar = CAIScriptDataManager::getInstance()->getPersistentVariables(); const TVariableSets &variableSet = persistentVar.getVariableSet(); @@ -3186,7 +3187,7 @@ NLMISC_COMMAND(getPersistentVarAsString, "get a persistent ai var", "") log.displayNL("Variable '%s' has value '%s'", varName.c_str(), value.c_str() ); return true; } - + return false; } @@ -3203,12 +3204,12 @@ NLMISC_COMMAND(getPersistentVarAsFloat, "get a persistent ai var", "") nlinfo("Variable '%s' has value '%f'", varName.c_str(), value ); return true; } - + return false; } NLMISC_COMMAND(deletePersistentVar, "deletes an AI script persistent var", "") -{ +{ if (args.size() == 1) { std::string varName = args[0].c_str(); @@ -3218,7 +3219,7 @@ NLMISC_COMMAND(deletePersistentVar, "deletes an AI script persistent var", "") log.displayNL("Var '%s' deleted", varName.c_str()); return true; } - + return false; } diff --git a/ryzom/server/src/ai_service/commands.h b/ryzom/server/src/ai_service/commands.h index 196e7f3aa..728ccf8b5 100644 --- a/ryzom/server/src/ai_service/commands.h +++ b/ryzom/server/src/ai_service/commands.h @@ -32,10 +32,10 @@ public: { } virtual ~CStringFilter() { } - + bool operator !=(std::string const& other) const { return !operator ==(other); } bool operator ==(std::string const& other) const { return NLMISC::testWildCard(other, _Filter); } - + private: std::string _Filter; }; @@ -183,6 +183,25 @@ void buildOutpostList(TContainer& container) } } + +template +void buildNpcManagerList(TContainer& container) +{ + std::deque aiinstances; + buildInstanceList(aiinstances); + FOREACH(itAIInstance, std::deque, aiinstances) + { + CAIInstance* aiinstance = *itAIInstance; + if (aiinstance == NULL) + continue; + + CManager* ManagerPtr = CAIS::instance().tryToGetManager("i0:m1"); + if (ManagerPtr) + container.push_back(ManagerPtr); + } +} + + template void buildManagerList(TContainer& container) { @@ -329,9 +348,9 @@ void buildFaunaPlaceList(TContainer& container) { CGrpFauna *grpFauna = dynamic_cast(*itGroup); if (!grpFauna) - continue; + continue; FOREACH(itPlaces, CAliasCont, grpFauna->places()) - { + { container.push_back(*itPlaces); } } @@ -535,7 +554,7 @@ void despawn(CAIPlace &value) else { nlwarning("Places %s is not time driven, cannot deactivate it", value.getIndexString().c_str()); - } + } } } diff --git a/ryzom/server/src/ai_service/nf_grp.cpp b/ryzom/server/src/ai_service/nf_grp.cpp index 2e3197714..43d571157 100644 --- a/ryzom/server/src/ai_service/nf_grp.cpp +++ b/ryzom/server/src/ai_service/nf_grp.cpp @@ -107,6 +107,52 @@ void despawn_f_(CStateInstance* entity, CScriptStack& stack) grp->despawnBots(immediatly!=0); } +//---------------------------------------------------------------------------- +/** @page code + +@subsection spawnBot_fsssffff_ +Spawn new bots in the current group. + +Arguments: f(NbrBots), s(Sheet), s(Name), s(Look), f(x), f(y), f(orientation), f(dispersion) -> + +@code + +@endcode + +*/ +// CGroup +void spawnBot_fsssffff_(CStateInstance* entity, CScriptStack& stack) +{ + double dispersionRadius = (double)(float)stack.top(); + stack.pop(); + double orientation = (double)(float)stack.top(); + stack.pop(); + double y = (double)(float)stack.top(); + stack.pop(); + double x = (double)(float)stack.top(); + stack.pop(); + string look = (string)stack.top(); + stack.pop(); + string name = (string)stack.top(); + + stack.pop(); + CSheetId sheetId((string)stack.top()); + stack.pop(); + uint nbBots = (uint)(float)stack.top(); + stack.pop(); + + IManagerParent* const managerParent = entity->getGroup()->getOwner()->getOwner(); + CAIInstance* const aiInstance = dynamic_cast(managerParent); + if (!aiInstance) + return; + + CGroupNpc* grp = dynamic_cast(entity->getGroup()); + if (grp) + aiInstance->eventCreateNpcBot(grp, nbBots, true, sheetId, CAIVector(x, y), name, orientation, dispersionRadius, look); + return; +} + + //---------------------------------------------------------------------------- /** @page code @@ -2426,6 +2472,49 @@ void getPlayerStat_ss_f(CStateInstance* entity, CScriptStack& stack) } +//---------------------------------------------------------------------------- +/** @page code + +@subsection getPlayerPosition_ss_ff +Get player position (x or y). + +Arguments: s(playerEidAsString), s(statName) -> s(result) +@param[in] playerEidAsString is EntityId as string from the player we want infos +@param[in] axis ("X" or "Y") +@param[out] value is a the value of the parameter + +@code +($playerEid)getCurrentPlayerEid(); +(x, y)getPlayerPosition($playerEid); +@endcode +*/ +void getPlayerPosition_s_ff(CStateInstance* entity, CScriptStack& stack) +{ + std::string funName = "getPlayerPosition_s_ff"; + // reaed input + std::string statName = ((std::string)stack.top()); stack.pop(); + std::string playerEidStr = ((std::string)stack.top()); stack.pop(); + + + // get Dataset of the player to have access to mirror values + NLMISC::CEntityId playerEid; + playerEid.fromString(playerEidStr.c_str()); + TDataSetRow playerRow = TheDataset.getDataSetRow( playerEid ); + if (! TheDataset.isAccessible( playerRow ) ) + { + nlwarning("Try to call %s with on a player '%s' that is not accessible. The isPlayerAlived function must be called to be sure that the palyer is still alived.", funName.c_str(), playerEidStr.c_str() ); + stack.push((float)0); + return; + } + + CMirrorPropValue mirrorSymbol( TheDataset, playerRow, DSPropertyPOSY ); + stack.push((float)mirrorSymbol.getValue()); + CMirrorPropValue mirrorSymbol2( TheDataset, playerRow, DSPropertyPOSX ); + stack.push((float)mirrorSymbol2.getValue()); + return; + +} + /** @page code @subsection getPlayerDistance_fs_f @@ -4771,6 +4860,7 @@ std::map nfGetGroupNativeFunctions() REGISTER_NATIVE_FUNC(functions, spawn__); REGISTER_NATIVE_FUNC(functions, despawn_f_); REGISTER_NATIVE_FUNC(functions, isAlived__f); + REGISTER_NATIVE_FUNC(functions, spawnBot_fsssffff_); REGISTER_NATIVE_FUNC(functions, newNpcChildGroupPos_ssfff_c); REGISTER_NATIVE_FUNC(functions, newNpcChildGroupPos_ssfff_); REGISTER_NATIVE_FUNC(functions, newNpcChildGroupPos_ssff_c); @@ -4858,6 +4948,7 @@ std::map nfGetGroupNativeFunctions() // Boss functions (Player infos) REGISTER_NATIVE_FUNC(functions, isPlayerAlived_s_f); REGISTER_NATIVE_FUNC(functions, getPlayerStat_ss_f); + REGISTER_NATIVE_FUNC(functions, getPlayerPosition_s_ff); REGISTER_NATIVE_FUNC(functions, getPlayerDistance_fs_f); REGISTER_NATIVE_FUNC(functions, getCurrentPlayerEid__s); REGISTER_NATIVE_FUNC(functions, queryEgs_sscfs_); diff --git a/ryzom/server/src/ai_service/nf_grp_npc.cpp b/ryzom/server/src/ai_service/nf_grp_npc.cpp index da962df04..d12b8eade 100644 --- a/ryzom/server/src/ai_service/nf_grp_npc.cpp +++ b/ryzom/server/src/ai_service/nf_grp_npc.cpp @@ -2246,7 +2246,7 @@ Arguments: c(group1), s(botname1), c(group2), s(botname2), -> @code (@group1)group_name1.context(); -(@group1)group_name2.context(); +(@group2)group_name2.context(); ()facing(@group1, "bob", @group2, "bobette"); @endcode @@ -2642,7 +2642,8 @@ void rename_s_(CStateInstance* entity, CScriptStack& stack) { string newName = (string)stack.top(); stack.pop(); ucstring name; - name.fromUtf8(newName); CGroup* group = entity->getGroup(); + name.fromUtf8(newName); + CGroup* group = entity->getGroup(); if (group->isSpawned()) { diff --git a/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp b/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp index 932b55f92..78e361739 100644 --- a/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp +++ b/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp @@ -1047,6 +1047,74 @@ string getJewelEnchantAttr(CSheetId sbrick) //enchantEquipedItem 530162 WristR jmod_focus_tryker_1.sbrick //enchantEquipedItem 530162 Neck tag_fyros_3.sbrick //enchantEquipedItem 530162 Neck jrez_fulllife_tryker.sbrick,jboost2.sbrick +//---------------------------------------------------------------------------- +NLMISC_COMMAND(checkInventoryItems, "Check items from a characters inventory", " ") +{ + if (args.size () < 5) + { + log.displayNL("ERR: Invalid number of parameters. Parameters: "); + return false; + } + + GET_ACTIVE_CHARACTER + + std::map need_items; + + string selected_inv = args[1]; + + std::vector sheet_names; + NLMISC::splitString(args[2], ",", sheet_names); + std::vector qualities; + NLMISC::splitString(args[3], ",", qualities); + std::vector quantities; + NLMISC::splitString(args[4], ",", quantities); + + for (uint32 i=0; i < std::min(quantities.size(), std::min(qualities.size(), sheet_names.size())); i++) + { + uint32 quantity = 0; + fromString(quantities[i], quantity); + need_items.insert(make_pair(sheet_names[i]+":"+qualities[i], quantity)); + } + + std::map slots; + std::map::iterator itNeedItems; + + // Save list of slots and quantities to delete + CInventoryPtr inventory = getInventory(c, selected_inv); + if (inventory != NULL) + { + for (uint32 j = 0; j < inventory->getSlotCount(); j++) + { + CGameItemPtr itemPtr = inventory->getItem(j); + if (itemPtr != NULL) + { + string sheet = itemPtr->getSheetId().toString(); + uint32 item_quality = itemPtr->quality(); + itNeedItems = need_items.find(sheet+":"+NLMISC::toString("%d", item_quality)); + if (itNeedItems != need_items.end() && (*itNeedItems).second > 0) + { + uint32 quantity = std::min((*itNeedItems).second, itemPtr->getStackSize()); + slots.insert(make_pair(j, quantity)); + (*itNeedItems).second -= quantity; + } + } + } + + // Check if all items has been found + for (itNeedItems = need_items.begin(); itNeedItems != need_items.end(); ++itNeedItems) + { + if ((*itNeedItems).second != 0) { + log.displayNL("ERR: Not enough items."); + return false; + } + } + } + + log.displayNL("OK"); + return true; +} + + //---------------------------------------------------------------------------- NLMISC_COMMAND(enchantEquipedItem, "enchantEquipedItem", " ,[ ...] []") {