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/>.
22 #include "ai_share/ai_coord.h"
23 #include "nel/misc/sheet_id.h"
33 #pragma warning (disable : 4355)
34 #endif // NL_OS_WINDOWS
36 //////////////////////////////////////////////////////////////////////////////
38 //////////////////////////////////////////////////////////////////////////////
40 // Player is considered as both a persistent and a spawned entity (philosophycally, the spawning process is part of the client).
42 : public NLMISC::CDbgRefCount
<CBotPlayer
>
43 , public CChild
<CManagerPlayer
>
45 , public CAIEntityPhysical
46 , public CPersistentOfPhysical
49 CBotPlayer(CManagerPlayer
* owner
, TDataSetRow
const& dataSetRow
, NLMISC::CEntityId
const& id
, uint32 level
);
50 virtual ~CBotPlayer();
52 /// @name CChild implementation
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;
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; }
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. (!?).
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;
114 static bool useOldUnreachable
;
117 uint16 _CurrentTeamId
;
119 bool _PlayerPosIsInvalid
;
121 std::vector
<TDataSetRow
> _AggroerList
;
122 std::set
<uint32
> _InsideTriggerZones
;
123 AISHEETS::IRaceStatsCPtr _Sheet
;
126 //////////////////////////////////////////////////////////////////////////////
128 //////////////////////////////////////////////////////////////////////////////
131 : public CCont
<CBotPlayer
>
132 , public CChild
<CAIInstance
>
135 typedef CHashMap
<TDataSetRow
, NLMISC::CDbgPtr
<CBotPlayer
>, TDataSetRow::CHashCode
> TPlayerMap
;
138 CManagerPlayer(CAIInstance
* owner
)
139 : CChild
<CAIInstance
>(owner
)
143 virtual ~CManagerPlayer();
145 CAIInstance
* getAIInstance() const
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.
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
;
178 TPlayerMap _spawnedPlayers
; // hum .. still useful ?
179 /// Team composition.
180 typedef CHashMap
<int, std::set
<TDataSetRow
> > TTeamMap
;
184 static std::set
<TDataSetRow
> emptySet
;