ThingDef_ClusterPlant class.
Inheritance: ThingDef
コード例 #1
0
ファイル: ClusterPlant.cs プロジェクト: schoolly/Rimworld
        public static bool CanTerrainSupportPlantAt(ThingDef_ClusterPlant plantDef, Map map, IntVec3 position)
        {
            bool isValidSpot = true;

            if (plantDef.growOnlyOnRoughRock)
            {
                isValidSpot &= IsNaturalRoughRockAt(map, position);
            }
            else
            {
                isValidSpot &= IsFertilityConditionOkAt(plantDef, map, position);
            }
            if (plantDef.growOnlyUndeRoof)
            {
                isValidSpot &= map.roofGrid.Roofed(position);
            }
            else
            {
                isValidSpot &= (map.roofGrid.Roofed(position) == false);
            }
            if (plantDef.growOnlyNearNaturalRock)
            {
                isValidSpot &= IsNearNaturalRockBlock(map, position);
            }
            return(isValidSpot);
        }
コード例 #2
0
ファイル: Cluster.cs プロジェクト: smileve/Rimworld
 public void Initialize(ThingDef_ClusterPlant plantDef, int desiredSize)
 {
     this.Growth      = 1f; // For texture dimension.
     this.plantDef    = plantDef;
     this.actualSize  = 1;
     this.desiredSize = desiredSize;
 }
コード例 #3
0
        // ===================== Static exported functions =====================
        public static bool IsFertilityConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
        {
            float fertility = Find.FertilityGrid.FertilityAt(position);

            return((fertility >= plantDef.minFertility) &&
                   (fertility <= plantDef.maxFertility));
        }
コード例 #4
0
        public static bool IsTemperatureConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
        {
            float temperature = position.GetTemperature();

            return((temperature >= plantDef.minGrowTemperature) &&
                   (temperature <= plantDef.maxGrowTemperature));
        }
コード例 #5
0
        /// <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, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

            Predicate<IntVec3> validator = delegate(IntVec3 cell)
            {
                // Check a plant can be spawned here.
                if (GenClusterPlantReproduction.IsValidPositionToGrowPlant(plantDef, cell) == false)
                {
                    return false;
                }
                // Check there is no third cluster nearby.
                if (GenClusterPlantReproduction.IsClusterAreaClear(plantDef, newDesiredClusterSize, cell) == false)
                {
                    return false;
                }
                return true;
            };

            bool validCellIsFound = CellFinderLoose.TryGetRandomCellWith(validator, 1000, out spawnCell);
            if (validCellIsFound == false)
            {
                // Just for robustness, TryGetRandomCellWith set result to IntVec3.Invalid if no valid cell is found.
                spawnCell = IntVec3.Invalid;
            }
        }
コード例 #6
0
        /// <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;
            }
        }
コード例 #7
0
ファイル: Cluster.cs プロジェクト: Rikiki123456789/Rimworld
 // New cluster initialization.
 public static ClusterPlant SpawnNewClusterAt(IntVec3 spawnCell, ThingDef_ClusterPlant plantDef, int desiredSize)
 {
     ClusterPlant newPlant = ThingMaker.MakeThing(plantDef) as ClusterPlant;
     GenSpawn.Spawn(newPlant, spawnCell);
     Cluster newCluster = ThingMaker.MakeThing(Util_CaveworldFlora.ClusterDef) as Cluster;
     newCluster.Initialize(plantDef, desiredSize);
     GenSpawn.Spawn(newCluster, spawnCell);
     newPlant.cluster = newCluster;
     return newPlant;
 }
コード例 #8
0
        public static bool IsLightConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
        {
            float light = Find.GlowGrid.GameGlowAt(position);

            if ((light >= plantDef.minLight) &&
                (light <= plantDef.maxLight))
            {
                return(true);
            }
            return(false);
        }
コード例 #9
0
ファイル: Cluster.cs プロジェクト: schoolly/Rimworld
        // New cluster initialization.
        public static ClusterPlant SpawnNewClusterAt(Map map, IntVec3 spawnCell, ThingDef_ClusterPlant plantDef, int desiredSize)
        {
            ClusterPlant newPlant = ThingMaker.MakeThing(plantDef) as ClusterPlant;

            GenSpawn.Spawn(newPlant, spawnCell, map);
            Cluster newCluster = ThingMaker.MakeThing(Util_CaveworldFlora.ClusterDef) as Cluster;

            newCluster.Initialize(plantDef, desiredSize);
            GenSpawn.Spawn(newCluster, spawnCell, map);
            newPlant.cluster = newCluster;
            return(newPlant);
        }
コード例 #10
0
        /// <summary>
        /// Tries to spawn a new cluster at a random position on the map. The exclusivity radius still applies.
        /// </summary>
        public void TrySpawnNewClusterAtRandomPosition()
        {
            ThingDef_ClusterPlant cavePlantDef = cavePlantDefs.RandomElementByWeight((ThingDef_ClusterPlant plantDef) => plantDef.plant.wildCommonalityMaxFraction / plantDef.clusterSizeRange.Average);

            int     newDesiredClusterSize = cavePlantDef.clusterSizeRange.RandomInRange;
            IntVec3 spawnCell             = IntVec3.Invalid;

            GenClusterPlantReproduction.TryGetRandomClusterSpawnCell(cavePlantDef, newDesiredClusterSize, true, this.map, out spawnCell);
            if (spawnCell.IsValid)
            {
                Cluster.SpawnNewClusterAt(this.map, spawnCell, cavePlantDef, newDesiredClusterSize);
            }
        }
