Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_aggro.h
blob07081ef5dc5d7d367d63b1c7f9e49f4eb7ba0225
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 AI_AGGRO_H
18 #define AI_AGGRO_H
20 #include "timer.h"
21 #include "ai.h"
22 #include "ai_place.h"
24 class CBotAggroOwner;
25 class CAIEntityPhysical;
27 //////////////////////////////////////////////////////////////////////////////
28 // CBotAggroEntry //
29 //////////////////////////////////////////////////////////////////////////////
31 /** A pair of aggro/entity values.
33 * Aggro values are between 0 and 1. 0 means no aggro, 1 means full aggro.
35 class CBotAggroEntry
36 : public NLMISC::CRefCount
38 public:
39 CBotAggroEntry(TDataSetRow const& bot, float aggro, CBotAggroOwner const& owner, NLMISC::CSmartPtr<CAIPlace const> place = NLMISC::CSmartPtr<CAIPlace const>(NULL));
40 virtual ~CBotAggroEntry();
42 float finalAggro() const { return _Aggro; }
44 void addAggro(float aggro, NLMISC::CSmartPtr<CAIPlace const> place = NLMISC::CSmartPtr<CAIPlace const>(NULL));
45 void decrementAggros(uint32 ticks);
47 bool updateTime(uint32 const& ticks) const;
49 TDataSetRow const& getBot() const { return _Bot; }
50 NLMISC::CSmartPtr<CAIPlace const> getLastHitPlace() const { return _LastHitPlace; }
52 void setMinimum(float aggro, NLMISC::CSmartPtr<CAIPlace const> place = NLMISC::CSmartPtr<CAIPlace const>(NULL));
53 void setMaximum(float aggro);
55 void scaleBy(float const& scale) { _Aggro *= scale; }
57 void operator=(CBotAggroEntry const& other);
59 virtual bool atPlace(CAIVector const& pos) const { if (_LastHitPlace) return _LastHitPlace->atPlace(pos); else return true; }
60 virtual bool atPlace(CAIVectorMirror const& pos) const { if (_LastHitPlace) return _LastHitPlace->atPlace(pos); else return true; }
61 virtual bool atPlace(CAIEntityPhysical const* entity) const { if (_LastHitPlace) return _LastHitPlace->atPlace(entity); else return true; }
63 private:
64 CBotAggroOwner const& _Owner;
65 TDataSetRow _Bot;
66 float _Aggro;
67 NLMISC::CSmartPtr<CAIPlace const> _LastHitPlace;
70 //////////////////////////////////////////////////////////////////////////////
71 // CBotAggroOwner //
72 //////////////////////////////////////////////////////////////////////////////
74 class CBotAggroOwner
76 public:
77 typedef NLMISC::CSmartPtr<CBotAggroEntry> TAggroEntryPtr;
78 typedef std::map<TDataSetRow, TAggroEntryPtr> TBotAggroList;
80 public:
81 CBotAggroOwner();
82 virtual ~CBotAggroOwner();
84 static bool isAggroable(TDataSetRow const& dataSetRow);
86 void update(uint32 ticks);
88 /// @name Management of an aggro entry
89 //@{
90 /// Command used by fight script only
91 void blockAggro(sint32 blockTime);
92 void ignoreReturnAggro(bool ignored);
93 virtual void maximizeAggroFor(TDataSetRow const& botRow);
94 /// Command used by fight script only
95 void minimizeAggroFor(TDataSetRow const& botRow);
96 void addAggroFor(TDataSetRow const& bot, float aggro, bool forceReturnAggro, NLMISC::CSmartPtr<CAIPlace const> place = NLMISC::CSmartPtr<CAIPlace const>(NULL), bool transferAggro = true);
97 // Sets the minimum value the aggro can have in [0;1]
98 void setAggroMinimumFor(TDataSetRow const& bot, float aggro, bool forceReturnAggro, NLMISC::CSmartPtr<CAIPlace const> place = NLMISC::CSmartPtr<CAIPlace const>(NULL), bool transferAggro = true);
99 void forgetAggroFor(TDataSetRow const& bot, bool forgetDamages = false);
100 bool isAggroValid(TDataSetRow const& bot);
101 bool isNewAggroValid(TDataSetRow const& bot);
102 bool haveAggro() const { return !_BotAggroList.empty(); }
103 bool haveAggroWithEntity(const TDataSetRow& rowId) const;
104 bool haveAggroOrReturnPlace() const { return haveAggro() || _FirstHitPlace!=NULL; }
105 virtual RYAI_MAP_CRUNCH::CWorldPosition getAggroPos() const;
106 virtual NLMISC::CEntityId getAggroOwnerEid() const;
107 virtual NLMISC::CSmartPtr<CAIPlace const> buildFirstHitPlace(TDataSetRow const& aggroBot) const;
108 virtual std::set<CBotAggroOwner*> getAggroGroup(bool primary) const { return std::set<CBotAggroOwner*>(); }
109 virtual void propagateAggro() const { }
111 virtual float getReturnDistCheck() const;
112 virtual float getD1Radius() const;
113 virtual float getD2Radius() const;
114 virtual float getPrimaryGroupAggroDist() const;
115 virtual float getPrimaryGroupAggroCoef() const;
116 virtual float getSecondaryGroupAggroDist() const;
117 virtual float getSecondaryGroupAggroCoef() const;
118 virtual float getAggroPropagationRadius() const;
119 //@}
121 float getAggroFor(TDataSetRow const& bot);
123 /// Used by CSpawnBotFauna for assist only
124 bool hasBeenHit(uint32 ticks) const;
126 /// Used by group fight profile only
127 /// merge all the aggro value from the other aggro list into this aggro list
128 void mergeAggroList(CBotAggroOwner const& otherList, float scale);
130 void updateListAndMarkBot(std::vector<CAIEntityPhysical*>& botList, float coef);
132 void setCanAggro(bool canAggro);
134 bool getSendAggroLostToEGS() const { return _SendAggroLostToEGS; }
136 /// @name Accessors
137 //@{
138 TBotAggroList const& getBotAggroList() const { return _BotAggroList; }
139 void clearAggroList(bool sendMessageToEGS = true);
140 bool isReturning() const { return _BotAggroList.empty() && _FirstHitPlace; }
141 RYAI_MAP_CRUNCH::CWorldPosition getReturnPos() const { return _ReturnPos; }
142 //@}
144 /// @name Event handlers
145 //@{
146 virtual void aggroLost(TDataSetRow const& aggroBot) const = 0;
147 virtual void aggroGain(TDataSetRow const& aggroBot) const = 0;
148 //@}
150 private:
151 virtual bool atPlace(CAIVector const& pos) const { if (_FirstHitPlace) return _FirstHitPlace->atPlace(pos); else return true; }
152 virtual bool atPlace(CAIVectorMirror const& pos) const { if (_FirstHitPlace) return _FirstHitPlace->atPlace(pos); else return true; }
153 virtual bool atPlace(CAIEntityPhysical const* entity) const { if (_FirstHitPlace) return _FirstHitPlace->atPlace(entity); else return true; }
155 private:
156 TBotAggroList _BotAggroList;
157 uint32 _LastHitTime;
158 bool _AggroBlocked;
159 bool _ReturnAggroIgnored;
160 bool _DontAggro;
161 bool _SendAggroLostToEGS;
162 CAITimer _AggroBlockTimer;
163 RYAI_MAP_CRUNCH::CWorldPosition _ReturnPos;
164 NLMISC::CSmartPtr<CAIPlace const> _FirstHitPlace;
167 #endif