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 spawnBots(const std::string
&name
, const std::string
&vpx
);
50 virtual void despawnBots(bool immediately
);
54 void sendInfoToEGS() const;
56 std::string
buildDebugString(uint idx
) const;
58 void stateChange(CAIState
const* oldState
, CAIState
const* newState
);
60 void botHaveDied(CBotNpc
* bot
);
61 void botHaveDespawn(CBotNpc
* bot
);
62 void botHaveSpawn(CBotNpc
* bot
);
65 void resetSlowUpdateCycle();
66 static void setSlowUpdatePeriod(uint32 ticks
);
67 static uint32
getSlowUpdatePeriod();
68 static void displaySlowUpdateBuckets();
70 void noMoreHandle(uint32 nNbTickBeforeDespawn
);
74 void setCell(sint32 cell
) { _Cell
= cell
; }
75 sint32
getCell() { return _Cell
; }
79 CAITimer _BotUpdateTimer
;
80 uint32 _LastUpdate
; // gamecycle at which update() last called
81 uint32 _LastBotUpdate
;
82 uint32 _SlowUpdateCycle
;
84 static uint32 _SlowUpdatePeriod
;
85 static std::vector
<uint32
> _SlowUpdateBuckets
;
87 bool _DespawnBotsWhenNoMoreHandleTimerActive
;
88 CAITimer _DespawnBotsWhenNoMoreHandleTimer
;
91 //////////////////////////////////////////////////////////////////////////////
93 //////////////////////////////////////////////////////////////////////////////
96 : public NLMISC::CDbgRefCount
<class CGroupNpc
>
99 , public CPersistentStateInstance
102 typedef std::set
<std::pair
<std::string
, sint32
> > TFactionAttackableSet
;
105 CGroupNpc(CMgrNpc
* mgr
, CAIAliasDescriptionNode
* aliasTree
, RYAI_MAP_CRUNCH::TAStarFlag denyFlags
);
106 CGroupNpc(CMgrNpc
* mgr
, uint32 alias
, std::string
const& name
, RYAI_MAP_CRUNCH::TAStarFlag denyFlags
);
108 virtual ~CGroupNpc();
110 /// @name CChild implementation
112 // virtual std::string getIndexString() const;
113 virtual std::string
getOneLineInfoString() const;
114 virtual std::vector
<std::string
> getMultiLineInfoString() const;
115 // virtual std::string getFullName() const;
118 CDynGrpBase
* getGrpDynBase() { return this; }
120 //////////////////////////////////////////////////////////////////////////
121 // PersistentStateInstance
123 CAliasTreeOwner
* aliasTreeOwner() { return this; }
125 void stateChange(CAIState
const* oldState
, CAIState
const* newState
);
127 CGroup
* getGroup() { return this; }
129 //////////////////////////////////////////////////////////////////////////
131 virtual void lastBotDespawned();
132 virtual void firstBotSpawned();
135 CDebugHistory
* getDebugHistory() { return this; }
137 CAIS::CCounter
& getSpawnCounter();
139 RYZOMID::TTypeId
getRyzomType() { return RYZOMID::npc
; }
141 NLMISC::CSmartPtr
<CSpawnGroup
> createSpawnGroup();
143 CSpawnGroupNpc
* getSpawnObj() const { return NLMISC::type_cast
<CSpawnGroupNpc
*>(CGroup::getSpawnObj()); }
145 CPersistentStateInstance
* getPersistentStateInstance() { return this; }
147 void setEvent(uint eventId
);
149 virtual void serviceEvent (const CServiceEvent
&info
);
156 // inheritted virtual interface ------------------------------------
157 virtual bool spawn();
158 virtual void despawnGrp();
160 virtual std::string
buildDebugString(uint idx
) const;
161 virtual void display(CStringWriter
& stringWriter
) const;
163 void updateDependencies(CAIAliasDescriptionNode
const& aliasTree
, CAliasTreeOwner
* aliasTreeOwner
);
164 IAliasCont
* getAliasCont(AITYPES::TAIType type
);
165 CAliasTreeOwner
* createChild(IAliasCont
* cont
, CAIAliasDescriptionNode
* aliasTree
);
167 // basic utilities -------------------------------------------------
168 CMgrNpc
& mgr() const;
170 // management of the bot population --------------------------------
171 // allocator for allocating new bot objects
174 bool botsAreNamed() { return _BotsAreNamed
; }
175 void setBotsAreNamedFlag() { _BotsAreNamed
= true; }
176 void clrBotsAreNamedFlag() { _BotsAreNamed
= false; }
179 void setStateAlias(const std::string
&state
, uint32 alias
);
180 uint32
getStateAlias(const std::string
&state
);
182 // States Events to Alias
183 void setStateEventAlias(const std::string
&stateEvent
, uint32 alias
);
184 uint32
getStateEventAlias(const std::string
&stateEvent
);
187 // Parameter management -------------------------------------
188 void clearParameters();
189 // Parse a paremeter for this group.
190 void addParameter(const std::string
¶meter
);
192 // set if the bots of the group are attackable by players
193 void setPlayerAttackable(bool playerAttackable
) { _PlayerAttackable
= playerAttackable
; }
194 bool getPlayerAttackable() { return _PlayerAttackable
; }
196 // set if the bots of the group are attackable by other bots
197 void setBotAttackable(bool botAttackable
) { _BotAttackable
= botAttackable
; }
198 bool getBotAttackable() { return _BotAttackable
; }
200 void setFactionAttackableAbove(std::string faction
, sint32 threshold
, bool botAttackable
);
201 TFactionAttackableSet
const& getFactionAttackableAbove() const { return _FactionAttackableAbove
; }
202 void setFactionAttackableBelow(std::string faction
, sint32 threshold
, bool botAttackable
);
203 TFactionAttackableSet
const& getFactionAttackableBelow() const { return _FactionAttackableBelow
; }
204 bool isFactionAttackable(std::string faction
, sint32 fame
);
206 uint32
getAggroDist() { return _AggroDist
; }
208 uint32
& despawnTime() { return _DespawnTime
; }
209 uint32
& respawnTime() { return _RespawnTime
; }
211 AITYPES::CPropertySetWithExtraList
<TAllianceId
>& faction() { return _faction
; }
212 AITYPES::CPropertySetWithExtraList
<TAllianceId
>& ennemyFaction() { return _ennemyFaction
; }
213 AITYPES::CPropertySetWithExtraList
<TAllianceId
>& friendFaction() { return _friendFaction
; }
215 AITYPES::CPropertySetWithExtraList
<TAllianceId
> const& faction() const { return _faction
; }
216 AITYPES::CPropertySetWithExtraList
<TAllianceId
> const& ennemyFaction() const { return _ennemyFaction
; }
217 AITYPES::CPropertySetWithExtraList
<TAllianceId
> const& friendFaction() const { return _friendFaction
; }
220 void addHpUpTrigger(float threshold
, int eventId
);
221 void delHpUpTrigger(float threshold
, int eventId
);
222 void addHpUpTrigger(float threshold
, std::string cbFunc
);
223 void delHpUpTrigger(float threshold
, std::string cbFunc
);
225 void addHpDownTrigger(float threshold
, int eventId
);
226 void delHpDownTrigger(float threshold
, int eventId
);
227 void addHpDownTrigger(float threshold
, std::string cbFunc
);
228 void delHpDownTrigger(float threshold
, std::string cbFunc
);
230 bool haveHpTriggers();
231 void hpTriggerCb(float oldVal
, float newVal
);
233 void addNamedEntityListener(std::string
const& name
, std::string
const& prop
, int event
);
234 void delNamedEntityListener(std::string
const& name
, std::string
const& prop
, int event
);
235 void addNamedEntityListener(std::string
const& name
, std::string
const& prop
, std::string functionName
);
236 void delNamedEntityListener(std::string
const& name
, std::string
const& prop
, std::string functionName
);
237 void namedEntityListenerCb(std::string
const& name
, std::string
const& prop
);
239 void addHandle(TDataSetRow playerRowId
, uint32 missionAlias
, uint32 DespawnTimeInTick
);
240 void delHandle(TDataSetRow playerRowId
, uint32 missionAlias
);
242 void addHealGroup(CGroupNpc
*healGroups
) { _HealGroups
.push_back(healGroups
); }
243 std::vector
<CGroupNpc
*> getHealGroups() { return _HealGroups
; }
244 void resetHealGroups() { _HealGroups
.clear(); }
246 uint32
getTimerWhenNoMoreHandle();
248 void setSpawnZone(const CNpcZone
*zone
) { _SpawnZone
= zone
; }
249 const CNpcZone
*getSpawnZone() const { return _SpawnZone
; }
252 void setColour(uint8 colour
);
254 void setOutpostSide(OUTPOSTENUMS::TPVPSide side
);
255 void setOutpostFactions(std::string
const& alias
, OUTPOSTENUMS::TPVPSide side
);
256 bool isRingGrp() const { return _RingGrp
;}
260 bool _BotsAreNamed
; // true if the bots in the group are explicitly placed in level editor tool - false otherwise
261 /// NPCs are attackable by player ?
262 bool _PlayerAttackable
;
263 /// NPCs are attackable by npcs
265 /// NPCs are attackable by players with fame for faction (string) above threshold (float)
266 TFactionAttackableSet _FactionAttackableAbove
;
267 /// NPCs are attackable by players with fame for faction (string) below threshold (float)
268 TFactionAttackableSet _FactionAttackableBelow
;
269 /// Aggro distance : any player passing at less this distance will be attacked
271 /// Respawn time in ticks
273 /// Despawn time in ticks
278 AITYPES::CPropertySetWithExtraList
<TAllianceId
> _faction
;
279 AITYPES::CPropertySetWithExtraList
<TAllianceId
> _ennemyFaction
;
280 AITYPES::CPropertySetWithExtraList
<TAllianceId
> _friendFaction
;
282 typedef std::multimap
<float, int> THpTriggerList
;
283 typedef std::multimap
<float, std::string
> THpTriggerList2
;
284 THpTriggerList _hpUpTriggers
;
285 THpTriggerList _hpDownTriggers
;
286 THpTriggerList2 _hpUpTriggers2
;
287 THpTriggerList2 _hpDownTriggers2
;
289 typedef std::multimap
<std::pair
<std::string
, std::string
>, int> TNamedEntityListenerList
;
290 TNamedEntityListenerList _namedEntityListeners
;
291 typedef std::multimap
<std::pair
<std::string
, std::string
>, std::string
> TNamedEntityListenerList2
;
292 TNamedEntityListenerList2 _namedEntityListeners2
;
293 typedef std::map
<std::string
, uint32
> TStatesToAlias
;
294 TStatesToAlias _StatesToAlias
;
295 TStatesToAlias _StateEventToAlias
;
299 TDataSetRow PlayerRowId
;
302 bool operator < (const SHandle
&h
) const
304 if (PlayerRowId
< h
.PlayerRowId
) return true;
306 if (PlayerRowId
== h
.PlayerRowId
)
307 if (MissionAlias
< h
.MissionAlias
)
314 std::set
<SHandle
> _Handles
;
315 uint32 _DespawnTimeWhenNoMoreHandle
;
316 bool _AutoSpawnWhenNoMoreHandle
;
317 NLMISC::CVirtualRefPtr
<const CNpcZone
> _SpawnZone
;
318 bool _RingGrp
;//Ring rulez: like a override bandit profile
319 std::vector
<CGroupNpc
*> _HealGroups
;