コード例 #11
0
        public override string GetInspectString()
        {
            float temperature = GenTemperature.GetTemperatureForCell(this.Position, this.Map);
            ThingDef_ClusterPlant clusterPlantDef = this.GetPlantDefToGrow() as ThingDef_ClusterPlant;

            if (temperature < clusterPlantDef.minGrowTemperature)
            {
                return("CaveworldFlora.CannotGrowTooCold".Translate());
            }
            else if (temperature > clusterPlantDef.maxGrowTemperature)
            {
                return("CaveworldFlora.CannotGrowTooHot".Translate());
            }
            else
            {
                return("CaveworldFlora.Growing".Translate());
            }
        }
コード例 #12
0
        public override string GetInspectString()
        {
            float temperature = GenTemperature.GetTemperatureForCell(this.Position);
            ThingDef_ClusterPlant clusterPlantDef = this.GetPlantDefToGrow() as ThingDef_ClusterPlant;

            if (temperature < clusterPlantDef.minGrowTemperature)
            {
                return("Cannot grow now: too cold.");
            }
            else if (temperature > clusterPlantDef.maxGrowTemperature)
            {
                return("Cannot grow now: too hot.");
            }
            else
            {
                return("Growing.");
            }
        }
コード例 #13
0
        /// <summary>
        /// Check if there is another cluster too close.
        /// </summary>
        public static bool IsClusterAreaClear(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, Map map, IntVec3 position)
        {
            float newClusterExclusivityRadius = Cluster.GetExclusivityRadius(plantDef, newDesiredClusterSize);

            foreach (Thing thing in map.listerThings.ThingsOfDef(Util_CaveworldFlora.ClusterDef))
            {
                Cluster cluster = thing as Cluster;
                if (cluster.plantDef != plantDef)
                {
                    continue;
                }
                if (cluster.Position.InHorDistOf(position, cluster.exclusivityRadius + newClusterExclusivityRadius))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #14
0
        /// <summary>
        /// Tries to spawn a new cluster at a random position on the map. The exclusivity radius still applies.
        /// </summary>
        public void TrySpawnNewClusterAtRandomPosition()
        {
            //Log.Message("TrySpawnNewClusterAtRandomPosition");
            for (int defindex = 0; defindex < cavePlantDefs.Count; defindex++)
            {
                //Log.Message("cavePlantDefs: " + cavePlantDefs[defindex].ToString());
            }
            ThingDef_ClusterPlant cavePlantDef = cavePlantDefs.RandomElementByWeight((ThingDef_ClusterPlant plantDef) => plantDef.plant.wildCommonalityMaxFraction / plantDef.clusterSizeRange.Average);
            //Log.Message("selected cavePlantDef = " + cavePlantDef.ToString());

            int     newDesiredClusterSize = cavePlantDef.clusterSizeRange.RandomInRange;
            IntVec3 spawnCell             = IntVec3.Invalid;

            GenClusterPlantReproduction.TryGetRandomClusterSpawnCell(cavePlantDef, newDesiredClusterSize, true, out spawnCell);
            if (spawnCell.IsValid)
            {
                Cluster.SpawnNewClusterAt(spawnCell, cavePlantDef, newDesiredClusterSize);
            }
        }
コード例 #15
0
ファイル: Cluster.cs プロジェクト: schoolly/Rimworld
        public override void ExposeData()
        {
            base.ExposeData();
            string plantDefAsString = "";

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                plantDefAsString = this.plantDef.defName;
                Scribe_Values.LookValue <string>(ref plantDefAsString, "plantDefAsString");
            }
            else if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Scribe_Values.LookValue <string>(ref plantDefAsString, "plantDefAsString");
                this.plantDef = ThingDef.Named(plantDefAsString) as ThingDef_ClusterPlant;
            }
            Scribe_Values.LookValue <int>(ref this.actualSize, "actualSize");
            Scribe_Values.LookValue <int>(ref this.desiredSize, "desiredSize");

            Scribe_References.LookReference <Cluster>(ref this.symbiosisCluster, "symbiosisCluster");
        }
コード例 #16
0
ファイル: Cluster.cs プロジェクト: schoolly/Rimworld
 public static float GetMaxExclusivityRadius(ThingDef_ClusterPlant plantDef)
 {
     return(plantDef.clusterExclusivityRadiusOffset + ((float)plantDef.clusterSizeRange.max) * plantDef.clusterExclusivityRadiusFactor);
 }
コード例 #17
0
ファイル: Cluster.cs プロジェクト: schoolly/Rimworld
 public static float GetExclusivityRadius(ThingDef_ClusterPlant plantDef, int clusterSize)
 {
     return(plantDef.clusterExclusivityRadiusOffset + (float)clusterSize * plantDef.clusterExclusivityRadiusFactor);
 }
