public static bool EnvironmentAllowsEatingVirtualPlantsNowAt(int tile)
        {
            BiomeDef biome = Find.WorldGrid[tile].biome;

            if (!biome.hasVirtualPlants)
            {
                return(false);
            }
            float temperatureAtTile = GenTemperature.GetTemperatureAtTile(tile);

            return(temperatureAtTile >= 0f);
        }
示例#2
0
        static bool Prefix(ref int __result, int tile, bool perceivedStatic, float yearPercent = -1f)
        {
            Settlement settlement = Find.WorldObjects.SettlementAt(tile);

            if (settlement != null && Faction.OfPlayerSilentFail != null && (settlement.Faction == Faction.OfPlayerSilentFail || settlement.Visitable))
            {
                __result = 0; // Friendly or player-controlled settlements ignore all terrain costs. Home, sweet home!
                return(false);
            }
            int  num   = 0;
            Tile tile2 = Find.WorldGrid[tile];

            if (tile2.biome.impassable)
            {
                __result = 1000000;
                return(false);
            }
            bool current = yearPercent == -1f;

            if (yearPercent < 0f)
            {
                yearPercent = (float)DayOfYearAt0Long / 60f;
            }
            float num2 = yearPercent;

            if (Find.WorldGrid.LongLatOf(tile).y < 0f)
            {
                num2 = (num2 + 0.5f) % 1f;
            }
            // If we are calculating path for now, don't apply snow penalty if there are... Well, you know, no snow.
            if (current && GenTemperature.GetTemperatureAtTile(tile) >= 0)
            {
                num2 = 0.33f;
            }
            num += Mathf.RoundToInt(tile2.biome.pathCost.Evaluate(num2) * GetSettlementMoveModifier(tile));
            if (tile2.hilliness == Hilliness.Impassable)
            {
                __result = 1000000;
                return(false);
            }
            num     += Mathf.RoundToInt(CostFromTileHilliness(tile2.hilliness) * GetSettlementMoveModifier(tile));
            __result = num;
            return(false);
        }
示例#3
0
        public static int CheckSnowAndSettlementMods(int biomeCost, int hillnessCost, int tile)
        {
            // no snow - no seasonal penalty
            if (CurrentTime && Settings.snow_mod && GenTemperature.GetTemperatureAtTile(tile) > 0)
            {
                biomeCost = Find.WorldGrid[tile].biome.pathCost_summer;
            }

            biomeCost    = (int)(biomeCost * Settings.biome_time_modifier);
            hillnessCost = (int)(hillnessCost * Settings.hillness_time_modifier);

            // check settlement factor
            if (Settings.settlement_mod)
            {
                return(GetSettlementMoveModifier(tile, biomeCost + hillnessCost));
            }

            return(biomeCost + hillnessCost);
        }
