Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_bot_fauna.h
blobbb0306afcfc206da00397a986ebda36194192474
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_FAUNA_H
18 #define RYAI_BOT_FAUNA_H
20 #define FAUNA_BEHAVIOR_GLOBAL_SCALE (4)
22 #include "ai_bot.h"
23 #include "timer.h"
24 #include "path_behaviors.h"
26 class CFauna;
27 class CSpawnGroupFauna;
28 class CBotPlayer;
29 class CBotFauna;
30 class CGrpFauna;
31 class CMgrFauna;
33 class CGeneralFaunaUpdate;
35 //////////////////////////////////////////////////////////////////////////////
36 // CFaunaActivity //
37 //////////////////////////////////////////////////////////////////////////////
39 class CFaunaActivity
41 public:
42 virtual ~CFaunaActivity() { }
44 enum TCycleState
46 // eat behaviour cycles.
47 CycleStateHungry = 0,
48 CycleStateVeryHungry,
49 CycleStateStarving,
50 CycleStateDigesting,
52 // sleep behaviour cycles.
53 CycleStateTired,
54 CycleStateVeryTired,
55 CycleStateExhausted,
56 CycleStateShaking,
58 CycleStateUndefined
61 virtual void update() = 0;
62 virtual AITYPES::TProfiles getActivityType() = 0;
65 //////////////////////////////////////////////////////////////////////////////
66 // CSpawnBotFauna //
67 //////////////////////////////////////////////////////////////////////////////
69 class CSpawnBotFauna
70 : public CSpawnBot
72 public:
73 CSpawnBotFauna(TDataSetRow const& row, CBot& owner, NLMISC::CEntityId const& id, float radius, uint32 level, RYAI_MAP_CRUNCH::TAStarFlag denyFlags);
74 virtual ~CSpawnBotFauna();
76 CSpawnGroupFauna& spawnGrp();
78 void update(AITYPES::TProfiles activity, uint32 ticksSinceLastUpdate);
80 bool canMove() const;
82 //////////////////////////////////////////////////////////////////////////
83 // Specific
84 //////////////////////////////////////////////////////////////////////////
86 CFaunaActivity::TCycleState const& cycleState() const { return _CycleState; }
87 void setCycleState(CFaunaActivity::TCycleState const& cycleState) { _CycleState=cycleState; }
89 //////////////////////////////////////////////////////////////////////////
90 // Fight Features.
91 //////////////////////////////////////////////////////////////////////////
93 void getBestTarget();
95 void processEvent(CCombatInterface::CEvent const& event);
96 void eventEngaged(TDataSetRow const& originId);
98 /// @name Profiles transition
99 //@{
100 void doFight(CAIEntityPhysical* ennemy);
101 void setDefaultComportment();
102 //@}
105 float aggroRadius();
107 float getCollisionDist(float angTo) const;
109 void setHungry() { _Hungry = 1.f; }
110 float& hungry() { return _Hungry; }
112 // fauna are always attackable by other bots
113 virtual bool isBotAttackable() const { return true; }
115 //////////////////////////////////////////////////////////////////////////
116 // Specific ( Comportement )
117 //////////////////////////////////////////////////////////////////////////
119 //----------------------------------------------------------------------------------------------
120 // Dispatching message to EGS to describe chat possibilities
121 //----------------------------------------------------------------------------------------------
123 void sendInfoToEGS() const;
125 CBotFauna& getPersistent() const;
127 // replace by 'getRYZOMType'
128 virtual RYZOMID::TTypeId getRyzomType() const { return RYZOMID::creature; }
130 //////////////////////////////////////////////////////////////////////////
131 // Specific ( Comportement )
132 //////////////////////////////////////////////////////////////////////////
134 CFaunaActivity::TCycleState _CycleState;
136 CAITimer& timeBeforeNextCuriosity() { return _TimeBeforeNextCuriosity; }
138 CAITimer& VisualTargetTimer() { return _VisualTargetTimer; }
140 float getReturnDistCheck() const;
142 private:
143 float _Hungry;
144 float _Food;
145 CAITimer _TimeBeforeNextCuriosity;
146 CAITimer _VisualTargetTimer;
147 CAITimer _NextBestTargetUpdate;
150 //////////////////////////////////////////////////////////////////////////////
151 // CMovementMagnet //
152 //////////////////////////////////////////////////////////////////////////////
154 class CMovementMagnet
155 : public NLMISC::CRefCount
157 public:
158 enum TMovementType
160 Movement_Anim = 0,
161 Movement_Wait_Anim,
162 Movement_Move
165 CMovementMagnet(CSpawnBotFauna& botFauna, RYAI_MAP_CRUNCH::TAStarFlag flag);
166 virtual ~CMovementMagnet();
167 virtual void update(uint32 waitTime, uint32 ticksSinceLastUpdate) { update(waitTime, ticksSinceLastUpdate, false); }
168 void setBotAngle();
170 virtual void getNewDestination(RYAI_MAP_CRUNCH::CWorldPosition const& alternativePos, RYAI_MAP_CRUNCH::TAStarFlag denyFlag);
171 CAIVector const& getDestination() const;
172 bool isDestinationValid() const;
173 TMovementType getMovementType() const { return _State; }
175 CAITimer& stateTimer() { return _StateTimer; }
177 void setState(TMovementType state) { _State = state; }
179 protected:
180 void update(uint32 waitTime, uint32 ticksSinceLastUpdate, bool ignoreBadPos);
181 CPathCont _PathCont;
182 private:
183 float _Speed;
184 CAngle _dTheta; // the change in orientation at last update
185 CAITimer _dThetaTimer; // the time for which the current rotation will be applied
187 CAITimer _StateTimer;
188 TMovementType _State;
190 RYAI_MAP_CRUNCH::TAStarFlag _denyFlags;
192 CSpawnBotFauna& _BotFauna;
193 CPathPosition _PathPos;
194 CAIVector _LastDest;
197 //////////////////////////////////////////////////////////////////////////////
198 // CReturnMovementMagnet //
199 //////////////////////////////////////////////////////////////////////////////
201 class CReturnMovementMagnet
202 : public CMovementMagnet
204 public:
205 CReturnMovementMagnet(RYAI_MAP_CRUNCH::CWorldPosition const& forcedDest, CSpawnBotFauna& botFauna, RYAI_MAP_CRUNCH::TAStarFlag flag);
206 virtual void getNewDestination(RYAI_MAP_CRUNCH::CWorldPosition const& alternativePos, RYAI_MAP_CRUNCH::TAStarFlag denyFlag);
207 virtual void update(uint32 waitTime, uint32 ticksSinceLastUpdate) { CMovementMagnet::update(waitTime, ticksSinceLastUpdate, true); }
209 private:
210 RYAI_MAP_CRUNCH::CWorldPosition _ForcedDest;
213 //////////////////////////////////////////////////////////////////////////////
214 // IMouvementMagnetOwner //
215 //////////////////////////////////////////////////////////////////////////////
217 class IMouvementMagnetOwner
219 public:
220 virtual NLMISC::CSmartPtr<CMovementMagnet> const& getMovementMagnet() const = 0;
223 //////////////////////////////////////////////////////////////////////////////
224 // CBotFaunaSheet //
225 //////////////////////////////////////////////////////////////////////////////
227 class CBotFaunaSheet
228 : public AISHEETS::CCreatureProxy
230 public:
231 CBotFaunaSheet(AISHEETS::ICreatureCPtr const& sheet)
232 : AISHEETS::CCreatureProxy(sheet)
233 , _AggroRadiusNotHungry(0.f)
234 , _AggroRadiusHungry(0.f)
235 , _AggroRadiusHunting(0.f)
237 reset();
240 virtual void setSheet(AISHEETS::ICreatureCPtr const& sheet)
242 CCreatureProxy::setSheet(sheet);
243 reset();
246 ///@name ICreature overloads
247 //@{
248 virtual float AggroRadiusNotHungry() const { return _AggroRadiusNotHungry; }
249 virtual float AggroRadiusHungry() const { return _AggroRadiusHungry; }
250 virtual float AggroRadiusHunting() const { return _AggroRadiusHunting; }
251 //@}
253 ///@name Setters
254 //@{
255 void setAggroRadiusNotHungry(float val) { _AggroRadiusNotHungry = val; }
256 void setAggroRadiusHungry(float val) { _AggroRadiusHungry = val; }
257 void setAggroRadiusHunting(float val) { _AggroRadiusHunting = val; }
258 //@}
260 void reset()
262 if (_Sheet)
264 _AggroRadiusNotHungry = _Sheet->AggroRadiusNotHungry();
265 _AggroRadiusHungry = _Sheet->AggroRadiusHungry();
266 _AggroRadiusHunting = _Sheet->AggroRadiusHunting();
270 private:
271 float _AggroRadiusNotHungry;
272 float _AggroRadiusHungry;
273 float _AggroRadiusHunting;
275 typedef NLMISC::CSmartPtr<CBotFaunaSheet> CBotFaunaSheetPtr;
276 typedef NLMISC::CSmartPtr<CBotFaunaSheet const> CBotFaunaSheetCPtr;
278 //////////////////////////////////////////////////////////////////////////////
279 // CBotFauna //
280 //////////////////////////////////////////////////////////////////////////////
282 class CBotFauna
283 : public NLMISC::CDbgRefCount<CBotFauna>
284 , public CBot
286 public:
287 CBotFauna(AITYPES::TFaunaType type, CGroup* owner, CAIAliasDescriptionNode* alias = NULL);
289 virtual ~CBotFauna();
291 AITYPES::TFaunaType faunaType() const { return _Type; }
293 CSpawnBot* getSpawnBot(TDataSetRow const& row, NLMISC::CEntityId const& id, float radius);
295 CAIS::CCounter& getSpawnCounter();
297 virtual bool spawn();
298 void despawnBot();
299 bool reSpawn(bool sendMessage = true);
301 CSpawnBotFauna* getSpawn() { return static_cast<CSpawnBotFauna*>(getSpawnObj()); }
303 RYZOMID::TTypeId getRyzomType() const { return RYZOMID::creature; }
305 CGrpFauna& grp() const;
306 CMgrFauna& mgr() const;
308 // (assuming targetPlace is always valid ..)
309 void getSpawnPos(CAIVector& triedPos, RYAI_MAP_CRUNCH::CWorldPosition& pos, RYAI_MAP_CRUNCH::CWorldMap const& worldMap, CAngle& spawnTheta);
311 virtual std::string getOneLineInfoString() const;
313 virtual AISHEETS::ICreatureCPtr getSheet() const { return _Sheet.getPtr(); }
314 virtual void setSheet(AISHEETS::ICreatureCPtr const& sheet)
316 _Sheet->setSheet(sheet);
317 sheetChanged();
319 virtual bool isSheetValid() const
321 return _Sheet!=NULL && _Sheet->isValid();
324 void setAggroRadiusNotHungry(float val) { _Sheet->setAggroRadiusNotHungry(val); }
325 void setAggroRadiusHungry(float val) { _Sheet->setAggroRadiusHungry(val); }
326 void setAggroRadiusHunting(float val) { _Sheet->setAggroRadiusHunting(val); }
327 void resetAggroRadius() { _Sheet->reset(); }
329 void triggerSetSheet(AISHEETS::ICreatureCPtr const& sheet);
331 protected:
332 virtual void sheetChanged();
333 bool finalizeSpawnFauna();
335 private:
336 AITYPES::TFaunaType _Type;
337 CAIPos _SpawnPos;
338 CBotFaunaSheetPtr _Sheet;
341 #endif