private void doTides() { //notes 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]; if (tideType == "high") { cell.overrideType = "wet"; } else if (tideType == "low") { cell.overrideType = "dry"; } cell.setTerrain("tide"); /* * if (Rand.Value < .001) * { * this.spawnSpecialPlants(c); * } */ } 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++; } } }
public void checkThingsforLava() { HashSet <IntVec3> removeFromLava = new HashSet <IntVec3>(); foreach (IntVec3 c in this.lavaCellsList) { cellData cell = this.cellWeatherAffects[c]; //check to see if it's still lava. Ignore roughhewn because lava can freeze/rain will cool it. if (!c.GetTerrain(map).HasTag("Lava") && c.GetTerrain(map).defName != "TKKN_LavaRock_RoughHewn") { cell.baseTerrain = c.GetTerrain(map); removeFromLava.Add(c); continue; } //moving this to a harmony patch /* * List<Thing> things = c.GetThingList(this.map); * for (int j = things.Count - 1; j >= 0; j--) * { * //thing.TryAttachFire(5); * FireUtility.TryStartFireIn(c, this.map, 5f); * * Thing thing = things[j]; * float statValue = thing.GetStatValue(StatDefOf.Flammability, true); * bool alt = thing.def.altitudeLayer == AltitudeLayer.Item; * if (statValue == 0f && alt == true) * { * if (!thing.Destroyed && thing.def.destroyable) * { * thing.Destroy(DestroyMode.Vanish); * } * } * } */ } foreach (IntVec3 c in removeFromLava) { this.lavaCellsList.Remove(c); } int n = 0; foreach (IntVec3 c in this.lavaCellsList.InRandomOrder()) { GenTemperature.PushHeat(c, map, 1); if (n > 50) { break; } if (this.map.weatherManager.curWeather.rainRate > .0001f) { if (Rand.Value < .0009f) { MoteMaker.ThrowHeatGlow(c, this.map, 5f); MoteMaker.ThrowSmoke(c.ToVector3(), this.map, 4f); } } else { /* * if (Rand.Value < .0001f) * { * * MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("TKKN_HeatWaver"), null); * moteThrown.Scale = Rand.Range(2f, 4f) * 2; * moteThrown.exactPosition = c.ToVector3(); * moteThrown.SetVelocity(Rand.Bool ? -90 : 90, 0.12f); * GenSpawn.Spawn(moteThrown, c, this.map); * } * else */ if (Rand.Value < .0005f) { MoteMaker.ThrowSmoke(c.ToVector3(), this.map, 4f); } } n++; } }
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--; } } }
/* * //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; }
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("Water")) { 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"); } } } }
public void rebuildCellLists() { if (Settings.regenCells == true) { this.regenCellLists = Settings.regenCells; } /* #region devonly * this.regenCellLists = true; * Log.Error("DEV STUFF IS ON"); * this.cellWeatherAffects = new Dictionary<IntVec3, cellData>(); #endregion */ if (this.regenCellLists) { //spawn oasis. Do before cell list building so it's stored correctly. this.spawnOasis(); this.fixLava(); Rot4 rot = Find.World.CoastDirectionAt(map.Tile); IEnumerable <IntVec3> tmpTerrain = map.AllCells.InRandomOrder(); //random so we can spawn plants and stuff in this step. this.cellWeatherAffects = new Dictionary <IntVec3, cellData>(); foreach (IntVec3 cell in tmpTerrain) { TerrainDef terrain = cell.GetTerrain(map); if (!cell.InBounds(map)) { continue; } cellData thiscell = new cellData(); thiscell.location = cell; thiscell.baseTerrain = terrain; if (terrain.defName == "TKKN_Lava") { //fix for lava pathing. If lava is near not!lava, make it impassable. bool edgeLava = false; int num = GenRadial.NumCellsInRadius(1); for (int i = 0; i < num; i++) { IntVec3 lavaCheck = cell + GenRadial.RadialPattern[i]; if (lavaCheck.InBounds(map)) { TerrainDef lavaCheckTerrain = lavaCheck.GetTerrain(this.map); if (lavaCheckTerrain.defName != "TKKN_Lava" && lavaCheckTerrain.defName != "TKKN_LavaDeep") { edgeLava = true; } } } if (!edgeLava) { this.map.terrainGrid.SetTerrain(cell, TerrainDefOf.TKKN_LavaDeep); } } else if (rot.IsValid && (terrain.defName == "Sand" || terrain.defName == "TKKN_SandBeachWetSalt")) { //get all the sand pieces that are touching water. for (int j = 0; j < this.howManyTideSteps; j++) { IntVec3 waterCheck = this.adjustForRotation(rot, cell, j); if (waterCheck.InBounds(map) && waterCheck.GetTerrain(map).defName == "WaterOceanShallow") { this.map.terrainGrid.SetTerrain(cell, TerrainDefOf.TKKN_SandBeachWetSalt); thiscell.tideLevel = j; break; } } } else if (terrain.HasTag("Water") && terrain.defName != "WaterOceanShallow" && terrain.defName != "WaterOceanDeep") { for (int j = 0; j < this.howManyFloodSteps; j++) { int num = GenRadial.NumCellsInRadius(j); for (int i = 0; i < num; i++) { IntVec3 bankCheck = cell + GenRadial.RadialPattern[i]; if (bankCheck.InBounds(map)) { TerrainDef bankCheckTerrain = bankCheck.GetTerrain(this.map); if (!bankCheckTerrain.HasTag("Water") && terrain.defName != "TKKN_SandBeachWetSalt") // || ((terrain.defName == "WaterDeep" || terrain.defName == "WaterDeep" || terrain.defName == "WaterMovingDeep") && bankCheckTerrain.defName != terrain.defName)) { //see if this cell has already been done, because we can have each cell in multiple flood levels. cellData bankCell; if (this.cellWeatherAffects.ContainsKey(bankCheck)) { bankCell = this.cellWeatherAffects[bankCheck]; } else { bankCell = new cellData(); bankCell.location = bankCheck; bankCell.baseTerrain = bankCheckTerrain; } bankCell.floodLevel.Add(j); } } } } } //Spawn special elements: this.spawnSpecialElements(cell); this.spawnSpecialPlants(cell); this.cellWeatherAffects[cell] = thiscell; } } //rebuild lookup lists. this.lavaCellsList = new HashSet <IntVec3>(); this.tideCellsList = new List <List <IntVec3> >(); this.floodCellsList = new List <List <IntVec3> >(); for (int k = 0; k < this.howManyTideSteps; k++) { this.tideCellsList.Add(new List <IntVec3>()); } for (int k = 0; k < this.howManyFloodSteps; k++) { this.floodCellsList.Add(new List <IntVec3>()); } FrostGrid frostGrid = map.GetComponent <FrostGrid>(); foreach (KeyValuePair <IntVec3, cellData> thiscell in cellWeatherAffects) { cellWeatherAffects[thiscell.Key].map = this.map; if (!bugFixFrostIsRemoved) { thiscell.Value.doFrostOverlay("remove"); } //temp fix until I can figure out why regenerate wasn't working // frostGrid.SetDepth(thiscell.Value.location, 0); frostGrid.SetDepth(thiscell.Value.location, thiscell.Value.frostLevel); if (thiscell.Value.baseTerrain.defName == "TKKN_ColdSprings") { thiscell.Value.baseTerrain = TerrainDefOf.TKKN_ColdSpringsWater; } if (thiscell.Value.baseTerrain.defName == "TKKN_HotSprings") { thiscell.Value.baseTerrain = TerrainDefOf.TKKN_HotSpringsWater; } if (thiscell.Value.tideLevel > -1) { this.tideCellsList[thiscell.Value.tideLevel].Add(thiscell.Key); } if (thiscell.Value.floodLevel.Count != 0) { foreach (int level in thiscell.Value.floodLevel) { this.floodCellsList[level].Add(thiscell.Key); } } if (thiscell.Value.baseTerrain.HasTag("Lava")) { //future me: to do: split lava actions into ones that will affect pawns and ones that won't, since pawns can't walk on deep lava this.lavaCellsList.Add(thiscell.Key); } } bugFixFrostIsRemoved = true; if (this.regenCellLists) { this.setUpTidesBanks(); this.regenCellLists = false; } }
static void Postfix() { IntVec3 c = UI.MouseCell(); Map map = Find.CurrentMap; if (!c.InBounds(map)) { return; } Rect rect; Vector2 BotLeft = new Vector2(15f, 65f); float num = 38f; Zone zone = c.GetZone(map); if (zone != null) { num += 19f; } float depth = map.snowGrid.GetDepth(c); if (depth > 0.03f) { num += 19f; } List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.category != ThingCategory.Mote) { num += 19f; } } RoofDef roof = c.GetRoof(map); if (roof != null) { num += 19f; } if (Settings.showDevReadout) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string label3 = "C: x-" + c.x.ToString() + " y-" + c.y.ToString() + " z-" + c.z.ToString(); Widgets.Label(rect, label3); num += 19f; Watcher watcher = map.GetComponent <Watcher>(); cellData cell = watcher.cellWeatherAffects[c]; rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string label2 = "Temperature: " + cell.temperature; Widgets.Label(rect, label2); num += 19f; rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string label4 = "Cell Info: Base Terrain " + cell.baseTerrain.defName + " Current Terrain " + cell.currentTerrain.defName + " | Wet " + cell.isWet.ToString() + " | Melt " + cell.isMelt.ToString() + " | Flooded " + cell.isFlooded.ToString() + " | Frozen " + cell.isFrozen.ToString() + " | Thawed " + cell.isThawed.ToString() + " | Getting Wet? " + cell.gettingWet.ToString(); Widgets.Label(rect, label4); num += 19f; rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string label6 = "TKKN_Wet " + cell.currentTerrain.HasTag("TKKN_Wet") + "TKKN_Swim " + cell.currentTerrain.HasTag("TKKN_Swim"); Widgets.Label(rect, label6); num += 19f; rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string label5 = "Cell Info: howWet " + cell.howWet.ToString() + " | How Wet (Plants) " + cell.howWetPlants.ToString() + " | How Packed " + cell.howPacked.ToString(); if (cell.weather != null) { if (cell.weather.wetTerrain != null) { label5 += " | T Wet " + cell.weather.wetTerrain.defName; } if (cell.weather.dryTerrain != null) { label5 += " | T Dry " + cell.weather.dryTerrain.defName; } if (cell.weather.freezeTerrain != null) { label5 += " | T Freeze " + cell.weather.freezeTerrain.defName; } } if (cell.originalTerrain != null) { label5 += " | Orig Terrain " + cell.originalTerrain.defName; } Widgets.Label(rect, label5); num += 19f; } depth = map.GetComponent <FrostGrid>().GetDepth(c); if (depth > 0.01f) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); FrostCategory frostCategory = FrostUtility.GetFrostCategory(depth); string label2 = FrostUtility.GetDescription(frostCategory); Widgets.Label(rect, label2); // Widgets.Label(rect, label2 + " " + depth.ToString()); num += 19f; } }