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/>.
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
))
36 CFxEntity::~CFxEntity()
40 bool CFxEntity::spawn()
43 if (!CMirrors::createEntity(_EntityId
).isValid())
45 _DataSetRow
= TheDataset
.getDataSetRow(_EntityId
);
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());
59 md
.setModeAndPos( MBEHAV::NORMAL
, _DataSetRow
);
60 CMirrorPropValue
<MBEHAV::TMode
> mode( TheDataset
, _DataSetRow
, DSPropertyMODE
);
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
);
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));
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
92 std::string
CFxEntity::get(std::string
const& prop
)
95 return _Sheet
.toString();
96 else if (prop
=="position")
97 return _Pos
.toString();
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
);