Extend the rmgen AndConstraint to be more permissive and receive falsy values or a Constraint to remove some Constraint conversion duplication, refs #4805.

This was SVN commit r20861.
This commit is contained in:
elexis
2018-01-13 22:11:06 +00:00
parent e8dea23cc4
commit 495f83663e
3 changed files with 14 additions and 20 deletions
@@ -17,7 +17,12 @@ NullConstraint.prototype.allows = function(x, z)
*/
function AndConstraint(constraints)
{
this.constraints = constraints;
if (constraints instanceof Array)
this.constraints = constraints
else if (!constraints)
this.constraints = [];
else
this.constraints = [constraints];
}
AndConstraint.prototype.allows = function(x, z)
@@ -65,10 +65,9 @@ function createMountains(terrain, constraint, tileClass, count, maxHeight, minRa
/**
* Create a mountain using a technique very similar to ChainPlacer.
*/
function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraint, x, z, terrain, tileClass, fcc = 0, q = [])
function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraints, x, z, terrain, tileClass, fcc = 0, q = [])
{
if (constraint instanceof Array)
constraint = new AndConstraint(constraint);
let constraint = new AndConstraint(constraints);
if (!g_Map.inMapBounds(x, z) || !constraint.allows(x, z))
return;
@@ -247,17 +247,12 @@ function getTileClass(id)
}
/**
* Constructs a new Area shaped by the Placer meeting the Constraint and calls the Painters there.
* Constructs a new Area shaped by the Placer meeting the Constraints and calls the Painters there.
* Supports both Centered and Non-Centered Placers.
*/
function createArea(placer, painter, constraint)
function createArea(placer, painter, constraints)
{
if (!constraint)
constraint = new NullConstraint();
else if (constraint instanceof Array)
constraint = new AndConstraint(constraint);
let points = placer.place(constraint);
let points = placer.place(new AndConstraint(constraints));
if (!points)
return undefined;
@@ -296,17 +291,12 @@ function unPaintTileClassBasedOnHeight(minHeight, maxHeight, mode, tileClass)
}
/**
* Places the Entities of the given Group if they meet the Constraint
* Places the Entities of the given Group if they meet the Constraints
* and sets the given player as the owner.
*/
function createObjectGroup(group, player, constraint)
function createObjectGroup(group, player, constraints)
{
if (!constraint)
constraint = new NullConstraint();
else if (constraint instanceof Array)
constraint = new AndConstraint(constraint);
return group.place(player, constraint);
return group.place(player, new AndConstraint(constraints));
}
function getMapSize()