Index: binaries/data/mods/public/simulation/components/GarrisonHolder.js =================================================================== --- binaries/data/mods/public/simulation/components/GarrisonHolder.js +++ binaries/data/mods/public/simulation/components/GarrisonHolder.js @@ -691,11 +691,23 @@ }; /** + * Sets the intitGarrison to the specified entities. Used by Atlas' mapreader. + * + * @param {number} entity - An entity ID to garrison on init. + */ +GarrisonHolder.prototype.AddInitGarrisonEntity = function(entity) +{ + if (!this.initGarrison) + this.initGarrison = []; + this.initGarrison.push(entity); +}; + +/** * Initialise the garrisoned units. */ GarrisonHolder.prototype.OnGlobalInitGame = function(msg) { - if (!this.initGarrison) + if (!this.initGarrison || !this.initGarrison.length) return; for (let ent of this.initGarrison) Index: binaries/data/mods/public/simulation/components/interfaces/GarrisonHolder.js =================================================================== --- binaries/data/mods/public/simulation/components/interfaces/GarrisonHolder.js +++ binaries/data/mods/public/simulation/components/interfaces/GarrisonHolder.js @@ -1,4 +1,4 @@ -Engine.RegisterInterface("GarrisonHolder"); +//Engine.RegisterInterface("GarrisonHolder"); /** * Message of the form { "added": number[], "removed": number[] } Index: binaries/data/mods/public/simulation/components/interfaces/Garrisonable.js =================================================================== --- binaries/data/mods/public/simulation/components/interfaces/Garrisonable.js +++ binaries/data/mods/public/simulation/components/interfaces/Garrisonable.js @@ -1 +1 @@ -Engine.RegisterInterface("Garrisonable"); +//Engine.RegisterInterface("Garrisonable"); Index: source/graphics/MapReader.cpp =================================================================== --- source/graphics/MapReader.cpp +++ source/graphics/MapReader.cpp @@ -41,6 +41,8 @@ #include "renderer/WaterManager.h" #include "simulation2/Simulation2.h" #include "simulation2/components/ICmpCinemaManager.h" +#include "simulation2/components/ICmpGarrisonable.h" +#include "simulation2/components/ICmpGarrisonHolder.h" #include "simulation2/components/ICmpObstruction.h" #include "simulation2/components/ICmpOwnership.h" #include "simulation2/components/ICmpPlayer.h" @@ -416,11 +418,13 @@ int el_tracks; int el_template, el_player; int el_position, el_orientation, el_obstruction; + int el_garrison, el_garrisonholder; int el_actor; int at_x, at_y, at_z; int at_group, at_group2; int at_angle; int at_uid; + int at_gid; int at_seed; XMBElementList nodes; // children of root @@ -465,6 +469,8 @@ EL(template); EL(player); EL(position); + EL(garrison); + EL(garrisonholder); EL(orientation); EL(obstruction); EL(actor); @@ -472,6 +478,7 @@ AT(group); AT(group2); AT(angle); AT(uid); + AT(gid); AT(seed); #undef AT #undef EL @@ -946,6 +953,8 @@ CStrW TemplateName; int PlayerID = 0; + std::set Garrison; + int GarrisonHolder = 0; CFixedVector3D Position; CFixedVector3D Orientation; long Seed = -1; @@ -994,6 +1003,24 @@ ControlGroup = attrs.GetNamedItem(at_group).ToInt(); ControlGroup2 = attrs.GetNamedItem(at_group2).ToInt(); } + // + 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. + } + } + // + else if (element_name == el_garrisonholder) + { + GarrisonHolder = setting.GetText().ToInt(); + } // else if (element_name == el_actor) { @@ -1029,6 +1056,17 @@ if (cmpOwnership) cmpOwnership->SetOwner(PlayerID); + CmpPtr cmpGarrisonable(sim, ent); + if (cmpGarrisonable) + cmpGarrisonable->SetGarrisonHolder(GarrisonHolder); + + CmpPtr cmpGarrisonHolder(sim, ent); + if (cmpGarrisonHolder) + { + cmpGarrisonHolder->SetInitEntities(Garrison); + Garrison.clear(); + } + CmpPtr cmpObstruction(sim, ent); if (cmpObstruction) { Index: source/graphics/MapWriter.cpp =================================================================== --- source/graphics/MapWriter.cpp +++ source/graphics/MapWriter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -39,6 +39,8 @@ #include "renderer/WaterManager.h" #include "simulation2/Simulation2.h" #include "simulation2/components/ICmpCinemaManager.h" +#include "simulation2/components/ICmpGarrisonable.h" +#include "simulation2/components/ICmpGarrisonHolder.h" #include "simulation2/components/ICmpObstruction.h" #include "simulation2/components/ICmpOwnership.h" #include "simulation2/components/ICmpPosition.h" @@ -341,6 +343,22 @@ if (cmpOwnership) entityTag.Setting("Player", static_cast(cmpOwnership->GetOwner())); + CmpPtr cmpGarrisonable(sim, ent); + if (cmpGarrisonable) + entityTag.Setting("GarrisonHolder", static_cast(cmpGarrisonable->GetGarrisonHolder())); + + CmpPtr cmpGarrisonHolder(sim, ent); + if (cmpGarrisonHolder) + { + std::set garrison = cmpGarrisonHolder->GetEntities(); + XMLWriter_Element garrisonTag(xmlMapFile, "Garrison"); + for (std::set::iterator garr_ent_id = garrison.begin(); garr_ent_id != garrison.end(); ++garr_ent_id) + { + XMLWriter_Element garrisonedEntityTag(xmlMapFile, "GarrisonedEntity"); + garrisonedEntityTag.Attribute("gid", static_cast(*garr_ent_id)); + } + } + CmpPtr cmpPosition(sim, ent); if (cmpPosition) { Index: source/simulation2/TypeList.h =================================================================== --- source/simulation2/TypeList.h +++ source/simulation2/TypeList.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -98,6 +98,12 @@ INTERFACE(Footprint) COMPONENT(Footprint) +INTERFACE(Garrisonable) +COMPONENT(GarrisonableScripted) + +INTERFACE(GarrisonHolder) +COMPONENT(GarrisonHolderScripted) + INTERFACE(GuiInterface) COMPONENT(GuiInterfaceScripted) Index: source/simulation2/components/ICmpGarrisonHolder.h =================================================================== --- /dev/null +++ source/simulation2/components/ICmpGarrisonHolder.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2020 Wildfire Games. +* This file is part of 0 A.D. +* +* 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 +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* 0 A.D. is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with 0 A.D. If not, see . +*/ + +#ifndef INCLUDED_ICMPGARRISONHOLDER +#define INCLUDED_ICMPGARRISONHOLDER + +#include "simulation2/system/Interface.h" + +class ICmpGarrisonHolder : public IComponent +{ +public: + virtual std::set GetEntities() const = 0; + + virtual void SetInitEntities(std::set entities) = 0; + + DECLARE_INTERFACE_TYPE(GarrisonHolder) +}; + +#endif // INCLUDED_ICMPGARRISONHOLDER Index: source/simulation2/components/ICmpGarrisonHolder.cpp =================================================================== --- /dev/null +++ source/simulation2/components/ICmpGarrisonHolder.cpp @@ -0,0 +1,51 @@ +/* Copyright (C) 2020 Wildfire Games. +* This file is part of 0 A.D. +* +* 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 +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* 0 A.D. is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with 0 A.D. If not, see . +*/ + +#include "precompiled.h" + +#include "ICmpGarrisonHolder.h" + +#include "simulation2/scripting/ScriptComponent.h" +#include "simulation2/system/InterfaceScripted.h" + +BEGIN_INTERFACE_WRAPPER(GarrisonHolder) +END_INTERFACE_WRAPPER(GarrisonHolder) + +class CCmpGarrisonHolderScripted : public ICmpGarrisonHolder +{ +public: + DEFAULT_SCRIPT_WRAPPER(GarrisonHolderScripted) + + virtual std::set GetEntities() const + { + std::vector entities = m_Script.Call>("GetEntities"); + std::set result; + for (std::vector::iterator it = entities.begin(); it != entities.end(); ++it) + result.insert(*it); + return result; + } + + virtual void SetInitEntities(std::set entities) + { + for (std::set::iterator it = entities.begin(); it != entities.end(); ++it) + { + m_Script.CallVoid("AddInitGarrisonEntity", *it); + } + } +}; + +REGISTER_COMPONENT_SCRIPT_WRAPPER(GarrisonHolderScripted) Index: source/simulation2/components/ICmpGarrisonable.h =================================================================== --- /dev/null +++ source/simulation2/components/ICmpGarrisonable.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2020 Wildfire Games. +* This file is part of 0 A.D. +* +* 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 +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* 0 A.D. is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with 0 A.D. If not, see . +*/ + +#ifndef INCLUDED_ICMPGARRISONABLE +#define INCLUDED_ICMPGARRISONABLE + +#include "simulation2/system/Interface.h" + +class ICmpGarrisonable : public IComponent +{ +public: + virtual entity_id_t GetGarrisonHolder() const = 0; + + virtual void SetGarrisonHolder(entity_id_t garrisonHolder) = 0; + + DECLARE_INTERFACE_TYPE(Garrisonable) +}; + +#endif // INCLUDED_ICMPGARRISONABLE Index: source/simulation2/components/ICmpGarrisonable.cpp =================================================================== --- /dev/null +++ source/simulation2/components/ICmpGarrisonable.cpp @@ -0,0 +1,44 @@ +/* Copyright (C) 2020 Wildfire Games. +* This file is part of 0 A.D. +* +* 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 +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* 0 A.D. is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with 0 A.D. If not, see . +*/ + +#include "precompiled.h" + +#include "ICmpGarrisonable.h" + +#include "simulation2/scripting/ScriptComponent.h" +#include "simulation2/system/InterfaceScripted.h" + +BEGIN_INTERFACE_WRAPPER(Garrisonable) +END_INTERFACE_WRAPPER(Garrisonable) + +class CCmpGarrisonableScripted : public ICmpGarrisonable +{ +public: + DEFAULT_SCRIPT_WRAPPER(GarrisonableScripted) + + virtual entity_id_t GetGarrisonHolder() const + { + return m_Script.Call("GetGarrisonHolder"); + } + + virtual void SetGarrisonHolder(entity_id_t garrisonHolder) + { + m_Script.CallVoid("SetGarrisonHolder", garrisonHolder); + } +}; + +REGISTER_COMPONENT_SCRIPT_WRAPPER(GarrisonableScripted)