Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapReader.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 26 Lines | |||||
#include "ps/LoaderThunks.h" | #include "ps/LoaderThunks.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "renderer/PostprocManager.h" | #include "renderer/PostprocManager.h" | ||||
#include "renderer/SkyManager.h" | #include "renderer/SkyManager.h" | ||||
#include "renderer/WaterManager.h" | #include "renderer/WaterManager.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpCinemaManager.h" | #include "simulation2/components/ICmpCinemaManager.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/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | private: | ||||
CXeromyces xmb_file; | CXeromyces xmb_file; | ||||
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_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_gid; | |||||
int at_seed; | int at_seed; | ||||
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; | ||||
Show All 28 Lines | void CXMLReader::Init(const VfsPath& xml_filename) | ||||
// (Needs to be synchronised with the list in CXMLReader - ugh) | // (Needs to be synchronised with the list in CXMLReader - ugh) | ||||
#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(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(gid); | |||||
AT(seed); | AT(seed); | ||||
#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(); | ||||
▲ 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::set<entity_id_t> Garrison; | |||||
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 All 32 Lines | XERO_ITER_EL(entity, setting) | ||||
} | } | ||||
// <obstruction> | // <obstruction> | ||||
else if (element_name == el_obstruction) | else if (element_name == el_obstruction) | ||||
{ | { | ||||
XMBAttributeList attrs = setting.GetAttributes(); | XMBAttributeList attrs = setting.GetAttributes(); | ||||
ControlGroup = attrs.GetNamedItem(at_group).ToInt(); | ControlGroup = attrs.GetNamedItem(at_group).ToInt(); | ||||
ControlGroup2 = attrs.GetNamedItem(at_group2).ToInt(); | ControlGroup2 = attrs.GetNamedItem(at_group2).ToInt(); | ||||
} | } | ||||
// <garrison> | |||||
else if (element_name == el_garrison) | |||||
{ | |||||
XMBElementList garrison = setting.GetChildNodes(); | |||||
size_t garrison_entity = 0; | |||||
while (garrison_entity < garrison.size()) | |||||
{ | |||||
XMBElement garr_ent = garrison[garrison_entity++]; | |||||
XMBAttributeList attrs = garr_ent.GetAttributes(); | |||||
Garrison.insert(attrs.GetNamedItem(at_gid).ToInt()); | |||||
// ToDo: We can store turret position as well. | |||||
} | |||||
} | |||||
// <actor> | // <actor> | ||||
wraitii: this you need a SetInitEntities call here? | |||||
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(); | ||||
ENSURE(Seed >= 0); | ENSURE(Seed >= 0); | ||||
Show All 17 Lines | else | ||||
cmpPosition->JumpTo(Position.X, Position.Z); | cmpPosition->JumpTo(Position.X, Position.Z); | ||||
cmpPosition->SetYRotation(Orientation.Y); | cmpPosition->SetYRotation(Orientation.Y); | ||||
// TODO: other parts of the position | // TODO: other parts of the position | ||||
} | } | ||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent); | CmpPtr<ICmpOwnership> cmpOwnership(sim, ent); | ||||
if (cmpOwnership) | if (cmpOwnership) | ||||
cmpOwnership->SetOwner(PlayerID); | cmpOwnership->SetOwner(PlayerID); | ||||
CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent); | |||||
if (cmpGarrisonHolder) | |||||
{ | |||||
cmpGarrisonHolder->SetInitEntities(Garrison); | |||||
Garrison.clear(); | |||||
} | |||||
CmpPtr<ICmpObstruction> cmpObstruction(sim, ent); | CmpPtr<ICmpObstruction> cmpObstruction(sim, ent); | ||||
Done Inline ActionsNah, I need to set init turrets here ^^ Freagarach: Nah, I need to set init turrets here ^^ | |||||
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); | ||||
cmpObstruction->ResolveFoundationCollisions(); | cmpObstruction->ResolveFoundationCollisions(); | ||||
▲ Show 20 Lines • Show All 520 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
this you need a SetInitEntities call here?