private void doTides()
        {
            //nots to future me: use this.howManyTideSteps - 1 so we always have a little bit of wet sand, or else it looks stupid.
            if (!this.doCoast || !Settings.doTides || this.ticks % 100 != 0)
            {
                return;
            }

            string tideType = getTideLevel();
            int    half     = (int)Math.Round((this.howManyTideSteps - 1M) / 2);
            int    max      = this.howManyTideSteps - 1;

            if ((tideType == "normal" && tideLevel == half) || (tideType == "high" && tideLevel == max) || (tideType == "low" && tideLevel == 0))
            {
                return;
            }
            if (tideType == "normal" && tideLevel == max)
            {
                tideLevel--;
                return;
            }


            List <IntVec3> cellsToChange = this.tideCellsList[this.tideLevel];

            for (int i = 0; i < cellsToChange.Count; i++)
            {
                IntVec3  c    = cellsToChange[i];
                cellData cell = this.cellWeatherAffects[c];
                cell.setTerrain("tide");
            }

            if (tideType == "high")
            {
                if (this.tideLevel < max)
                {
                    this.tideLevel++;
                }
            }
            else if (tideType == "low")
            {
                if (this.tideLevel > 0)
                {
                    this.tideLevel--;
                }
            }
            else if (tideType == "normal")
            {
                if (this.tideLevel > half)
                {
                    this.tideLevel--;
                }
                else if (this.tideLevel < half)
                {
                    this.tideLevel++;
                }
            }
        }
示例#2
0
        public void doFloods()
        {
            if (this.ticks % 300 != 0)
            {
                int half = (int)Math.Round((this.howManyFloodSteps - 1M) / 2);
                int max  = this.howManyFloodSteps - 1;


                string flood = this.getFloodType();



                string overrideType = "";
                if (this.floodLevel < max && flood == "high")
                {
                    overrideType = "wet";
                }
                else if (this.floodLevel > 0 && flood == "low")
                {
                    overrideType = "dry";
                }
                else if (this.floodLevel < half && flood == "normal")
                {
                    overrideType = "wet";
                }
                else if (this.floodLevel > half && flood == "normal")
                {
                    overrideType = "dry";
                }

                if (this.floodLevel == this.howManyFloodSteps && flood == "high")
                {
                    return;
                }
                else if (this.floodLevel == 0 && flood == "low")
                {
                    return;
                }
                else if (this.floodLevel == half && flood == "normal")
                {
                    return;
                }


                List <IntVec3> cellsToChange = this.floodCellsList[this.floodLevel];
                for (int i = 0; i < cellsToChange.Count; i++)
                {
                    IntVec3  c    = cellsToChange[i];
                    cellData cell = this.cellWeatherAffects[c];
                    if (overrideType != "")
                    {
                        cell.overrideType = overrideType;
                    }
                    cell.setTerrain("flooded");
                }

                if (this.floodLevel < max && flood == "high")
                {
                    this.floodLevel++;
                }
                else if (this.floodLevel > 0 && flood == "low")
                {
                    this.floodLevel--;
                }
                else if (this.floodLevel < half && flood == "normal")
                {
                    this.floodLevel++;
                }
                else if (this.floodLevel > half && flood == "normal")
                {
                    this.floodLevel--;
                }
            }
        }
示例#3
0
        public void doCellEnvironment(IntVec3 c)
        {
            if (!this.cellWeatherAffects.ContainsKey(c))
            {
                return;
            }
            cellData cell = this.cellWeatherAffects[c];

            cell.DoCellSteadyEffects();

            if (this.ticks % 2 == 0)
            {
                cell.unpack();
            }

            TerrainDef currentTerrain = c.GetTerrain(this.map);
            Room       room           = c.GetRoom(this.map, RegionType.Set_All);
            bool       roofed         = this.map.roofGrid.Roofed(c);
            bool       flag2          = room != null && room.UsesOutdoorTemperature;

            bool gettingWet = false;

            cell.gettingWet = false;

            //check if the terrain has been floored
            DesignationCategoryDef cats = currentTerrain.designationCategory;

            if (cats != null)
            {
                if (cats.defName == "Floors")
                {
                    cell.baseTerrain = currentTerrain;
                }
            }

            //spawn special things
            if (Rand.Value < .0001f)
            {
                if (c.InBounds(this.map))
                {
                    string defName = "";

                    if (currentTerrain.defName == "TKKN_Lava")
                    {
                        defName = "TKKN_LavaRock";
                    }
                    else if (currentTerrain.defName == "TKKN_LavaRock_RoughHewn" && this.map.Biome.defName == "TKKN_VolcanicFlow")
                    {
                        defName = "TKKN_SteamVent";
                    }

                    if (defName != "")
                    {
                        Thing check = (Thing)(from t in c.GetThingList(this.map)
                                              where t.def.defName == defName
                                              select t).FirstOrDefault <Thing>();
                        if (check == null)
                        {
                            Thing thing = (Thing)ThingMaker.MakeThing(ThingDef.Named(defName), null);
                            GenSpawn.Spawn(thing, c, map);
                        }
                    }
                }
            }


            #region Rain
            if (Settings.showRain && !cell.currentTerrain.HasTag("TKKN_Wet"))
            {
                //if it's raining in this cell:
                if (!roofed && this.map.weatherManager.curWeather.rainRate > .0001f)
                {
                    if (this.floodThreat < 1090000)
                    {
                        this.floodThreat += 1 + 2 * (int)Math.Round(this.map.weatherManager.curWeather.rainRate);
                    }
                    gettingWet      = true;
                    cell.gettingWet = true;
                    cell.setTerrain("wet");
                }
                else if (Settings.showRain && !roofed && this.map.weatherManager.curWeather.snowRate > .001f)
                {
                    gettingWet      = true;
                    cell.gettingWet = true;
                    cell.setTerrain("wet");
                }
                else
                {
                    if (this.map.weatherManager.curWeather.rainRate == 0)
                    {
                        this.floodThreat--;
                    }
                    //DRY GROUND
                    cell.setTerrain("dry");
                }
            }
            #endregion

            #region Cold
            bool isCold = this.checkIfCold(c);
            if (isCold)
            {
                cell.setTerrain("frozen");
            }
            else
            {
                cell.setTerrain("thaw");
            }

            #region Frost

            if (isCold)
            {
                //handle frost based on snowing
                if (!roofed && this.map.weatherManager.SnowRate > 0.001f)
                {
                    this.map.GetComponent <FrostGrid>().AddDepth(c, this.map.weatherManager.SnowRate * -.01f);
                }
                else
                {
                    CreepFrostAt(c, 0.46f * .3f, map);
                }
            }
            else
            {
                float frosty = cell.temperature * -.025f;
//				float frosty = this.map.mapTemperature.OutdoorTemp * -.03f;
                this.map.GetComponent <FrostGrid>().AddDepth(c, frosty);
                if (this.map.GetComponent <FrostGrid>().GetDepth(c) > .3f)
                {
                    // cell.isMelt = true;
                }
            }


            #endregion

            #region plant damage

            //HANDLE PLANT DAMAGES:
            if (gettingWet)
            {
                //note - removed ismelt because the dirt shouldn't dry out in winter, and snow wets the ground then.
                if (cell.howWetPlants < (float)100)
                {
                    if (this.map.weatherManager.curWeather.rainRate > 0)
                    {
                        cell.howWetPlants += this.map.weatherManager.curWeather.rainRate * 2;
                    }
                    else if (this.map.weatherManager.curWeather.snowRate > 0)
                    {
                        cell.howWetPlants += this.map.weatherManager.curWeather.snowRate * 2;
                    }
                }
            }
            else
            {
                if (this.map.mapTemperature.OutdoorTemp > 20)
                {
                    cell.howWetPlants += -1 * ((this.map.mapTemperature.OutdoorTemp / humidity) / 10);
                    if (cell.howWetPlants <= 0)
                    {
                        if (cell.currentTerrain.HasModExtension <TerrainWeatherReactions>())
                        {
                            TerrainWeatherReactions weather = cell.currentTerrain.GetModExtension <TerrainWeatherReactions>();
                            if (weather.dryTerrain == null)
                            {
                                //only hurt plants on terrain that's not wet.
                                this.hurtPlants(c, false, true);
                            }
                        }
                        else
                        {
                            this.hurtPlants(c, false, true);
                        }
                    }
                }
            }

            #endregion

            /* MAKE THIS A WEATHER
             #region heat
             * Thing overlayHeat = (Thing)(from t in c.GetThingList(this.map)
             *                                                      where t.def.defName == "TKKN_HeatWaver"
             *                                                      select t).FirstOrDefault<Thing>();
             * if (this.checkIfHot(c))
             * {
             *      if (overlayHeat == null && Settings.showHot)
             *      {
             *              Thing heat = ThingMaker.MakeThing(ThingDefOf.TKKN_HeatWaver, null);
             *              GenSpawn.Spawn(heat, c, map);
             *      }
             * }
             * else
             * {
             *      if (overlayHeat != null)
             *      {
             *              overlayHeat.Destroy();
             *      }
             * }
             #endregion
             */

            #region Puddles
            if (cell.howWet < 3 && Settings.showRain && (cell.isMelt || gettingWet))
            {
                cell.howWet += 2;
            }
            else if (cell.howWet > -1)
            {
                cell.howWet--;
            }

            //PUDDLES
            Thing puddle = (Thing)(from t in c.GetThingList(this.map)
                                   where t.def.defName == "TKKN_FilthPuddle"
                                   select t).FirstOrDefault <Thing>();

            if (cell.howWet == 3 && !isCold && this.MaxPuddles > this.totalPuddles && cell.currentTerrain.defName != "TKKN_SandBeachWetSalt")
            {
                if (puddle == null)
                {
                    FilthMaker.MakeFilth(c, this.map, ThingDef.Named("TKKN_FilthPuddle"), 1);
                    this.totalPuddles++;
                }
            }
            else if (cell.howWet <= 0 && puddle != null)
            {
                puddle.Destroy();
                this.totalPuddles--;
            }
            cell.isMelt = false;
            #endregion

            /*CELL SHOULD BE HANDLING THIS NOW:
             * //since it changes, make sure the lava list is still good:
             *
             * if (currentTerrain.defName == "TKKN_Lava") {
             *      this.lavaCellsList.Add(c);
             * } else {
             *      this.lavaCellsList.Remove(c);
             * }
             */

            this.cellWeatherAffects[c] = cell;
        }
示例#4
0
        private void setUpTidesBanks()
        {
            //set up tides and river banks for the first time:
            if (this.doCoast)
            {
                //set up for low tide
                this.tideLevel = 0;

                for (int i = 0; i < this.howManyTideSteps; i++)
                {
                    List <IntVec3> makeSand = this.tideCellsList[i];
                    for (int j = 0; j < makeSand.Count; j++)
                    {
                        IntVec3  c    = makeSand[j];
                        cellData cell = this.cellWeatherAffects[c];
                        cell.baseTerrain = TerrainDefOf.TKKN_SandBeachWetSalt;
                        this.map.terrainGrid.SetTerrain(c, TerrainDefOf.TKKN_SandBeachWetSalt);
                    }
                }
                //bring to current tide levels
                string tideLevel = getTideLevel();
                int    max       = 0;
                if (tideLevel == "normal")
                {
                    max = (int)Math.Floor((this.howManyTideSteps - 1) / 2M);
                }
                else if (tideLevel == "high")
                {
                    max = this.howManyTideSteps - 1;
                }
                for (int i = 0; i < max; i++)
                {
                    List <IntVec3> makeSand = this.tideCellsList[i];
                    for (int j = 0; j < makeSand.Count; j++)
                    {
                        IntVec3  c    = makeSand[j];
                        cellData cell = this.cellWeatherAffects[c];
                        cell.setTerrain("tide");
                    }
                }
                this.tideLevel = max;
            }

            string flood = getFloodType();

            for (int i = 0; i < this.howManyFloodSteps; i++)
            {
                List <IntVec3> makeWater = this.floodCellsList[i];
                for (int j = 0; j < makeWater.Count; j++)
                {
                    IntVec3  c    = makeWater[j];
                    cellData cell = this.cellWeatherAffects[c];
                    if (!cell.baseTerrain.HasTag("TKKN_Wet"))
                    {
                        cell.baseTerrain = TerrainDefOf.TKKN_RiverDeposit;
                    }
                    if (flood == "high")
                    {
                        cell.setTerrain("flooded");
                    }
                    else if (flood == "low")
                    {
                        cell.overrideType = "dry";
                        cell.setTerrain("flooded");
                    }
                    else if (i < howManyFloodSteps / 2)
                    {
                        cell.setTerrain("flooded");
                    }
                    else
                    {
                        cell.overrideType = "dry";
                        cell.setTerrain("flooded");
                    }
                }
            }
        }
        /*
         * //MOVED TO STEADYATMOSPHEREEFFECTS
         * public void checkRandomTerrain() {
         *      int num = Mathf.RoundToInt((float)this.map.Area * 0.0001f);
         *      int area = this.map.Area;
         *      for (int i = 0; i < num; i++)
         *      {
         *              if (this.cycleIndex >= area)
         *              {
         *                      this.cycleIndex = 0;
         *              }
         *              IntVec3 c = this.map.cellsInRandomOrder.Get(this.cycleIndex);
         *              this.doCellEnvironment(c);
         *
         *              this.cycleIndex++;
         *      }
         *
         * }
         */

        public void doCellEnvironment(IntVec3 c)
        {
            if (!this.cellWeatherAffects.ContainsKey(c))
            {
                return;
            }
            cellData cell = this.cellWeatherAffects[c];

            TerrainDef currentTerrain = c.GetTerrain(this.map);
            Room       room           = c.GetRoom(this.map, RegionType.Set_All);
            bool       roofed         = this.map.roofGrid.Roofed(c);
            bool       flag2          = room != null && room.UsesOutdoorTemperature;

            bool gettingWet = false;
            bool isMelt     = false;

            //check if the terrain has been floored
            DesignationCategoryDef cats = currentTerrain.designationCategory;

            if (cats != null)
            {
                if (cats.defName == "Floors")
                {
                    cell.baseTerrain = currentTerrain;
                }
            }

            //spawn special things
            if (Rand.Value < .0001f)
            {
                if (c.InBounds(this.map))
                {
                    string defName = "";

                    if (currentTerrain.defName == "TKKN_Lava")
                    {
                        defName = "TKKN_LavaRock";
                    }
                    else if (currentTerrain.defName == "TKKN_LavaRock_RoughHewn" && this.map.Biome.defName == "TKKN_VolcanicFlow")
                    {
                        defName = "TKKN_SteamVent";
                    }

                    if (defName != "")
                    {
                        Thing check = (Thing)(from t in c.GetThingList(this.map)
                                              where t.def.defName == defName
                                              select t).FirstOrDefault <Thing>();
                        if (check == null)
                        {
                            Thing thing = (Thing)ThingMaker.MakeThing(ThingDef.Named(defName), null);
                            GenSpawn.Spawn(thing, c, map);
                        }
                    }
                }
            }


            #region Rain

            if (Settings.showRain && !roofed && this.map.weatherManager.curWeather.rainRate > .001f)
            {
                if (this.floodThreat < 1090000)
                {
                    this.floodThreat += 1 + 2 * (int)Math.Round(this.map.weatherManager.curWeather.rainRate);
                }
                gettingWet = true;
                cell.setTerrain("wet");
            }
            else
            {
                if (this.map.weatherManager.curWeather.rainRate == 0)
                {
                    this.floodThreat--;
                }
                //DRY GROUND
                cell.setTerrain("dry");
            }
            #endregion

            #region Cold
            bool isCold = this.checkIfCold(c);
            if (isCold)
            {
                cell.setTerrain("frozen");
            }
            else
            {
                cell.setTerrain("thaw");
            }

            #region Frost

//			if (c.x == 140)
//			{
            //	Log.Error("Cell temp " + cell.temperature.ToString() + " frosty: " + (cell.temperature + -.025f).ToString() + " current depth" +this.map.GetComponent<FrostGrid>().GetDepth(c).ToString());
//			}
//			Log.Error(c.ToString() + " ...... roofed:" + roofed.ToString() + " isCold:" + isCold.ToString() + " temp: " + this.map.mapTemperature.OutdoorTemp.ToString());
            if (isCold)
            {
                //handle frost based on snowing
                if (!roofed && this.map.weatherManager.SnowRate > 0.001f)
                {
                    this.map.GetComponent <FrostGrid>().AddDepth(c, this.map.weatherManager.SnowRate * -.01f);
                }
                else
                {
                    CreepFrostAt(c, 0.46f * .3f, map);
                }
            }
            else
            {
                float frosty = cell.temperature * -.025f;
//				float frosty = this.map.mapTemperature.OutdoorTemp * -.03f;
                this.map.GetComponent <FrostGrid>().AddDepth(c, frosty);
                if (this.map.GetComponent <FrostGrid>().GetDepth(c) > .3f)
                {
                    // cell.isMelt = true;
                }
            }


            #endregion

            /* MAKE THIS A WEATHER
             #region heat
             * Thing overlayHeat = (Thing)(from t in c.GetThingList(this.map)
             *                                                      where t.def.defName == "TKKN_HeatWaver"
             *                                                      select t).FirstOrDefault<Thing>();
             * if (this.checkIfHot(c))
             * {
             *      if (overlayHeat == null && Settings.showHot)
             *      {
             *              Thing heat = ThingMaker.MakeThing(ThingDefOf.TKKN_HeatWaver, null);
             *              GenSpawn.Spawn(heat, c, map);
             *      }
             * }
             * else
             * {
             *      if (overlayHeat != null)
             *      {
             *              overlayHeat.Destroy();
             *      }
             * }
             #endregion
             */

            #region Puddles

            if (cell.howWet < 3 && Settings.showRain && (cell.isMelt || gettingWet))
            {
                cell.howWet += 2;
            }
            else if (cell.howWet > -1)
            {
                cell.howWet--;
            }


            //PUDDLES
            Thing puddle = (Thing)(from t in c.GetThingList(this.map)
                                   where t.def.defName == "TKKN_FilthPuddle"
                                   select t).FirstOrDefault <Thing>();

            if (cell.howWet == 3 && !isCold && this.MaxPuddles > this.totalPuddles && cell.currentTerrain.defName != "TKKN_SandBeachWetSalt")
            {
                if (puddle == null)
                {
                    FilthMaker.MakeFilth(c, this.map, ThingDef.Named("TKKN_FilthPuddle"), 1);
                    this.totalPuddles++;
                }
            }
            else if (cell.howWet <= 0 && puddle != null)
            {
                puddle.Destroy();
                this.totalPuddles--;
            }
            cell.isMelt = false;
            #endregion

            /*CELL SHOULD BE HANDLING THIS NOW:
             * //since it changes, make sure the lava list is still good:
             *
             * if (currentTerrain.defName == "TKKN_Lava") {
             *      this.lavaCellsList.Add(c);
             * } else {
             *      this.lavaCellsList.Remove(c);
             * }
             */

            this.cellWeatherAffects[c] = cell;
        }