Differential D2952 Diff 14052 ps/trunk/binaries/data/mods/public/maps/random/rmgen-common/wall_builder.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/maps/random/rmgen-common/wall_builder.js
Show All 19 Lines | for (let civ in g_CivData) | ||||
let civInfo = g_CivData[civ]; | let civInfo = g_CivData[civ]; | ||||
if (!civInfo.WallSets) | if (!civInfo.WallSets) | ||||
continue; | continue; | ||||
for (let path of civInfo.WallSets) | for (let path of civInfo.WallSets) | ||||
{ | { | ||||
// File naming conventions: | // File naming conventions: | ||||
// - structures/wallset_{style} | // - structures/wallset_{style} | ||||
// - structures/{civ}_wallset_{style} | // - structures/{civ}/wallset_{style} | ||||
let style = basename(path).split("_"); | let style = basename(path).split("_")[1]; | ||||
style = style[0] == "wallset" ? style[1] : style[0] + "_" + style[2]; | if (path.split("/").indexOf(civ) != -1) | ||||
style = civ + "/" + style; | |||||
if (!wallsets[style]) | if (!wallsets[style]) | ||||
wallsets[style] = loadWallset(Engine.GetTemplate(path), civ); | wallsets[style] = loadWallset(Engine.GetTemplate(path), civ); | ||||
} | } | ||||
} | } | ||||
return wallsets; | return wallsets; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Valid elements: | * Valid elements: | ||||
* long, medium, short, start, end, cornerIn, cornerOut, tower, fort, gate, entry, entryTower, entryFort | * long, medium, short, start, end, cornerIn, cornerOut, tower, fort, gate, entry, entryTower, entryFort | ||||
* | * | ||||
* Dynamic elements: | * Dynamic elements: | ||||
* `gap_{x}` returns a non-blocking gap of length `x` meters. | * `gap_{x}` returns a non-blocking gap of length `x` meters. | ||||
* `turn_{x}` returns a zero-length turn of angle `x` radians. | * `turn_{x}` returns a zero-length turn of angle `x` radians. | ||||
* | * | ||||
* Any other arbitrary string passed will be attempted to be used as: `structures/{civ}_{arbitrary_string}`. | * Any other arbitrary string passed will be attempted to be used as: `structures/{civ}/{arbitrary_string}`. | ||||
* | * | ||||
* @param {string} element - What sort of element to fetch. | * @param {string} element - What sort of element to fetch. | ||||
* @param {string} [style] - The style from which this element should come from. | * @param {string} [style] - The style from which this element should come from. | ||||
* @returns {Object} The wall element requested. Or a tower element. | * @returns {Object} The wall element requested. Or a tower element. | ||||
*/ | */ | ||||
function getWallElement(element, style) | function getWallElement(element, style) | ||||
{ | { | ||||
style = validateStyle(style); | style = validateStyle(style); | ||||
if (g_WallStyles[style][element]) | if (g_WallStyles[style][element]) | ||||
return g_WallStyles[style][element]; | return g_WallStyles[style][element]; | ||||
// Attempt to derive any unknown elements. | // Attempt to derive any unknown elements. | ||||
// Defaults to a wall tower piece | // Defaults to a wall tower piece | ||||
const quarterBend = Math.PI / 2; | const quarterBend = Math.PI / 2; | ||||
let wallset = g_WallStyles[style]; | let wallset = g_WallStyles[style]; | ||||
let civ = style.split("_")[0]; | let civ = style.split("/")[1]; | ||||
let ret = wallset.tower ? clone(wallset.tower) : { "angle": 0, "bend": 0, "length": 0, "indent": 0 }; | let ret = wallset.tower ? clone(wallset.tower) : { "angle": 0, "bend": 0, "length": 0, "indent": 0 }; | ||||
switch (element) | switch (element) | ||||
{ | { | ||||
case "cornerIn": | case "cornerIn": | ||||
if (wallset.curves) | if (wallset.curves) | ||||
for (let curve of wallset.curves) | for (let curve of wallset.curves) | ||||
if (curve.bend == quarterBend) | if (curve.bend == quarterBend) | ||||
Show All 28 Lines | case "cornerOut": | ||||
break; | break; | ||||
case "entry": | case "entry": | ||||
ret.templateName = undefined; | ret.templateName = undefined; | ||||
ret.length = wallset.gate.length; | ret.length = wallset.gate.length; | ||||
break; | break; | ||||
case "entryTower": | case "entryTower": | ||||
ret.templateName = g_CivData[civ] ? "structures/" + civ + "_defense_tower" : "structures/palisades_watchtower"; | ret.templateName = g_CivData[civ] ? "structures/" + civ + "/defense_tower" : "structures/palisades_watchtower"; | ||||
ret.indent = ret.length * -3; | ret.indent = ret.length * -3; | ||||
ret.length = wallset.gate.length; | ret.length = wallset.gate.length; | ||||
break; | break; | ||||
case "entryFort": | case "entryFort": | ||||
ret = clone(wallset.fort); | ret = clone(wallset.fort); | ||||
ret.angle -= Math.PI; | ret.angle -= Math.PI; | ||||
ret.length *= 1.5; | ret.length *= 1.5; | ||||
Show All 26 Lines | else if (element.startsWith("turn_")) | ||||
ret.bend = +element.slice("turn_".length) * Math.PI; | ret.bend = +element.slice("turn_".length) * Math.PI; | ||||
ret.length = 0; | ret.length = 0; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (!g_CivData[civ]) | if (!g_CivData[civ]) | ||||
civ = Object.keys(g_CivData)[0]; | civ = Object.keys(g_CivData)[0]; | ||||
let templateName = "structures/" + civ + "_" + element; | let templateName = "structures/" + civ + "/" + element; | ||||
if (Engine.TemplateExists(templateName)) | if (Engine.TemplateExists(templateName)) | ||||
{ | { | ||||
ret.indent = ret.length * (element == "outpost" || element.endsWith("_tower") ? -3 : 3.5); | ret.indent = ret.length * (element == "outpost" || element.endsWith("_tower") ? -3 : 3.5); | ||||
ret.templateName = templateName; | ret.templateName = templateName; | ||||
ret.length = 0; | ret.length = 0; | ||||
} | } | ||||
else | else | ||||
warn("Unrecognised wall element: '" + element + "' (" + style + "). Defaulting to " + (wallset.tower ? "'tower'." : "a blank element.")); | warn("Unrecognised wall element: '" + element + "' (" + style + "). Defaulting to " + (wallset.tower ? "'tower'." : "a blank element.")); | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
function validateStyle(style, playerId = 0) | function validateStyle(style, playerId = 0) | ||||
{ | { | ||||
if (!style || !g_WallStyles[style]) | if (!style || !g_WallStyles[style]) | ||||
{ | { | ||||
if (playerId == 0) | if (playerId == 0) | ||||
return Object.keys(g_WallStyles)[0]; | return Object.keys(g_WallStyles)[0]; | ||||
style = getCivCode(playerId) + "_stone"; | style = getCivCode(playerId) + "/stone"; | ||||
return !g_WallStyles[style] ? Object.keys(g_WallStyles)[0] : style; | return !g_WallStyles[style] ? Object.keys(g_WallStyles)[0] : style; | ||||
} | } | ||||
return style; | return style; | ||||
} | } | ||||
/** | /** | ||||
* Define the different wall placer functions | * Define the different wall placer functions | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 531 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator