public static void DebugDraw() { if (DebugViewSettings.drawInfestationChance) { if (InfestationCellFinder.tmpCachedInfestationChanceCellColors == null) { InfestationCellFinder.tmpCachedInfestationChanceCellColors = new List <Pair <IntVec3, float> >(); } if (Time.frameCount % 8 == 0) { InfestationCellFinder.tmpCachedInfestationChanceCellColors.Clear(); Map currentMap = Find.CurrentMap; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(currentMap); cellRect = cellRect.ExpandedBy(1); InfestationCellFinder.CalculateTraversalDistancesToUnroofed(currentMap); InfestationCellFinder.CalculateClosedAreaSizeGrid(currentMap); InfestationCellFinder.CalculateDistanceToColonyBuildingGrid(currentMap); float num = 0.001f; for (int i = 0; i < currentMap.Size.z; i++) { for (int j = 0; j < currentMap.Size.x; j++) { IntVec3 cell = new IntVec3(j, 0, i); float scoreAt = InfestationCellFinder.GetScoreAt(cell, currentMap); if (scoreAt > num) { num = scoreAt; } } } for (int k = 0; k < currentMap.Size.z; k++) { for (int l = 0; l < currentMap.Size.x; l++) { IntVec3 intVec = new IntVec3(l, 0, k); if (cellRect.Contains(intVec)) { float scoreAt2 = InfestationCellFinder.GetScoreAt(intVec, currentMap); if (scoreAt2 > 7.5f) { float second = GenMath.LerpDouble(7.5f, num, 0f, 1f, scoreAt2); InfestationCellFinder.tmpCachedInfestationChanceCellColors.Add(new Pair <IntVec3, float>(intVec, second)); } } } } } for (int m = 0; m < InfestationCellFinder.tmpCachedInfestationChanceCellColors.Count; m++) { IntVec3 first = InfestationCellFinder.tmpCachedInfestationChanceCellColors[m].First; float second2 = InfestationCellFinder.tmpCachedInfestationChanceCellColors[m].Second; CellRenderer.RenderCell(first, SolidColorMaterials.SimpleSolidColorMaterial(new Color(0f, 0f, 1f, second2), false)); } } else { InfestationCellFinder.tmpCachedInfestationChanceCellColors = null; } }
public void MapInterfaceUpdate() { if (Find.CurrentMap != null) { if (!WorldRendererUtility.WorldRenderedNow) { Profiler.BeginSample("TargeterUpdate()"); this.targeter.TargeterUpdate(); Profiler.EndSample(); Profiler.BeginSample("DrawSelectionOverlays()"); SelectionDrawer.DrawSelectionOverlays(); Profiler.EndSample(); Profiler.BeginSample("EnvironmentStatsDrawer.DrawRoomOverlays()"); EnvironmentStatsDrawer.DrawRoomOverlays(); Profiler.EndSample(); Profiler.BeginSample("DesignatorManagerUpdate()"); this.designatorManager.DesignatorManagerUpdate(); Profiler.EndSample(); Profiler.BeginSample("RoofGridUpdate()"); Find.CurrentMap.roofGrid.RoofGridUpdate(); Profiler.EndSample(); Profiler.BeginSample("ExitMapGridUpdate()"); Find.CurrentMap.exitMapGrid.ExitMapGridUpdate(); Profiler.EndSample(); Profiler.BeginSample("DeepResourceGridUpdate()"); Find.CurrentMap.deepResourceGrid.DeepResourceGridUpdate(); Profiler.EndSample(); Profiler.BeginSample("Debug drawing"); if (DebugViewSettings.drawPawnDebug) { Find.CurrentMap.pawnDestinationReservationManager.DebugDrawDestinations(); Find.CurrentMap.reservationManager.DebugDrawReservations(); } if (DebugViewSettings.drawFoodSearchFromMouse) { FoodUtility.DebugFoodSearchFromMouse_Update(); } if (DebugViewSettings.drawPreyInfo) { FoodUtility.DebugDrawPredatorFoodSource(); } if (DebugViewSettings.drawAttackTargetScores) { AttackTargetFinder.DebugDrawAttackTargetScores_Update(); } MiscDebugDrawer.DebugDrawInteractionCells(); Find.CurrentMap.debugDrawer.DebugDrawerUpdate(); Find.CurrentMap.regionGrid.DebugDraw(); InfestationCellFinder.DebugDraw(); StealAIDebugDrawer.DebugDraw(); if (DebugViewSettings.drawRiverDebug) { Find.CurrentMap.waterInfo.DebugDrawRiver(); } Profiler.EndSample(); } } }
private static float GetScoreAt(IntVec3 cell, Map map) { if ((float)(int)InfestationCellFinder.distToColonyBuilding[cell] > 30.0) { return(0f); } if (!cell.Standable(map)) { return(0f); } if (cell.Fogged(map)) { return(0f); } if (InfestationCellFinder.CellHasBlockingThings(cell, map)) { return(0f); } if (cell.Roofed(map) && cell.GetRoof(map).isThickRoof) { Region region = cell.GetRegion(map, RegionType.Set_Passable); if (region == null) { return(0f); } if (InfestationCellFinder.closedAreaSize[cell] < 16) { return(0f); } float temperature = cell.GetTemperature(map); if (temperature < -17.0) { return(0f); } float mountainousnessScoreAt = InfestationCellFinder.GetMountainousnessScoreAt(cell, map); if (mountainousnessScoreAt < 0.17000000178813934) { return(0f); } int num = InfestationCellFinder.StraightLineDistToUnroofed(cell, map); float num2 = (float)(InfestationCellFinder.regionsDistanceToUnroofed.TryGetValue(region, out num2) ? Mathf.Min(num2, (float)((float)num * 4.0)) : ((float)num * 1.1499999761581421)); num2 = Mathf.Pow(num2, 1.55f); float num3 = Mathf.InverseLerp(0f, 12f, (float)num); float num4 = Mathf.Lerp(1f, 0.18f, map.glowGrid.GameGlowAt(cell, false)); float num5 = (float)(1.0 - Mathf.Clamp((float)(InfestationCellFinder.DistToBlocker(cell, map) / 11.0), 0f, 0.6f)); float num6 = Mathf.InverseLerp(-17f, -7f, temperature); float f = num2 * num3 * num5 * mountainousnessScoreAt * num4 * num6; f = Mathf.Pow(f, 1.2f); if (f < 7.5) { return(0f); } return(f); } return(0f); }
protected override bool CanFireNowSub(IncidentParms parms) { Map map = (Map)parms.target; IntVec3 cell; if (base.CanFireNowSub(parms) && HiveUtility.TotalSpawnedHivesCount(map) < 30) { return(InfestationCellFinder.TryFindCell(out cell, map)); } return(false); }
public static bool TryFindCell(out IntVec3 cell, Map map) { InfestationCellFinder.CalculateLocationCandidates(map); InfestationCellFinder.LocationCandidate locationCandidate; if (!InfestationCellFinder.locationCandidates.TryRandomElementByWeight((InfestationCellFinder.LocationCandidate x) => x.score, out locationCandidate)) { cell = IntVec3.Invalid; return(false); } cell = locationCandidate.cell; return(true); }
public static bool TryFindCell(out IntVec3 cell, Map map) { InfestationCellFinder.CalculateLocationCandidates(map); InfestationCellFinder.LocationCandidate locationCandidate; if (!InfestationCellFinder.locationCandidates.TryRandomElementByWeight((InfestationCellFinder.LocationCandidate x) => x.score, out locationCandidate)) { cell = IntVec3.Invalid; return(false); } cell = CellFinder.FindNoWipeSpawnLocNear(locationCandidate.cell, map, ThingDefOf.Hive, Rot4.North, 2, (IntVec3 x) => InfestationCellFinder.GetScoreAt(x, map) > 0f && x.GetFirstThing(map, ThingDefOf.Hive) == null && x.GetFirstThing(map, ThingDefOf.TunnelHiveSpawner) == null); return(true); }
public static bool TryFindCell(out IntVec3 cell, Map map) { InfestationCellFinder.CalculateLocationCandidates(map); LocationCandidate locationCandidate = default(LocationCandidate); if (!((IEnumerable <LocationCandidate>)InfestationCellFinder.locationCandidates).TryRandomElementByWeight <LocationCandidate>((Func <LocationCandidate, float>)((LocationCandidate x) => x.score), out locationCandidate)) { cell = IntVec3.Invalid; return(false); } cell = locationCandidate.cell; return(true); }
private static int StraightLineDistToUnroofed(IntVec3 cell, Map map) { int num = int.MaxValue; int i = 0; while (i < 4) { Rot4 rot = new Rot4(i); IntVec3 facingCell = rot.FacingCell; int num2 = 0; int num3; for (;;) { IntVec3 intVec = cell + facingCell * num2; if (!intVec.InBounds(map)) { goto Block_1; } num3 = num2; if (InfestationCellFinder.NoRoofAroundAndWalkable(intVec, map)) { break; } num2++; } IL_74: if (num3 < num) { num = num3; } i++; continue; Block_1: num3 = int.MaxValue; goto IL_74; } int result; if (num == 2147483647) { result = map.Size.x; } else { result = num; } return(result); }
public void MapInterfaceUpdate() { if (Find.CurrentMap != null && !WorldRendererUtility.WorldRenderedNow) { targeter.TargeterUpdate(); SelectionDrawer.DrawSelectionOverlays(); EnvironmentStatsDrawer.DrawRoomOverlays(); designatorManager.DesignatorManagerUpdate(); Find.CurrentMap.roofGrid.RoofGridUpdate(); Find.CurrentMap.fertilityGrid.FertilityGridUpdate(); Find.CurrentMap.terrainGrid.TerrainGridUpdate(); Find.CurrentMap.exitMapGrid.ExitMapGridUpdate(); Find.CurrentMap.deepResourceGrid.DeepResourceGridUpdate(); if (DebugViewSettings.drawPawnDebug) { Find.CurrentMap.pawnDestinationReservationManager.DebugDrawDestinations(); Find.CurrentMap.reservationManager.DebugDrawReservations(); } if (DebugViewSettings.drawDestReservations) { Find.CurrentMap.pawnDestinationReservationManager.DebugDrawReservations(); } if (DebugViewSettings.drawFoodSearchFromMouse) { FoodUtility.DebugFoodSearchFromMouse_Update(); } if (DebugViewSettings.drawPreyInfo) { FoodUtility.DebugDrawPredatorFoodSource(); } if (DebugViewSettings.drawAttackTargetScores) { AttackTargetFinder.DebugDrawAttackTargetScores_Update(); } MiscDebugDrawer.DebugDrawInteractionCells(); Find.CurrentMap.debugDrawer.DebugDrawerUpdate(); Find.CurrentMap.regionGrid.DebugDraw(); InfestationCellFinder.DebugDraw(); StealAIDebugDrawer.DebugDraw(); if (DebugViewSettings.drawRiverDebug) { Find.CurrentMap.waterInfo.DebugDrawRiver(); } BuildingsDamageSectionLayerUtility.DebugDraw(); } }
private static void CalculateTraversalDistancesToUnroofed(Map map) { InfestationCellFinder.tempUnroofedRegions.Clear(); for (int i = 0; i < map.Size.z; i++) { for (int j = 0; j < map.Size.x; j++) { IntVec3 intVec = new IntVec3(j, 0, i); Region region = intVec.GetRegion(map, RegionType.Set_Passable); if (region != null && InfestationCellFinder.NoRoofAroundAndWalkable(intVec, map)) { InfestationCellFinder.tempUnroofedRegions.Add(region); } } } Dijkstra <Region> .Run(InfestationCellFinder.tempUnroofedRegions, (Region x) => x.Neighbors, (Region a, Region b) => Mathf.Sqrt((float)a.extentsClose.CenterCell.DistanceToSquared(b.extentsClose.CenterCell)), InfestationCellFinder.regionsDistanceToUnroofed, null); InfestationCellFinder.tempUnroofedRegions.Clear(); }
private static void CalculateLocationCandidates(Map map) { InfestationCellFinder.locationCandidates.Clear(); InfestationCellFinder.CalculateTraversalDistancesToUnroofed(map); InfestationCellFinder.CalculateClosedAreaSizeGrid(map); InfestationCellFinder.CalculateDistanceToColonyBuildingGrid(map); for (int i = 0; i < map.Size.z; i++) { for (int j = 0; j < map.Size.x; j++) { IntVec3 cell = new IntVec3(j, 0, i); float scoreAt = InfestationCellFinder.GetScoreAt(cell, map); if (scoreAt > 0f) { InfestationCellFinder.locationCandidates.Add(new InfestationCellFinder.LocationCandidate(cell, scoreAt)); } } } }
private static int StraightLineDistToUnroofed(IntVec3 cell, Map map) { int num = 2147483647; int i = 0; while (i < 4) { Rot4 rot = new Rot4(i); IntVec3 facingCell = rot.FacingCell; int num2 = 0; int num3; while (true) { IntVec3 intVec = cell + facingCell * num2; if (!intVec.InBounds(map)) { goto Block_1; } num3 = num2; if (InfestationCellFinder.NoRoofAroundAndWalkable(intVec, map)) { break; } num2++; } IL_6F: if (num3 < num) { num = num3; } i++; continue; Block_1: num3 = 2147483647; goto IL_6F; } if (num == 2147483647) { return(map.Size.x); } return(num); }
public static void DebugDraw() { if (DebugViewSettings.drawInfestationChance) { Map visibleMap = Find.VisibleMap; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(visibleMap); cellRect = cellRect.ExpandedBy(1); InfestationCellFinder.CalculateTraversalDistancesToUnroofed(visibleMap); InfestationCellFinder.CalculateClosedAreaSizeGrid(visibleMap); InfestationCellFinder.CalculateDistanceToColonyBuildingGrid(visibleMap); float num = 0.001f; for (int i = 0; i < visibleMap.Size.z; i++) { for (int j = 0; j < visibleMap.Size.x; j++) { IntVec3 cell = new IntVec3(j, 0, i); float scoreAt = InfestationCellFinder.GetScoreAt(cell, visibleMap); if (scoreAt > num) { num = scoreAt; } } } for (int k = 0; k < visibleMap.Size.z; k++) { for (int l = 0; l < visibleMap.Size.x; l++) { IntVec3 intVec = new IntVec3(l, 0, k); if (cellRect.Contains(intVec)) { float scoreAt2 = InfestationCellFinder.GetScoreAt(intVec, visibleMap); if (scoreAt2 > 0f) { float a = GenMath.LerpDouble(7.5f, num, 0f, 1f, scoreAt2); CellRenderer.RenderCell(intVec, SolidColorMaterials.SimpleSolidColorMaterial(new Color(0f, 0f, 1f, a), false)); } } } } } }
private Thing SpawnTunnels(int hiveCount, Map map) { IntVec3 loc; if (!InfestationCellFinder.TryFindCell(out loc, map)) { return(null); } Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.TunnelHiveSpawner, null), loc, map, WipeMode.FullRefund); for (int i = 0; i < hiveCount - 1; i++) { loc = CompSpawnerHives.FindChildHiveLocation(thing.Position, map, ThingDefOf.Hive, ThingDefOf.Hive.GetCompProperties <CompProperties_SpawnerHives>(), false, true); if (loc.IsValid) { thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.TunnelHiveSpawner, null), loc, map, WipeMode.FullRefund); } } return(thing); }
private static int StraightLineDistToUnroofed(IntVec3 cell, Map map) { int num = 2147483647; for (int i = 0; i < 4; i++) { int num2 = 0; IntVec3 facingCell = new Rot4(i).FacingCell; int num3 = 0; while (true) { IntVec3 intVec = cell + facingCell * num3; if (!intVec.InBounds(map)) { num2 = 2147483647; } else { num2 = num3; if (!InfestationCellFinder.NoRoofAroundAndWalkable(intVec, map)) { num3++; continue; } } break; } if (num2 < num) { num = num2; } } if (num == 2147483647) { IntVec3 size = map.Size; return(size.x); } return(num); }
private static void CalculateLocationCandidates(Map map) { InfestationCellFinder.locationCandidates.Clear(); InfestationCellFinder.CalculateTraversalDistancesToUnroofed(map); InfestationCellFinder.CalculateClosedAreaSizeGrid(map); InfestationCellFinder.CalculateDistanceToColonyBuildingGrid(map); int num = 0; while (true) { int num2 = num; IntVec3 size = map.Size; if (num2 < size.z) { int num3 = 0; while (true) { int num4 = num3; IntVec3 size2 = map.Size; if (num4 < size2.x) { IntVec3 cell = new IntVec3(num3, 0, num); float scoreAt = InfestationCellFinder.GetScoreAt(cell, map); if (!(scoreAt <= 0.0)) { InfestationCellFinder.locationCandidates.Add(new LocationCandidate(cell, scoreAt)); } num3++; continue; } break; } num++; continue; } break; } }
private static void CalculateTraversalDistancesToUnroofed(Map map) { InfestationCellFinder.tempUnroofedRegions.Clear(); int num = 0; while (true) { int num2 = num; IntVec3 size = map.Size; if (num2 < size.z) { int num3 = 0; while (true) { int num4 = num3; IntVec3 size2 = map.Size; if (num4 < size2.x) { IntVec3 intVec = new IntVec3(num3, 0, num); Region region = intVec.GetRegion(map, RegionType.Set_Passable); if (region != null && InfestationCellFinder.NoRoofAroundAndWalkable(intVec, map)) { InfestationCellFinder.tempUnroofedRegions.Add(region); } num3++; continue; } break; } num++; continue; } break; } Dijkstra <Region> .Run(InfestationCellFinder.tempUnroofedRegions, (Region x) => x.Neighbors, (Region a, Region b) => Mathf.Sqrt((float)a.extentsClose.CenterCell.DistanceToSquared(b.extentsClose.CenterCell)), InfestationCellFinder.regionsDistanceToUnroofed, null); InfestationCellFinder.tempUnroofedRegions.Clear(); }
private Hive SpawnHiveCluster(int hiveCount, Map map) { IntVec3 loc = default(IntVec3); if (!InfestationCellFinder.TryFindCell(out loc, map)) { return(null); } Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), loc, map); hive.SetFaction(Faction.OfInsects, null); IncidentWorker_Infestation.SpawnInsectJellyInstantly(hive); for (int i = 0; i < hiveCount - 1; i++) { Hive hive2 = default(Hive); if (hive.GetComp <CompSpawnerHives>().TrySpawnChildHive(false, out hive2)) { IncidentWorker_Infestation.SpawnInsectJellyInstantly(hive2); hive = hive2; } } return(hive); }
// Token: 0x06000424 RID: 1060 RVA: 0x0002CE84 File Offset: 0x0002B284 protected override Job TryGiveJob(Pawn pawn) { CompXenoEggLayer compEggLayer = pawn.TryGetComp <CompXenoEggLayer>(); if (compEggLayer == null || !compEggLayer.CanLayNow) { return(null); } IntVec3 c; if (pawn.GetLord() != null && pawn.GetLord().LordJob is LordJob_DefendBase lordjob) { c = lordjob.lord.Graph.StartingToil.FlagLoc; c = RCellFinder.RandomWanderDestFor(pawn, c, 5f, null, Danger.Some); } else { Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(XenomorphDefOf.RRY_EggXenomorphFertilized), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 9999f, null, null, 0, -1, false, RegionType.Set_Passable, false); if (thing == null) { c = RCellFinder.RandomWanderDestFor(pawn, pawn.Position, 5f, null, Danger.Some); } else { InfestationCellFinder.TryFindCell(out c, pawn.Map); if (pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly)) { c = RCellFinder.RandomWanderDestFor(pawn, c, 3f, null, Danger.Some); } else { c = RCellFinder.RandomWanderDestFor(pawn, thing.Position, 3f, null, Danger.Some); } } } return(new Job(XenomorphDefOf.RRY_Job_LayXenomorphEgg, c)); }
// Token: 0x0600368B RID: 13963 RVA: 0x001A0E1C File Offset: 0x0019F21C public static bool TryFindCell(out IntVec3 cell, out IntVec3 locationC, Map map, bool allowFogged = true) { ThingDef namedA = XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon; ThingDef namedB = XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon; InfestationLikeCellFinder.CalculateLocationCandidates(map, allowFogged); Predicate <IntVec3> validator = delegate(IntVec3 y) { bool score = InfestationLikeCellFinder.GetScoreAt(y, map, allowFogged) > 0f; bool XenohiveA = y.GetFirstThing(map, XenomorphDefOf.RRY_XenomorphHive) == null; bool XenohiveB = y.GetFirstThing(map, XenomorphDefOf.RRY_XenomorphHive_Child) == null; bool filled = y.Filled(map); bool edifice = y.GetEdifice(map).DestroyedOrNull(); bool building = y.GetFirstBuilding(map).DestroyedOrNull(); bool thingA = y.GetFirstThing(map, namedA).DestroyedOrNull(); bool thingB = y.GetFirstThing(map, namedB).DestroyedOrNull(); Log.Message(string.Format("Cell: {0}, score: {1}, XenohiveA: {2}, XenohiveB: {3}, !filled: {4}, edifice: {5}, building: {6}, thingA: {7}, thingB: {8}\nResult: {9}", y, GetScoreAt(y, map, allowFogged), XenohiveA, XenohiveB, !filled, edifice, building, thingA, thingB, score && XenohiveA && XenohiveB && !filled && edifice && building && thingA && thingB)); return(score && XenohiveA && XenohiveB && !filled && edifice && building && thingA && thingB); }; if (!InfestationLikeCellFinder.locationCandidates.TryRandomElementByWeight((InfestationLikeCellFinder.LocationCandidate x) => x.score, out LocationCandidate locationCandidate)) { cell = IntVec3.Invalid; locationC = IntVec3.Invalid; if (!InfestationCellFinder.TryFindCell(out cell, map)) { cell = IntVec3.Invalid; return(false); } } locationC = locationCandidate.cell; cell = CellFinder.FindNoWipeSpawnLocNear(locationCandidate.cell, map, XenomorphDefOf.RRY_XenomorphHive, Rot4.North, 2, (IntVec3 x) => InfestationLikeCellFinder.GetScoreAt(x, map, allowFogged) > 0f && x.GetFirstThing(map, XenomorphDefOf.RRY_XenomorphHive) == null && x.GetFirstThing(map, OGHiveLikeDefOf.TunnelHiveLikeSpawner) == null && x.GetFirstThing(map, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon) == null && x.GetFirstThing(map, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon) == null); ThingDef td = XenomorphDefOf.RRY_Hive_Slime; GenSpawn.Spawn(td, cell, map); return(true); }
// Token: 0x0600368B RID: 13963 RVA: 0x001A0E1C File Offset: 0x0019F21C public static bool TryFindCell(out IntVec3 cell, out IntVec3 locationC, Map map, bool allowFogged = false, bool allowUnroofed = false, bool allowDigging = false, bool forceNew = false) { InfestationLikeCellFinder.CalculateLocationCandidates(map, allowFogged, allowUnroofed, allowDigging, forceNew); if (!forceNew) { // Log.Message("exsisting hivelocs allowed"); if (!map.HiveGrid().Hivelist.NullOrEmpty()) { cell = map.HiveGrid().Hivelist.RandomElement().Position; locationC = map.HiveGrid().Hivelist.RandomElement().Position; return(true); } if (!map.HiveGrid().HiveLoclist.NullOrEmpty()) { cell = map.HiveGrid().HiveLoclist.RandomElement(); locationC = map.HiveGrid().HiveLoclist.RandomElement(); return(true); } } Predicate <IntVec3> validator = delegate(IntVec3 y) { if (y.GetTerrain(map).HasTag("Water") || y.InNoBuildEdgeArea(map)) { return(false); } bool roofed = (!allowUnroofed && y.Roofed(map)) || allowUnroofed; bool score = InfestationLikeCellFinder.GetScoreAt(y, map, allowFogged, allowUnroofed, allowDigging) > 0f; bool XenohiveA = y.GetFirstThing(map, XenomorphDefOf.RRY_Xenomorph_Hive) == null; bool XenohiveB = y.GetFirstThing(map, XenomorphDefOf.RRY_Xenomorph_Hive_Child) == null; bool filled = y.Filled(map) && !allowDigging; bool edifice = y.GetEdifice(map).DestroyedOrNull() || allowDigging; bool building = y.GetFirstBuilding(map).DestroyedOrNull() || allowDigging; bool thing = !y.GetThingList(map).Any(x => x.GetType() == typeof(Building_XenomorphCocoon) || x.GetType() == typeof(Building_XenoEgg) || x.GetType() == typeof(HiveLike)) || !forceNew; bool result = score && XenohiveA && XenohiveB && !filled && edifice && building && thing && roofed; return(result); }; if (!InfestationLikeCellFinder.locationCandidates.Where(y => validator(y.cell)).TryRandomElementByWeight((InfestationLikeCellFinder.LocationCandidate x) => x.score, out LocationCandidate locationCandidate)) { // Log.Message(string.Format("Cant find any suitable location candidates")); cell = IntVec3.Invalid; if (!InfestationCellFinder.TryFindCell(out cell, map)) { if (!map.HiveGrid().PotentialHiveLoclist.NullOrEmpty()) { if (map.HiveGrid().PotentialHiveLoclist.Any(x => (x.X < 50 || x.Z < 50) && (!forceNew || !x.HiveLoc.GetThingList(map).Any(y => y.GetType() == typeof(HiveLike))))) { // Log.Message(string.Format("PotentialHiveLoclist location candidates 50 {0}", forceNew)); cell = map.HiveGrid().PotentialHiveLoclist.Where(x => (x.X < 50 || x.Z < 50) && (!forceNew || !x.HiveLoc.GetThingList(map).Any(y => y.GetType() == typeof(HiveLike)))).RandomElement().HiveLoc; locationC = cell; } else if (map.HiveGrid().PotentialHiveLoclist.Any(x => (x.X < 75 || x.Z < 75) && (!forceNew || !x.HiveLoc.GetThingList(map).Any(y => y.GetType() == typeof(HiveLike))))) { // Log.Message(string.Format("PotentialHiveLoclist location candidates 75 {0}", forceNew)); cell = map.HiveGrid().PotentialHiveLoclist.Where(x => (x.X < 75 || x.Z < 75) && (!forceNew || !x.HiveLoc.GetThingList(map).Any(y => y.GetType() == typeof(HiveLike)))).RandomElement().HiveLoc; locationC = cell; } else { // Log.Message(string.Format("PotentialHiveLoclist location candidates {0}", forceNew)); cell = map.HiveGrid().PotentialHiveLoclist.Where(x => (!forceNew || !x.HiveLoc.GetThingList(map).Any(y => y.GetType() == typeof(HiveLike)))).RandomElement().HiveLoc; locationC = cell; } return(true); } cell = IntVec3.Invalid; locationC = IntVec3.Invalid; return(false); } } locationC = locationCandidate.cell; cell = CellFinder.FindNoWipeSpawnLocNear(locationCandidate.cell, map, XenomorphDefOf.RRY_Xenomorph_Hive, Rot4.North, 2, validator); ThingDef td = XenomorphDefOf.RRY_Xenomorph_Hive_Slime; GenSpawn.Spawn(td, cell, map); return(true); }
protected override bool CanFireNowSub(IIncidentTarget target) { Map map = (Map)target; IntVec3 intVec = default(IntVec3); return(base.CanFireNowSub(target) && HivesUtility.TotalSpawnedHivesCount(map) < 30 && InfestationCellFinder.TryFindCell(out intVec, map)); }
protected override bool CanFireNowSub(IncidentParms parms) { Map map = (Map)parms.target; IntVec3 intVec; return(base.CanFireNowSub(parms) && HivesUtility.TotalSpawnedHivesCount(map) < 30 && InfestationCellFinder.TryFindCell(out intVec, map)); }
private static float GetScoreAt(IntVec3 cell, Map map) { if ((float)InfestationCellFinder.distToColonyBuilding[cell] > 30f) { return(0f); } if (!cell.Walkable(map)) { return(0f); } if (cell.Fogged(map)) { return(0f); } if (InfestationCellFinder.CellHasBlockingThings(cell, map)) { return(0f); } if (!cell.Roofed(map) || !cell.GetRoof(map).isThickRoof) { return(0f); } Region region = cell.GetRegion(map, RegionType.Set_Passable); if (region == null) { return(0f); } if (InfestationCellFinder.closedAreaSize[cell] < 2) { return(0f); } float temperature = cell.GetTemperature(map); if (temperature < -17f) { return(0f); } float mountainousnessScoreAt = InfestationCellFinder.GetMountainousnessScoreAt(cell, map); if (mountainousnessScoreAt < 0.17f) { return(0f); } int num = InfestationCellFinder.StraightLineDistToUnroofed(cell, map); float num2; if (!InfestationCellFinder.regionsDistanceToUnroofed.TryGetValue(region, out num2)) { num2 = (float)num * 1.15f; } else { num2 = Mathf.Min(num2, (float)num * 4f); } num2 = Mathf.Pow(num2, 1.55f); float num3 = Mathf.InverseLerp(0f, 12f, (float)num); float num4 = Mathf.Lerp(1f, 0.18f, map.glowGrid.GameGlowAt(cell, false)); float num5 = 1f - Mathf.Clamp(InfestationCellFinder.DistToBlocker(cell, map) / 11f, 0f, 0.6f); float num6 = Mathf.InverseLerp(-17f, -7f, temperature); float num7 = num2 * num3 * num5 * mountainousnessScoreAt * num4 * num6; num7 = Mathf.Pow(num7, 1.2f); if (num7 < 7.5f) { return(0f); } return(num7); }
internal bool <> m__0(IntVec3 x) { return(InfestationCellFinder.GetScoreAt(x, this.map) > 0f && x.GetFirstThing(this.map, ThingDefOf.Hive) == null && x.GetFirstThing(this.map, ThingDefOf.TunnelHiveSpawner) == null); }
public static void DebugDraw() { if (DebugViewSettings.drawInfestationChance) { Map visibleMap = Find.VisibleMap; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(visibleMap); cellRect = cellRect.ExpandedBy(1); InfestationCellFinder.CalculateTraversalDistancesToUnroofed(visibleMap); InfestationCellFinder.CalculateClosedAreaSizeGrid(visibleMap); InfestationCellFinder.CalculateDistanceToColonyBuildingGrid(visibleMap); float num = 0.001f; int num2 = 0; while (true) { int num3 = num2; IntVec3 size = visibleMap.Size; if (num3 < size.z) { int num4 = 0; while (true) { int num5 = num4; IntVec3 size2 = visibleMap.Size; if (num5 < size2.x) { IntVec3 cell = new IntVec3(num4, 0, num2); float scoreAt = InfestationCellFinder.GetScoreAt(cell, visibleMap); if (scoreAt > num) { num = scoreAt; } num4++; continue; } break; } num2++; continue; } break; } int num6 = 0; while (true) { int num7 = num6; IntVec3 size3 = visibleMap.Size; if (num7 < size3.z) { int num8 = 0; while (true) { int num9 = num8; IntVec3 size4 = visibleMap.Size; if (num9 < size4.x) { IntVec3 intVec = new IntVec3(num8, 0, num6); if (cellRect.Contains(intVec)) { float scoreAt2 = InfestationCellFinder.GetScoreAt(intVec, visibleMap); if (!(scoreAt2 <= 0.0)) { float a = GenMath.LerpDouble(7.5f, num, 0f, 1f, scoreAt2); CellRenderer.RenderCell(intVec, SolidColorMaterials.SimpleSolidColorMaterial(new Color(0f, 0f, 1f, a), false)); } } num8++; continue; } break; } num6++; continue; } break; } } }