1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
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"
32 //////////////////////////////////////////////////////////////////////////////
34 //////////////////////////////////////////////////////////////////////////////
37 : public NLMISC::CDbgRefCount
<CSpawnGroupNpc
>
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
);
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
);
64 void resetSlowUpdateCycle();
65 static void setSlowUpdatePeriod(uint32 ticks
);
66 static uint32
getSlowUpdatePeriod();
67 static void displaySlowUpdateBuckets();
69 void noMoreHandle(uint32 nNbTickBeforeDespawn
);
73 void setCell(sint32 cell
) { _Cell
= cell
; }
74 sint32
getCell() { return _Cell
; }
78 CAITimer _BotUpdateTimer
;
79 uint32 _LastUpdate
; // gamecycle at which update() last called
80 uint32 _LastBotUpdate
;
81 uint32 _SlowUpdateCycle
;
83 static uint32 _SlowUpdatePeriod
;
84 static std::vector
<uint32
> _SlowUpdateBuckets
;
86 bool _DespawnBotsWhenNoMoreHandleTimerActive
;
87 CAITimer _DespawnBotsWhenNoMoreHandleTimer
;
90 //////////////////////////////////////////////////////////////////////////////
92 //////////////////////////////////////////////////////////////////////////////
95 : public NLMISC::CDbgRefCount
<class CGroupNpc
>
98 , public CPersistentStateInstance
101 typedef std::set
<std::pair
<std::string
, sint32
> > TFactionAttackableSet
;
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
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;
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();
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
);
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
173 bool botsAreNamed() { return _BotsAreNamed
; }
174 void setBotsAreNamedFlag() { _BotsAreNamed
= true; }
175 void clrBotsAreNamedFlag() { _BotsAreNamed
= false; }
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
¶meter
);
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
; }
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
;}
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
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
270 /// Respawn time in ticks
272 /// Despawn time in ticks
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
;
298 TDataSetRow PlayerRowId
;
301 bool operator < (const SHandle
&h
) const
303 if (PlayerRowId
< h
.PlayerRowId
) return true;
305 if (PlayerRowId
== h
.PlayerRowId
)
306 if (MissionAlias
< h
.MissionAlias
)
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
;