Fix Units demo map following the addition of the special filter templates in D215 / d093f714d7.

Expose the FindAllPlaceableTemplates function to the simulation to
remove the hardcoded directory checks as suggested by fatherbushido.
Add the new special template directory from D176 / cd6c31e76e.
Move the code from XML to JS.

Differential Revision: https://code.wildfiregames.com/D277
Reviewed By: Vladislav
This was SVN commit r19399.
This commit is contained in:
elexis 2017-04-09 23:46:31 +00:00
parent 1b3f92d6e4
commit e4b4126293
4 changed files with 88 additions and 2 deletions

View File

@ -0,0 +1,84 @@
/**
* Whether to also place all actors.
*/
let actors = false;
/**
* Coordinates of the first entity.
*/
let startX = 20;
let startZ = 20;
/**
* Horizontal coordinate of the last entity in the current row.
*/
let stopX = 1580;
/**
* Coordinates of the current entity.
*/
let x = startX;
let z = startZ;
/**
* Recall the greatest length in the current row to prevent overlapping.
*/
let maxh = 0;
/**
* Space between entities.
*/
let gap = 14;
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
for (let template of cmpTemplateManager.FindAllPlaceableTemplates(actors))
{
print(template + "...\n");
let ent = Engine.AddEntity(template);
if (!ent)
{
error("Failed to load " + template + "\n");
continue;
}
let cmpFootprint = Engine.QueryInterface(ent, IID_Footprint);
if (!cmpFootprint)
{
print(template + " has no footprint\n");
continue;
}
let shape = cmpFootprint.GetShape();
let w = shape.width;
let h = shape.depth;
if (shape.type == 'circle')
w = h = shape.radius * 2;
if (x + w >= stopX)
{
// Start a new row
x = startX;
z += maxh + gap;
maxh = 0;
}
let cmpPosition = Engine.QueryInterface(ent, IID_Position);
if (!cmpPosition)
{
warn(template + " has no position\n");
Engine.DestroyEntity(ent);
continue;
}
cmpPosition.MoveTo(x + w / 2, z);
cmpPosition.SetYRotation(Math.PI * 3 / 4);
let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
if (cmpOwnership)
cmpOwnership.SetOwner(1);
x += w + gap;
maxh = Math.max(maxh, h);
}

Binary file not shown.

View File

@ -5,6 +5,7 @@
{"directory": "other", "file": "*.xml"},
{"directory": "structures", "file": "*.xml"},
{"directory": "units", "file": "*.xml"},
{"directory": "trigger", "file": "*.xml"},
{"directory": "skirmish/structures", "file": "*.xml"},
{"directory": "skirmish/units", "file": "*.xml"},
{"directory": "special", "file": "trigger_point*.xml"},

View File

@ -27,5 +27,6 @@ DEFINE_INTERFACE_METHOD_1("GetTemplateWithoutValidation", const CParamNode*, ICm
DEFINE_INTERFACE_METHOD_CONST_1("TemplateExists", bool, ICmpTemplateManager, TemplateExists, std::string)
DEFINE_INTERFACE_METHOD_CONST_1("GetCurrentTemplateName", std::string, ICmpTemplateManager, GetCurrentTemplateName, entity_id_t)
DEFINE_INTERFACE_METHOD_CONST_1("FindAllTemplates", std::vector<std::string>, ICmpTemplateManager, FindAllTemplates, bool)
DEFINE_INTERFACE_METHOD_CONST_1("FindAllPlaceableTemplates", std::vector<std::string>, ICmpTemplateManager, FindAllPlaceableTemplates, bool)
DEFINE_INTERFACE_METHOD_CONST_1("GetEntitiesUsingTemplate", std::vector<entity_id_t>, ICmpTemplateManager, GetEntitiesUsingTemplate, std::string)
END_INTERFACE_WRAPPER(TemplateManager)