コード例 #18
0
ファイル: Cluster.cs プロジェクト: schoolly/Rimworld
 public void Initialize(ThingDef_ClusterPlant plantDef, int desiredSize)
 {
     this.plantDef    = plantDef;
     this.actualSize  = 1;
     this.desiredSize = desiredSize;
 }
コード例 #19
0
 // ===================== Static exported functions =====================
 public static bool IsFertilityConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
 {
     float fertility = Find.FertilityGrid.FertilityAt(position);
     return ((fertility >= plantDef.minFertility)
         && (fertility <= plantDef.maxFertility));
 }
コード例 #20
0
 public static bool IsTemperatureConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
 {
     float temperature = position.GetTemperature();
     return ((temperature >= plantDef.minGrowTemperature)
         && (temperature <= plantDef.maxGrowTemperature));
 }
コード例 #21
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);
        }
コード例 #22
0
ファイル: Cluster.cs プロジェクト: Rikiki123456789/Rimworld
 public static float GetMaxExclusivityRadius(ThingDef_ClusterPlant plantDef)
 {
     return (plantDef.clusterExclusivityRadiusOffset + ((float)plantDef.clusterSizeRange.max) * plantDef.clusterExclusivityRadiusFactor);
 }
コード例 #23
0
ファイル: Cluster.cs プロジェクト: Rikiki123456789/Rimworld
        public override void ExposeData()
        {
            base.ExposeData();
            string plantDefAsString = "";
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                plantDefAsString = this.plantDef.defName;
                Scribe_Values.LookValue<string>(ref plantDefAsString, "plantDefAsString");
            }
            else if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Scribe_Values.LookValue<string>(ref plantDefAsString, "plantDefAsString");
                this.plantDef = ThingDef.Named(plantDefAsString) as ThingDef_ClusterPlant;
            }
            Scribe_Values.LookValue<int>(ref this.actualSize, "actualSize");
            Scribe_Values.LookValue<int>(ref this.desiredSize, "desiredSize");

            Scribe_References.LookReference<Cluster>(ref this.symbiosisCluster, "symbiosisCluster");
        }
コード例 #24
0
ファイル: Cluster.cs プロジェクト: Rikiki123456789/Rimworld
 public void Initialize(ThingDef_ClusterPlant plantDef, int desiredSize)
 {
     this.plantDef = plantDef;
     this.actualSize = 1;
     this.desiredSize = desiredSize;
 }
コード例 #25
0
        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;
        }
コード例 #26
0
 /// <summary>
 /// Check if there is another cluster too close.
 /// </summary>
 public static bool IsClusterAreaClear(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, IntVec3 position)
 {
     float newClusterExclusivityRadius = Cluster.GetExclusivityRadius(plantDef, newDesiredClusterSize);
     foreach (Thing thing in Find.ListerThings.ThingsOfDef(Util_CaveworldFlora.ClusterDef))
     {
         Cluster cluster = thing as Cluster;
         if (cluster.plantDef != plantDef)
         {
             continue;
         }
         if (cluster.Position.InHorDistOf(position, cluster.exclusivityRadius + newClusterExclusivityRadius))
         {
             return false;
         }
     }
     return true;
 }
コード例 #27
0
ファイル: Cluster.cs プロジェクト: Rikiki123456789/Rimworld
 public static float GetExclusivityRadius(ThingDef_ClusterPlant plantDef, int clusterSize)
 {
     return (plantDef.clusterExclusivityRadiusOffset + (float)clusterSize * plantDef.clusterExclusivityRadiusFactor);
 }
コード例 #28
0
        /// <summary>
        /// Check if position is valid to grow a plant. Does not check cluster exclusivity!
        /// </summary>
        public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, IntVec3 position, bool checkTemperature = true)
        {
            if (position.InBounds() == false)
            {
                return false;
            }
            if (plantDef.isSymbiosisPlant)
            {
                // For symbiosis plant, only check there is a source symbiosis plant.
                if (position.GetFirstThing(plantDef.symbiosisPlantDefSource) != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            // Check there is no building or cover.
            if ((position.GetEdifice() != null)
                || (position.GetCover() != null))
            {
                return false;
            }
            // Check terrain condition.
            if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, position) == false)
            {
                return false;
            }
            // Check temperature conditions.
            if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check light conditions.
            if (ClusterPlant.IsLightConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check there is no other plant.
            if (Find.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 = Find.ThingGrid.ThingsListAt(position);
	        for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
	        {
                Thing thing = thingList[thingIndex];
                //Log.Message("checking thing + " + thing.ToString() + " at " + position.ToString());
		        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) == false)
            {
                return false;
            }
            return true;
        }
コード例 #29
0
 public static bool IsLightConditionOkAt(ThingDef_ClusterPlant plantDef, IntVec3 position)
 {
     float light = Find.GlowGrid.GameGlowAt(position);
     if ((light >= plantDef.minLight)
         && (light <= plantDef.maxLight))
     {
         return true;
     }
     return false;
 }