Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapReader.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#include "simulation2/components/ICmpCinemaManager.h" | #include "simulation2/components/ICmpCinemaManager.h" | ||||
#include "simulation2/components/ICmpGarrisonHolder.h" | #include "simulation2/components/ICmpGarrisonHolder.h" | ||||
#include "simulation2/components/ICmpObstruction.h" | #include "simulation2/components/ICmpObstruction.h" | ||||
#include "simulation2/components/ICmpOwnership.h" | #include "simulation2/components/ICmpOwnership.h" | ||||
#include "simulation2/components/ICmpPlayer.h" | #include "simulation2/components/ICmpPlayer.h" | ||||
#include "simulation2/components/ICmpPlayerManager.h" | #include "simulation2/components/ICmpPlayerManager.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
#include "simulation2/components/ICmpTurretHolder.h" | |||||
#include "simulation2/components/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
#include <boost/algorithm/string/predicate.hpp> | #include <boost/algorithm/string/predicate.hpp> | ||||
CMapReader::CMapReader() | CMapReader::CMapReader() | ||||
: xml_reader(0), m_PatchesPerSide(0), m_MapGen(0) | : xml_reader(0), m_PatchesPerSide(0), m_MapGen(0) | ||||
▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | private: | ||||
CMapReader& m_MapReader; | CMapReader& m_MapReader; | ||||
int el_entity; | int el_entity; | ||||
int el_tracks; | int el_tracks; | ||||
int el_template, el_player; | int el_template, el_player; | ||||
int el_position, el_orientation, el_obstruction; | int el_position, el_orientation, el_obstruction; | ||||
int el_garrison; | int el_garrison; | ||||
int el_turrets; | |||||
int el_actor; | int el_actor; | ||||
int at_x, at_y, at_z; | int at_x, at_y, at_z; | ||||
int at_group, at_group2; | int at_group, at_group2; | ||||
int at_angle; | int at_angle; | ||||
int at_uid; | int at_uid; | ||||
int at_seed; | int at_seed; | ||||
int at_turret; | |||||
XMBElementList nodes; // children of root | XMBElementList nodes; // children of root | ||||
// loop counters | // loop counters | ||||
size_t node_idx; | size_t node_idx; | ||||
size_t entity_idx; | size_t entity_idx; | ||||
// # entities+nonentities processed and total (for progress calc) | // # entities+nonentities processed and total (for progress calc) | ||||
Show All 28 Lines | |||||
#define EL(x) el_##x = xmb_file.GetElementID(#x) | #define EL(x) el_##x = xmb_file.GetElementID(#x) | ||||
#define AT(x) at_##x = xmb_file.GetAttributeID(#x) | #define AT(x) at_##x = xmb_file.GetAttributeID(#x) | ||||
EL(entity); | EL(entity); | ||||
EL(tracks); | EL(tracks); | ||||
EL(template); | EL(template); | ||||
EL(player); | EL(player); | ||||
EL(position); | EL(position); | ||||
EL(garrison); | EL(garrison); | ||||
EL(turrets); | |||||
EL(orientation); | EL(orientation); | ||||
EL(obstruction); | EL(obstruction); | ||||
EL(actor); | EL(actor); | ||||
AT(x); AT(y); AT(z); | AT(x); AT(y); AT(z); | ||||
AT(group); AT(group2); | AT(group); AT(group2); | ||||
AT(angle); | AT(angle); | ||||
AT(uid); | AT(uid); | ||||
AT(seed); | AT(seed); | ||||
AT(turret); | |||||
#undef AT | #undef AT | ||||
#undef EL | #undef EL | ||||
XMBElement root = xmb_file.GetRoot(); | XMBElement root = xmb_file.GetRoot(); | ||||
ENSURE(xmb_file.GetElementString(root.GetNodeName()) == "Scenario"); | ENSURE(xmb_file.GetElementString(root.GetNodeName()) == "Scenario"); | ||||
nodes = root.GetChildNodes(); | nodes = root.GetChildNodes(); | ||||
// find out total number of entities+nonentities | // find out total number of entities+nonentities | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | while (entity_idx < entities.size()) | ||||
XMBAttributeList attrs = entity.GetAttributes(); | XMBAttributeList attrs = entity.GetAttributes(); | ||||
CStr uid = attrs.GetNamedItem(at_uid); | CStr uid = attrs.GetNamedItem(at_uid); | ||||
ENSURE(!uid.empty()); | ENSURE(!uid.empty()); | ||||
int EntityUid = uid.ToInt(); | int EntityUid = uid.ToInt(); | ||||
CStrW TemplateName; | CStrW TemplateName; | ||||
int PlayerID = 0; | int PlayerID = 0; | ||||
std::vector<entity_id_t> Garrison; | std::vector<entity_id_t> Garrison; | ||||
std::vector<std::pair<std::string, entity_id_t> > Turrets; | |||||
CFixedVector3D Position; | CFixedVector3D Position; | ||||
CFixedVector3D Orientation; | CFixedVector3D Orientation; | ||||
long Seed = -1; | long Seed = -1; | ||||
// Obstruction control groups. | // Obstruction control groups. | ||||
entity_id_t ControlGroup = INVALID_ENTITY; | entity_id_t ControlGroup = INVALID_ENTITY; | ||||
entity_id_t ControlGroup2 = INVALID_ENTITY; | entity_id_t ControlGroup2 = INVALID_ENTITY; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | XERO_ITER_EL(entity, setting) | ||||
XMBElementList garrison = setting.GetChildNodes(); | XMBElementList garrison = setting.GetChildNodes(); | ||||
Garrison.reserve(garrison.size()); | Garrison.reserve(garrison.size()); | ||||
for (const XMBElement& garr_ent : garrison) | for (const XMBElement& garr_ent : garrison) | ||||
{ | { | ||||
XMBAttributeList attrs = garr_ent.GetAttributes(); | XMBAttributeList attrs = garr_ent.GetAttributes(); | ||||
Garrison.push_back(attrs.GetNamedItem(at_uid).ToInt()); | Garrison.push_back(attrs.GetNamedItem(at_uid).ToInt()); | ||||
} | } | ||||
} | } | ||||
// <turrets> | |||||
else if (element_name == el_turrets) | |||||
{ | |||||
XMBElementList turrets = setting.GetChildNodes(); | |||||
Turrets.reserve(turrets.size()); | |||||
for (const XMBElement& turretPoint : turrets) | |||||
{ | |||||
XMBAttributeList attrs = turretPoint.GetAttributes(); | |||||
Turrets.push_back(std::make_pair( | |||||
attrs.GetNamedItem(at_turret), | |||||
attrs.GetNamedItem(at_uid).ToInt() | |||||
)); | |||||
} | |||||
} | |||||
wraitii: this you need a SetInitEntities call here? | |||||
// <actor> | // <actor> | ||||
else if (element_name == el_actor) | else if (element_name == el_actor) | ||||
{ | { | ||||
XMBAttributeList attrs = setting.GetAttributes(); | XMBAttributeList attrs = setting.GetAttributes(); | ||||
CStr seedStr = attrs.GetNamedItem(at_seed); | CStr seedStr = attrs.GetNamedItem(at_seed); | ||||
if (!seedStr.empty()) | if (!seedStr.empty()) | ||||
{ | { | ||||
Seed = seedStr.ToLong(); | Seed = seedStr.ToLong(); | ||||
Show All 27 Lines | else | ||||
if (!Garrison.empty()) | if (!Garrison.empty()) | ||||
{ | { | ||||
CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent); | CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent); | ||||
if (cmpGarrisonHolder) | if (cmpGarrisonHolder) | ||||
cmpGarrisonHolder->SetInitEntities(Garrison); | cmpGarrisonHolder->SetInitEntities(Garrison); | ||||
else | else | ||||
LOGERROR("CXMLMapReader::ReadEntities() entity '%d' of player '%d' has no GarrisonHolder component and thus cannot garrison units.", ent, PlayerID); | LOGERROR("CXMLMapReader::ReadEntities() entity '%d' of player '%d' has no GarrisonHolder component and thus cannot garrison units.", ent, PlayerID); | ||||
Garrison.clear(); | Garrison.clear(); | ||||
} | } | ||||
Done Inline ActionsNah, I need to set init turrets here ^^ Freagarach: Nah, I need to set init turrets here ^^ | |||||
if (!Turrets.empty()) | |||||
{ | |||||
CmpPtr<ICmpTurretHolder> cmpTurretHolder(sim, ent); | |||||
if (cmpTurretHolder) | |||||
cmpTurretHolder->SetInitEntities(Turrets); | |||||
else | |||||
LOGERROR("CXMLMapReader::ReadEntities() entity '%d' of player '%d' has no TurretHolder component and thus cannot use turrets.", ent, PlayerID); | |||||
Turrets.clear(); | |||||
} | |||||
CmpPtr<ICmpObstruction> cmpObstruction(sim, ent); | CmpPtr<ICmpObstruction> cmpObstruction(sim, ent); | ||||
if (cmpObstruction) | if (cmpObstruction) | ||||
{ | { | ||||
if (ControlGroup != INVALID_ENTITY) | if (ControlGroup != INVALID_ENTITY) | ||||
cmpObstruction->SetControlGroup(ControlGroup); | cmpObstruction->SetControlGroup(ControlGroup); | ||||
if (ControlGroup2 != INVALID_ENTITY) | if (ControlGroup2 != INVALID_ENTITY) | ||||
cmpObstruction->SetControlGroup2(ControlGroup2); | cmpObstruction->SetControlGroup2(ControlGroup2); | ||||
▲ Show 20 Lines • Show All 521 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
this you need a SetInitEntities call here?