mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 16:23:44 +00:00
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:
@@ -475,7 +475,7 @@ function placePlayersNomad(playerClass, constraints)
|
||||
let success = false;
|
||||
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;
|
||||
playerPosition[i] = group.centerPosition;
|
||||
|
||||
@@ -84,28 +84,24 @@ function randomPositionOnTile(tilePosition)
|
||||
/**
|
||||
* 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 results = [];
|
||||
let good = 0;
|
||||
let bad = 0;
|
||||
|
||||
while (good < amount && bad <= maxFail)
|
||||
while (results.length < amount && bad <= maxFail)
|
||||
{
|
||||
let result = placeFunc();
|
||||
|
||||
if (result !== undefined || behaveDeprecated)
|
||||
{
|
||||
++good;
|
||||
if (getResult)
|
||||
results.push(result);
|
||||
}
|
||||
results.push(result);
|
||||
else
|
||||
++bad;
|
||||
}
|
||||
return getResult ? results : good;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// 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 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 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 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 retryPlacing(placeFunc, retryFactor, amount, false, behaveDeprecated);
|
||||
return retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated);
|
||||
}
|
||||
|
||||
function createTerrain(terrain)
|
||||
|
||||
Reference in New Issue
Block a user