/// <summary>
/// Try to get a valid cell to spawn a new cluster anywhere on the map.
/// </summary>
public static void TryGetRandomClusterSpawnCell(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, bool checkTemperature, Map map, out IntVec3 spawnCell)
{
spawnCell = IntVec3.Invalid;
Predicate <IntVec3> validator = delegate(IntVec3 cell)
{
// Check a plant can be spawned here.
if (GenClusterPlantReproduction.IsValidPositionToGrowPlant(plantDef, map, cell, checkTemperature) == false)
{
return(false);
}
// Check there is no third cluster nearby.
if (GenClusterPlantReproduction.IsClusterAreaClear(plantDef, newDesiredClusterSize, map, cell) == false)
{
return(false);
}
return(true);
};
bool validCellIsFound = CellFinderLoose.TryGetRandomCellWith(validator, map, 1000, out spawnCell);
if (validCellIsFound == false)
{
// Just for robustness, TryGetRandomCellWith set result to IntVec3.Invalid if no valid cell is found.
spawnCell = IntVec3.Invalid;
}
}