Return the placed Groups (containing the Objects (containing Entities)) from the createObjectGroups (plural) functions, refs c6af8b4e76
.
This way maps can further modify the terrain or place entities at the resulting position. Generalizes retryPlacing. This was SVN commit r21406.
This commit is contained in:
parent
c6af8b4e76
commit
c214bbd1ec
@ -475,7 +475,7 @@ function placePlayersNomad(playerClass, constraints)
|
|||||||
let success = false;
|
let success = false;
|
||||||
for (let distanceFactor of [1, 1/2, 1/4, 0])
|
for (let distanceFactor of [1, 1/2, 1/4, 0])
|
||||||
{
|
{
|
||||||
if (createObjectGroups(group, playerIDs[i], new AndConstraint([constraint, avoidClasses(playerClass, distance * distanceFactor)]), 1, 200, false))
|
if (createObjectGroups(group, playerIDs[i], new AndConstraint([constraint, avoidClasses(playerClass, distance * distanceFactor)]), 1, 200, false).length)
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
playerPosition[i] = group.centerPosition;
|
playerPosition[i] = group.centerPosition;
|
||||||
|
@ -84,28 +84,24 @@ function randomPositionOnTile(tilePosition)
|
|||||||
/**
|
/**
|
||||||
* Retries the given function with those arguments as often as specified.
|
* Retries the given function with those arguments as often as specified.
|
||||||
*/
|
*/
|
||||||
function retryPlacing(placeFunc, retryFactor, amount, getResult, behaveDeprecated = false)
|
function retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated = false)
|
||||||
{
|
{
|
||||||
let maxFail = amount * retryFactor;
|
let maxFail = amount * retryFactor;
|
||||||
|
|
||||||
let results = [];
|
let results = [];
|
||||||
let good = 0;
|
|
||||||
let bad = 0;
|
let bad = 0;
|
||||||
|
|
||||||
while (good < amount && bad <= maxFail)
|
while (results.length < amount && bad <= maxFail)
|
||||||
{
|
{
|
||||||
let result = placeFunc();
|
let result = placeFunc();
|
||||||
|
|
||||||
if (result !== undefined || behaveDeprecated)
|
if (result !== undefined || behaveDeprecated)
|
||||||
{
|
results.push(result);
|
||||||
++good;
|
|
||||||
if (getResult)
|
|
||||||
results.push(result);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
++bad;
|
++bad;
|
||||||
}
|
}
|
||||||
return getResult ? results : good;
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is a hack to simulate the old behaviour of those functions
|
// TODO this is a hack to simulate the old behaviour of those functions
|
||||||
@ -131,7 +127,7 @@ function createAreas(centeredPlacer, painter, constraint, amount, retryFactor =
|
|||||||
return createArea(centeredPlacer, painter, constraint);
|
return createArea(centeredPlacer, painter, constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return retryPlacing(placeFunc, retryFactor, amount, true, false);
|
return retryPlacing(placeFunc, retryFactor, amount, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,7 +141,7 @@ function createAreasInAreas(centeredPlacer, painter, constraint, amount, retryFa
|
|||||||
return createArea(centeredPlacer, painter, constraint);
|
return createArea(centeredPlacer, painter, constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return retryPlacing(placeFunc, retryFactor, amount, true, false);
|
return retryPlacing(placeFunc, retryFactor, amount, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,7 +155,7 @@ function createObjectGroups(group, player, constraint, amount, retryFactor = 10,
|
|||||||
return createObjectGroup(group, player, constraint);
|
return createObjectGroup(group, player, constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return retryPlacing(placeFunc, retryFactor, amount, false, behaveDeprecated);
|
return retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,7 +169,7 @@ function createObjectGroupsByAreas(group, player, constraint, amount, retryFacto
|
|||||||
return createObjectGroup(group, player, constraint);
|
return createObjectGroup(group, player, constraint);
|
||||||
};
|
};
|
||||||
|
|
||||||
return retryPlacing(placeFunc, retryFactor, amount, false, behaveDeprecated);
|
return retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTerrain(terrain)
|
function createTerrain(terrain)
|
||||||
|
Loading…
Reference in New Issue
Block a user