Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/TileClass.js
Context not available. | |||||
this.rangeCount[position.y].add(position.x, -1); | this.rangeCount[position.y].add(position.x, -1); | ||||
}; | }; | ||||
TileClass.prototype.countInRadius = function(position, radius, returnMembers) | TileClass.prototype.intersect = function(position, radius, near) | ||||
{ | { | ||||
let members = 0; | |||||
let nonMembers = 0; | |||||
let radius2 = Math.square(radius); | let radius2 = Math.square(radius); | ||||
for (let y = position.y - radius; y <= position.y + radius; ++y) | for (let y = position.y - radius; y <= position.y + radius; ++y) | ||||
Context not available. | |||||
let newMembers = this.rangeCount[iy].get(minX, maxX); | let newMembers = this.rangeCount[iy].get(minX, maxX); | ||||
members += newMembers; | if (near && newMembers > 0) | ||||
nonMembers += maxX - minX - newMembers; | return true; | ||||
else if (!near && maxX - minX - newMembers > 0) | |||||
return false; | |||||
} | } | ||||
} | } | ||||
else // Simply check the tiles one by one to find the number | else // Simply check the tiles one by one to find the number | ||||
Context not available. | |||||
if (Math.square(dx) + Math.square(dy) <= radius2) | if (Math.square(dx) + Math.square(dy) <= radius2) | ||||
{ | { | ||||
if (this.inclusionCount[ix] && this.inclusionCount[ix][iy] && this.inclusionCount[ix][iy] > 0) | if (this.inclusionCount[ix] && this.inclusionCount[ix][iy] && this.inclusionCount[ix][iy] > 0) | ||||
++members; | { | ||||
else | if (near) | ||||
++nonMembers; | return true; | ||||
} | |||||
else if (!near) | |||||
return false; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (returnMembers) | if (near) | ||||
return members; | return false; | ||||
else | else | ||||
return nonMembers; | return true; | ||||
}; | }; | ||||
TileClass.prototype.countMembersInRadius = function(position, radius) | TileClass.prototype.isNear = function(position, radius) | ||||
{ | { | ||||
return this.countInRadius(position, radius, true); | return this.intersect(position, radius, true); | ||||
}; | }; | ||||
TileClass.prototype.countNonMembersInRadius = function(position, radius) | TileClass.prototype.isWithin = function(position, radius) | ||||
{ | { | ||||
return this.countInRadius(position, radius, false); | return this.intersect(position, radius, false); | ||||
}; | }; | ||||
Context not available. |
Wildfire Games · Phabricator