public override void CompTick()
        {
            base.CompTick();
            this.UpdateDesiredPowerOutput();
            if (this.radiationRadius > 0)
            {
                if (Find.TickManager.TicksGame % tickRadiation == 0)
                {
                    int num = GenRadial.NumCellsInRadius(this.radiationRadius);
                    for (int i = 0; i < num; i++)
                    {
                        AffectCell(this.parent.Position + GenRadial.RadialPattern[i]);
                    }
                }
            }


            float result;

            GenTemperature.TryGetTemperatureForCell(this.parent.Position, this.parent.Map, out result);
            temperatureRightNow = (int)Math.Round(result);
            if ((temperatureRightNow > criticalTemp) && !signalMeltdown)
            {
                signalMeltdown = true;
                this.breakdownableComp.DoBreakdown();
                this.refuelableComp.ConsumeFuel(refuelableComp.Fuel);
                List <ThingDef> links = new List <ThingDef>();
                links.Add(ThingDef.Named("VPE_NuclearGenerator"));
                Find.LetterStack.ReceiveLetter("VPE_MeltdownLetterLabel".Translate(), "VPE_MeltdownLetter".Translate(), LetterDefOf.NegativeEvent, this.parent, null, null, links, null);
            }
        }
        public static TaleData_Surroundings GenerateFrom(IntVec3 c, Map map)
        {
            TaleData_Surroundings taleData_Surroundings = new TaleData_Surroundings();

            taleData_Surroundings.tile = map.Tile;
            Room roomOrAdjacent = c.GetRoomOrAdjacent(map, RegionType.Set_All);

            if (roomOrAdjacent != null)
            {
                if (roomOrAdjacent.PsychologicallyOutdoors)
                {
                    taleData_Surroundings.weather = map.weatherManager.CurWeatherPerceived;
                }
                taleData_Surroundings.roomRole           = roomOrAdjacent.Role;
                taleData_Surroundings.roomImpressiveness = roomOrAdjacent.GetStat(RoomStatDefOf.Impressiveness);
                taleData_Surroundings.roomBeauty         = roomOrAdjacent.GetStat(RoomStatDefOf.Beauty);
                taleData_Surroundings.roomCleanliness    = roomOrAdjacent.GetStat(RoomStatDefOf.Cleanliness);
            }
            if (!GenTemperature.TryGetTemperatureForCell(c, map, out taleData_Surroundings.temperature))
            {
                taleData_Surroundings.temperature = 21f;
            }
            taleData_Surroundings.snowDepth = map.snowGrid.GetDepth(c);
            return(taleData_Surroundings);
        }
 public static bool Prefix(Plant __instance, ref float __result)
 {
     if (__instance.def.isOrkoidFungus())
     {
         float num;
         if (!GenTemperature.TryGetTemperatureForCell(__instance.Position, __instance.Map, out num))
         {
             __result = 1f;
         }
         else
         if (num < 0f)
         {
             if (__instance.def == OGOrkThingDefOf.OG_Plant_Orkoid_Cocoon)
             {
                 __result = Mathf.InverseLerp(-50f, -10f, num);
             }
             else
             {
                 __result = Mathf.InverseLerp(-30f, 0f, num);
             }
         }
         else
         if (num > 62f)
         {
             __result = Mathf.InverseLerp(116f, 62f, num);
         }
         else
         {
             __result = 1f;
         }
         return(false);
     }
     return(true);
 }
