Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_grp_npc.h
blob382c6840ed969ed805cc6f23f81ce7ab878ad4e4
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RYAI_GRP_NPC_H
18 #define RYAI_GRP_NPC_H
20 #include "ai_grp.h"
21 #include "timer.h"
22 #include "ai_vision.h"
23 #include "ai_keywords.h"
24 #include "state_instance.h"
25 #include "named_entity_manager.h"
26 #include "nel/misc/string_mapper.h"
28 class CMgrNpc;
29 class CBotNpc;
30 class CSpawnBotNpc;
32 //////////////////////////////////////////////////////////////////////////////
33 // CSpawnGroupNpc //
34 //////////////////////////////////////////////////////////////////////////////
36 class CSpawnGroupNpc
37 : public NLMISC::CDbgRefCount<CSpawnGroupNpc>
38 , public CSpawnGroup
40 public:
41 CSpawnGroupNpc(CPersistent<CSpawnGroup>& owner);
43 virtual ~CSpawnGroupNpc() { }
45 CGroupNpc& getPersistent() const;
47 virtual void spawnBots();
48 virtual void spawnBots(const std::string &name);
49 virtual void despawnBots(bool immediately);
51 void update();
53 void sendInfoToEGS() const;
55 std::string buildDebugString(uint idx) const;
57 void stateChange(CAIState const* oldState, CAIState const* newState);
59 void botHaveDied(CBotNpc* bot);
60 void botHaveDespawn(CBotNpc* bot);
61 void botHaveSpawn(CBotNpc* bot);
63 public:
64 void resetSlowUpdateCycle();
65 static void setSlowUpdatePeriod(uint32 ticks);
66 static uint32 getSlowUpdatePeriod();
67 static void displaySlowUpdateBuckets();
69 void noMoreHandle(uint32 nNbTickBeforeDespawn);
70 void handlePresent();
72 // set the cell
73 void setCell(sint32 cell) { _Cell = cell; }
74 sint32 getCell() { return _Cell; }
76 private:
77 bool _GroupInVision;
78 CAITimer _BotUpdateTimer;
79 uint32 _LastUpdate; // gamecycle at which update() last called
80 uint32 _LastBotUpdate;
81 uint32 _SlowUpdateCycle;
82 sint32 _Cell;
83 static uint32 _SlowUpdatePeriod;
84 static std::vector<uint32> _SlowUpdateBuckets;
86 bool _DespawnBotsWhenNoMoreHandleTimerActive;
87 CAITimer _DespawnBotsWhenNoMoreHandleTimer;
90 //////////////////////////////////////////////////////////////////////////////
91 // CGroupNpc //
92 //////////////////////////////////////////////////////////////////////////////
94 class CGroupNpc
95 : public NLMISC::CDbgRefCount<class CGroupNpc>
96 , public CGroup
97 , public CDynGrpBase
98 , public CPersistentStateInstance
100 public:
101 typedef std::set<std::pair<std::string, sint32> > TFactionAttackableSet;
103 public:
104 CGroupNpc(CMgrNpc* mgr, CAIAliasDescriptionNode* aliasTree, RYAI_MAP_CRUNCH::TAStarFlag denyFlags);
105 CGroupNpc(CMgrNpc* mgr, uint32 alias, std::string const& name, RYAI_MAP_CRUNCH::TAStarFlag denyFlags);
107 virtual ~CGroupNpc();
109 /// @name CChild implementation
110 //@{
111 // virtual std::string getIndexString() const;
112 virtual std::string getOneLineInfoString() const;
113 virtual std::vector<std::string> getMultiLineInfoString() const;
114 // virtual std::string getFullName() const;
115 //@}
117 CDynGrpBase* getGrpDynBase() { return this; }
119 //////////////////////////////////////////////////////////////////////////
120 // PersistentStateInstance
122 CAliasTreeOwner* aliasTreeOwner() { return this; }
124 void stateChange(CAIState const* oldState, CAIState const* newState);
126 CGroup* getGroup() { return this; }
128 //////////////////////////////////////////////////////////////////////////
130 virtual void lastBotDespawned();
131 virtual void firstBotSpawned();
133 // debugging stuff
134 CDebugHistory* getDebugHistory() { return this; }
136 CAIS::CCounter& getSpawnCounter();
138 RYZOMID::TTypeId getRyzomType() { return RYZOMID::npc; }
140 NLMISC::CSmartPtr<CSpawnGroup> createSpawnGroup();
142 CSpawnGroupNpc* getSpawnObj() const { return NLMISC::type_cast<CSpawnGroupNpc*>(CGroup::getSpawnObj()); }
144 CPersistentStateInstance* getPersistentStateInstance() { return this; }
146 void setEvent(uint eventId);
148 virtual void serviceEvent (const CServiceEvent &info);
150 void init() { }
152 void release() { }
155 // inheritted virtual interface ------------------------------------
156 virtual bool spawn();
157 virtual void despawnGrp();
159 virtual std::string buildDebugString(uint idx) const;
160 virtual void display(CStringWriter& stringWriter) const;
162 void updateDependencies(CAIAliasDescriptionNode const& aliasTree, CAliasTreeOwner* aliasTreeOwner);
163 IAliasCont* getAliasCont(AITYPES::TAIType type);
164 CAliasTreeOwner* createChild(IAliasCont* cont, CAIAliasDescriptionNode* aliasTree);
166 // basic utilities -------------------------------------------------
167 CMgrNpc& mgr() const;
169 // management of the bot population --------------------------------
170 // allocator for allocating new bot objects
171 CGroupNpc* newBot();
173 bool botsAreNamed() { return _BotsAreNamed; }
174 void setBotsAreNamedFlag() { _BotsAreNamed = true; }
175 void clrBotsAreNamedFlag() { _BotsAreNamed = false; }
177 // States to Alias
178 void setStateAlias(const std::string &state, uint32 alias);
179 uint32 getStateAlias(const std::string &state);
181 // States Events to Alias
182 void setStateEventAlias(const std::string &stateEvent, uint32 alias);
183 uint32 getStateEventAlias(const std::string &stateEvent);
186 // Parameter management -------------------------------------
187 void clearParameters();
188 // Parse a paremeter for this group.
189 void addParameter(const std::string &parameter);
191 // set if the bots of the group are attackable by players
192 void setPlayerAttackable(bool playerAttackable) { _PlayerAttackable = playerAttackable; }
193 bool getPlayerAttackable() { return _PlayerAttackable; }
195 // set if the bots of the group are attackable by other bots
196 void setBotAttackable(bool botAttackable) { _BotAttackable = botAttackable; }
197 bool getBotAttackable() { return _BotAttackable; }
199 void setFactionAttackableAbove(std::string faction, sint32 threshold, bool botAttackable);
200 TFactionAttackableSet const& getFactionAttackableAbove() const { return _FactionAttackableAbove; }
201 void setFactionAttackableBelow(std::string faction, sint32 threshold, bool botAttackable);
202 TFactionAttackableSet const& getFactionAttackableBelow() const { return _FactionAttackableBelow; }
203 bool isFactionAttackable(std::string faction, sint32 fame);
205 uint32 getAggroDist() { return _AggroDist; }
207 uint32& despawnTime() { return _DespawnTime; }
208 uint32& respawnTime() { return _RespawnTime; }
210 AITYPES::CPropertySetWithExtraList<TAllianceId>& faction() { return _faction; }
211 AITYPES::CPropertySetWithExtraList<TAllianceId>& ennemyFaction() { return _ennemyFaction; }
212 AITYPES::CPropertySetWithExtraList<TAllianceId>& friendFaction() { return _friendFaction; }
214 AITYPES::CPropertySetWithExtraList<TAllianceId> const& faction() const { return _faction; }
215 AITYPES::CPropertySetWithExtraList<TAllianceId> const& ennemyFaction() const { return _ennemyFaction; }
216 AITYPES::CPropertySetWithExtraList<TAllianceId> const& friendFaction() const { return _friendFaction; }
218 public:
219 void addHpUpTrigger(float threshold, int eventId);
220 void delHpUpTrigger(float threshold, int eventId);
221 void addHpUpTrigger(float threshold, std::string cbFunc);
222 void delHpUpTrigger(float threshold, std::string cbFunc);
224 void addHpDownTrigger(float threshold, int eventId);
225 void delHpDownTrigger(float threshold, int eventId);
226 void addHpDownTrigger(float threshold, std::string cbFunc);
227 void delHpDownTrigger(float threshold, std::string cbFunc);
229 bool haveHpTriggers();
230 void hpTriggerCb(float oldVal, float newVal);
232 void addNamedEntityListener(std::string const& name, std::string const& prop, int event);
233 void delNamedEntityListener(std::string const& name, std::string const& prop, int event);
234 void addNamedEntityListener(std::string const& name, std::string const& prop, std::string functionName);
235 void delNamedEntityListener(std::string const& name, std::string const& prop, std::string functionName);
236 void namedEntityListenerCb(std::string const& name, std::string const& prop);
238 void addHandle(TDataSetRow playerRowId, uint32 missionAlias, uint32 DespawnTimeInTick);
239 void delHandle(TDataSetRow playerRowId, uint32 missionAlias);
241 void addHealGroup(CGroupNpc *healGroups) { _HealGroups.push_back(healGroups); }
242 std::vector<CGroupNpc*> getHealGroups() { return _HealGroups; }
243 void resetHealGroups() { _HealGroups.clear(); }
245 uint32 getTimerWhenNoMoreHandle();
247 void setSpawnZone(const CNpcZone *zone) { _SpawnZone = zone; }
248 const CNpcZone *getSpawnZone() const { return _SpawnZone; }
251 void setColour(uint8 colour);
253 void setOutpostSide(OUTPOSTENUMS::TPVPSide side);
254 void setOutpostFactions(std::string const& alias, OUTPOSTENUMS::TPVPSide side);
255 bool isRingGrp() const { return _RingGrp;}
257 private:
258 /// group basics
259 bool _BotsAreNamed; // true if the bots in the group are explicitly placed in level editor tool - false otherwise
260 /// NPCs are attackable by player ?
261 bool _PlayerAttackable;
262 /// NPCs are attackable by npcs
263 bool _BotAttackable;
264 /// NPCs are attackable by players with fame for faction (string) above threshold (float)
265 TFactionAttackableSet _FactionAttackableAbove;
266 /// NPCs are attackable by players with fame for faction (string) below threshold (float)
267 TFactionAttackableSet _FactionAttackableBelow;
268 /// Aggro distance : any player passing at less this distance will be attacked
269 uint32 _AggroDist;
270 /// Respawn time in ticks
271 uint32 _RespawnTime;
272 /// Despawn time in ticks
273 uint32 _DespawnTime;
277 AITYPES::CPropertySetWithExtraList<TAllianceId> _faction;
278 AITYPES::CPropertySetWithExtraList<TAllianceId> _ennemyFaction;
279 AITYPES::CPropertySetWithExtraList<TAllianceId> _friendFaction;
281 typedef std::multimap<float, int> THpTriggerList;
282 typedef std::multimap<float, std::string> THpTriggerList2;
283 THpTriggerList _hpUpTriggers;
284 THpTriggerList _hpDownTriggers;
285 THpTriggerList2 _hpUpTriggers2;
286 THpTriggerList2 _hpDownTriggers2;
288 typedef std::multimap<std::pair<std::string, std::string>, int> TNamedEntityListenerList;
289 TNamedEntityListenerList _namedEntityListeners;
290 typedef std::multimap<std::pair<std::string, std::string>, std::string> TNamedEntityListenerList2;
291 TNamedEntityListenerList2 _namedEntityListeners2;
292 typedef std::map <std::string, uint32> TStatesToAlias;
293 TStatesToAlias _StatesToAlias;
294 TStatesToAlias _StateEventToAlias;
296 struct SHandle
298 TDataSetRow PlayerRowId;
299 uint32 MissionAlias;
301 bool operator < (const SHandle &h) const
303 if (PlayerRowId < h.PlayerRowId) return true;
305 if (PlayerRowId == h.PlayerRowId)
306 if (MissionAlias < h.MissionAlias)
307 return true;
309 return false;
313 std::set<SHandle> _Handles;
314 uint32 _DespawnTimeWhenNoMoreHandle;
315 bool _AutoSpawnWhenNoMoreHandle;
316 NLMISC::CVirtualRefPtr<const CNpcZone> _SpawnZone;
317 bool _RingGrp;//Ring rulez: like a override bandit profile
318 std::vector<CGroupNpc*> _HealGroups;
322 #endif