Added ai command setEquipment
[ryzomcore.git] / ryzom / server / src / ai_service / ai_profile_fauna.h
blobf4799874a52a5601d300c7202656cc1cfdcfb711
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /**
21 * This file defines the classes:
22 * - CPlanteIdleFaunaProfile
23 * - CStaticPlanteIdleFaunaProfile
24 * - CAIFaunaActivityBaseSpawnProfile
25 * - CWanderFaunaProfile
26 * - CStaticWanderFaunaProfile
27 * - CGrazeFaunaProfile
28 * - CStaticGrazeFaunaProfile
29 * - CRestFaunaProfile
30 * - CStaticRestFaunaProfile
31 * - CStaticFightFaunaProfile
32 * - CCorpseFaunaProfileFactory
33 * - CEatCorpseFaunaProfile
34 * - CStaticEatCorpseFaunaProfile
35 * - CCuriosityFaunaProfile
36 * - CStaticCuriosityFaunaProfile
39 #ifndef AI_PROFILE_FAUNA_H
40 #define AI_PROFILE_FAUNA_H
42 #include "profile.h" // for CAIBaseProfile
43 #include "path_behaviors.h" // for CPathPosition
44 #include "ai_bot_fauna.h" // for CCorpseFaunaProfile
45 #include "ai_grp_fauna.h"
46 #include "ai_mgr_fauna.h"
48 class CSpawnBotFauna;
49 class CMovementMagnet;
51 // ---------------------------------------------------------------------------
52 // Debug defines
53 // ---------------------------------------------------------------------------
54 // COMPACT_POS_WARNINGS compress flooding warnings concerning path problems.
55 // Positions where the problems occures are stored and displayed and cleared
56 // every minute.
57 // :TODO: /!\ As it cannot be tested without long-time run with several
58 // players the following define can be commented to restore previous behavior.
59 #define COMPACT_POS_WARNINGS 1
61 class CFaunaProfileFloodLogger
63 public:
64 typedef std::map<std::string, int> TLogPositions;
66 public:
67 CFaunaProfileFloodLogger(int period)
68 : logLastTick(0)
69 , logPeriod(period)
73 public:
74 TLogPositions logPositions;
75 int logLastTick;
76 int logPeriod;
79 //////////////////////////////////////////////////////////////////////////////
80 // CPlanteIdleFaunaProfile //
81 //////////////////////////////////////////////////////////////////////////////
83 class CPlanteIdleFaunaProfile
84 : public CAIBaseProfile
86 public:
87 CPlanteIdleFaunaProfile(CProfileOwner* owner);
89 /// @name IAIProfile implementation
90 //@{
91 virtual void beginProfile();
92 virtual void updateProfile(uint ticksSinceLastUpdate);
93 virtual void endProfile();
94 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_PLANTIDLE; }
95 virtual std::string getOneLineInfoString() const;
96 //@}
98 protected:
99 CSpawnBotFauna* _Bot;
102 //////////////////////////////////////////////////////////////////////////////
103 // CAIFaunaActivityBaseSpawnProfile //
104 //////////////////////////////////////////////////////////////////////////////
106 class CAIFaunaActivityBaseSpawnProfile
107 : public CAIBaseProfile
108 , public IMouvementMagnetOwner
110 public:
111 CAIFaunaActivityBaseSpawnProfile(CProfileOwner* owner);
113 virtual NLMISC::CSmartPtr<CMovementMagnet> const& getMovementMagnet() const;
115 protected:
116 NLMISC::CSmartPtr<CMovementMagnet> _MovementMagnet;
117 CPathPosition _PathPos;
118 bool _OutOfMagnet;
121 //////////////////////////////////////////////////////////////////////////////
122 // CWanderFaunaProfile //
123 //////////////////////////////////////////////////////////////////////////////
125 class CWanderFaunaProfile
126 : public CAIFaunaActivityBaseSpawnProfile
128 public:
129 CWanderFaunaProfile(CProfileOwner* owner);
131 /// @name IAIProfile implementation
132 //@{
133 virtual void beginProfile();
134 virtual void updateProfile(uint ticksSinceLastUpdate);
135 virtual void endProfile();
136 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_WANDERING; }
137 virtual std::string getOneLineInfoString() const;
138 //@}
140 protected:
141 RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
142 CSpawnBotFauna* _Bot;
143 double _magnetDistSq; ///< square distance from bot to his magnet at last move
144 static CFaunaProfileFloodLogger _FloodLogger;
147 //////////////////////////////////////////////////////////////////////////////
148 // CGrazeFaunaProfile //
149 //////////////////////////////////////////////////////////////////////////////
151 class CGrazeFaunaProfile
152 : public CAIFaunaActivityBaseSpawnProfile
154 public:
155 CGrazeFaunaProfile(CProfileOwner* owner);
157 /// @name IAIProfile implementation
158 //@{
159 virtual void beginProfile();
160 virtual void updateProfile(uint ticksSinceLastUpdate);
161 virtual void endProfile();
162 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_GRAZING; }
163 virtual std::string getOneLineInfoString() const;
164 //@}
166 protected:
167 CSpawnBotFauna* _Bot;
168 private:
169 CAITimer _CycleTimer;
170 uint _CycleTimerBaseTime;
171 bool _ArrivedInZone;
172 double _magnetDistSq; ///< square distance from bot to his magnet at last move
173 RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
174 static CFaunaProfileFloodLogger _FloodLogger;
177 //////////////////////////////////////////////////////////////////////////////
178 // CRestFaunaProfile //
179 //////////////////////////////////////////////////////////////////////////////
181 class CRestFaunaProfile
182 : public CAIFaunaActivityBaseSpawnProfile
184 public:
185 CRestFaunaProfile(CProfileOwner* owner);
187 /// @name IAIProfile implementation
188 //@{
189 virtual void beginProfile();
190 virtual void updateProfile(uint ticksSinceLastUpdate);
191 virtual void endProfile();
192 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_RESTING; }
193 virtual std::string getOneLineInfoString() const;
194 //@}
196 protected:
197 CSpawnBotFauna* _Bot;
198 private:
199 CAITimer _CycleTimer;
200 uint _CycleTimerBaseTime;
201 bool _ArrivedInZone;
202 double _magnetDistSq; // square distance from bot to his magnet at last move
203 RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
204 static CFaunaProfileFloodLogger _FloodLogger;
207 //////////////////////////////////////////////////////////////////////////////
208 // CEatCorpseFaunaProfile //
209 //////////////////////////////////////////////////////////////////////////////
211 class CEatCorpseFaunaProfile
212 : public CAIBaseProfile
214 public:
215 CEatCorpseFaunaProfile(CProfileOwner* owner, TDataSetRow const& corpse, RYAI_MAP_CRUNCH::TAStarFlag flag);
217 /// @name IAIProfile implementation
218 //@{
219 virtual void beginProfile();
220 virtual void updateProfile(uint ticksSinceLastUpdate);
221 virtual void endProfile();
222 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_EAT_CORPSE; }
223 virtual std::string getOneLineInfoString() const;
224 //@}
226 TDataSetRow _eated;
227 protected:
228 CSpawnBotFauna* _Bot;
229 private:
230 bool _atGoodDist;
231 CAITimer _eatTimer;
232 CPathPosition _PathPos;
233 CPathCont _PathCont;
236 //////////////////////////////////////////////////////////////////////////////
237 // CCuriosityFaunaProfile //
238 //////////////////////////////////////////////////////////////////////////////
240 class CCuriosityFaunaProfile
241 : public CAIBaseProfile
243 public:
244 CCuriosityFaunaProfile(CProfileOwner* owner, TDataSetRow const& player, RYAI_MAP_CRUNCH::TAStarFlag flag);
246 /// @name IAIProfile implementation
247 //@{
248 virtual void beginProfile();
249 virtual void updateProfile(uint ticksSinceLastUpdate);
250 virtual void endProfile();
251 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_CURIOSITY; }
252 virtual std::string getOneLineInfoString() const;
253 //@}
255 TDataSetRow _player;
256 protected:
257 CSpawnBotFauna* _Bot;
258 private:
259 bool _atGoodDist;
260 CAITimer _curiosityTimer;
261 CPathPosition _PathPos;
262 CPathCont _PathCont;
263 uint32 _addCuriosityTime;
264 bool _TooFar;
265 RYAI_MAP_CRUNCH::TAStarFlag _Flag;
268 //////////////////////////////////////////////////////////////////////////////
269 // CCorpseFaunaProfile //
270 //////////////////////////////////////////////////////////////////////////////
272 class CCorpseFaunaProfile
273 : public CAIBaseProfile
275 public:
276 CCorpseFaunaProfile(CProfileOwner* owner);
278 virtual void beginProfile();
280 virtual void endProfile() { }
282 virtual void updateProfile(uint ticksSinceLastUpdate) { }
284 virtual std::string getOneLineInfoString() const { return NLMISC::toString("corpse fauna profile"); }
286 virtual AITYPES::TProfiles getAIProfileType() const { return AITYPES::ACTIVITY_CORPSE; }
288 bool eated() const { return _Eated; }
289 void setEated(bool eated) { _Eated = eated; }
291 void setEater(bool eater) { _HaveEater = eater; }
292 bool haveEater() const { return _HaveEater; }
294 protected:
295 CSpawnBotFauna* _Bot;
297 private:
298 bool _HaveEater;
299 bool _Eated;
302 /****************************************************************************/
303 /* Profile factories */
304 /****************************************************************************/
306 //- Simple profile factories -------------------------------------------------
308 // CPlanteIdleFaunaProfileFactory
309 typedef CAIGenericProfileFactory<CPlanteIdleFaunaProfile> CPlanteIdleFaunaProfileFactory;
311 // CWanderFaunaProfileFactory
312 typedef CAIGenericProfileFactory<CWanderFaunaProfile> CWanderFaunaProfileFactory;
314 // CGrazeFaunaProfileFactory
315 typedef CAIGenericProfileFactory<CGrazeFaunaProfile> CGrazeFaunaProfileFactory;
317 // CRestFaunaProfileFactory
318 typedef CAIGenericProfileFactory<CRestFaunaProfile> CRestFaunaProfileFactory;
320 // CCorpseFaunaProfileFactory
321 typedef CAIGenericProfileFactory<CCorpseFaunaProfile> CCorpseFaunaProfileFactory;
323 //- Complex profile factories ------------------------------------------------
325 // CStaticFightFaunaProfile
326 class CFightFaunaProfileFactory
327 : public IAIProfileFactory
329 public:
330 NLMISC::CSmartPtr<IAIProfile> createAIProfile(CProfileOwner* owner)
332 return NULL;
336 // CStaticEatCorpseFaunaProfile
337 class CEatCorpseFaunaProfileFactory
338 : public IAIProfileFactory
340 public:
341 NLMISC::CSmartPtr<IAIProfile> createAIProfile(CProfileOwner* owner)
343 #ifdef NL_DEBUG
344 nlassert(false);
345 #endif
346 return NULL;
350 // CStaticCuriosityFaunaProfile
351 class CCuriosityFaunaProfileFactory
352 : public IAIProfileFactory
354 public:
355 NLMISC::CSmartPtr<IAIProfile> createAIProfile(CProfileOwner* owner)
357 #ifdef NL_DEBUG
358 nlassert(false);
359 #endif
360 return NULL;
364 //- Profile factories singletons ---------------------------------------------
366 extern CPlanteIdleFaunaProfileFactory PlanteIdleFaunaProfileFactory;
367 extern CWanderFaunaProfileFactory WanderFaunaProfileFactory;
368 extern CGrazeFaunaProfileFactory GrazeFaunaProfileFactory;
369 extern CRestFaunaProfileFactory RestFaunaProfileFactory;
370 extern CFightFaunaProfileFactory FightFaunaProfileFactory;
371 extern CCorpseFaunaProfileFactory CorpseFaunaProfileFactory;
372 extern CEatCorpseFaunaProfileFactory EatCorpseFaunaProfileFactory;
373 extern CCuriosityFaunaProfileFactory CuriosityFaunaProfileFactory;
375 #endif