public static void FindStartingCellsFor2Groups(Map map, out IntVec3 first, out IntVec3 second) { for (int i = 0; i < 10; i++) { if (MultipleCaravansCellFinder.TryFindOppositeSpots(map, 0.05f, out first, out second)) { return; } } for (int j = 0; j < 10; j++) { if (MultipleCaravansCellFinder.TryFindOppositeSpots(map, 0.15f, out first, out second)) { return; } } if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map), map, CellFinder.EdgeRoadChance_Neutral, out first)) { Log.Error("Could not find any valid starting cell for a caravan.", false); first = CellFinder.RandomCell(map); second = CellFinder.RandomCell(map); return; } IntVec3 localFirst = first; float tryMinDistBetweenSpots = (float)Mathf.Max(map.Size.x, map.Size.z) * 0.6f; if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && !x.InHorDistOf(localFirst, tryMinDistBetweenSpots), map, CellFinder.EdgeRoadChance_Neutral, out second) && !CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map), map, 0.5f, out second)) { Log.Error("Could not find any valid starting cell for a caravan.", false); second = CellFinder.RandomCell(map); return; } first = CellFinder.RandomClosewalkCellNear(first, map, 7, null); second = CellFinder.RandomClosewalkCellNear(second, map, 7, null); }
private static bool TryFindOppositeSpots(Map map, float maxDistPctToOppositeSpots, out IntVec3 first, out IntVec3 second) { IntVec3 intVec = MultipleCaravansCellFinder.RandomSpotNearEdge(map); IntVec3 intVec2 = MultipleCaravansCellFinder.OppositeSpot(intVec, map); IntVec3 size = map.Size; int x = size.x; IntVec3 size2 = map.Size; int num = Mathf.Min(x, size2.z); CellRect cellRect = CellRect.CenteredOn(intVec, Mathf.Max(Mathf.RoundToInt((float)num * maxDistPctToOppositeSpots), 1)).ClipInsideMap(map); CellRect cellRect2 = CellRect.CenteredOn(intVec2, Mathf.Max(Mathf.RoundToInt((float)num * maxDistPctToOppositeSpots), 1)).ClipInsideMap(map); for (int i = 0; i < 20; i++) { IntVec3 intVec3 = (i != 0) ? cellRect.RandomCell : intVec; IntVec3 intVec4 = (i != 0) ? cellRect2.RandomCell : intVec2; if (intVec3.Standable(map) && !intVec3.Fogged(map) && intVec4.Standable(map) && !intVec4.Fogged(map) && map.reachability.CanReach(intVec3, intVec4, PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false))) { first = intVec3; second = intVec4; return(true); } } first = IntVec3.Invalid; second = IntVec3.Invalid; return(false); }
public static void FindStartingCellsFor2Groups(Map map, out IntVec3 first, out IntVec3 second) { int num = 0; while (num < 10) { if (!MultipleCaravansCellFinder.TryFindOppositeSpots(map, 0.05f, out first, out second)) { num++; continue; } return; } int num2 = 0; while (num2 < 10) { if (!MultipleCaravansCellFinder.TryFindOppositeSpots(map, 0.15f, out first, out second)) { num2++; continue; } return; } if (!CellFinder.TryFindRandomEdgeCellWith((Predicate <IntVec3>)((IntVec3 x) => x.Standable(map) && !x.Fogged(map)), map, CellFinder.EdgeRoadChance_Neutral, out first)) { Log.Error("Could not find any valid starting cell for a caravan."); first = CellFinder.RandomCell(map); second = CellFinder.RandomCell(map); } else { IntVec3 localFirst = first; IntVec3 size = map.Size; int x2 = size.x; IntVec3 size2 = map.Size; float tryMinDistBetweenSpots = (float)((float)Mathf.Max(x2, size2.z) * 0.60000002384185791); if (!CellFinder.TryFindRandomEdgeCellWith((Predicate <IntVec3>)((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && !x.InHorDistOf(localFirst, tryMinDistBetweenSpots)), map, CellFinder.EdgeRoadChance_Neutral, out second) && !CellFinder.TryFindRandomEdgeCellWith((Predicate <IntVec3>)((IntVec3 x) => x.Standable(map) && !x.Fogged(map)), map, 0.5f, out second)) { Log.Error("Could not find any valid starting cell for a caravan."); second = CellFinder.RandomCell(map); } else { first = CellFinder.RandomClosewalkCellNear(first, map, 7, null); second = CellFinder.RandomClosewalkCellNear(second, map, 7, null); } } }
public static Map SetupCaravanAttackMap(Caravan caravan, List<Pawn> enemies) { int num = CaravanIncidentUtility.CalculateIncidentMapSize(caravan.PawnsListForReading, enemies); Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(num, 1, num), WorldObjectDefOf.Ambush); IntVec3 playerStartingSpot; IntVec3 root; MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out playerStartingSpot, out root); CaravanEnterMapUtility.Enter(caravan, map, (Pawn x) => CellFinder.RandomSpawnCellForPawnNear(playerStartingSpot, map, 4), CaravanDropInventoryMode.DoNotDrop, true); for (int i = 0; i < enemies.Count; i++) { IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(root, map, 4); GenSpawn.Spawn(enemies[i], loc, map, Rot4.Random, false); } return map; }
public static Map SetupCaravanAttackMap(Caravan caravan, List <Pawn> enemies, bool sendLetterIfRelatedPawns) { int num = CalculateIncidentMapSize(caravan.PawnsListForReading, enemies); Map map = GetOrGenerateMapForIncident(caravan, new IntVec3(num, 1, num), WorldObjectDefOf.Ambush); MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out var playerStartingSpot, out var second); CaravanEnterMapUtility.Enter(caravan, map, (Pawn x) => CellFinder.RandomSpawnCellForPawnNear(playerStartingSpot, map), CaravanDropInventoryMode.DoNotDrop, draftColonists: true); for (int i = 0; i < enemies.Count; i++) { IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(second, map); GenSpawn.Spawn(enemies[i], loc, map, Rot4.Random); } if (sendLetterIfRelatedPawns) { PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(enemies, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, informEvenIfSeenBefore: true); } return(map); }