/// <summary>
        /// Get a valid cell in this cluster to spawn another cave plant.
        /// </summary>
        public static void TryGetRandomSpawnCellNearCluster(Cluster cluster, bool checkTemperature, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

            float maxSpawnDistance = GenRadial.RadiusOfNumCells(cluster.actualSize + 1); // Min radius to hold cluster's plants + new plant.

            maxSpawnDistance += 2f;                                                      // Add a margin so the cluster does not have a perfect circle shape.
            Predicate <IntVec3> validator = delegate(IntVec3 cell)
            {
                // Check cell is not too far away from current cluster.
                if (cell.InHorDistOf(cluster.Position, maxSpawnDistance) == false)
                {
                    return(false);
                }
                // Check cell is in the same room.
                Room clusterRoom = cluster.GetRoom();
                Room cellRoom    = cell.GetRoom(cluster.Map);
                if ((cellRoom == null) ||
                    (cellRoom != clusterRoom))
                {
                    return(false);
                }
                return(IsValidPositionToGrowPlant(cluster.plantDef, cluster.Map, cell, checkTemperature));
            };
            bool validCellIsFound = CellFinder.TryFindRandomCellNear(cluster.Position, cluster.Map, (int)maxSpawnDistance, validator, out spawnCell);

            if (validCellIsFound == false)
            {
                // Note that TryFindRandomCellNear set result to root if no valid cell is found!
                spawnCell = IntVec3.Invalid;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get a valid cell in this cluster to spawn another cave plant.
        /// </summary>
        public static void TryGetRandomSpawnCellNearCluster(Cluster cluster, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

            float maxSpawnDistance = GenRadial.RadiusOfNumCells(cluster.actualSize + 1); // Min radius to hold cluster's plants + new plant.

            //Log.Message("Cluster at " + clusterCenter.ToString() + ": actualClusterSize/desiredClusterSize => maxSpawnDistance " + actualClusterSize + "/" + desiredClusterSize + " => " + maxSpawnDistance);
            maxSpawnDistance += 2f; // Add a margin so the cluster does not have a perfect circle shape.

            /* = plantDef.clusterSpawnRadius;
             * if (plantDef.clusterSizeRange.max > plantDef.clusterSizeRange.min)
             * {
             *  maxSpawnDistance *= clusterMaturity;
             *  maxSpawnDistance = Math.Max(2f, maxSpawnDistance);
             * }
             * Log.Message("maxSpawnDistance at " + clusterCenter.ToString() + ": maturity/maxSpawnDistance => " + clusterMaturity + "/" + maxSpawnDistance);*/
            Predicate <IntVec3> validator = delegate(IntVec3 cell)
            {
                // Check cell is not too far away from current cluster.
                if (cell.InHorDistOf(cluster.Position, maxSpawnDistance) == false)
                {
                    return(false);
                }
                // Check cell is in the same room.
                if (cell.GetRoom() != cluster.GetRoom())
                {
                    return(false);
                }
                return(IsValidPositionToGrowPlant(cluster.plantDef, cell));
            };
            bool validCellIsFound = CellFinder.TryFindRandomCellNear(cluster.Position, (int)maxSpawnDistance, validator, out spawnCell);

            if (validCellIsFound == false)
            {
                // Note that TryFindRandomCellNear set result to root if no valid cell is found!
                spawnCell = IntVec3.Invalid;
            }
        }