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/>.
19 #ifndef RYAI_GENERIC_FIGHT_H
20 #define RYAI_GENERIC_FIGHT_H
24 #include "path_behaviors.h"
27 // Forward declarations
28 class CAIEntityPhysical
;
29 class CModEntityPhysical
;
32 // a big bad global var !
33 extern CAIEntityPhysical
*TempSpeaker
;
34 extern CBotPlayer
*TempPlayer
;
35 extern float getDistBetWeen(CAIEntityPhysical
& creat1
, CAIEntityPhysical
& creat2
);
37 template <class TVectorSrc
, class TVectorDst
>
38 float buildDecalage(TVectorSrc
const& src
, TVectorDst
const& dst
, CAIVector
* decalage
)
42 CAIVector
& vect
= *decalage
;
45 float normXY
= (float)vect
.norm();
46 float normZ
= (dst
.h()-src
.h())/1000.f
;
47 // :KLUDGE: This is a dirty dirty hack
48 // As z precision is 2m, entities can be near contact but considered 2m away if they are on differents PACS planes.
49 // So we bring back all z dists 2m closer to 0.
50 if (normZ
> 2.f
) normZ
-= 2.f
;
51 else if (normZ
< -2.f
) normZ
+= 2.f
;
54 float normXYZ
= (float)sqrt(normXY
*normXY
+ normZ
*normZ
);
60 return buildDecalage(src
, dst
, &vect
);
64 //////////////////////////////////////////////////////////////////////////////
65 // CBotProfileFightHeal //
66 //////////////////////////////////////////////////////////////////////////////
67 class CBotProfileFightHeal
68 : public CAIBaseProfile
71 CBotProfileFightHeal() : CAIBaseProfile() { }
72 virtual void eventTargetKilled() = 0;
73 virtual void noMoreTarget() = 0;
76 /// @name Fight ranges/distances parameters
78 static float fightDists
[AISHEETS::FIGHTCFG_MAX
];
79 static float fightDefaultMinRange
;
80 static float fightDefaultMaxRange
;
81 static float fightMeleeMinRange
;
82 static float fightMeleeMaxRange
;
83 static float fightRangeMinRange
;
84 static float fightRangeMaxRange
;
85 static float fightMixedMinRange
;
86 static float fightMixedMaxRange
;
87 static float giveUpDistance
;
88 static bool fleeUnreachableTargets
;
92 //////////////////////////////////////////////////////////////////////////////
93 // CBotProfileFight //
94 //////////////////////////////////////////////////////////////////////////////
96 /// Generic fight profile class
97 class CBotProfileFight
98 : public CBotProfileFightHeal
99 , public NLMISC::IDbgPtrData
102 /// @name Constructors, destructor
104 CBotProfileFight(CProfileOwner
* owner
, CAIEntityPhysical
* ennemy
);
105 virtual ~CBotProfileFight();
108 /// @name Event handlers
110 virtual void eventBeginFight() = 0;
111 virtual void eventTargetKilled() = 0;
114 /// @name IAIProfile implementation
116 virtual void beginProfile();
117 virtual void resumeProfile();
118 virtual void endProfile();
119 virtual void updateProfile(uint ticksSinceLastUpdate
);
120 virtual std::string
getOneLineInfoString() const;
123 virtual void noMoreTarget() = 0;
128 bool isHitting() const { return _Bot
->isHitting(); }
129 bool atAttackDist() const { return _AtAttackDist
; }
130 virtual AITYPES::TProfiles
getAIProfileType() const { return AITYPES::BOT_FIGHT
; }
134 NLMISC::CDbgPtr
<CSpawnBot
> _Bot
;
135 NLMISC::CRefPtr
<CAIEntityPhysical
> _Ennemy
;
139 CPathPosition _PathPos
;
142 bool _RangeCalculated
;
143 bool _UseFightConfig
;
149 bool _SearchAlternativePath
;
152 //////////////////////////////////////////////////////////////////////////////
153 // CBotProfileHeal //
154 //////////////////////////////////////////////////////////////////////////////
156 /// Generic fight profile class
157 class CBotProfileHeal
158 : public CBotProfileFightHeal
161 /// @name Constructors, destructor
163 CBotProfileHeal(TDataSetRow
const& row
, CProfileOwner
* owner
);
164 virtual ~CBotProfileHeal();
167 /// @name Event handlers
169 // virtual void eventBeginFight() = 0;
170 virtual void eventTargetKilled() { nlwarning("eventTargetKilled called on a heal profile"); }
173 /// @name IAIProfile implementation
175 virtual void beginProfile();
176 virtual void resumeProfile();
177 virtual void endProfile();
178 virtual void updateProfile(uint ticksSinceLastUpdate
);
179 virtual std::string
getOneLineInfoString() const;
182 virtual void noMoreTarget() = 0;
187 bool isHitting() const { return (_Bot
->getActionFlags()&RYZOMACTIONFLAGS::Attacks
)!=0; }
188 bool atAttackDist() const { return _AtAttackDist
; }
189 virtual AITYPES::TProfiles
getAIProfileType() const { return AITYPES::BOT_HEAL
; }
193 NLMISC::CDbgPtr
<CSpawnBot
> _Bot
;
197 CPathPosition _PathPos
;
201 bool _RangeCalculated
;
202 bool _UseFightConfig
;
208 bool _SearchAlternativePath
;
211 //////////////////////////////////////////////////////////////////////////////
212 // CBotProfileFlee //
213 //////////////////////////////////////////////////////////////////////////////
215 class CBotProfileFlee
216 : public CAIBaseProfile
219 /// @name Constructor and destructor
221 CBotProfileFlee(CProfileOwner
*owner
);
222 virtual ~CBotProfileFlee();
225 /// @name IAIProfile implementation
227 virtual void beginProfile();
228 virtual void updateProfile(uint ticksSinceLastUpdate
);
229 virtual void endProfile() { }
230 virtual AITYPES::TProfiles
getAIProfileType () const { return AITYPES::BOT_FLEE
; }
231 virtual std::string
getOneLineInfoString() const;
235 RYAI_MAP_CRUNCH::CDirection _LastDir
;
236 RYAI_MAP_CRUNCH::CMapPosition _LastStartPos
;
238 RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags
;
240 CPathPosition _PathPos
;
241 CPathCont _fightFleePathContainer
;
244 /// @name Flee ranges/distances parameters
246 static float giveUpDistanceUnreachable
;
250 NLMISC::CDbgPtr
<CSpawnBot
> _Bot
;
253 //////////////////////////////////////////////////////////////////////////////
254 // CBotProfileReturnAfterFight //
255 //////////////////////////////////////////////////////////////////////////////
257 class CBotProfileFollowPos
;
259 class CBotProfileReturnAfterFight
260 : public CAIBaseProfile
263 /// @name Constructor and destructor
265 CBotProfileReturnAfterFight(CProfileOwner
*owner
);
266 virtual ~CBotProfileReturnAfterFight();
269 /// @name IAIProfile implementation
271 virtual void beginProfile();
272 virtual void updateProfile(uint ticksSinceLastUpdate
);
273 virtual void endProfile();
274 virtual AITYPES::TProfiles
getAIProfileType () const { return AITYPES::BOT_RETURN_AFTER_FIGHT
; }
275 virtual std::string
getOneLineInfoString() const;
276 virtual void stateChangeProfile();
281 RYAI_MAP_CRUNCH::CDirection _LastDir;
282 RYAI_MAP_CRUNCH::CMapPosition _LastStartPos;
284 RYAI_MAP_CRUNCH::TAStarFlag _DenyFlags;
286 CPathPosition _PathPos;
287 CPathCont _fightFleePathContainer;
289 // CPathCont _PathCont;
290 // NLMISC::CSmartPtr<CBotProfileFollowPos> _MoveProfile;
293 /// @name Flee ranges/distances parameters
295 // static float giveUpDistanceUnreachable;
299 NLMISC::CDbgPtr
<CSpawnBot
> _Bot
;
302 //////////////////////////////////////////////////////////////////////////////
303 // CFightOrganizer //
304 //////////////////////////////////////////////////////////////////////////////
306 class CFightOrganizer
311 template <class TContainerIterator
>
312 void reorganize(TContainerIterator
const& first
, TContainerIterator
const& last
)
314 H_AUTO(CFightOrganizer_reorganize
);
317 for (TContainerIterator it
=first
, itEnd
=last
;it
!=itEnd
;++it
)
320 if (!reorganizeIteration(bot
))
325 /// @name Virtual interface
327 virtual void setFight(CSpawnBot
* bot
, CAIEntityPhysical
* ennemy
) = 0;
328 virtual void setHeal(CSpawnBot
* bot
, CAIEntityPhysical
* target
) = 0;
329 virtual void setNoFight(CSpawnBot
* bot
) = 0;
330 virtual void setFlee(CSpawnBot
* bot
, CAIVector
& fleeVect
) = 0;
331 virtual void setReturnAfterFight(CSpawnBot
* bot
) = 0;
335 bool healIteration(CBot
* bot
, CBot
* otherBot
);
336 bool reorganizeIteration(CBot
* bot
);
342 /****************************************************************************/
343 /* Profile factories */
344 /****************************************************************************/
346 //////////////////////////////////////////////////////////////////////////////
347 // CBotProfileFightFactory //
348 //////////////////////////////////////////////////////////////////////////////
350 class CBotProfileFightFactory
351 : public IAIProfileFactory
354 NLMISC::CSmartPtr
<IAIProfile
> createAIProfile(CProfileOwner
* owner
)
360 RYAI_DECLARE_PROFILE_FACTORY(CBotProfileFightFactory
);
362 //////////////////////////////////////////////////////////////////////////////
363 // CBotProfileFleeFactory //
364 //////////////////////////////////////////////////////////////////////////////
366 class CBotProfileFleeFactory
367 : public IAIProfileFactory
370 NLMISC::CSmartPtr
<IAIProfile
> createAIProfile(CProfileOwner
* owner
)
376 RYAI_DECLARE_PROFILE_FACTORY(CBotProfileFleeFactory
);