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_BOT_NPC_H
18 #define RYAI_BOT_NPC_H
20 #include "game_share/msg_ais_egs_gen.h"
23 #include "npc_description_msg.h"
25 #include "ai_player.h"
31 class CPlayerControlNpc
;
33 //////////////////////////////////////////////////////////////////////////////
35 //////////////////////////////////////////////////////////////////////////////
38 : public NLMISC::CDbgRefCount
<CSpawnBotNpc
>
43 CSpawnBotNpc(TDataSetRow
const& row
, CBot
& owner
, NLMISC::CEntityId
const& id
, float radius
, uint32 level
, RYAI_MAP_CRUNCH::TAStarFlag denyFlags
);
45 void update(uint32 ticks
);
47 CSpawnGroupNpc
& spawnGrp() const;
49 // Accessors for NPC dynamic parameters -----------------------------
50 void setCurrentChatProfile(CNpcChatProfileImp
* chatProfile
);
52 void updateChat(CAIState
const* state
);
54 virtual void processEvent(CCombatInterface::CEvent
const& event
);
56 CAIEntityPhysical
& getPhysical() { return *this; }
58 /// @name Chat parameter management
60 void beginBotChat(CBotPlayer
* plr
);
61 void endBotChat(CBotPlayer
* plr
);
62 void beginDynChat() { ++_NbCurrentDynChats
; }
63 void endDynChat() { --_NbCurrentDynChats
; }
66 // Return the active bot chats
67 std::vector
<CBotPlayer
*>& getActiveChats() { return _ActiveChats
; }
69 // Return the number of dyn chats (these chats are not managed by the AIS)
70 uint
getNbActiveDynChats() { return _NbCurrentDynChats
; }
72 /// Dispatching message to EGS to describe chat possibilities
73 void sendInfoToEGS() const;
75 virtual std::vector
<std::string
> getMultiLineInfoString() const;
77 CBotNpc
& getPersistent() const;
79 virtual RYZOMID::TTypeId
getRyzomType() const { return RYZOMID::npc
; }
81 virtual bool isBotAttackable() const;
83 virtual void propagateAggro() const;
85 float getReturnDistCheck() const;
87 void setPlayerController(CBotPlayer
* player
);
89 void setFacing(CAngle theta
);
91 void setUserModelId(const std::string
&id
);
93 std::string
getUserModelId();
95 void setCustomLootTableId(const std::string
&id
);
97 std::string
getCustomLootTableId();
99 void setPrimAlias(uint32 alias
);
100 uint32
getPrimAlias() const;
103 std::vector
<CBotPlayer
*> _ActiveChats
; // vector of ptrs to players currently chatting with bot
104 float _OldHpPercentage
; // Fix for HP triggers
106 CNpcChatProfileImp _CurrentChatProfile
;
107 sint32 _NbCurrentDynChats
;
108 NLMISC::CSmartPtr
<CPlayerControlNpc
> _PlayerController
;
112 std::string _UserModelId
;
113 std::string _CustomLootTableId
;
117 //////////////////////////////////////////////////////////////////////////////
119 //////////////////////////////////////////////////////////////////////////////
122 : public AISHEETS::CCreatureProxy
125 CBotNpcSheet(AISHEETS::ICreatureCPtr
const& sheet
)
126 : AISHEETS::CCreatureProxy(sheet
)
127 , _LeftItem(NLMISC::CSheetId::Unknown
)
128 , _RightItem(NLMISC::CSheetId::Unknown
)
139 ///@name ICreature overloads
141 virtual uint8
ColorHead() const { return _ColorHead
; }
142 virtual uint8
ColorArms() const { return _ColorArms
; }
143 virtual uint8
ColorHands() const { return _ColorHands
; }
144 virtual uint8
ColorBody() const { return _ColorBody
; }
145 virtual uint8
ColorLegs() const { return _ColorLegs
; }
146 virtual uint8
ColorFeets() const { return _ColorFeets
; }
148 virtual NLMISC::CSheetId
const& LeftItem() const
150 if (_LeftItem
!=NLMISC::CSheetId::Unknown
)
153 return this->CCreatureProxy::LeftItem();
155 virtual NLMISC::CSheetId
const& RightItem() const
157 if (_RightItem
!=NLMISC::CSheetId::Unknown
)
160 return this->CCreatureProxy::RightItem();
166 void setColorHead(uint8 val
) { _ColorHead
= val
; }
167 void setColorArms(uint8 val
) { _ColorArms
= val
; }
168 void setColorHands(uint8 val
) { _ColorHands
= val
; }
169 void setColorBody(uint8 val
) { _ColorBody
= val
; }
170 void setColorLegs(uint8 val
) { _ColorLegs
= val
; }
171 void setColorFeets(uint8 val
) { _ColorFeets
= val
; }
173 void setLeftItem(NLMISC::CSheetId
const& val
) { _LeftItem
= val
; }
174 void setRightItem(NLMISC::CSheetId
const& val
) { _RightItem
= val
; }
181 _LeftItem
= _Sheet
->LeftItem();
182 _RightItem
= _Sheet
->RightItem();
183 _ColorHead
= _Sheet
->ColorHead();
184 _ColorArms
= _Sheet
->ColorArms();
185 _ColorHands
= _Sheet
->ColorHands();
186 _ColorBody
= _Sheet
->ColorBody();
187 _ColorLegs
= _Sheet
->ColorLegs();
188 _ColorFeets
= _Sheet
->ColorFeets();
193 NLMISC::CSheetId _LeftItem
;
194 NLMISC::CSheetId _RightItem
;
202 typedef NLMISC::CSmartPtr
<CBotNpcSheet
> CBotNpcSheetPtr
;
203 typedef NLMISC::CSmartPtr
<CBotNpcSheet
const> CBotNpcSheetCPtr
;
205 //////////////////////////////////////////////////////////////////////////////
207 //////////////////////////////////////////////////////////////////////////////
211 , public CKeyWordOwner
214 friend class CSpawnBotNpc
; // allows CSpawnBotNpc to acceed his definition.
217 CBotNpc(CGroup
* owner
, CAIAliasDescriptionNode
* alias
= NULL
);
218 CBotNpc(CGroup
* owner
, uint32 alias
, std::string
const& name
);
223 RYZOMID::TTypeId
getRyzomType() const { return RYZOMID::npc
; }
225 CSpawnBotNpc
* getSpawn();
226 CSpawnBotNpc
const* getSpawn() const;
228 CAIS::CCounter
& getSpawnCounter();
230 void calcSpawnPos(RYAI_MAP_CRUNCH::CWorldMap
const& worldMap
);
232 void getSpawnPos(CAIVector
& triedPos
, RYAI_MAP_CRUNCH::CWorldPosition
& pos
, RYAI_MAP_CRUNCH::CWorldMap
const& worldMap
, CAngle
& spawnTheta
);
234 CSpawnBot
* getSpawnBot(TDataSetRow
const& row
, NLMISC::CEntityId
const& id
, float radius
);
236 // spawn & despawn --------------------------------------------------
237 virtual bool spawn();
238 virtual void despawnBot();
240 bool reSpawn(bool sendMessage
= true);
242 //------------------------------------------------------------
243 // accessing the parent mgr, group, etc
244 CGroupNpc
& grp() const;
246 // Carried equipment management -------------------------------------
247 void equipmentInit();
248 void equipmentAdd(std::string
const& kit
);
250 // Write accessors for NPC base parameters --------------------------
251 void setStartPos(double x
, double y
, float theta
, AITYPES::TVerticalPos verticalPos
);
253 void setColour(uint8 colour
);
254 void setColours(std::string colours
);
256 void setVisualProperties(std::string input
);
258 inline void saveFirstPosition(CAIVector pos
, uint8 value
) { _FirstPosition
= pos
, _DispersionRadius
= value
; }
260 inline void setMaxHitRangeForPlayer(float maxHitRange
) { _MaxHitRangeForPC
= maxHitRange
; }
261 // void setMissionStepIconHidden(bool hide) { _MissionIconFlags.IsMissionStepIconDisplayable = !hide; }
262 // void setMissionGiverIconHidden(bool hide) { _MissionIconFlags.IsMissionGiverIconDisplayable = !hide; }
264 // Read accessors for NPC base parameters ---------------------------
265 NLMISC::CSheetId
getStats() const { return getSheet()->SheetId(); }
266 CAIPos
const& getStartPos() const { return _StartPos
; }
267 AITYPES::TVerticalPos
getStartVerticalPos() const { return _VerticalPos
; }
269 // Callback called on state change of parent group (including changes to/from punctual states)
271 // the update routine (delegates control to the _aiProfile object) --
272 // void update(uint32 ticks);
274 // do nothing for 'ticks' ticks
275 // return number of ticks of movement time left after destination reached (or 0)
279 void sendVisualProperties();
283 NLMISC::CSmartPtr
<CNpcChatProfileImp
> const& getChat() const { return _ChatProfile
; }
284 void setUserModelId(const std::string
&userModelId
);
285 std::string
getUserModelId();
287 void setCustomLootTableId(const std::string
&customLootTableId
);
288 std::string
getCustomLootTableId();
290 void setPrimAlias(uint32 alias
);
291 uint32
getPrimAlias() const;
293 // void fillDescriptionMsg(CNpcBotDescriptionImp& msg) const;
294 void fillDescriptionMsg(RYMSG::TGenNpcDescMsg
& msg
) const;
297 virtual std::string
getOneLineInfoString() const { return std::string("NPC bot '") + getName() + "'"; }
299 virtual AISHEETS::ICreatureCPtr
getSheet() const { return _Sheet
.getPtr(); }
301 virtual void setSheet(AISHEETS::ICreatureCPtr
const& sheet
);
303 virtual bool isSheetValid() const
305 return _Sheet
!=NULL
&& _Sheet
->isValid();
308 void setOutpostSide(OUTPOSTENUMS::TPVPSide side
) { _OutpostSide
= side
; }
310 virtual bool getFaunaBotUseBotName() const;
313 virtual void sheetChanged();
314 bool finalizeSpawnNpc();
315 virtual void initAdditionalMirrorValues();
318 // stuff supplied by CAIBot ------------------
319 // sheet (.creature) for game parameters
320 // position & orientation
321 // mode and behaviour
323 // A static bot object with a fauna sheet must not display SheetName but botobject name
324 bool _FaunaBotUseBotName
;
328 // /// Allows to hide icons for current missions steps having interactions with this NPC
329 // bool IsMissionStepIconDisplayable : 1;
331 // /// Allows to hide icons for missions proposed by this NPC
332 // bool IsMissionGiverIconDisplayable : 1;
333 // } _MissionIconFlags;
335 // look parameters ---------------------------
338 bool _useVisualProperties
; // true => use VisualPropertyA, B, C instead of alternate VPA
339 uint64 _VisualPropertyA
;
340 uint64 _VisualPropertyB
;
341 uint64 _VisualPropertyC
;
343 CBotNpcSheetPtr _Sheet
;
346 // spawn place -------------------------------
348 CAIVector _FirstPosition
;
349 uint8 _DispersionRadius
;
351 std::vector
<NLMISC::CSheetId
> _LootList
;
353 // static chat parameters --------------------
354 NLMISC::CSmartPtr
<CNpcChatProfileImp
> _ChatProfile
;
357 OUTPOSTENUMS::TPVPSide _OutpostSide
;
359 // Max range a PC can hit this bot
360 float _MaxHitRangeForPC
;
362 //userModelId used for this bot
363 std::string _UserModelId
;
365 std::string _CustomLootTableId
;