Index: binaries/data/mods/public/maps/scenarios/Structures_demo.js =================================================================== --- binaries/data/mods/public/maps/scenarios/Structures_demo.js +++ binaries/data/mods/public/maps/scenarios/Structures_demo.js @@ -0,0 +1,133 @@ +/** + * Coordinates of the first entity. + */ +let startX = 50; +let startZ = 50; + +/** + * Coordinates of the current entity. + */ +let x = startX; +let z = startZ; + +/** + * Horizontal coordinate of the last entity in the current row. + */ +let stopX = 1550; + +/** + * Space between entities. + */ +let gap = 14; +let maxh = 50; + +let row = "" +let ents = []; +let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + +for (let template of cmpTemplateManager.FindAllPlaceableTemplates(false)) +{ + if (template.substr(0,4) != "stru") + continue; + + if (template.indexOf("wallset") != -1) + continue; + + // comment out these two lines to do all civs +// if (template.substr(0,15) != "structures/maur") +// continue; + + 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 cmpPosition = Engine.QueryInterface(ent, IID_Position); + if (!cmpPosition) + { + warn(template + " has no position\n"); + Engine.DestroyEntity(ent); + continue; + } + + let shape = cmpFootprint.GetShape(); + let w = shape.width; + let h = shape.depth; + + if (shape.type == 'circle') + w = h = shape.radius * 2; + + // add a gap when starting a new civ + if (row != template.substr(0,15)) + { + row = template.substr(0,15); + x += maxh; + } + + // start a new row + if (x + w >= stopX) + { + x = startX; + z += 3 * maxh + gap; + } + + cmpPosition.MoveTo(x + w / 2, z + 2 * maxh); + cmpPosition.SetYRotation(Math.PI * 3 / 4); + + let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); + if (cmpOwnership) + cmpOwnership.SetOwner(1); + + // add the corresponding halfway-built foundation to the next row + let template2 = "foundation|" + template; + let ent2 = Engine.AddEntity(template2); + + let cmpPosition2 = Engine.QueryInterface(ent2, IID_Position); + cmpPosition2.MoveTo(x + w / 2, z + maxh); + cmpPosition2.SetYRotation(Math.PI * 3 / 4); + + let cmpOwnership2 = Engine.QueryInterface(ent2, IID_Ownership); + cmpOwnership2.SetOwner(1); + + let cmpFoundation2 = Engine.QueryInterface(ent2, IID_Foundation); + cmpFoundation2.InitialiseConstruction(1, template); + + let cmpCost = Engine.QueryInterface(ent, IID_Cost); + cmpFoundation2.Build(0, cmpCost.GetBuildTime() / 2); + + // add the corresponding foundation to the next row + let template3 = "foundation|" + template; + let ent3 = Engine.AddEntity(template3); + + let cmpPosition3 = Engine.QueryInterface(ent3, IID_Position); + cmpPosition3.MoveTo(x + w / 2, z); + cmpPosition3.SetYRotation(Math.PI * 3 / 4); + + let cmpOwnership3 = Engine.QueryInterface(ent3, IID_Ownership); + cmpOwnership3.SetOwner(1); + + let cmpFoundation3 = Engine.QueryInterface(ent3, IID_Foundation); + cmpFoundation3.InitialiseConstruction(1, template); + + x += w + gap; + ents.push(ent); + ents.push(ent2); + ents.push(ent3); +} + +print(ents.length + " entities\n"); + +// draw the footprint around every building and foundation +let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); +cmpGUIInterface.SetSelectionHighlight(1, { "entities": ents, "alpha": 1, "selected": true }); Index: binaries/data/mods/public/maps/scenarios/Structures_demo.xml =================================================================== --- binaries/data/mods/public/maps/scenarios/Structures_demo.xml +++ binaries/data/mods/public/maps/scenarios/Structures_demo.xml @@ -0,0 +1,51 @@ + + + + + + default + + + + + + + + lake + + 5 + 4.0 + 0.45 + + + + + + + + + + + + + +