Support garrisoned enitites defined in map files.

This is adding support to handle garrisoned entities defined in map
files by game engine and atlas allowing future extension for atlas ui
and solving recreation of entites on init in D1958. Also solving
deepfreeze described in D2562.

Differential Revision; https://code.wildfiregames.com/D2597
Ticket: #3008
Patch by: Freagarach
Comments by: elexis
This was SVN commit r23529.
This commit is contained in:
Angen 2020-03-15 13:54:50 +00:00
parent 0a7649318b
commit 8bfb449375
11 changed files with 152 additions and 17 deletions

View File

@ -103,6 +103,11 @@ Scenario = element Scenario {
attribute group { xsd:positiveInteger },
attribute group2 { xsd:positiveInteger }?
}? &
element Garrison {
element GarrisonedEntity {
attribute uid { xsd:positiveInteger } &
} &
} &
element Actor {
attribute seed { xsd:integer }
}?

View File

@ -256,6 +256,17 @@
</optional>
</element>
</optional>
<optional>
<element name="Garrison">
<zeroOrMore>
<element name="GarrisonedEntity">
<attribute name="uid">
<data type="positiveInteger"/>
</attribute>
</element>
</zeroOrMore>
</element>
</optional>
<optional>
<element name="Actor">
<attribute name="seed">

Binary file not shown.

View File

@ -690,6 +690,16 @@ GarrisonHolder.prototype.IsEjectable = function(entity)
return MatchesClassList(entityClasses, ejectableClasses);
};
/**
* Sets the intitGarrison to the specified entities. Used by the mapreader.
*
* @param {number[]} entities - The entity IDs to garrison on init.
*/
GarrisonHolder.prototype.SetInitGarrison = function(entities)
{
this.initGarrison = clone(entities);
};
/**
* Initialise the garrisoned units.
*/

View File

@ -1,5 +1,3 @@
Engine.RegisterInterface("GarrisonHolder");
/**
* Message of the form { "added": number[], "removed": number[] }
* sent from the GarrisonHolder component to the current entity whenever the garrisoned units change.

View File

@ -64,16 +64,6 @@ function LoadMapSettings(settings)
if (settings.LockTeams && settings.LastManStanding)
warn("Last man standing is only available in games with unlocked teams!");
if (settings.Garrison)
for (let holder in settings.Garrison)
{
let cmpGarrisonHolder = Engine.QueryInterface(+holder, IID_GarrisonHolder);
if (!cmpGarrisonHolder)
warn("Map error in Setup.js: entity " + holder + " can not garrison units");
else
cmpGarrisonHolder.initGarrison = settings.Garrison[holder];
}
let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager);
if (settings.Ceasefire)
cmpCeasefireManager.StartCeasefire(settings.Ceasefire * 60 * 1000);

View File

@ -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
@ -41,6 +41,7 @@
#include "renderer/WaterManager.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpCinemaManager.h"
#include "simulation2/components/ICmpGarrisonHolder.h"
#include "simulation2/components/ICmpObstruction.h"
#include "simulation2/components/ICmpOwnership.h"
#include "simulation2/components/ICmpPlayer.h"
@ -416,6 +417,7 @@ private:
int el_tracks;
int el_template, el_player;
int el_position, el_orientation, el_obstruction;
int el_garrison;
int el_actor;
int at_x, at_y, at_z;
int at_group, at_group2;
@ -465,6 +467,7 @@ void CXMLReader::Init(const VfsPath& xml_filename)
EL(template);
EL(player);
EL(position);
EL(garrison);
EL(orientation);
EL(obstruction);
EL(actor);
@ -946,6 +949,7 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
CStrW TemplateName;
int PlayerID = 0;
std::vector<entity_id_t> Garrison;
CFixedVector3D Position;
CFixedVector3D Orientation;
long Seed = -1;
@ -994,6 +998,17 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
ControlGroup = attrs.GetNamedItem(at_group).ToInt();
ControlGroup2 = attrs.GetNamedItem(at_group2).ToInt();
}
// <garrison>
else if (element_name == el_garrison)
{
XMBElementList garrison = setting.GetChildNodes();
Garrison.reserve(garrison.size());
for (const XMBElement& garr_ent : garrison)
{
XMBAttributeList attrs = garr_ent.GetAttributes();
Garrison.push_back(attrs.GetNamedItem(at_uid).ToInt());
}
}
// <actor>
else if (element_name == el_actor)
{
@ -1029,6 +1044,16 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
if (cmpOwnership)
cmpOwnership->SetOwner(PlayerID);
if (!Garrison.empty())
{
CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent);
if (cmpGarrisonHolder)
cmpGarrisonHolder->SetInitEntities(Garrison);
else
LOGERROR("CXMLMapReader::ReadEntities() entity '%d' of player '%d' has no GarrisonHolder component and thus cannot garrison units.", ent, PlayerID);
Garrison.clear();
}
CmpPtr<ICmpObstruction> cmpObstruction(sim, ent);
if (cmpObstruction)
{

View File

@ -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,7 @@
#include "renderer/WaterManager.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpCinemaManager.h"
#include "simulation2/components/ICmpGarrisonHolder.h"
#include "simulation2/components/ICmpObstruction.h"
#include "simulation2/components/ICmpOwnership.h"
#include "simulation2/components/ICmpPosition.h"
@ -341,6 +342,19 @@ void CMapWriter::WriteXML(const VfsPath& filename,
if (cmpOwnership)
entityTag.Setting("Player", static_cast<int>(cmpOwnership->GetOwner()));
CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent);
if (cmpGarrisonHolder)
{
XMLWriter_Element garrisonTag(xmlMapFile, "Garrison");
std::vector<entity_id_t> garrison = cmpGarrisonHolder->GetEntities();
for (const entity_id_t garr_ent_id : garrison)
{
XMLWriter_Element garrisonedEntityTag(xmlMapFile, "GarrisonedEntity");
garrisonedEntityTag.Attribute("uid", static_cast<int>(garr_ent_id));
// ToDo: We can store turret position as well.
}
}
CmpPtr<ICmpPosition> cmpPosition(sim, ent);
if (cmpPosition)
{

View File

@ -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,9 @@ COMPONENT(FoggingScripted)
INTERFACE(Footprint)
COMPONENT(Footprint)
INTERFACE(GarrisonHolder)
COMPONENT(GarrisonHolderScripted)
INTERFACE(GuiInterface)
COMPONENT(GuiInterfaceScripted)

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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::vector<entity_id_t> GetEntities() const
{
return m_Script.Call<std::vector<entity_id_t> >("GetEntities");
}
virtual void SetInitEntities(std::vector<entity_id_t> entities)
{
m_Script.CallVoid("SetInitGarrison", entities);
}
};
REGISTER_COMPONENT_SCRIPT_WRAPPER(GarrisonHolderScripted)

View File

@ -0,0 +1,35 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_ICMPGARRISONHOLDER
#define INCLUDED_ICMPGARRISONHOLDER
#include "simulation2/system/Interface.h"
#include <vector>
class ICmpGarrisonHolder : public IComponent
{
public:
virtual std::vector<entity_id_t> GetEntities() const = 0;
virtual void SetInitEntities(const std::vector<entity_id_t> entities) = 0;
DECLARE_INTERFACE_TYPE(GarrisonHolder)
};
#endif // INCLUDED_ICMPGARRISONHOLDER