public static void CheckDefeated(FactionBase factionBase) { if (factionBase.Faction != Faction.OfPlayer) { Map map = factionBase.Map; if (map != null && FactionBaseDefeatUtility.IsDefeated(map, factionBase.Faction)) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("LetterFactionBaseDefeated".Translate(factionBase.Label, TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000))); if (!FactionBaseDefeatUtility.HasAnyOtherBase(factionBase)) { factionBase.Faction.defeated = true; stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.Append("LetterFactionBaseDefeated_FactionDestroyed".Translate(factionBase.Faction.Name)); } Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), stringBuilder.ToString(), LetterDefOf.PositiveEvent, new GlobalTargetInfo(factionBase.Tile), null); DestroyedFactionBase destroyedFactionBase = (DestroyedFactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedFactionBase); destroyedFactionBase.Tile = factionBase.Tile; Find.WorldObjects.Add(destroyedFactionBase); map.info.parent = destroyedFactionBase; Find.WorldObjects.Remove(factionBase); ((WorldObject)destroyedFactionBase).GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown(); TaleRecorder.RecordTale(TaleDefOf.CaravanAssaultSuccessful, map.mapPawns.FreeColonists.RandomElement()); } } }
private static void AddAbandonedBase(FactionBase factionBase) { WorldObject worldObject = WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.AbandonedFactionBase); worldObject.Tile = factionBase.Tile; worldObject.SetFaction(factionBase.Faction); Find.WorldObjects.Add(worldObject); }
public static FactionBase AddNewHome(int tile, Faction faction) { FactionBase factionBase = (FactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.FactionBase); factionBase.Tile = tile; factionBase.SetFaction(faction); factionBase.Name = FactionBaseNameGenerator.GenerateFactionBaseName(factionBase); Find.WorldObjects.Add(factionBase); return(factionBase); }
private static void Abandon(MapParent settlement) { Find.WorldObjects.Remove(settlement); FactionBase factionBase = settlement as FactionBase; if (factionBase != null) { SettlementAbandonUtility.AddAbandonedBase(factionBase); } Find.GameEnder.CheckOrUpdateGameOver(); }
private static bool HasAnyOtherBase(FactionBase defeatedFactionBase) { List <FactionBase> factionBases = Find.WorldObjects.FactionBases; for (int i = 0; i < factionBases.Count; i++) { FactionBase factionBase = factionBases[i]; if (factionBase.Faction == defeatedFactionBase.Faction && factionBase != defeatedFactionBase) { return(true); } } return(false); }
public static string GenerateFactionBaseName(FactionBase factionBase) { if (factionBase.Faction != null && factionBase.Faction.def.baseNameMaker != null) { FactionBaseNameGenerator.usedNames.Clear(); List <FactionBase> factionBases = Find.WorldObjects.FactionBases; for (int i = 0; i < factionBases.Count; i++) { FactionBase factionBase2 = factionBases[i]; if (factionBase2.Name != null) { FactionBaseNameGenerator.usedNames.Add(factionBase2.Name); } } return(NameGenerator.GenerateName(factionBase.Faction.def.baseNameMaker, FactionBaseNameGenerator.usedNames, true, null)); } return(factionBase.def.label); }
public static void Settle(Caravan caravan) { Faction faction = caravan.Faction; if (faction != Faction.OfPlayer) { Log.Error("Cannot settle with non-player faction."); return; } FactionBase newHome = SettleUtility.AddNewHome(caravan.Tile, faction); LongEventHandler.QueueLongEvent(delegate { GetOrGenerateMapUtility.GetOrGenerateMap(caravan.Tile, Find.World.info.initialMapSize, null); }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap)); LongEventHandler.QueueLongEvent(delegate { Map map = newHome.Map; Pawn t = caravan.PawnsListForReading[0]; CaravanEnterMapUtility.Enter(caravan, map, CaravanEnterMode.Center, CaravanDropInventoryMode.DropInstantly, false, (IntVec3 x) => x.GetRoom(map, RegionType.Set_Passable).CellCount >= 600); CameraJumper.TryJump(t); }, "SpawningColonists", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap)); }
public static void Settle(Map map) { MapParent parent = map.info.parent; FactionBase factionBase = SettleUtility.AddNewHome(map.Tile, Faction.OfPlayer); map.info.parent = factionBase; if (parent != null) { Find.WorldObjects.Remove(parent); } Messages.Message("MessageSettledInExistingMap".Translate(), factionBase, MessageTypeDefOf.PositiveEvent); SettleInExistingMapUtility.tmpPlayerPawns.Clear(); SettleInExistingMapUtility.tmpPlayerPawns.AddRange(from x in map.mapPawns.AllPawnsSpawned where x.Faction == Faction.OfPlayer || x.HostFaction == Faction.OfPlayer select x); CaravanEnterMapUtility.DropAllInventory(SettleInExistingMapUtility.tmpPlayerPawns); SettleInExistingMapUtility.tmpPlayerPawns.Clear(); List <Pawn> prisonersOfColonySpawned = map.mapPawns.PrisonersOfColonySpawned; for (int i = 0; i < prisonersOfColonySpawned.Count; i++) { prisonersOfColonySpawned[i].guest.WaitInsteadOfEscapingForDefaultTicks(); } }