public int CalculatedCostAt(IntVec3 c, bool perceivedStatic, IntVec3 prevCell) { bool flag = false; TerrainDef terrainDef = this.map.terrainGrid.TerrainAt(c); if (terrainDef == null || terrainDef.passability == Traversability.Impassable) { return(10000); } int num = terrainDef.pathCost; List <Thing> list = this.map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.passability == Traversability.Impassable) { return(10000); } if (!PathGrid.IsPathCostIgnoreRepeater(thing.def) || !prevCell.IsValid || !this.ContainsPathCostIgnoreRepeater(prevCell)) { int pathCost = thing.def.pathCost; if (pathCost > num) { num = pathCost; } } if (thing is Building_Door && prevCell.IsValid) { Building edifice = prevCell.GetEdifice(this.map); if (edifice != null && edifice is Building_Door) { flag = true; } } } int num2 = SnowUtility.MovementTicksAddOn(this.map.snowGrid.GetCategory(c)); if (num2 > num) { num = num2; } if (flag) { num += 45; } if (perceivedStatic) { for (int j = 0; j < 9; j++) { IntVec3 b = GenAdj.AdjacentCellsAndInside[j]; IntVec3 c2 = c + b; if (c2.InBounds(this.map)) { Fire fire = null; list = this.map.thingGrid.ThingsListAtFast(c2); for (int k = 0; k < list.Count; k++) { fire = (list[k] as Fire); if (fire != null) { break; } } if (fire != null && fire.parent == null) { if (b.x == 0 && b.z == 0) { num += 1000; } else { num += 150; } } } } } return(num); }
public void MouseoverReadoutOnGUI() { if (Find.MainTabsRoot.OpenTab != null) { return; } GenUI.DrawTextWinterShadow(new Rect(256f, (float)(Screen.height - 256), -256f, 256f)); Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.8f); IntVec3 c = Gen.MouseCell(); if (!c.InBounds()) { return; } float num = 0f; Rect rect; if (c.Fogged()) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); Widgets.Label(rect, "Undiscovered".Translate()); GUI.color = Color.white; return; } rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); Widgets.Label(rect, Find.GlowGrid.PsychGlowAt(c).GetLabel() + " (" + Find.GlowGrid.GameGlowAt(c).ToStringPercent() + ")"); num += 19f; rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); TerrainDef terrain = c.GetTerrain(); if (terrain != this.cachedTerrain) { this.cachedTerrainString = terrain.LabelCap + ((terrain.passability != Traversability.Impassable) ? (" (" + "WalkSpeed".Translate(new object[] { this.SpeedPercentString((float)terrain.pathCost) }) + ")") : null); this.cachedTerrain = terrain; } Widgets.Label(rect, this.cachedTerrainString); num += 19f; Zone zone = c.GetZone(); if (zone != null) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); string label = zone.label; Widgets.Label(rect, label); num += 19f; } float depth = Find.SnowGrid.GetDepth(c); if ((double)depth > 0.03) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); SnowCategory snowCategory = SnowUtility.GetSnowCategory(depth); string label2 = SnowUtility.GetDescription(snowCategory) + " (" + "WalkSpeed".Translate(new object[] { this.SpeedPercentString((float)SnowUtility.MovementTicksAddOn(snowCategory)) }) + ")"; Widgets.Label(rect, label2); num += 19f; } List <Thing> list = Find.ThingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.category != ThingCategory.Mote) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); string labelMouseover = thing.LabelMouseover; Widgets.Label(rect, labelMouseover); num += 19f; } } RoofDef roof = c.GetRoof(); if (roof != null) { rect = new Rect(MouseoverReadout.BotLeft.x, (float)Screen.height - MouseoverReadout.BotLeft.y - num, 999f, 999f); Widgets.Label(rect, roof.LabelCap); num += 19f; } GUI.color = Color.white; }
// Modified PathGrid.CalculatedCostAt() public static int PathGrid_CalculatedCostAt(Pawn Pawn, IntVec3 c) { IntVec3 prevCell = Pawn.Position; // Modified beahaviour: // - Apply CountersIcePenalty and CountersSnowPenalty stats // - When snow it's medium or thicker, terrain does not apply anymore. TerrainDef terrainDef = Pawn.Map.terrainGrid.TerrainAt(c); if (terrainDef == null || terrainDef.passability == Traversability.Impassable) { return(10000); } // Get terrain path cost int pcTerrain = terrainDef.pathCost; if (terrainDef == TerrainDefOf.Ice) { // Apply counter ice penalty pcTerrain = (int)Math.Ceiling((double)((float)pcTerrain * (1f - Pawn.GetStatValue(StatDef.Named("CountersIcePenalty"), true)))); } // Get snow path cost int pcSnow = SnowUtility.MovementTicksAddOn(Pawn.Map.snowGrid.GetCategory(c)); // Apply counter snow penalty pcSnow = (int)Math.Ceiling((double)((float)pcSnow * (1f - Pawn.GetStatValue(StatDef.Named("CountersSnowPenalty"), true)))); int pc = 0; if (Pawn.Map.snowGrid.GetCategory(c) >= SnowCategory.Medium) { // Snow is thick, we don't consider terrain path cost pc = pcSnow; } else { // Snow is thin, we apply the highest path cost pc = pcTerrain > pcSnow ? pcTerrain : pcSnow; } bool flagDoor = false; List <Thing> list = Pawn.Map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.passability == Traversability.Impassable) { return(10000); } if (!PathGrid_IsPathCostIgnoreRepeater(thing.def) || !prevCell.IsValid || !PathGrid_ContainsPathCostIgnoreRepeater(Pawn.Map, prevCell)) { int pcThing = thing.def.pathCost; if (pcThing > pc) { pc = pcThing; } } if (thing is Building_Door && prevCell.IsValid) { Building edifice = prevCell.GetEdifice(Pawn.Map); if (edifice != null && edifice is Building_Door) { flagDoor = true; } } } if (flagDoor) { pc += 45; } return(pc); }
public static bool CalculatedCostAt(PathGrid __instance, ref int __result, IntVec3 c, bool perceivedStatic, IntVec3 prevCell) { int num = 0; bool flag = false; TerrainDef terrainDef = map(__instance).terrainGrid.TerrainAt(c); if (terrainDef == null || terrainDef.passability == Traversability.Impassable) { __result = 10000; return(false); } num = terrainDef.pathCost; List <Thing> list = map(__instance).thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing; try { thing = list[i]; } catch (ArgumentOutOfRangeException) { break; } if (thing != null) { if (thing.def.passability == Traversability.Impassable) { __result = 10000; return(false); } if (!IsPathCostIgnoreRepeater(thing.def) || !prevCell.IsValid || !ContainsPathCostIgnoreRepeater2(__instance, prevCell)) { int pathCost = thing.def.pathCost; if (pathCost > num) { num = pathCost; } } if (thing is Building_Door && prevCell.IsValid) { Building edifice = prevCell.GetEdifice(map(__instance)); if (edifice != null && edifice is Building_Door) { flag = true; } } } } int num2 = SnowUtility.MovementTicksAddOn(map(__instance).snowGrid.GetCategory(c)); if (num2 > num) { num = num2; } if (flag) { num += 45; } if (perceivedStatic) { for (int j = 0; j < 9; j++) { IntVec3 b = GenAdj.AdjacentCellsAndInside[j]; IntVec3 c2 = c + b; if (!c2.InBounds(map(__instance))) { continue; } Fire fire = null; list = map(__instance).thingGrid.ThingsListAtFast(c2); for (int k = 0; k < list.Count; k++) { try { fire = (list[k] as Fire); } catch (ArgumentOutOfRangeException) { break; } if (fire != null) { break; } } if (fire != null && fire.parent == null) { num = ((b.x != 0 || b.z != 0) ? (num + 150) : (num + 1000)); } } } __result = num; return(false); }
public int CalculatedCostAt(IntVec3 c, bool perceivedStatic, IntVec3 prevCell) { int num = 0; TerrainDef terrainDef = this.map.terrainGrid.TerrainAt(c); num = ((terrainDef != null && terrainDef.passability != Traversability.Impassable) ? (num + terrainDef.pathCost) : 10000); int num2 = SnowUtility.MovementTicksAddOn(this.map.snowGrid.GetCategory(c)); num += num2; List <Thing> list = this.map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.passability == Traversability.Impassable) { return(10000); } if (!PathGrid.IsPathCostIgnoreRepeater(thing.def) || !prevCell.IsValid || !this.ContainsPathCostIgnoreRepeater(prevCell)) { num += thing.def.pathCost; } if (prevCell.IsValid && thing is Building_Door) { Building edifice = prevCell.GetEdifice(this.map); if (edifice != null && edifice is Building_Door) { num += 45; } } } if (perceivedStatic) { for (int j = 0; j < 9; j++) { IntVec3 b = GenAdj.AdjacentCellsAndInside[j]; IntVec3 c2 = c + b; if (c2.InBounds(this.map)) { Fire fire = null; list = this.map.thingGrid.ThingsListAtFast(c2); int num3 = 0; while (num3 < list.Count) { fire = (list[num3] as Fire); if (fire == null) { num3++; continue; } break; } if (fire != null && fire.parent == null) { num = ((b.x != 0 || b.z != 0) ? (num + 150) : (num + 1000)); } } } } return(num); }
public static bool MouseoverReadoutOnGUI(MouseoverReadout __instance) { IntVec3 c = UI.MouseCell(); if (!c.InBounds(Find.CurrentMap) || Event.current.type != EventType.Repaint || Find.MainTabsRoot.OpenTab != null) { return(false); } if (Find.CurrentMap.GetComponent <MapComponent_FertilityMods>().Get is MapComponent_FertilityMods fert && fert.ActiveCells.Contains(c)) { //Original Variables Vector2 BotLeft = new Vector2(15f, 65f); GenUI.DrawTextWinterShadow(new Rect(256f, (float)(UI.screenHeight - 256), -256f, 256f)); Text.Font = GameFont.Small; GUI.color = new Color(1f, 1f, 1f, 0.8f); float num = 0f; Rect rect; if (c.Fogged(Find.CurrentMap)) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); Widgets.Label(rect, "Undiscovered".Translate()); GUI.color = Color.white; return(false); } rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); int num2 = Mathf.RoundToInt(Find.CurrentMap.glowGrid.GameGlowAt(c) * 100f); string[] glowStrings = Traverse.Create(__instance).Field("glowStrings").GetValue <string[]>(); Widgets.Label(rect, glowStrings[num2]); num += 19f; rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); TerrainDef terrain = c.GetTerrain(Find.CurrentMap); //string SpeedPercentString = Traverse.Create(__instance).Method("SpeedPercentString", (float)terrain.pathCost).GetValue<string>(); //TerrainDef cachedTerrain = Traverse.Create(__instance).Field("cachedTerrain").GetValue<TerrainDef>(); string cachedTerrainString = Traverse.Create(__instance).Field("cachedTerrainString").GetValue <string>(); //if (terrain != cachedTerrain) //{ float fertNum = Find.CurrentMap.fertilityGrid.FertilityAt(c); string str = ((double)fertNum <= 0.0001) ? string.Empty : (" " + "FertShort".Translate() + " " + fertNum.ToStringPercent()); cachedTerrainString = terrain.LabelCap + ((terrain.passability == Traversability.Impassable) ? null : (" (" + "WalkSpeed".Translate(new object[] { SpeedPercentString((float)terrain.pathCost) }) + str + ")")); //cachedTerrain = terrain; //} Widgets.Label(rect, cachedTerrainString); num += 19f; Zone zone = c.GetZone(Find.CurrentMap); if (zone != null) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string label = zone.label; Widgets.Label(rect, label); num += 19f; } float depth = Find.CurrentMap.snowGrid.GetDepth(c); if (depth > 0.03f) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); SnowCategory snowCategory = SnowUtility.GetSnowCategory(depth); string label2 = SnowUtility.GetDescription(snowCategory) + " (" + "WalkSpeed".Translate(new object[] { SpeedPercentString((float)SnowUtility.MovementTicksAddOn(snowCategory)) }) + ")"; Widgets.Label(rect, label2); num += 19f; } List <Thing> thingList = c.GetThingList(Find.CurrentMap); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.category != ThingCategory.Mote) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); string labelMouseover = thing.LabelMouseover; Widgets.Label(rect, labelMouseover); num += 19f; } } RoofDef roof = c.GetRoof(Find.CurrentMap); if (roof != null) { rect = new Rect(BotLeft.x, (float)UI.screenHeight - BotLeft.y - num, 999f, 999f); Widgets.Label(rect, roof.LabelCap); num += 19f; } GUI.color = Color.white; return(false); } return(true); }
public static int TerrainCalculatedCostAt(this PathGrid grid, Map map, Pawn pawn, IntVec3 c, bool perceivedStatic, IntVec3 prevCell) { int num; bool flag = false; TerrainDef terrainDef = map.terrainGrid.TerrainAt(c); if (terrainDef == null || terrainDef.passability == Traversability.Impassable) { return(10000); } // Replace the pathCost with a terrain aware value based on the best movement option for a pawn //num = terrainDef.pathCost; num = pawn.TerrainMoveCost(terrainDef); List <Thing> list = map.thingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.passability == Traversability.Impassable) { return(10000); } if (!(bool)IsPathCostIgnoreRepeaterInfo.Invoke(null, new object[] { thing.def }) || !prevCell.IsValid || !(bool)ContainsPathCostIgnoreRepeaterInfo.Invoke(grid, new object[] { prevCell })) { int pathCost = thing.def.pathCost; if (pathCost > num) { num = pathCost; } } if (thing is Building_Door && prevCell.IsValid) { Building edifice = prevCell.GetEdifice(map); if (edifice != null && edifice is Building_Door) { flag = true; } } } int num2 = SnowUtility.MovementTicksAddOn(map.snowGrid.GetCategory(c)); if (num2 > num) { num = num2; } if (flag) { num += 45; } if (perceivedStatic) { for (int j = 0; j < 9; j++) { IntVec3 b = GenAdj.AdjacentCellsAndInside[j]; IntVec3 c2 = c + b; if (!c2.InBounds(map)) { continue; } Fire fire = null; list = map.thingGrid.ThingsListAtFast(c2); for (int k = 0; k < list.Count; k++) { fire = (list[k] as Fire); if (fire != null) { break; } } if (fire != null && fire.parent == null) { num = ((b.x != 0 || b.z != 0) ? (num + 150) : (num + 1000)); } } } return(num); }