Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/maps/random/rmgen/placer.js
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | ChainPlacer.prototype.place = function(constraint) | ||||
var gotRet = new Array(size).fill(0).map(p => new Array(size).fill(-1)); | var gotRet = new Array(size).fill(0).map(p => new Array(size).fill(-1)); | ||||
--size; | --size; | ||||
this.minRadius = Math.min(this.maxRadius, Math.max(this.minRadius, 1)); | this.minRadius = Math.min(this.maxRadius, Math.max(this.minRadius, 1)); | ||||
var edges = [[this.x, this.z]]; | var edges = [[this.x, this.z]]; | ||||
for (var i = 0; i < this.numCircles; ++i) | for (var i = 0; i < this.numCircles; ++i) | ||||
{ | { | ||||
var point = edges[randInt(edges.length)]; | var [cx, cz] = pickRandom(edges); | ||||
var cx = point[0], cz = point[1]; | |||||
if (queueEmpty) | if (queueEmpty) | ||||
var radius = randInt(this.minRadius, this.maxRadius); | var radius = randInt(this.minRadius, this.maxRadius); | ||||
else | else | ||||
{ | { | ||||
var radius = this.q.pop(); | var radius = this.q.pop(); | ||||
queueEmpty = !this.q.length; | queueEmpty = !this.q.length; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | while(true) | ||||
if (!fail) | if (!fail) | ||||
{ | { | ||||
if (!constraint.allows(Math.floor(x), Math.floor(z))) | if (!constraint.allows(Math.floor(x), Math.floor(z))) | ||||
fail = true; | fail = true; | ||||
else | else | ||||
{ | { | ||||
var angle = randFloat(this.minAngle, this.maxAngle); | var angle = randFloat(this.minAngle, this.maxAngle); | ||||
resultObjs.push(new Entity(pickRandom(this.types), player, x, z, angle)); | |||||
//Randomly select entity | |||||
var type = this.types[randInt(this.types.length)]; | |||||
resultObjs.push(new Entity(type, player, x, z, angle)); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (fail) | if (fail) | ||||
{ | { | ||||
failCount++; | failCount++; | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | function RandomGroup(elements, avoidSelf, tileClass, x, z) | ||||
this.tileClass = tileClass !== undefined ? getTileClass(tileClass) : undefined; | this.tileClass = tileClass !== undefined ? getTileClass(tileClass) : undefined; | ||||
this.avoidSelf = avoidSelf !== undefined ? avoidSelf : false; | this.avoidSelf = avoidSelf !== undefined ? avoidSelf : false; | ||||
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) | ||||
{ | { | ||||
// Pick one of the object placers at random | var resultObjs = pickRandom(this.elements).place(this.x, this.z, player, this.avoidSelf, constraint); | ||||
var placer = this.elements[randInt(this.elements.length)]; | |||||
var resultObjs = placer.place(this.x, this.z, player, this.avoidSelf, constraint); | |||||
if (resultObjs === undefined) | if (resultObjs === undefined) | ||||
return false; | return false; | ||||
// 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 true; | ||||
}; | }; |
Wildfire Games · Phabricator