Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/placer.js
Show First 20 Lines • Show All 510 Lines • ▼ Show 20 Lines | SimpleGroup.prototype.place = function(player, constraint) | ||||
var resultObjs = []; | var resultObjs = []; | ||||
// Try placement of objects | // Try placement of objects | ||||
for (let element of this.elements) | for (let element of this.elements) | ||||
{ | { | ||||
var objs = element.place(this.x, this.z, player, this.avoidSelf, constraint); | var objs = element.place(this.x, this.z, player, this.avoidSelf, constraint); | ||||
if (objs === undefined) | if (objs === undefined) | ||||
return false; | return undefined; | ||||
resultObjs = resultObjs.concat(objs); | resultObjs = resultObjs.concat(objs); | ||||
} | } | ||||
// Add placed objects to map | // Add placed objects to map | ||||
for (let obj of resultObjs) | for (let obj of resultObjs) | ||||
{ | { | ||||
if (g_Map.validT(obj.position.x / CELL_SIZE, obj.position.z / CELL_SIZE, MAP_BORDER_WIDTH)) | if (g_Map.validT(obj.position.x / CELL_SIZE, obj.position.z / CELL_SIZE, MAP_BORDER_WIDTH)) | ||||
g_Map.addObject(obj); | g_Map.addObject(obj); | ||||
// Convert position to integer number of tiles | // Convert position to integer number of tiles | ||||
if (this.tileClass !== undefined) | if (this.tileClass !== undefined) | ||||
this.tileClass.add(Math.floor(obj.position.x/CELL_SIZE), Math.floor(obj.position.z/CELL_SIZE)); | this.tileClass.add(Math.floor(obj.position.x/CELL_SIZE), Math.floor(obj.position.z/CELL_SIZE)); | ||||
} | } | ||||
return true; | return resultObjs; | ||||
}; | }; | ||||
///////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////// | ||||
// RandomGroup | // RandomGroup | ||||
// | // | ||||
// Class for placing group of a random simple object | // Class for placing group of a random simple object | ||||
// | // | ||||
// elements: Array of SimpleObjects | // elements: Array of SimpleObjects | ||||
Show All 11 Lines | function RandomGroup(elements, avoidSelf, tileClass, x, z) | ||||
this.x = x !== undefined ? x : -1; | this.x = x !== undefined ? x : -1; | ||||
this.z = z !== undefined ? z : -1; | this.z = z !== undefined ? z : -1; | ||||
} | } | ||||
RandomGroup.prototype.place = function(player, constraint) | RandomGroup.prototype.place = function(player, constraint) | ||||
{ | { | ||||
var resultObjs = pickRandom(this.elements).place(this.x, this.z, player, this.avoidSelf, constraint); | var resultObjs = pickRandom(this.elements).place(this.x, this.z, player, this.avoidSelf, constraint); | ||||
if (resultObjs === undefined) | if (resultObjs === undefined) | ||||
return false; | return undefined; | ||||
// Add placed objects to map | // Add placed objects to map | ||||
for (let obj of resultObjs) | for (let obj of resultObjs) | ||||
{ | { | ||||
g_Map.addObject(obj); | g_Map.addObject(obj); | ||||
// Convert position to integer number of tiles | // Convert position to integer number of tiles | ||||
if (this.tileClass !== undefined) | if (this.tileClass !== undefined) | ||||
this.tileClass.add(Math.floor(obj.position.x/CELL_SIZE), Math.floor(obj.position.z/CELL_SIZE)); | this.tileClass.add(Math.floor(obj.position.x/CELL_SIZE), Math.floor(obj.position.z/CELL_SIZE)); | ||||
} | } | ||||
return true; | return resultObjs; | ||||
}; | }; |
Wildfire Games · Phabricator