/// <summary>
/// Check if position is valid to grow a plant. Does not check cluster exclusivity!
/// </summary>
public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, Map map, IntVec3 position, bool checkTemperature = true)
{
if (position.InBounds(map) == false)
{
return(false);
}
if (plantDef.isSymbiosisPlant)
{
// For symbiosis plant, only check there is a source symbiosis plant.
if (position.GetFirstThing(map, plantDef.symbiosisPlantDefSource) != null)
{
return(true);
}
else
{
return(false);
}
}
// Check there is no building or cover.
if ((position.GetEdifice(map) != null) ||
(position.GetCover(map) != null))
{
return(false);
}
// Check terrain condition.
if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, map, position) == false)
{
return(false);
}
// Check temperature conditions.
if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, map, position) == false)
{
return(false);
}
// Check light conditions.
if (ClusterPlant.IsLightConditionOkAt(plantDef, map, position) == false)
{
return(false);
}
// Check there is no other plant.
if (map.thingGrid.ThingAt(position, ThingCategory.Plant) != null)
{
return(false);
}
// Check the cell is not blocked by a plant, an item, a pawn, a rock...
List <Thing> thingList = map.thingGrid.ThingsListAt(position);
for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
{
Thing thing = thingList[thingIndex];
if (thing.def.BlockPlanting)
{
return(false);
}
if (plantDef.passability == Traversability.Impassable &&
(thing.def.category == ThingCategory.Pawn ||
thing.def.category == ThingCategory.Item ||
thing.def.category == ThingCategory.Building ||
thing.def.category == ThingCategory.Plant))
{
return(false);
}
}
// Check snow level.
if (GenPlant.SnowAllowsPlanting(position, map) == false)
{
return(false);
}
return(true);
}