Пример #4
0
 public static bool Patch_Plant_GrowthRateFactor_Temperature_get(ref Plant __instance, ref float __result)
 {
     if (__instance is FrostPlant)
     {
         float num  = default(float);
         float num2 = __result = (!GenTemperature.TryGetTemperatureForCell(__instance.Position, __instance.Map, out num)) ? 1f : ((!(num > 42f)) ? 1f : Mathf.InverseLerp(58f, 42f, num));
         return(false);
     }
     return(true);
 }
        public override void CompTick()
        {
            base.CompTick();
            this.UpdateDesiredPowerOutput();

            Room room = this.parent.PositionHeld.GetRoom(this.parent.Map, RegionType.Set_All);

            if (room != null)
            {
                if ((room.OutdoorsForWork || (!this.parent.Map.roofGrid.Roofed(this.parent.PositionHeld))) || room.OpenRoofCount > 0)
                {
                    noReactorRoom = true;
                }
                else
                {
                    noReactorRoom = false;
                }
            }

            if (!noReactorRoom)
            {
                if (this.radiationRadius > 0)
                {
                    if (Find.TickManager.TicksGame % tickRadiation == 0)
                    {
                        int num = GenRadial.NumCellsInRadius(this.radiationRadius);
                        for (int i = 0; i < num; i++)
                        {
                            AffectCell(this.parent.Position + GenRadial.RadialPattern[i]);
                        }
                    }
                }


                float result;
                GenTemperature.TryGetTemperatureForCell(this.parent.Position, this.parent.Map, out result);
                temperatureRightNow = (int)Math.Round(result);
                if ((temperatureRightNow > criticalTemp) && !signalMeltdown)
                {
                    signalMeltdown = true;
                    this.parent.Map.weatherManager.curWeather = WeatherDef.Named("VPE_RadioactiveFog");
                    this.parent.Map.weatherManager.TransitionTo(WeatherDef.Named("VPE_RadioactiveFog"));
                    this.breakdownableComp.DoBreakdown();
                    this.refuelableComp.ConsumeFuel(refuelableComp.Fuel);
                    List <ThingDef> links = new List <ThingDef>();
                    links.Add(ThingDef.Named("VPE_NuclearGenerator"));
                    Find.LetterStack.ReceiveLetter("VPE_MeltdownLetterLabel".Translate(), "VPE_MeltdownLetter".Translate(), LetterDefOf.NegativeEvent, this.parent, null, null, links, null);
                }
            }
        }
        private static void WriteMoreDebugOutput(StringBuilder debugString, IntVec3 mouseCell)
        {
            var map = Find.CurrentMap;

            if (MoreDebugViewSettings.writeTemperature)
            {
                debugString.AppendLine("---");
                debugString.AppendLine("Temperature: " +
                                       (GenTemperature.TryGetTemperatureForCell(mouseCell, map, out var temperature) ? $"{temperature:f1}" : ""));
            }

            if (MoreDebugViewSettings.writeEdificeGrid)
            {
                debugString.AppendLine("---");
                debugString.AppendLine("Building at edifice grid: " + map.edificeGrid[mouseCell]);
            }

            if (MoreDebugViewSettings.writeDoors)
            {
                debugString.AppendLine("---");
                var pawn = Find.Selector.SingleSelectedObject as Pawn;
                if (pawn != null)
                {
                    debugString.AppendLine("From selected pawn " + pawn + " to door");
                    debugString.AppendLine("- CaresAboutForbidden(p, false): " + ForbidUtility.CaresAboutForbidden(pawn, false));
                    //debugString.AppendLine("- mindState.maxDistToSquadFlag: " + pawn.mindState.maxDistToSquadFlag);
                }

                foreach (var thing in map.thingGrid.ThingsAt(mouseCell))
                {
                    if (thing is Building_Door door)
                    {
                        debugString.AppendLine("Door: " + door);
                        debugString.AppendLine("- Open: " + door.Open);
                        debugString.AppendLine("- HoldOpen: " + door.HoldOpen);
                        debugString.AppendLine("- FreePassage: " + door.FreePassage);
                        debugString.AppendLine("- WillCloseSoon: " + door.WillCloseSoon);
                        debugString.AppendLine("- BlockedOpenMomentary: " + door.BlockedOpenMomentary);
                        debugString.AppendLine("- SlowsPawns: " + door.SlowsPawns);
                        debugString.AppendLine("- TicksToOpenNow: " + door.TicksToOpenNow);
                        debugString.AppendLine("- FriendlyTouchedRecently: " +
                                               methodof_Building_Door_FriendlyTouchedRecently.Invoke(door, Array.Empty <object>()));
                        debugString.AppendLine("- lastFriendlyTouchTick: " + Building_Door_lastFriendlyTouchTick(door));
                        debugString.AppendLine("- ticksUntilClose: " + Building_Door_ticksUntilClose(door));
                        debugString.AppendLine("- ticksSinceOpen: " + Building_Door_ticksSinceOpen(door));
                        debugString.AppendLine("- IsForbidden(player): " + door.IsForbidden(Faction.OfPlayer));
                        debugString.AppendLine("- def.Fillage: " + door.def.Fillage);
                        debugString.AppendLine("- CanBeSeenOver: " + door.CanBeSeenOver());
                        debugString.AppendLine("- BaseBlockChance: " + door.BaseBlockChance());

                        if (pawn != null)
                        {
                            debugString.AppendLine("- For selected pawn: " + pawn);
                            debugString.AppendLine("  - CanPhysicallyPass(p): " + door.CanPhysicallyPass(pawn));
                            debugString.AppendLine("  - PawnCanOpen(p): " + door.PawnCanOpen(pawn));
                            debugString.AppendLine("  - BlocksPawn(p): " + door.BlocksPawn(pawn));
                            debugString.AppendLine("  - p.HostileTo(this): " + pawn.HostileTo(door));
                            debugString.AppendLine("  - PathWalkCostFor(p): " + door.PathWalkCostFor(pawn));
                            debugString.AppendLine("  - IsDangerousFor(p): " + door.IsDangerousFor(pawn));
                            debugString.AppendLine("  - IsForbidden(p): " + door.IsForbidden(pawn));
                            debugString.AppendLine("  - Position.IsForbidden(p): " + door.Position.IsForbidden(pawn));
                            debugString.AppendLine("  - Position.InAllowedArea(p): " + door.Position.InAllowedArea(pawn));
                            //debugString.AppendLine("  - Position.InHorDistOf(p.DutyLocation,p.mindState.maxDistToSquadFlag): " +
                            //    (pawn.mindState.maxDistToSquadFlag > 0f ?
                            //        door.Position.InHorDistOf(pawn.DutyLocation(), pawn.mindState.maxDistToSquadFlag).ToString() :
                            //        "N/A"));
                            //debugString.AppendLine("  - IsForbidden(p.Faction): " + door.IsForbidden(pawn.Faction));
                            //debugString.AppendLine("  - IsForbidden(p.HostFaction): " + door.IsForbidden(pawn.HostFaction));
                            //debugString.AppendLine("  - pawn.Lord.extraForbiddenThings.Contains(this): " +
                            //    (pawn.GetLord()?.extraForbiddenThings?.Contains(door) ?? false));
                            debugString.AppendLine("  - IsForbiddenToPass(p): " + door.IsForbiddenToPass(pawn));
                        }

                        if (door is Building_DoorRegionHandler invisDoor)
                        {
                            var parentDoor = invisDoor.ParentDoor;
                            debugString.AppendLine("- ParentDoor: " + parentDoor);
                            debugString.AppendLine("  - DrawPos: " + parentDoor.DrawPos);
                            debugString.AppendLine("  - debugDrawVectors.percentOpen: " + parentDoor.debugDrawVectors?.percentOpen);
                            debugString.AppendLine("  - debugDrawVectors.offsetVector: " + parentDoor.debugDrawVectors?.offsetVector);
                            debugString.AppendLine("  - debugDrawVectors.scaleVector: " + parentDoor.debugDrawVectors?.scaleVector);
                            debugString.AppendLine("  - debugDrawVectors.graphicVector: " + parentDoor.debugDrawVectors?.graphicVector);
                            debugString.AppendLine("  - Open: " + parentDoor.Open);
                            debugString.AppendLine("  - HoldOpen: " + parentDoor.HoldOpen);
                            debugString.AppendLine("  - FreePassage: " + parentDoor.FreePassage);
                            debugString.AppendLine("  - WillCloseSoon: " + parentDoor.WillCloseSoon);
                            debugString.AppendLine("  - BlockedOpenMomentary: " + parentDoor.BlockedOpenMomentary);
                            debugString.AppendLine("  - SlowsPawns: " + parentDoor.SlowsPawns);
                            debugString.AppendLine("  - TicksToOpenNow: " + parentDoor.TicksToOpenNow);
                            debugString.AppendLine("  - FriendlyTouchedRecently: " + parentDoor.FriendlyTouchedRecently);
                            debugString.AppendLine("  - lastFriendlyTouchTick: " + Building_DoorExpanded_lastFriendlyTouchTick(parentDoor));
                            debugString.AppendLine("  - ticksUntilClose: " + parentDoor.TicksUntilClose);
                            debugString.AppendLine("  - ticksSinceOpen: " + parentDoor.TicksSinceOpen);
                            debugString.AppendLine("  - Forbidden: " + parentDoor.Forbidden);
                            debugString.AppendLine("  - def.Fillage: " + parentDoor.def.Fillage);
                            debugString.AppendLine("  - CanBeSeenOver: " + parentDoor.CanBeSeenOver());
                            debugString.AppendLine("  - BaseBlockChance: " + parentDoor.BaseBlockChance());

                            if (parentDoor is Building_DoorRemote parentDoorRemote)
                            {
                                debugString.AppendLine("  - Button: " + parentDoorRemote.Button);
                                debugString.AppendLine("  - SecuredRemotely: " + parentDoorRemote.SecuredRemotely);
                                debugString.AppendLine("  - HoldOpenRemotely: " + parentDoorRemote.HoldOpenRemotely);
                                debugString.AppendLine("  - ForcedClosed: " + parentDoorRemote.ForcedClosed);
                            }

                            if (pawn != null)
                            {
                                debugString.AppendLine("  - For selected pawn: " + pawn);
                                //debugString.AppendLine("    - CanPhysicallyPass(p): " + parentDoor.CanPhysicallyPass(pawn));
                                debugString.AppendLine("    - PawnCanOpen(p): " + parentDoor.PawnCanOpen(pawn));
                                debugString.AppendLine("    - BlocksPawn(p): " + parentDoor.BlocksPawn(pawn));
                                debugString.AppendLine("    - p.HostileTo(this): " + pawn.HostileTo(parentDoor));
                                debugString.AppendLine("    - PathWalkCostFor(p): " + parentDoor.PathWalkCostFor(pawn));
                                debugString.AppendLine("    - IsDangerousFor(p): " + parentDoor.IsDangerousFor(pawn));
                                debugString.AppendLine("    - IsForbidden(p): " + parentDoor.IsForbidden(pawn));
                                debugString.AppendLine("    - Position.IsForbidden(p): " + parentDoor.Position.IsForbidden(pawn));
                                debugString.AppendLine("    - Position.InAllowedArea(p): " + parentDoor.Position.InAllowedArea(pawn));
                                //debugString.AppendLine("    - Position.InHorDistOf(p.DutyLocation,p.mindState.maxDistToSquadFlag): " +
                                //    (pawn.mindState.maxDistToSquadFlag > 0f ?
                                //        parentDoor.Position.InHorDistOf(pawn.DutyLocation(), pawn.mindState.maxDistToSquadFlag).ToString() :
                                //        "N/A"));
                                //debugString.AppendLine("    - IsForbidden(p.Faction): " + parentDoor.IsForbidden(pawn.Faction));
                                //debugString.AppendLine("    - IsForbidden(p.HostFaction): " + parentDoor.IsForbidden(pawn.HostFaction));
                                //debugString.AppendLine("    - pawn.Lord.extraForbiddenThings.Contains(this): " +
                                //    (pawn.GetLord()?.extraForbiddenThings?.Contains(parentDoor) ?? false));
                            }
                        }
                    }
                    else if (thing is Building_DoorRemoteButton remoteButton)
                    {
                        debugString.AppendLine("RemoteButton: " + remoteButton);
                        debugString.AppendLine("- LinkedDoors: " + remoteButton.LinkedDoors.ToStringSafeEnumerable());
                        debugString.AppendLine("- ButtonOn: " + remoteButton.ButtonOn);
                        debugString.AppendLine("- NeedsToBeSwitched: " + remoteButton.NeedsToBeSwitched);
                    }
                }
            }

            if (MoreDebugViewSettings.writePatchCallRegistry)
            {
                debugString.AppendLine("---");
                debugString.AppendLine("Harmony Patch Call Registry:");
                foreach (var pair in patchCallRegistry)
                {
                    debugString.AppendLine($"- {pair.Key}: {pair.Value}");
                }
            }
        }
