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 152 Lines • ▼ Show 20 Lines | ChainPlacer.prototype.place = function(constraint) | ||||
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 [cx, cz] = pickRandom(edges); | var [cx, cz] = pickRandom(edges); | ||||
if (queueEmpty) | if (queueEmpty) | ||||
var radius = randInt(this.minRadius, this.maxRadius); | var radius = randIntInclusive(this.minRadius, this.maxRadius); | ||||
else | else | ||||
{ | { | ||||
var radius = this.q.pop(); | var radius = this.q.pop(); | ||||
queueEmpty = !this.q.length; | queueEmpty = !this.q.length; | ||||
} | } | ||||
var sx = cx - radius, lx = cx + radius; | var sx = cx - radius, lx = cx + radius; | ||||
var sz = cz - radius, lz = cz + radius; | var sz = cz - radius, lz = cz + radius; | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | function SimpleObject(type, minCount, maxCount, minDistance, maxDistance, minAngle, maxAngle) | ||||
if (minAngle > maxAngle) | if (minAngle > maxAngle) | ||||
warn("SimpleObject: minAngle should be less than or equal to maxAngle"); | warn("SimpleObject: minAngle should be less than or equal to maxAngle"); | ||||
} | } | ||||
SimpleObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, maxFailCount = 20) | SimpleObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, maxFailCount = 20) | ||||
{ | { | ||||
var failCount = 0; | var failCount = 0; | ||||
var count = randInt(this.minCount, this.maxCount); | |||||
var resultObjs = []; | var resultObjs = []; | ||||
for (var i=0; i < count; i++) | for (var i = 0; i < randIntInclusive(this.minCount, this.maxCount); ++i) | ||||
{ | |||||
while(true) | while(true) | ||||
{ | { | ||||
var distance = randFloat(this.minDistance, this.maxDistance); | var distance = randFloat(this.minDistance, this.maxDistance); | ||||
var direction = randFloat(0, 2*PI); | var direction = randFloat(0, 2*PI); | ||||
var x = cx + 0.5 + distance*cos(direction); | var x = cx + 0.5 + distance*cos(direction); | ||||
var z = cz + 0.5 + distance*sin(direction); | var z = cz + 0.5 + distance*sin(direction); | ||||
var fail = false; // reset place failure flag | var fail = false; // reset place failure flag | ||||
Show All 30 Lines | while(true) | ||||
if (fail) | if (fail) | ||||
{ | { | ||||
failCount++; | failCount++; | ||||
if (failCount > maxFailCount) | if (failCount > maxFailCount) | ||||
return undefined; | return undefined; | ||||
} | } | ||||
} | } | ||||
} | |||||
return resultObjs; | return resultObjs; | ||||
}; | }; | ||||
///////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////// | ||||
// RandomObject | // RandomObject | ||||
// | // | ||||
// Class specifying entities that can be placed on the map, selected randomly | // Class specifying entities that can be placed on the map, selected randomly | ||||
Show All 23 Lines | function RandomObject(types, minCount, maxCount, minDistance, maxDistance, minAngle, maxAngle) | ||||
if (minAngle > maxAngle) | if (minAngle > maxAngle) | ||||
warn("RandomObject: minAngle should be less than or equal to maxAngle"); | warn("RandomObject: minAngle should be less than or equal to maxAngle"); | ||||
} | } | ||||
RandomObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, maxFailCount = 20) | RandomObject.prototype.place = function(cx, cz, player, avoidSelf, constraint, maxFailCount = 20) | ||||
{ | { | ||||
var failCount = 0; | var failCount = 0; | ||||
var count = randInt(this.minCount, this.maxCount); | |||||
var resultObjs = []; | var resultObjs = []; | ||||
for (var i=0; i < count; i++) | for (var i = 0; i < randIntInclusive(this.minCount, this.maxCount); ++i) | ||||
{ | |||||
while(true) | while(true) | ||||
{ | { | ||||
var distance = randFloat(this.minDistance, this.maxDistance); | var distance = randFloat(this.minDistance, this.maxDistance); | ||||
var direction = randFloat(0, 2*PI); | var direction = randFloat(0, 2*PI); | ||||
var x = cx + 0.5 + distance*cos(direction); | var x = cx + 0.5 + distance*cos(direction); | ||||
var z = cz + 0.5 + distance*sin(direction); | var z = cz + 0.5 + distance*sin(direction); | ||||
var fail = false; // reset place failure flag | var fail = false; // reset place failure flag | ||||
Show All 30 Lines | while(true) | ||||
if (fail) | if (fail) | ||||
{ | { | ||||
failCount++; | failCount++; | ||||
if (failCount > maxFailCount) | if (failCount > maxFailCount) | ||||
return undefined; | return undefined; | ||||
} | } | ||||
} | } | ||||
} | |||||
return resultObjs; | return resultObjs; | ||||
}; | }; | ||||
///////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////// | ||||
// SimpleGroup | // SimpleGroup | ||||
// | // | ||||
// Class for placing groups of different objects | // Class for placing groups of different objects | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator