Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / fx_entity.cpp
blob8b2dc8c371535480cfaf0005916f5cd229ea15c4
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 #include "stdpch.h"
19 #include "fx_entity.h"
20 #include "ai_instance.h"
21 #include "game_share/ryzom_entity_id.h"
22 #include "ai_grp_npc.h"
23 #include "server_share/r2_variables.h"
24 #include "server_share/r2_vision.h"
26 using namespace MULTI_LINE_FORMATER;
28 CFxEntity::CFxEntity(CAIPos const& pos, NLMISC::CSheetId const& sheet)
29 : _EntityId(NLMISC::CEntityId::getNewEntityId(RYZOMID::fx_entity))
30 , _DataSetRow()
31 , _Pos(pos)
32 , _Sheet(sheet)
36 CFxEntity::~CFxEntity()
40 bool CFxEntity::spawn()
42 // Add into mirror
43 if (!CMirrors::createEntity(_EntityId).isValid())
44 return false;
45 _DataSetRow = TheDataset.getDataSetRow(_EntityId);
47 // Set the sheet id
48 CMirrorPropValue<TYPE_SHEET> sheetMirror( TheDataset, _DataSetRow, DSPropertySHEET );
49 sheetMirror = _Sheet.asInt();
51 // Set the initial position
52 CMirrorPropValue<TYPE_POSX> posX( TheDataset, _DataSetRow, DSPropertyPOSX );
53 CMirrorPropValue<TYPE_POSY> posY( TheDataset, _DataSetRow, DSPropertyPOSY );
54 posX = (TYPE_POSX)(_Pos.x().asInt());
55 posY = (TYPE_POSY)(_Pos.y().asInt());
57 // Set the mode
58 MBEHAV::TMode md;
59 md.setModeAndPos( MBEHAV::NORMAL, _DataSetRow );
60 CMirrorPropValue<MBEHAV::TMode> mode( TheDataset, _DataSetRow, DSPropertyMODE );
61 mode = md;
63 // Set the WhoSeesMe bitfield (every bit set to 1)
64 const uint64 bitfield = IsRingShard? R2_VISION::buildWhoSeesMe(R2_VISION::VISIBLE, true): UINT64_CONSTANT(0xffffffffffffffff);
65 CMirrorPropValue<TYPE_WHO_SEES_ME> whoSeesMe(TheDataset, _DataSetRow, DSPropertyWHO_SEES_ME );
66 whoSeesMe = bitfield;
68 // Contextual properties init
69 CMirrorPropValue<TYPE_CONTEXTUAL> contextualProperties(TheDataset, _DataSetRow, DSPropertyCONTEXTUAL );
70 contextualProperties = 0;
72 CMirrors::declareEntity( _DataSetRow );
74 CFxEntityManager::getInstance()->registerEntity(CFxEntityPtr(this));
76 return true;
79 void CFxEntity::despawn()
81 CFxEntityManager::getInstance()->unregisterEntity(CFxEntityPtr(this));
83 if (_DataSetRow.isValid())
84 CMirrors::removeEntity(_EntityId);
87 NLMISC::CEntityId const& CFxEntity::id() const
89 return _EntityId;
92 std::string CFxEntity::get(std::string const& prop)
94 if (prop=="sheet")
95 return _Sheet.toString();
96 else if (prop=="position")
97 return _Pos.toString();
98 else
99 nlwarning("Trying to get a bad property ('%s') on fx entity '%s'", prop.c_str(), _EntityId.toString().c_str());
100 return std::string();
103 std::string CFxEntity::getOneLineInfoString() const
105 return "FxEntity eid=" + _EntityId.toString() + " sheet=" + _Sheet.toString() + " x=" + NLMISC::toString(_Pos.x()) + " y=" + NLMISC::toString(_Pos.x());
108 std::vector<std::string> CFxEntity::getMultiLineInfoString() const
110 std::vector<std::string> container;
113 pushTitle(container, "CFxEntity");
114 pushEntry(container, "eid=" + _EntityId.toString());
115 container.back() += " sheet=" + _Sheet.toString();
116 pushFooter(container);
119 return container;