示例#4
0
        /// <summary>
        ///     Fetch the mountain rooms with thick roofs and no heating/cooling devices.
        /// </summary>
        private void FetchNaturalRooms()
        {
            // Clear our list of natural rooms
            naturalRooms = new List <NaturalRoom>();

            // Get the list of rooms from the region grid
            var allRooms = map.regionGrid.allRooms;

            // No rooms to check, abort now
            if (allRooms == null || allRooms.Count < 1)
            {
                return;
            }

            // Get the outdoor temperature
            var outdoorTemp = GenTemperature.GetTemperatureAtTile(map.Tile);

#if DEBUG
            var debugDump = "FetchNaturalRooms:" +
                            "\n\toutdoorTemp: " + outdoorTemp +
                            "\n\tallRooms.Count: " + allRooms.Count;
#endif

            // Find all the coolers in the world
            //var allCoolers = Find.ListerBuildings.AllBuildingsColonistOfClass<Building_Cooler>().ToList();

            // Iterate the rooms
            foreach (var room in allRooms)
            {
                //float controlledTemp = 0f;
                //int controlUnits = 0;

                // Open roof?  Not what we want
                try
                {
                    if (room.OpenRoofCount > 0)
                    {
                        goto Skip_Room;
                    }

                    // Get the cells which are contained in the room
                    var roomCells = room.Cells.ToList();

                    // No cells, no want
                    if (roomCells == null ||
                        roomCells.Count < 1)
                    {
                        goto Skip_Room;
                    }

                    // Make sure the roof is at least partly natural
                    if (!roomCells.Any(
                            cell => cell.GetRoof(map).isNatural))
                    {
                        goto Skip_Room;
                    }

                    // Check for embrasures and fences, anything that transfers heat freely
                    if (room.BorderCells.Any(cell => cell.GetCover(map).def.fillPercent < 1))
                    {
                        goto Skip_Room;
                    }

                    /*
                     * // Find all heaters contained in the room
                     * var heaters = room.AllContainedThings.Where( t =>
                     *  ( ( t as Building_Heater ) != null ) ).ToList();
                     *
                     * // Does this room have any heaters?
                     * if( ( heaters != null )&&
                     *  ( heaters.Count > 0 ) ){
                     *
                     *  // If so, are they powered?
                     *  foreach( var thing in heaters ){
                     *
                     *      var heater = thing as Building_Heater;
                     *      if( heater.compPowerTrader.PowerOn == true ){
                     *
                     *          // Add heater temp to controlled temp
                     *          controlledTemp += heater.compTempControl.targetTemperature;
                     *          controlUnits++;
                     *      }
                     *  }
                     * }
                     *
                     * // Does this room have any coolers?
                     * if( ( allCoolers != null )&&
                     *  ( allCoolers.Count > 0 ) ){
                     *
                     *  // Check to see if any of the coolers effect this room
                     *  foreach( var cooler in allCoolers ){
                     *
                     *      if( cooler.compPowerTrader.PowerOn == true ){
                     *
                     #if DEBUG
                     *          //debugDump += "\n\tcooler rotation: " + cooler.Rotation.FacingCell;
                     *
                     #endif
                     *
                     *          // Get heating and cooling sides of the cooler
                     *          var cellHeated = cooler.Position + cooler.Rotation.FacingCell;
                     *          var cellCooled = cooler.Position - cooler.Rotation.FacingCell;
                     *
                     *          // Does either side of the cooler effect this room?
                     *          if( cellHeated.GetRoom() == room ){
                     *
                     *              // Subtract this temp from controlled temp
                     *              controlledTemp -= ( cooler.compTempControl.targetTemperature * 2 );
                     *              controlUnits++;
                     *
                     *          } else if( cellCooled.GetRoom() == room ){
                     *
                     *              // Add this temp from the controlled temp
                     *              controlledTemp += cooler.compTempControl.targetTemperature;
                     *              controlUnits++;
                     *          }
                     *      }
                     *  }
                     * }
                     */

                    // Create new natural room entry
                    var naturalRoom = new NaturalRoom
                    {
                        Room = room
                    };

                    var   roofCount  = (float)roomCells.Count;
                    float thickCount = 0;
                    float thinCount  = 0;

                    // Count thick roofs
                    foreach (var cell in roomCells)
                    {
                        var roof = cell.GetRoof(map);
                        if (roof.isThickRoof)
                        {
                            thickCount++;
                        }
                        else if (roof.isNatural)
                        {
                            thinCount++;
                        }
                    }

                    // Now calculate percent of roof that is thick/thin/constructed
                    var thickFactor = thickCount / roofCount;
                    var thinFactor  = thinCount / roofCount;
                    //var roofedFactor = 1.0f - thickFactor - thinFactor;
                    //if (roofedFactor < 0f)
                    //    // Handle rounding errors
                    //{
                    //    roofedFactor = 0f;
                    //}

                    // Factor for pushing heat
                    naturalRoom.NaturalEqualizationFactor = thickFactor + (thinFactor * 0.5f);

                    // Calculate new temp based on roof factors
                    var thickRate = thickFactor * TargetTemperature;
                    var thinRate  = thinFactor * (outdoorTemp - TargetTemperature) * 0.25f;
                    //float roofedRate = roofedFactor * ( outdoorTemp - UNDERGROUND_TEMPERATURE ) * 0.5f;

                    // Assign the natural temp based on aggregate ratings
                    //naturalRoom.naturalTemp = thickFactor * UNDERGROUND_TEMPERATURE +
                    //    ( 1.0f - thickFactor ) * outdoorTemp;
                    naturalRoom.NaturalTemp = thickRate + thinRate; // + roofedRate;

                    // Compute average controlled temperature for room

                    /*
                     * if( controlUnits == 0 ){
                     *  naturalRoom.controlledTemp = INVALID_CONTROL_TEMP;
                     * } else {
                     *  naturalRoom.controlledTemp = (int)( controlledTemp / controlUnits );
                     * }
                     */

#if DEBUG
                    /*
                     * debugDump += "\n\tID: " + room.ID +
                     *  "\n\t\troomCells.Count: " + roomCells.Count +
                     *  "\n\t\troofCount: " + roofCount +
                     *  "\n\t\tCount thick/thin/man: " + thickCount + "/" + thinCount + "/" + ( roofCount - thickCount - thinCount ) +
                     *  "\n\t\tFactor thick/thin/man: " + thickFactor + "/" + thinFactor + "/" + roofedFactor +
                     *  "\n\t\tRate thick/thin/man: " + thickRate + "/" + thinRate + "/" + roofedRate +
                     *  "\n\t\toutside.Temperature: " + outdoorTemp +
                     *  "\n\t\troom.Temperature: " + naturalRoom.room.Temperature +
                     *  "\n\t\tcontrolledTemp: " + naturalRoom.controlledTemp +
                     *  "\n\t\tdesiredTemp: " + naturalRoom.naturalTemp;
                     */
#endif

                    // Add the natural room to the list
                    naturalRooms.Add(naturalRoom);
                }
                catch (Exception)
                {
                    // Exception only used in debug
#if DEBUG
                    debugDump += $"Got exception for room: {exception}";
#endif
                }

                Skip_Room :;
                // We skipped this room, need to do it this way because
                // using 'continue' in the controller loops will
                // continue the controller loops and not the room loop
            }
#if DEBUG
            /*
             * Log.Message( debugDump );
             */
#endif
        }