Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_player.h
blob69bd14ffc085cf42205448f909961ad28323b701
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/>.
19 #ifndef AI_PLAYER_H
20 #define AI_PLAYER_H
22 #include "ai_share/ai_coord.h"
23 #include "nel/misc/sheet_id.h"
24 #include "ai.h"
25 #include "ai_bot.h"
26 #include "owners.h"
28 class CFauna;
32 #ifdef NL_OS_WINDOWS
33 #pragma warning (disable : 4355)
34 #endif // NL_OS_WINDOWS
36 //////////////////////////////////////////////////////////////////////////////
37 // CBotPlayer //
38 //////////////////////////////////////////////////////////////////////////////
40 // Player is considered as both a persistent and a spawned entity (philosophycally, the spawning process is part of the client).
41 class CBotPlayer
42 : public NLMISC::CDbgRefCount<CBotPlayer>
43 , public CChild<CManagerPlayer>
44 , public CPetOwner
45 , public CAIEntityPhysical
46 , public CPersistentOfPhysical
48 public:
49 CBotPlayer(CManagerPlayer* owner, TDataSetRow const& dataSetRow, NLMISC::CEntityId const& id, uint32 level);
50 virtual ~CBotPlayer();
52 /// @name CChild implementation
53 //@{
54 virtual std::string getIndexString() const;
55 virtual std::string getEntityIdString() const;
56 virtual std::string getOneLineInfoString() const;
57 std::vector<std::string> getMultiLineInfoString() const;
58 //@}
60 CAIInstance* getAIInstance() const;
62 void setAggroable(bool aggroable = true) { _Aggroable = aggroable; }
63 bool isAggroable() const { return _Aggroable; }
65 // player are always attackable (this is a IA point of view, it mean that IA can attack player)
66 virtual bool isBotAttackable() const { return true; }
68 virtual bool spawn();
69 void despawnBot();
71 void update();
73 // update the pos and link of player (if the position is valid, otherwise, no move are done)
74 // perhaps should we invalidate the player worldPosition. (!?).
75 void updatePos();
76 virtual CAIPos aipos() const;
78 void setTarget(CAIEntityPhysical* target) { CTargetable<CAIEntityPhysical>::setTarget(target); }
79 void setVisualTarget(CAIEntityPhysical* target) { CTargetable<CAIEntityPhysical>::setVisualTarget(target); }
81 bool isUnReachable() const;
83 bool setPos(CAIPos const& pos);
85 float walkSpeed() const;
86 float runSpeed() const;
88 CAIEntityPhysical& getPhysical() { return *this; }
90 virtual RYZOMID::TTypeId getRyzomType() const { return RYZOMID::player; }
92 bool isAggressive() const;
94 void processEvent(const CCombatInterface::CEvent &);
96 uint16 getCurrentTeamId() const { return _CurrentTeamId;}
97 void setCurrentTeamId(uint16 teamId) { _CurrentTeamId = teamId;}
99 bool getFollowMode() const { return _FollowMode; }
100 void setFollowMode(bool followMode) { _FollowMode = followMode; }
102 void addAggroer(TDataSetRow const& row);
104 void removeAggroer(TDataSetRow const& row);
106 void forgotAggroForAggroer();
107 /// Updates the reference to zone in which the player is that can trigger event (on enter, on leave)
108 void updateInsideTriggerZones(const std::set<uint32>& newInsideTriggerZone, std::vector<uint32>& onEnterZone, std::vector<uint32>& onLeaveZone);
110 virtual sint32 getFame(std::string const& faction, bool modulated = false, bool returnUnknowValue = false) const;
111 virtual sint32 getFameIndexed(uint32 factionIndex, bool modulated = false, bool returnUnknowValue = false) const;
113 public:
114 static bool useOldUnreachable;
116 private:
117 uint16 _CurrentTeamId;
118 bool _FollowMode;
119 bool _PlayerPosIsInvalid;
120 bool _Aggroable;
121 std::vector<TDataSetRow> _AggroerList;
122 std::set<uint32> _InsideTriggerZones;
123 AISHEETS::IRaceStatsCPtr _Sheet;
126 //////////////////////////////////////////////////////////////////////////////
127 // CManagerPlayer //
128 //////////////////////////////////////////////////////////////////////////////
130 class CManagerPlayer
131 : public CCont<CBotPlayer>
132 , public CChild<CAIInstance>
134 public:
135 typedef CHashMap<TDataSetRow, NLMISC::CDbgPtr<CBotPlayer>, TDataSetRow::CHashCode> TPlayerMap;
137 public:
138 CManagerPlayer(CAIInstance* owner)
139 : CChild<CAIInstance>(owner)
143 virtual ~CManagerPlayer();
145 CAIInstance* getAIInstance() const
147 return getOwner();
150 void addSpawnedPlayer(TDataSetRow const& dataSetRow, NLMISC::CEntityId const& id);
151 // Strict mean that the player MUST be in this manager (otherwise, the function log a warning)
152 void removeDespawnedPlayer(TDataSetRow const& dataSetRow);
153 /// Called when the team id value from mirror change.
154 void updatePlayerTeam(TDataSetRow const& dataSetRow);
156 // update the manager.
157 void update();
159 /// Return a set of player in the same team of the indicated player
160 std::set<TDataSetRow> const& getPlayerTeam(TDataSetRow const& playerRow);
161 /// Return a set of player in the specified team
162 std::set<TDataSetRow> const& getPlayerTeam(uint16 teamId);
164 /// Debug feature, build a set of currently active team.
165 void getTeamIds(std::vector<uint16>& teamIds);
167 std::string getIndexString() const
169 return getOwner()->getIndexString()+NLMISC::toString(":players");
172 TPlayerMap& playerList()
174 return _spawnedPlayers;
177 private:
178 TPlayerMap _spawnedPlayers; // hum .. still useful ?
179 /// Team composition.
180 typedef CHashMap<int, std::set<TDataSetRow> > TTeamMap;
181 TTeamMap _teams;
183 private:
184 static std::set<TDataSetRow> emptySet;
187 #endif