NotifyPlantAdded() public method

public NotifyPlantAdded ( ) : void
return void
示例#1
0
        /// <summary>
        /// Try to spawn another plant in this cluster.
        /// </summary>
        public static ClusterPlant TryGrowCluster(Cluster cluster)
        {
            IntVec3 spawnCell = IntVec3.Invalid;

            TryGetRandomSpawnCellNearCluster(cluster, out spawnCell);
            if (spawnCell.IsValid)
            {
                ClusterPlant newPlant = ThingMaker.MakeThing(cluster.plantDef) as ClusterPlant;
                GenSpawn.Spawn(newPlant, spawnCell, cluster.Map);
                newPlant.cluster = cluster;
                cluster.NotifyPlantAdded();
                if (cluster.plantDef.isSymbiosisPlant)
                {
                    // Destroy source symbiosis plant.
                    Thing sourceSymbiosisPlant = spawnCell.GetFirstThing(cluster.Map, cluster.plantDef.symbiosisPlantDefSource);
                    if (sourceSymbiosisPlant != null)
                    {
                        sourceSymbiosisPlant.Destroy();
                    }
                }
                return(newPlant);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Get the center of a cluster and its actual size.
        /// </summary>
        /*public static void GetClusterCenterAndActualSize(ClusterPlant plant, out IntVec3 clusterCenter, out int actualClusterSize)
        {
            // Default values.
            clusterCenter = plant.Position;
            actualClusterSize = 1;

            if (plant.desiredClusterSize == 1)
            {
                return;
            }
            else
            {
                clusterCenter = IntVec3.Zero;
                actualClusterSize = 0;
                Room plantRoom = plant.Position.GetRoom();
                // We only check with clusterSpawnRadius (+ a small offset). No need to check entire cluster exclusivity area.
                IEnumerable<IntVec3> cellsInCluster = GenRadial.RadialCellsAround(plant.Position, plant.clusterPlantProps.clusterSpawnRadius + 3f, true);
                foreach (IntVec3 cell in cellsInCluster)
                {
                    if ((cell.GetRoom() == plantRoom)
                        && (Find.ThingGrid.ThingAt(cell, plant.def) != null))
                    {
                        actualClusterSize++;
                        clusterCenter += cell;
                    }
                }
                clusterCenter.x = (int)Mathf.Round(clusterCenter.x / (float)actualClusterSize);
                clusterCenter.z = (int)Mathf.Round(clusterCenter.z / (float)actualClusterSize);
                if (clusterCenter.x < 0)
                {
                    clusterCenter.x = 0;
                }
                else if (clusterCenter.x > Find.Map.Size.x)
                {
                    clusterCenter.x = Find.Map.Size.x;
                }
                if (clusterCenter.z < 0)
                {
                    clusterCenter.z = 0;
                }
                else if (clusterCenter.z > Find.Map.Size.z)
                {
                    clusterCenter.z = Find.Map.Size.z;
                }
                //Log.Message("GetClusterActualSizeAndCenter: " + plant.Position.ToString() + "/" + clusterActualSize + "/" + clusterCenter);
            }
        }*/

        /// <summary>
        /// Try to spawn another plant in this cluster.
        /// </summary>
        public static ClusterPlant TryGrowCluster(Cluster cluster)
        {
            IntVec3 spawnCell = IntVec3.Invalid;
            TryGetRandomSpawnCellNearCluster(cluster, out spawnCell);
            if (spawnCell.IsValid)
            {
                ClusterPlant newPlant = ThingMaker.MakeThing(cluster.plantDef) as ClusterPlant;
                GenSpawn.Spawn(newPlant, spawnCell);
                newPlant.cluster = cluster;
                cluster.NotifyPlantAdded();
                if (cluster.plantDef.isSymbiosisPlant)
                {
                    // Destroy source symbiosis plant.
                    Thing sourceSymbiosisPlant = spawnCell.GetFirstThing(cluster.plantDef.symbiosisPlantDefSource);
                    if (sourceSymbiosisPlant != null)
                    {
                        sourceSymbiosisPlant.Destroy();
                    }
                }
                return newPlant;
            }
            else
            {
                return null;
            }
        }