CaveworldFlora.ClusterPlant.CanTerrainSupportPlantAt C# (CSharp) Method

CanTerrainSupportPlantAt() public static method

public static CanTerrainSupportPlantAt ( ThingDef_ClusterPlant plantDef, IntVec3 position ) : bool
plantDef ThingDef_ClusterPlant
position IntVec3
return bool
        public static bool CanTerrainSupportPlantAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
        {
            bool isValidSpot = true;

            if (plantDef.growOnlyOnRoughRock)
            {
                isValidSpot &= IsNaturalRoughRockAt(position);
            }
            else
            {
                isValidSpot &= IsFertilityConditionOkAt(plantDef, position);
            }
            if (plantDef.growOnlyUndeRoof)
            {
                isValidSpot &= Find.RoofGrid.Roofed(position);
            }
            if (plantDef.growOnlyNearNaturalRock)
            {
                isValidSpot &= IsNearNaturalRockBlock(position);
            }
            return isValidSpot;
        }

Usage Example

Beispiel #1
0
        /// <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);
        }