Пример #7
0
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (Controller.Settings.waterFreezes.Equals(false))
            {
                return;
            }
            int   num  = Mathf.RoundToInt((float)this.map.Area * 0.00005f);
            int   area = this.map.Area;
            float cellTemp;

            for (int i = 0; i < num; i++)
            {
                this.cycleIndex++;
                if (this.cycleIndex >= area)
                {
                    this.cycleIndex = 0;
                }
                IntVec3 c          = this.map.cellsInRandomOrder.Get(this.cycleIndex);
                var     terrainDef = map.terrainGrid.TerrainAt(c);
                if (!GenTemperature.TryGetTemperatureForCell(c, map, out cellTemp))
                {
                    cellTemp = 0f;
                }
                float shallowChance    = (cellTemp * cellTemp) / 100f;
                float deepChance       = (cellTemp * cellTemp * 0.2f) / 100f;
                float permafrostChance = deepChance;
                if (permafrostChance > 0.2f)
                {
                    permafrostChance = 0.2f;
                }
                if (cellTemp < 0f)
                {
                    if (terrainDef.defName == "WaterShallow" || terrainDef.defName == "WaterMovingShallow" || terrainDef.defName == "IceST" || terrainDef.defName == "IceSMT")
                    {
                        int freezable = 0;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (!map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") && map.terrainGrid.TerrainAt(newSpot).defName != "Marsh" && map.terrainGrid.TerrainAt(newSpot).defName != "BridgeMarsh" && map.terrainGrid.TerrainAt(newSpot).defName != "Bridge")
                                        {
                                            freezable++;
                                        }
                                    }
                                }
                            }
                        }
                        if (Rand.Value < shallowChance * freezable)
                        {
                            List <Thing> thingList = c.GetThingList(map);
                            for (int j = 0; j < thingList.Count; j++)
                            {
                                Thing item = thingList[j];
                                if (item.def.defName == "Fishing Spot" || item.def.defName == "ZARS_FishingSpot")
                                {
                                    item.Destroy(DestroyMode.Vanish);
                                }
                            }
                            string iceType;
                            if (terrainDef.defName == "WaterShallow")
                            {
                                iceType = "IceST";
                            }
                            else if (terrainDef.defName == "WaterMovingShallow")
                            {
                                iceType = "IceSMT";
                            }
                            else if (terrainDef.defName == "IceST")
                            {
                                iceType = "IceS";
                            }
                            else
                            {
                                iceType = "IceSM";
                            }
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named(iceType));
                        }
                    }
                    if (terrainDef.defName == "WaterDeep" || terrainDef.defName == "WaterMovingChestDeep" || terrainDef.defName == "IceDT" || terrainDef.defName == "IceDMT")
                    {
                        int freezable = 0;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (!map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") && map.terrainGrid.TerrainAt(newSpot).defName != "Marsh" && map.terrainGrid.TerrainAt(newSpot).defName != "BridgeMarsh" && map.terrainGrid.TerrainAt(newSpot).defName != "Bridge")
                                        {
                                            freezable++;
                                        }
                                    }
                                }
                            }
                        }
                        if (Rand.Value < deepChance * freezable)
                        {
                            List <Thing> thingList = c.GetThingList(map);
                            for (int j = 0; j < thingList.Count; j++)
                            {
                                Thing item = thingList[j];
                                if (item.def.defName == "Fishing Spot" || item.def.defName == "ZARS_FishingSpot")
                                {
                                    item.Destroy(DestroyMode.Vanish);
                                }
                            }
                            string iceType;
                            if (terrainDef.defName == "WaterDeep")
                            {
                                iceType = "IceDT";
                            }
                            else if (terrainDef.defName == "WaterMovingChestDeep")
                            {
                                iceType = "IceDMT";
                            }
                            else if (terrainDef.defName == "IceDT")
                            {
                                iceType = "IceD";
                            }
                            else
                            {
                                iceType = "IceDM";
                            }
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named(iceType));
                        }
                    }
                    if (terrainDef.defName == "Marsh" || terrainDef.defName == "IceMarshT")
                    {
                        int freezable = 0;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (!map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") && map.terrainGrid.TerrainAt(newSpot).defName != "Marsh" && map.terrainGrid.TerrainAt(newSpot).defName != "BridgeMarsh" && map.terrainGrid.TerrainAt(newSpot).defName != "Bridge")
                                        {
                                            freezable++;
                                        }
                                    }
                                }
                            }
                        }
                        if (Rand.Value < shallowChance * freezable)
                        {
                            List <Thing> thingList = c.GetThingList(map);
                            for (int j = 0; j < thingList.Count; j++)
                            {
                                Thing item = thingList[j];
                                if (item.def.defName == "Fishing Spot" || item.def.defName == "ZARS_FishingSpot")
                                {
                                    item.Destroy(DestroyMode.Vanish);
                                }
                            }
                            string iceType;
                            if (terrainDef.defName == "Marsh")
                            {
                                iceType = "IceMarshT";
                            }
                            else
                            {
                                iceType = "IceMarsh";
                            }
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named(iceType));
                        }
                    }
                    if ((terrainDef.defName == "Soil" || terrainDef.defName == "Gravel" || terrainDef.defName == "MossyTerrain") && map.Biome.defName.Contains("Permafrost"))
                    {
                        int freezable = 0;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (map.terrainGrid.TerrainAt(newSpot).defName == "Ice")
                                        {
                                            freezable++;
                                        }
                                    }
                                }
                            }
                        }
                        if (Rand.Value < (permafrostChance / 8) * freezable)
                        {
                            List <Thing> thingList = c.GetThingList(map);
                            for (int j = 0; j < thingList.Count; j++)
                            {
                                Thing item = thingList[j];
                                if (item.def.thingClass == typeof(Plant))
                                {
                                    item.Destroy(DestroyMode.Vanish);
                                }
                            }
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named("Ice"));
                        }
                    }
                }
                if (cellTemp > 0f)
                {
                    if (terrainDef.defName.Contains("IceS") || terrainDef.defName.Contains("IceD"))
                    {
                        int quickThaw = 1;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (!terrainDef.label.Contains("Thin"))
                                        {
                                            if (map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") || map.terrainGrid.TerrainAt(newSpot).defName == "Marsh" || map.terrainGrid.TerrainAt(newSpot).label.Contains("Thin"))
                                            {
                                                quickThaw++;
                                            }
                                        }
                                        else
                                        {
                                            if (map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") || map.terrainGrid.TerrainAt(newSpot).defName == "Marsh")
                                            {
                                                quickThaw++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (quickThaw == 1)
                        {
                            if (Rand.Value < 0.67f)
                            {
                                quickThaw = 0;
                            }
                        }
                        if (Rand.Value < (shallowChance * quickThaw))
                        {
                            string waterType;
                            if (terrainDef.defName == "IceST")
                            {
                                waterType = "WaterShallow";
                            }
                            else if (terrainDef.defName == "IceS")
                            {
                                waterType = "IceST";
                            }
                            else if (terrainDef.defName == "IceDT")
                            {
                                waterType = "WaterDeep";
                            }
                            else if (terrainDef.defName == "IceD")
                            {
                                waterType = "IceDT";
                            }
                            else if (terrainDef.defName == "IceSMT")
                            {
                                waterType = "WaterMovingShallow";
                            }
                            else if (terrainDef.defName == "IceSM")
                            {
                                waterType = "IceSMT";
                            }
                            else if (terrainDef.defName == "IceDMT")
                            {
                                waterType = "WaterMovingChestDeep";
                            }
                            else
                            {
                                waterType = "IceDMT";
                            }
                            if (waterType.Contains("Water"))
                            {
                                map.snowGrid.SetDepth(c, 0f);
                            }
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named(waterType));
                        }
                    }
                    if (terrainDef.defName.Contains("IceMarsh"))
                    {
                        int quickThaw = 1;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (!terrainDef.label.Contains("Thin"))
                                        {
                                            if (map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") || map.terrainGrid.TerrainAt(newSpot).defName == "Marsh" || map.terrainGrid.TerrainAt(newSpot).label.Contains("Thin"))
                                            {
                                                quickThaw++;
                                            }
                                        }
                                        else
                                        {
                                            if (map.terrainGrid.TerrainAt(newSpot).defName.Contains("Water") || map.terrainGrid.TerrainAt(newSpot).defName == "Marsh")
                                            {
                                                quickThaw++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (quickThaw == 1)
                        {
                            if (Rand.Value < 0.67f)
                            {
                                quickThaw = 0;
                            }
                        }
                        if (Rand.Value < (shallowChance * quickThaw))
                        {
                            string waterType;
                            if (terrainDef.defName == "IceMarsh")
                            {
                                waterType = "IceMarshT";
                            }
                            else
                            {
                                waterType = "Marsh";
                                map.snowGrid.SetDepth(c, 0f);
                            }
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named(waterType));
                        }
                    }
                    if (terrainDef.defName == "Ice" && map.Biome.defName.Contains("Permafrost"))
                    {
                        int quickThaw = 0;
                        for (int k = -1; k < 2; k++)
                        {
                            for (int j = -1; j < 2; j++)
                            {
                                int x = c.x + k;
                                int z = c.z + j;
                                if ((k == 0 && j == 1) || (k == 0 && j == -1) || (k == 1 && j == 0) || (k == -1 && j == 0))
                                {
                                    if (x > 0 && x < this.map.Size.x && z > 0 && z < this.map.Size.z)
                                    {
                                        IntVec3 newSpot = new IntVec3(x, 0, z);
                                        if (!map.terrainGrid.TerrainAt(newSpot).defName.Contains("Ice"))
                                        {
                                            quickThaw++;
                                        }
                                    }
                                }
                            }
                        }
                        if (Rand.Value < ((permafrostChance / 4) * quickThaw))
                        {
                            map.terrainGrid.SetTerrain(c, TerrainDef.Named("Gravel"));
                        }
                    }
                }
            }
        }
Пример #8
0
        public override void MapComponentTick()
        {
            if (Controller.Settings.waterResponsive.Equals(false) || map.Biome == BiomeDefOf.SeaIce)
            {
                return;
            }
            base.MapComponentTick();
            int mapArea;

            if (MP.enabled)
            {
                mapArea = Mathf.RoundToInt(map.Area * 0.000175f);
            }
            else
            {
                mapArea = Mathf.RoundToInt(map.Area * Rand.Range(0.000065f, 0.000320f));
            }
            for (int i = 0; i < mapArea; i++)
            {
                loopCycle++;
                if (loopCycle >= map.Area)
                {
                    loopCycle = 0;
                }
                IntVec3 terrainCell = map.cellsInRandomOrder.Get(loopCycle);
                GenTemperature.TryGetTemperatureForCell(terrainCell, map, out float terrainTemp);
                float shallowSpeed = terrainTemp <0f && terrainTemp> -20f ? -terrainTemp * 7f : -terrainTemp * 18f;
                float deepSpeed    = terrainTemp <0f && terrainTemp> -20f ? -terrainTemp / 10f : -terrainTemp / 3f;
                float thawSpeed    = terrainTemp < 0f ? -terrainTemp * 10f : terrainTemp * 21f;
                var   terrainDef   = map.terrainGrid.TerrainAt(terrainCell);

                // freeze process
                if (terrainTemp < -35f)
                {
                    if (terrainDef.defName == "WaterOceanShallow")
                    {
                        int            toFreeze     = 0;
                        float          tempConstant = 0f;
                        List <IntVec3> tileList     = GenAdjFast.AdjacentCellsCardinal(terrainCell);
                        tileList.Add(terrainCell);
                        IntVec3 newTile = tileList.RandomElement();
                        if (newTile.InBounds(map))
                        {
                            if (!map.terrainGrid.TerrainAt(newTile).defName.Contains("Water") &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Marsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "BridgeMarsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Bridge")
                            {
                                toFreeze++;
                                tempConstant++;
                            }
                            if (terrainDef.defName == "WaterOceanShallow")
                            {
                                if (Rand.Value < shallowSpeed * toFreeze * (tempConstant * 30f))
                                {
                                    string iceName;
                                    if (terrainDef.defName == "WaterOceanShallow")
                                    {
                                        iceName = "IceOceanShallow";
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                    map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(iceName));
                                }
                            }
                        }
                    }
                }
                if (terrainTemp < -20f)
                {
                    if (terrainDef.defName == "WaterMovingShallow" || terrainDef.defName == "WaterMovingChestDeep")
                    {
                        int            toFreeze     = 0;
                        float          tempConstant = 0f;
                        List <IntVec3> tileList     = GenAdjFast.AdjacentCellsCardinal(terrainCell);
                        tileList.Add(terrainCell);
                        IntVec3 newTile = tileList.RandomElement();
                        if (newTile.InBounds(map))
                        {
                            if (!map.terrainGrid.TerrainAt(newTile).defName.Contains("Water") &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Marsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "BridgeMarsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Bridge")
                            {
                                toFreeze++;
                                tempConstant++;
                            }
                            if (terrainDef.defName == "WaterMovingShallow")
                            {
                                if (Rand.Value < shallowSpeed * toFreeze * (tempConstant * 30f))
                                {
                                    string iceName;
                                    if (terrainDef.defName == "WaterMovingShallow")
                                    {
                                        iceName = "IceMovingShallow";
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                    map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(iceName));
                                }
                            }
                            if (terrainDef.defName == "WaterMovingChestDeep")
                            {
                                if (Rand.Value < deepSpeed * toFreeze * (tempConstant * 3f))
                                {
                                    string iceName;
                                    if (terrainDef.defName == "WaterMovingChestDeep")
                                    {
                                        iceName = "IceMovingChestDeep";
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                    map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(iceName));
                                }
                            }
                        }
                    }
                }
                if (terrainTemp < 0f)
                {
                    if (terrainDef.defName == "WaterShallow" || terrainDef.defName == "Marsh" || terrainDef.defName == "WaterDeep" || terrainDef.defName == "WaterOceanShallow")
                    {
                        int            toFreeze     = 0;
                        float          tempConstant = 0f;
                        List <IntVec3> tileList     = GenAdjFast.AdjacentCellsCardinal(terrainCell);
                        tileList.Add(terrainCell);
                        IntVec3 newTile = tileList.RandomElement();
                        if (newTile.InBounds(map))
                        {
                            if (!map.terrainGrid.TerrainAt(newTile).defName.Contains("Water") &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Marsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "BridgeMarsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Bridge")
                            {
                                toFreeze++;
                                tempConstant++;
                            }
                            if (terrainDef.defName == "WaterShallow" || terrainDef.defName == "Marsh")
                            {
                                if (Rand.Value < shallowSpeed * toFreeze * (tempConstant * 10f))
                                {
                                    string iceName;
                                    if (terrainDef.defName == "WaterShallow")
                                    {
                                        iceName = "IceShallow";
                                    }
                                    else
                                    {
                                        iceName = "IceMarsh";
                                    }
                                    map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(iceName));
                                }
                            }
                            if (terrainDef.defName == "WaterDeep")
                            {
                                if (Rand.Value < deepSpeed * toFreeze * (tempConstant * 10f))
                                {
                                    string iceName;
                                    if (terrainDef.defName == "WaterDeep")
                                    {
                                        iceName = "IceDeep";
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                    map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(iceName));
                                }
                            }
                        }
                    }
                }

                // Thaw process
                if (terrainTemp > -19f)
                {
                    if (terrainDef.defName == "IceOceanShallow")
                    {
                        int            toThaw       = 0;
                        float          tempConstant = 0f;
                        List <IntVec3> tileList     = GenAdjFast.AdjacentCellsCardinal(terrainCell);
                        tileList.Add(terrainCell);
                        IntVec3 newTile = tileList.RandomElement();
                        if (newTile.InBounds(map))
                        {
                            if (!map.terrainGrid.TerrainAt(newTile).defName.Contains("Ice") &&
                                map.terrainGrid.TerrainAt(newTile).defName != "BridgeMarsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Bridge")
                            {
                                toThaw++;
                                tempConstant++;
                            }
                            if (Rand.Value < thawSpeed * toThaw * (tempConstant * 5f))
                            {
                                string waterName;
                                if (terrainDef.defName == "IceOceanShallow")
                                {
                                    waterName = "WaterOceanShallow";
                                }
                                else
                                {
                                    continue;
                                }
                                if (waterName.Contains("Water"))
                                {
                                    map.snowGrid.SetDepth(terrainCell, 0f);
                                }
                                map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(waterName));
                            }
                        }
                    }
                }
                if (terrainTemp > -13f)
                {
                    if (terrainDef.defName == "IceMovingShallow" || terrainDef.defName == "IceMovingChestDeep")
                    {
                        int            toThaw       = 0;
                        float          tempConstant = 0f;
                        List <IntVec3> tileList     = GenAdjFast.AdjacentCellsCardinal(terrainCell);
                        tileList.Add(terrainCell);
                        IntVec3 newTile = tileList.RandomElement();
                        if (newTile.InBounds(map))
                        {
                            if (!map.terrainGrid.TerrainAt(newTile).defName.Contains("Ice") &&
                                map.terrainGrid.TerrainAt(newTile).defName != "BridgeMarsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Bridge")
                            {
                                toThaw++;
                                tempConstant++;
                            }
                            if (Rand.Value < thawSpeed * toThaw * (tempConstant * 5f))
                            {
                                string waterName;
                                if (terrainDef.defName == "IceMovingShallow")
                                {
                                    waterName = "WaterMovingShallow";
                                }
                                else
                                {
                                    waterName = "WaterMovingChestDeep";
                                }

                                if (waterName.Contains("Water"))
                                {
                                    map.snowGrid.SetDepth(terrainCell, 0f);
                                }
                                map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(waterName));
                            }
                        }
                    }
                }
                if (terrainTemp > 0f)
                {
                    if (terrainDef.defName == "IceShallow" || terrainDef.defName == "IceDeep" || terrainDef.defName == "IceMarsh")
                    {
                        int            toThaw   = 0;
                        List <IntVec3> tileList = GenAdjFast.AdjacentCellsCardinal(terrainCell);
                        tileList.Add(terrainCell);
                        IntVec3 newTile = tileList.RandomElement();
                        if (newTile.InBounds(map))
                        {
                            if (!map.terrainGrid.TerrainAt(newTile).defName.Contains("Ice") &&
                                map.terrainGrid.TerrainAt(newTile).defName != "BridgeMarsh" &&
                                map.terrainGrid.TerrainAt(newTile).defName != "Bridge")
                            {
                                toThaw++;
                            }
                            if (Rand.Value < thawSpeed * toThaw)
                            {
                                string waterName;
                                if (terrainDef.defName == "IceShallow")
                                {
                                    waterName = "WaterShallow";
                                }
                                else if (terrainDef.defName == "IceDeep")
                                {
                                    waterName = "WaterDeep";
                                }
                                else
                                {
                                    waterName = "Marsh";
                                }

                                if (waterName.Contains("Water") || waterName == "Marsh")
                                {
                                    map.snowGrid.SetDepth(terrainCell, 0f);
                                }
                                map.terrainGrid.SetTerrain(terrainCell, TerrainDef.Named(waterName));
                            }
                        }
                    }
                }
            }
        }