// Token: 0x0600368B RID: 13963 RVA: 0x001A0E1C File Offset: 0x0019F21C public static bool TryFindCell(out IntVec3 cell, Map map, ThingDef thingDef, FactionDef factionDef = null) { //Log.Message(string.Format("Tick: 1")); InfestationLikeCellFinder.CalculateLocationCandidates(map, thingDef); InfestationLikeCellFinder.LocationCandidate locationCandidate; if (!InfestationLikeCellFinder.locationCandidates.TryRandomElementByWeight((InfestationLikeCellFinder.LocationCandidate x) => x.score, out locationCandidate)) { cell = IntVec3.Invalid; //Log.Message(string.Format("TryFindCell: {0} From !InfestationLikeCellFinder.TryFindCell(out loc, map)", cell)); return(false); } cell = CellFinder.FindNoWipeSpawnLocNear(locationCandidate.cell, map, thingDef, Rot4.North, 2, (IntVec3 x) => InfestationLikeCellFinder.GetScoreAt(x, map, thingDef) > 0f && x.GetFirstThing(map, thingDef) == null && x.GetFirstThing(map, ((ThingDef_HiveLike)thingDef).TunnelDef) == null); return(true); }
private static void CalculateLocationCandidates(Map map, ThingDef thingDef) { InfestationLikeCellFinder.locationCandidates.Clear(); InfestationLikeCellFinder.CalculateTraversalDistancesToUnroofed(map); InfestationLikeCellFinder.CalculateClosedAreaSizeGrid(map); InfestationLikeCellFinder.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 = InfestationLikeCellFinder.GetScoreAt(cell, map, thingDef); if (scoreAt > 0f) { InfestationLikeCellFinder.locationCandidates.Add(new InfestationLikeCellFinder.LocationCandidate(cell, scoreAt)); } } } }
// Token: 0x06003694 RID: 13972 RVA: 0x001A1654 File Offset: 0x0019FA54 private static void CalculateTraversalDistancesToUnroofed(Map map) { InfestationLikeCellFinder.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 && InfestationLikeCellFinder.NoRoofAroundAndWalkable(intVec, map)) { InfestationLikeCellFinder.tempUnroofedRegions.Add(region); } } } Dijkstra <Region> .Run(InfestationLikeCellFinder.tempUnroofedRegions, (Region x) => x.Neighbors, (Region a, Region b) => Mathf.Sqrt((float)a.extentsClose.CenterCell.DistanceToSquared(b.extentsClose.CenterCell)), InfestationLikeCellFinder.regionsDistanceToUnroofed, null); InfestationLikeCellFinder.tempUnroofedRegions.Clear(); }
// Token: 0x0600368C RID: 13964 RVA: 0x001A0EAC File Offset: 0x0019F2AC private static float GetScoreAt(IntVec3 cell, Map map, ThingDef thingDef) { if ((float)InfestationLikeCellFinder.distToColonyBuilding[cell] > 30f) { return(0f); } if (!cell.Walkable(map)) { return(0f); } if (cell.Fogged(map)) { return(0f); } if (InfestationLikeCellFinder.CellHasBlockingThings(cell, map, thingDef)) { 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 (InfestationLikeCellFinder.closedAreaSize[cell] < 2) { return(0f); } float temperature = cell.GetTemperature(map); if (temperature < -17f) { return(0f); } float mountainousnessScoreAt = InfestationLikeCellFinder.GetMountainousnessScoreAt(cell, map); if (mountainousnessScoreAt < 0.17f) { return(0f); } int num = InfestationLikeCellFinder.StraightLineDistToUnroofed(cell, map); float num2; if (!InfestationLikeCellFinder.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(InfestationLikeCellFinder.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); }