Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_bot_npc.h
blobaaaeb67575ac7bceb9cc23cfd0969d0691725e03
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_BOT_NPC_H
18 #define RYAI_BOT_NPC_H
20 #include "game_share/msg_ais_egs_gen.h"
21 #include "ai_bot.h"
22 #include "owners.h"
23 #include "npc_description_msg.h"
24 #include "states.h"
25 #include "ai_player.h"
27 class CBotNpc;
28 class CNpc;
29 class CSpawnGroupNpc;
30 class CBotPlayer;
31 class CPlayerControlNpc;
33 //////////////////////////////////////////////////////////////////////////////
34 // CSpawnBotNpc //
35 //////////////////////////////////////////////////////////////////////////////
37 class CSpawnBotNpc
38 : public NLMISC::CDbgRefCount<CSpawnBotNpc>
39 , public CSpawnBot
40 , public CPetOwner
42 public:
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
59 //@{
60 void beginBotChat(CBotPlayer* plr);
61 void endBotChat(CBotPlayer* plr);
62 void beginDynChat() { ++_NbCurrentDynChats; }
63 void endDynChat() { --_NbCurrentDynChats; }
64 //@}
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;
102 private:
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;
109 uint32 _FacingTick;
110 CAngle _FacingTheta;
112 std::string _UserModelId;
113 std::string _CustomLootTableId;
114 uint32 _PrimAlias;
117 //////////////////////////////////////////////////////////////////////////////
118 // CBotNpcSheet //
119 //////////////////////////////////////////////////////////////////////////////
121 class CBotNpcSheet
122 : public AISHEETS::CCreatureProxy
124 public:
125 CBotNpcSheet(AISHEETS::ICreatureCPtr const& sheet)
126 : AISHEETS::CCreatureProxy(sheet)
127 , _LeftItem(NLMISC::CSheetId::Unknown)
128 , _RightItem(NLMISC::CSheetId::Unknown)
129 , _ColorHead(0)
130 , _ColorArms(0)
131 , _ColorHands(0)
132 , _ColorBody(0)
133 , _ColorLegs(0)
134 , _ColorFeets(0)
136 reset();
139 ///@name ICreature overloads
140 //@{
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)
151 return _LeftItem;
152 else
153 return this->CCreatureProxy::LeftItem();
155 virtual NLMISC::CSheetId const& RightItem() const
157 if (_RightItem!=NLMISC::CSheetId::Unknown)
158 return _RightItem;
159 else
160 return this->CCreatureProxy::RightItem();
162 //@}
164 ///@name Setters
165 //@{
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; }
175 //@}
177 void reset()
179 if (_Sheet)
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();
192 private:
193 NLMISC::CSheetId _LeftItem;
194 NLMISC::CSheetId _RightItem;
195 uint8 _ColorHead;
196 uint8 _ColorArms;
197 uint8 _ColorHands;
198 uint8 _ColorBody;
199 uint8 _ColorLegs;
200 uint8 _ColorFeets;
202 typedef NLMISC::CSmartPtr<CBotNpcSheet> CBotNpcSheetPtr;
203 typedef NLMISC::CSmartPtr<CBotNpcSheet const> CBotNpcSheetCPtr;
205 //////////////////////////////////////////////////////////////////////////////
206 // CBotNpc //
207 //////////////////////////////////////////////////////////////////////////////
209 class CBotNpc
210 : public CBot
211 , public CKeyWordOwner
213 public:
214 friend class CSpawnBotNpc; // allows CSpawnBotNpc to acceed his definition.
216 public:
217 CBotNpc(CGroup* owner, CAIAliasDescriptionNode* alias = NULL);
218 CBotNpc(CGroup* owner, uint32 alias, std::string const& name);
219 virtual ~CBotNpc();
221 void init();
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)
278 void sendVPA();
279 void sendVisualProperties();
281 void newChat();
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;
312 protected:
313 virtual void sheetChanged();
314 bool finalizeSpawnNpc();
315 virtual void initAdditionalMirrorValues();
317 protected:
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;
326 // struct
327 // {
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 ---------------------------
336 bool _Hat;
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 -------------------------------
347 CAIPos _StartPos;
348 CAIVector _FirstPosition;
349 uint8 _DispersionRadius;
351 std::vector<NLMISC::CSheetId> _LootList;
353 // static chat parameters --------------------
354 NLMISC::CSmartPtr<CNpcChatProfileImp> _ChatProfile;
356 // Outpost side
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;
367 uint32 _PrimAlias;
370 #endif