Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / animal_position_state.h
blob61abddafc0dbf110d1f60611992576c2d9230e9b
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef NL_ANIMAL_POSITION_STATE_H
23 #define NL_ANIMAL_POSITION_STATE_H
25 #include "nel/misc/types_nl.h"
26 #include "nel/misc/smart_ptr.h"
27 #include "nel/misc/class_registry.h"
28 #include "game_share/entity_types.h"
31 // ***************************************************************************
32 namespace NLMISC{
33 class CCDBNodeLeaf;
36 // ***************************************************************************
37 /**
38 * A class used to retrieve position of some entities like animals or team mates
39 * The best position is returned: if entity in vision, its pos is returned, else take from Database
40 * \author Matthieu Besson
41 * \author Nevrax France
42 * \date February 2003
44 class CPositionState : public NLMISC::CRefCount, public NLMISC::IStreamable
46 public:
47 virtual ~CPositionState() {}
50 /** From DB/EntityMngr, get the accurate entity position (*1000).
51 * 0 and return false, if error or if the animal no more present
53 bool getPos(sint32 &px, sint32 &py);
55 // serial supported ?
56 virtual bool canSave() const = 0;
58 protected:
59 virtual bool dbOk() = 0;
60 // if an entity is available, get it for more precise localisation
61 virtual class CEntityCL *getEntity() = 0;
62 // if no entity is available, then can retrieve less precise position from database
63 virtual bool getDbPos(sint32 &px, sint32 &py) = 0;
65 // helper to serial a CDBNodeLeaf, based on itsname
66 void serialNodeLeaf(NLMISC::IStream &f, NLMISC::CCDBNodeLeaf *&dbNode);
70 // ***************************************************************************
71 /**
72 * Implementation of CPositionState for an entity that is identified by its compressed uid
73 * \author Nicolas Vizerie
74 * \author Nevrax France
75 * \date 2004
77 class CUIDEntityPositionState : public CPositionState
79 public:
80 CUIDEntityPositionState();
81 virtual bool dbOk() {return _DBPos && _Uid;}
82 /// get the DB states related to the animal
83 void build(const std::string &baseDB);
84 // try to retrieve current tracked pos
85 bool getPos(sint32 &px, sint32 &py);
87 virtual void serial(NLMISC::IStream &f);
88 protected:
89 // Database infos
90 NLMISC::CCDBNodeLeaf *_DBPos;
91 NLMISC::CCDBNodeLeaf *_Uid;
92 // The slot of the entity that may be used to get more precise position
93 CLFECOMMON::TCLEntityId _EntitySlot;
94 virtual CEntityCL *getEntity();
95 virtual bool getDbPos(sint32 &px, sint32 &py);
99 // ***************************************************************************
101 * Implementation of CPositionState for an entity that is identified by its name (encoded as a dynamic string id in db)
102 * \author Nicolas Vizerie
103 * \author Nevrax France
104 * \date 2004
106 class CNamedEntityPositionState : public CPositionState
108 public:
109 NLMISC_DECLARE_CLASS(CNamedEntityPositionState)
110 virtual bool dbOk() {return _Name && _X && _Y;}
111 void build(NLMISC::CCDBNodeLeaf *name, NLMISC::CCDBNodeLeaf *x, NLMISC::CCDBNodeLeaf *y);
112 NLMISC::CCDBNodeLeaf *getNameNode() const { return _Name; }
113 NLMISC::CCDBNodeLeaf *getXNode() const { return _X; }
114 NLMISC::CCDBNodeLeaf *getYNode() const { return _X; }
116 virtual bool canSave() const { return true; }
117 virtual void serial(NLMISC::IStream &f);
118 protected:
119 // Database infos
120 NLMISC::CCDBNodeLeaf *_Name;
121 NLMISC::CCDBNodeLeaf *_X;
122 NLMISC::CCDBNodeLeaf *_Y;
123 virtual CEntityCL *getEntity();
124 virtual bool getDbPos(sint32 &px, sint32 &py);
128 // ***************************************************************************
130 * A class used to retrieve position of some entities like animals or team mates
131 * The best position is returned: if entity in vision, its pos is returned, else take from Database
132 * \author Matthieu Besson
133 * \author Nevrax France
134 * \date February 2003
136 class CTeammatePositionState : public CUIDEntityPositionState
138 public:
139 NLMISC_DECLARE_CLASS(CTeammatePositionState)
140 /// Constructor
141 CTeammatePositionState();
143 /// get the DB states related to the animal
144 void build(const std::string &baseDB);
146 /** From DB/EntityMngr, get the accurate entity position (*1000).
147 * 0 and return false, if error or if the animal no more present
149 bool getPos(sint32 &px, sint32 &py);
151 virtual bool canSave() const { return false; }
153 virtual void serial(NLMISC::IStream &/* f */) { nlassert(0); /* notsavable */ }
154 protected:
155 // Database infos
156 NLMISC::CCDBNodeLeaf *_Present;
157 // DB ok.
158 bool dbOk() {return _DBPos && _Present && _Uid;}
162 // ***************************************************************************
164 * A class used to retrieve position of the Steed or of a PackAnimal.
165 * The best position is returned: if entity in vision, its pos is returned, else take from Database
166 * \author Lionel Berenguier
167 * \author Nevrax France
168 * \date 2003
170 class CAnimalPositionState : public CUIDEntityPositionState
172 public:
173 NLMISC_DECLARE_CLASS(CAnimalPositionState)
174 /// Constructor
175 CAnimalPositionState();
177 /// get the DB states related to the animal
178 void build(const std::string &baseDB);
180 /** From DB/EntityMngr, get the accurate entity position (*1000).
181 * 0 and return false, if error or if the animal no more present
183 bool getPos(sint32 &px, sint32 &py);
185 virtual bool canSave() const { return true; }
186 virtual void serial(NLMISC::IStream &f);
188 private:
189 // Animal Database infos
190 NLMISC::CCDBNodeLeaf *_Status;
191 // DB ok.
192 bool dbOk() {return _DBPos && _Status && _Uid;}
197 // ***************************************************************************
199 * A class used to retrieve position of some entities sent by server as "compass dialog"
200 * The best position is returned: if entity in vision, its pos is returned, else take from Database
201 * \author Matthieu Besson
202 * \author Nevrax France
203 * \date February 2003
205 class CDialogEntityPositionState : public CPositionState
207 public:
208 NLMISC_DECLARE_CLASS(CDialogEntityPositionState)
209 CDialogEntityPositionState(uint dialogIndex = 0)
210 :CPositionState(),_DialogIndex(dialogIndex){}
211 virtual bool dbOk() {return true;}
213 virtual bool canSave() const { return false; }
215 virtual void serial(NLMISC::IStream &/* f */) { nlassert(0); /* notsavable */ }
217 protected:
218 uint _DialogIndex;
219 virtual CEntityCL *getEntity();
220 virtual bool getDbPos(sint32 &px, sint32 &py);
222 #endif // NL_ANIMAL_POSITION_STATE_H
224 /* End of animal_position_state.h */