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_FAUNA_H
18 #define RYAI_BOT_FAUNA_H
20 #define FAUNA_BEHAVIOR_GLOBAL_SCALE (4)
24 #include "path_behaviors.h"
27 class CSpawnGroupFauna
;
33 class CGeneralFaunaUpdate
;
35 //////////////////////////////////////////////////////////////////////////////
37 //////////////////////////////////////////////////////////////////////////////
42 virtual ~CFaunaActivity() { }
46 // eat behaviour cycles.
52 // sleep behaviour cycles.
61 virtual void update() = 0;
62 virtual AITYPES::TProfiles
getActivityType() = 0;
65 //////////////////////////////////////////////////////////////////////////////
67 //////////////////////////////////////////////////////////////////////////////
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
);
82 //////////////////////////////////////////////////////////////////////////
84 //////////////////////////////////////////////////////////////////////////
86 CFaunaActivity::TCycleState
const& cycleState() const { return _CycleState
; }
87 void setCycleState(CFaunaActivity::TCycleState
const& cycleState
) { _CycleState
=cycleState
; }
89 //////////////////////////////////////////////////////////////////////////
91 //////////////////////////////////////////////////////////////////////////
95 void processEvent(CCombatInterface::CEvent
const& event
);
96 void eventEngaged(TDataSetRow
const& originId
);
98 /// @name Profiles transition
100 void doFight(CAIEntityPhysical
* ennemy
);
101 void setDefaultComportment();
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;
145 CAITimer _TimeBeforeNextCuriosity
;
146 CAITimer _VisualTargetTimer
;
147 CAITimer _NextBestTargetUpdate
;
150 //////////////////////////////////////////////////////////////////////////////
151 // CMovementMagnet //
152 //////////////////////////////////////////////////////////////////////////////
154 class CMovementMagnet
155 : public NLMISC::CRefCount
165 CMovementMagnet(CSpawnBotFauna
& botFauna
, RYAI_MAP_CRUNCH::TAStarFlag flag
);
166 virtual ~CMovementMagnet();
167 virtual void update(uint32 waitTime
, uint32 ticksSinceLastUpdate
) { update(waitTime
, ticksSinceLastUpdate
, false); }
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
; }
180 void update(uint32 waitTime
, uint32 ticksSinceLastUpdate
, bool ignoreBadPos
);
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
;
197 //////////////////////////////////////////////////////////////////////////////
198 // CReturnMovementMagnet //
199 //////////////////////////////////////////////////////////////////////////////
201 class CReturnMovementMagnet
202 : public CMovementMagnet
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); }
210 RYAI_MAP_CRUNCH::CWorldPosition _ForcedDest
;
213 //////////////////////////////////////////////////////////////////////////////
214 // IMouvementMagnetOwner //
215 //////////////////////////////////////////////////////////////////////////////
217 class IMouvementMagnetOwner
220 virtual NLMISC::CSmartPtr
<CMovementMagnet
> const& getMovementMagnet() const = 0;
223 //////////////////////////////////////////////////////////////////////////////
225 //////////////////////////////////////////////////////////////////////////////
228 : public AISHEETS::CCreatureProxy
231 CBotFaunaSheet(AISHEETS::ICreatureCPtr
const& sheet
)
232 : AISHEETS::CCreatureProxy(sheet
)
233 , _AggroRadiusNotHungry(0.f
)
234 , _AggroRadiusHungry(0.f
)
235 , _AggroRadiusHunting(0.f
)
240 virtual void setSheet(AISHEETS::ICreatureCPtr
const& sheet
)
242 CCreatureProxy::setSheet(sheet
);
246 ///@name ICreature overloads
248 virtual float AggroRadiusNotHungry() const { return _AggroRadiusNotHungry
; }
249 virtual float AggroRadiusHungry() const { return _AggroRadiusHungry
; }
250 virtual float AggroRadiusHunting() const { return _AggroRadiusHunting
; }
255 void setAggroRadiusNotHungry(float val
) { _AggroRadiusNotHungry
= val
; }
256 void setAggroRadiusHungry(float val
) { _AggroRadiusHungry
= val
; }
257 void setAggroRadiusHunting(float val
) { _AggroRadiusHunting
= val
; }
264 _AggroRadiusNotHungry
= _Sheet
->AggroRadiusNotHungry();
265 _AggroRadiusHungry
= _Sheet
->AggroRadiusHungry();
266 _AggroRadiusHunting
= _Sheet
->AggroRadiusHunting();
271 float _AggroRadiusNotHungry
;
272 float _AggroRadiusHungry
;
273 float _AggroRadiusHunting
;
275 typedef NLMISC::CSmartPtr
<CBotFaunaSheet
> CBotFaunaSheetPtr
;
276 typedef NLMISC::CSmartPtr
<CBotFaunaSheet
const> CBotFaunaSheetCPtr
;
278 //////////////////////////////////////////////////////////////////////////////
280 //////////////////////////////////////////////////////////////////////////////
283 : public NLMISC::CDbgRefCount
<CBotFauna
>
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();
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
);
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
);
332 virtual void sheetChanged();
333 bool finalizeSpawnFauna();
336 AITYPES::TFaunaType _Type
;
338 CBotFaunaSheetPtr _Sheet
;