Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/Constraint.js
Context not available. | |||||
*/ | */ | ||||
/** | /** | ||||
* The following functions are for easily creating constraints in batches. | |||||
*/ | |||||
/** | |||||
* Create an avoid constraint for the given classes by the given distances | |||||
elexis: Not global constants | |||||
Done Inline ActionsWhy not? I did this purely to avoid having to type quotation marks millions of times, because it's a serious pain as I found out firsthand. I don't see why they shouldn't just be reserved names. aeonios: Why not? I did this purely to avoid having to type quotation marks millions of times, because… | |||||
*/ | |||||
function avoidClasses(/* class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new AvoidTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a stay constraint for the given classes by the given distances | |||||
*/ | |||||
function stayClasses(/* class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new StayInTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a stay constraint for the given classes by the given distances | |||||
*/ | |||||
function nearClasses(/* class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new NearTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a border constraint for the given classes by the given distances | |||||
*/ | |||||
function borderClasses(/* class1, idist1, odist1, class2, idist2, odist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/3; ++i) | |||||
ar.push(new BorderTileClassConstraint(arguments[3*i], arguments[3*i+1], arguments[3*i+2])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
Not Done Inline ActionsI personally would not recommend proxy functions that are that short and I removed many of them (library.js). elexis: I personally would not recommend proxy functions that are that short and I removed many of them… | |||||
Done Inline ActionsIt saves on parenthesis. A lot. It's also a pain to sort out the various arguments when you've got all that other mess going on, and this is still way easier to use and learn than that. aeonios: It saves on parenthesis. A lot. It's also a pain to sort out the various arguments when you've… | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* The NullConstraint is always satisfied. | * The NullConstraint is always satisfied. | ||||
*/ | */ | ||||
function NullConstraint() {} | function NullConstraint() {} | ||||
Context not available. |
Wildfire Games · Phabricator
Not global constants