1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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/>.
24 #include "animal_position_state.h"
25 #include "../entities.h"
26 #include "interface_manager.h"
27 #include "group_compas.h"
28 #include "game_share/animal_status.h"
30 using NLMISC::CCDBNodeLeaf
;
32 // ***************************************************************************
34 // ***************************************************************************
38 // ***************************************************************************
39 bool CPositionState::getPos(sint32
&px
, sint32
&py
)
41 // only if the animal is spawned
44 CEntityCL
*entity
= getEntity();
45 // If the entity is not in vision, take Database position
48 return getDbPos(px
, py
);
50 // else take VisualProp more precise position
53 px
= (sint32
)((float)entity
->lastFramePos().x
* 1000);
54 py
= (sint32
)((float)entity
->lastFramePos().y
* 1000);
67 // ***************************************************************************
68 void CPositionState::serialNodeLeaf(NLMISC::IStream
&f
, CCDBNodeLeaf
*&dbNode
)
70 f
.serialCheck(NELID("NL__"));
79 CInterfaceManager
*im
= CInterfaceManager::getInstance();
80 dbNode
= NLGUI::CDBManager::getInstance()->getDbProp(dbPath
, false);
87 dbPath
= dbNode
->getFullName();
91 f
.serialCheck(NELID("END_"));
95 // ***************************************************************************
96 void CUIDEntityPositionState::serial(NLMISC::IStream
&f
)
98 f
.serialCheck(NELID("UIDE"));
100 serialNodeLeaf(f
, _DBPos
);
101 serialNodeLeaf(f
, _Uid
);
102 f
.serialCheck(NELID("_END"));
105 // ***************************************************************************
106 CEntityCL
*CUIDEntityPositionState::getEntity()
108 if (!dbOk()) return NULL
;
109 CLFECOMMON::TClientDataSetIndex uid
= _Uid
->getValue32();
110 // If the _EntitySlot is not set, try to acquire the animal in vision.
111 if(_EntitySlot
== CLFECOMMON::INVALID_SLOT
)
114 CEntityCL
*entity
= EntitiesMngr
.getEntityByCompressedIndex(uid
);
115 // the entity position must be valid, else don't take it.
116 if((entity
!= NULL
) && entity
->firstPositionReceived())
117 _EntitySlot
= entity
->slot();
120 // else check that the cache slot is OK with this UID
124 CEntityCL
*entity
= EntitiesMngr
.entity(_EntitySlot
);
125 // Is data slot changed ? animal no more in vision -> try to acquire it at next pass
126 if((entity
== NULL
) || ((entity
!= NULL
) && (entity
->dataSetId() != uid
)))
127 _EntitySlot
= CLFECOMMON::INVALID_SLOT
;
129 CEntityCL
*entity
= EntitiesMngr
.entity(_EntitySlot
);
134 // ***************************************************************************
135 bool CUIDEntityPositionState::getDbPos(sint32
&px
, sint32
&py
)
137 if (!dbOk()) return false;
138 px
= (sint32
) (_DBPos
->getValue64() >> 32);
139 py
= _DBPos
->getValue32();
144 // ***************************************************************************
145 // CUIDEntityPositionState
146 // ***************************************************************************
149 // ***************************************************************************
150 CUIDEntityPositionState::CUIDEntityPositionState()
154 _EntitySlot
= CLFECOMMON::INVALID_SLOT
;
157 // ***************************************************************************
158 void CUIDEntityPositionState::build(const std::string
&baseDB
)
160 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
162 _DBPos
= NLGUI::CDBManager::getInstance()->getDbProp(baseDB
+":POS", false);
163 _Uid
= NLGUI::CDBManager::getInstance()->getDbProp(baseDB
+":UID", false);
165 _EntitySlot
= CLFECOMMON::INVALID_SLOT
;
168 // ***************************************************************************
169 // CTeammatePositionState
170 // ***************************************************************************
172 // ***************************************************************************
173 CTeammatePositionState::CTeammatePositionState() : CUIDEntityPositionState()
179 // ***************************************************************************
180 void CTeammatePositionState::build(const std::string
&baseDB
)
182 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
183 _Present
= NLGUI::CDBManager::getInstance()->getDbProp(baseDB
+":NAME", false);
185 CUIDEntityPositionState::build(baseDB
);
189 // ***************************************************************************
190 bool CTeammatePositionState::getPos(sint32
&px
, sint32
&py
)
193 CEntityCL
*entity
= getEntity();
195 // only if the animal is spawned
196 if( dbOk() && (_Present
->getValue32() != 0))
198 return CPositionState::getPos(px
, py
);
208 // ***************************************************************************
209 // CAnimalPositionState
210 // ***************************************************************************
212 // ***************************************************************************
213 CAnimalPositionState::CAnimalPositionState() : CUIDEntityPositionState()
219 // ***************************************************************************
220 void CAnimalPositionState::build(const std::string
&baseDB
)
222 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
223 _Status
= NLGUI::CDBManager::getInstance()->getDbProp(baseDB
+":STATUS", false);
225 CUIDEntityPositionState::build(baseDB
);
229 // ***************************************************************************
230 bool CAnimalPositionState::getPos(sint32
&px
, sint32
&py
)
232 // only if the animal is spawned
233 if( dbOk() && ANIMAL_STATUS::isSpawned((ANIMAL_STATUS::EAnimalStatus
)_Status
->getValue32()))
235 return CPositionState::getPos(px
, py
);
244 // ***************************************************************************
245 void CAnimalPositionState::serial(NLMISC::IStream
&f
)
247 f
.serialCheck(NELID("APS_"));
249 CUIDEntityPositionState::serial(f
);
250 serialNodeLeaf(f
, _Status
);
251 f
.serialCheck(NELID("END_"));
255 // ***************************************************************************
256 // CNamedEntityPositionState
257 // ***************************************************************************
260 // ***************************************************************************
261 CEntityCL
*CNamedEntityPositionState::getEntity()
263 if (!dbOk()) return NULL
;
264 return EntitiesMngr
.getEntityByName(_Name
->getValue32());
267 // ***************************************************************************
268 bool CNamedEntityPositionState::getDbPos(sint32
&px
, sint32
&py
)
270 if (!dbOk()) return false;
271 px
= _X
->getValue32();
272 py
= _Y
->getValue32();
276 // ***************************************************************************
277 void CNamedEntityPositionState::build(CCDBNodeLeaf
*name
, CCDBNodeLeaf
*x
, CCDBNodeLeaf
*y
)
285 // ***************************************************************************
286 CEntityCL
*CDialogEntityPositionState::getEntity()
288 if ( CCompassDialogsManager::getInstance().getEntries().size() >= _DialogIndex
)
290 return EntitiesMngr
.getEntityByName(CCompassDialogsManager::getInstance().getEntries()[_DialogIndex
].Text
);
293 bool CDialogEntityPositionState::getDbPos(sint32
&px
, sint32
&py
)
295 if ( CCompassDialogsManager::getInstance().getEntries().size() < _DialogIndex
)
297 px
= CCompassDialogsManager::getInstance().getEntries()[_DialogIndex
].X
;
298 py
= CCompassDialogsManager::getInstance().getEntries()[_DialogIndex
].Y
;
302 // ***************************************************************************
303 void CNamedEntityPositionState::serial(NLMISC::IStream
&f
)
305 f
.serialCheck(NELID("NEPS"));
307 serialNodeLeaf(f
, _Name
);
308 serialNodeLeaf(f
, _X
);
309 serialNodeLeaf(f
, _Y
);
310 f
.serialCheck(NELID("END_"));