public static void ImportantPawnCompPostLoadInit(ImportantPawnComp c) { if (c.pawn == null) { c.pawn = new ThingOwner <Pawn>(c, true, LookMode.Deep); } }
public override void PostExposeData(object obj) { if (Scribe.mode == LoadSaveMode.LoadingVars) { Game game = obj as Game; if (game != null && game.battleLog == null) { game.battleLog = new BattleLog(); } BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = obj as BattleLogEntry_MeleeCombat; if (battleLogEntry_MeleeCombat != null) { if (battleLogEntry_MeleeCombat.RuleDef == null) { RulePackDef value = null; RulePackDef value2 = null; Scribe_Defs.Look(ref value, "outcomeRuleDef"); Scribe_Defs.Look(ref value2, "maneuverRuleDef"); if (value != null && value2 != null) { foreach (RulePackDef item in DefDatabase <RulePackDef> .AllDefsListForReading) { if (!item.include.NullOrEmpty() && item.include.Count == 2 && ((item.include[0] == value && item.include[1] == value2) || (item.include[1] == value && item.include[0] == value2))) { battleLogEntry_MeleeCombat.RuleDef = item; break; } } } } if (battleLogEntry_MeleeCombat.def == null) { battleLogEntry_MeleeCombat.def = LogEntryDefOf.MeleeAttack; } } } if (Scribe.mode == LoadSaveMode.PostLoadInit) { Map map = obj as Map; if (map != null && map.pawnDestinationReservationManager == null) { map.pawnDestinationReservationManager = new PawnDestinationReservationManager(); } Pawn pawn = obj as Pawn; if (pawn != null && pawn.Spawned && pawn.rotationTracker == null) { pawn.rotationTracker = new Pawn_RotationTracker(pawn); } Pawn_MindState pawn_MindState = obj as Pawn_MindState; if (pawn_MindState != null && pawn_MindState.inspirationHandler == null) { pawn_MindState.inspirationHandler = new InspirationHandler(pawn_MindState.pawn); } ImportantPawnComp importantPawnComp = obj as ImportantPawnComp; if (importantPawnComp != null && importantPawnComp.pawn == null) { importantPawnComp.pawn = new ThingOwner <Pawn>(importantPawnComp, oneStackOnly: true); } Pawn_RecordsTracker pawn_RecordsTracker = obj as Pawn_RecordsTracker; if (pawn_RecordsTracker != null && Find.TaleManager.AnyTaleConcerns(pawn_RecordsTracker.pawn)) { pawn_RecordsTracker.AccumulateStoryEvent(StoryEventDefOf.TaleCreated); } WorldPawns worldPawns = obj as WorldPawns; if (worldPawns != null && worldPawns.gc == null) { worldPawns.gc = new WorldPawnGC(); } GameCondition gameCondition = obj as GameCondition; if (gameCondition != null && !gameCondition.Permanent && gameCondition.Duration > 1000000000) { gameCondition.Permanent = true; } Building_TurretGun building_TurretGun = obj as Building_TurretGun; if (building_TurretGun != null && building_TurretGun.gun == null) { building_TurretGun.MakeGun(); } } }
public void Notify_RelationKindChanged(Faction other, FactionRelationKind previousKind, bool canSendLetter, string reason, GlobalTargetInfo lookTarget, out bool sentLetter) { if (Current.ProgramState != ProgramState.Playing || other != Faction.OfPlayer) { canSendLetter = false; } sentLetter = false; FactionRelationKind factionRelationKind = this.RelationKindWith(other); if (factionRelationKind == FactionRelationKind.Hostile && Current.ProgramState == ProgramState.Playing) { foreach (Pawn current in PawnsFinder.AllMapsWorldAndTemporary_Alive.ToList <Pawn>()) { if ((current.Faction == this && current.HostFaction == other) || (current.Faction == other && current.HostFaction == this)) { current.guest.SetGuestStatus(current.HostFaction, true); } } } if (other == Faction.OfPlayer && !this.HostileTo(Faction.OfPlayer)) { List <Site> list = new List <Site>(); List <Site> sites = Find.WorldObjects.Sites; for (int i = 0; i < sites.Count; i++) { if (sites[i].factionMustRemainHostile && sites[i].Faction == this && !sites[i].HasMap) { list.Add(sites[i]); } } if (list.Any <Site>()) { string label; string text; if (list.Count == 1) { label = "LetterLabelSiteNoLongerHostile".Translate(); text = "LetterSiteNoLongerHostile".Translate(new object[] { this.Name, list[0].Label }); } else { StringBuilder stringBuilder = new StringBuilder(); for (int j = 0; j < list.Count; j++) { if (stringBuilder.Length != 0) { stringBuilder.AppendLine(); } stringBuilder.Append(" - " + list[j].LabelCap); ImportantPawnComp component = list[j].GetComponent <ImportantPawnComp>(); if (component != null && component.pawn.Any) { stringBuilder.Append(" (" + component.pawn[0].LabelCap + ")"); } } label = "LetterLabelSiteNoLongerHostileMulti".Translate(); text = "LetterSiteNoLongerHostileMulti".Translate(new object[] { this.Name }) + ":\n\n" + stringBuilder; } Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NeutralEvent, new LookTargets(from x in list select new GlobalTargetInfo(x.Tile)), null, null); for (int k = 0; k < list.Count; k++) { Find.WorldObjects.Remove(list[k]); } } } if (other == Faction.OfPlayer && this.HostileTo(Faction.OfPlayer)) { List <WorldObject> allWorldObjects = Find.WorldObjects.AllWorldObjects; for (int l = 0; l < allWorldObjects.Count; l++) { if (allWorldObjects[l].Faction == this) { TradeRequestComp component2 = allWorldObjects[l].GetComponent <TradeRequestComp>(); if (component2 != null && component2.ActiveRequest) { component2.Disable(); } } } } if (canSendLetter) { string empty = string.Empty; this.TryAppendRelationKindChangedInfo(ref empty, previousKind, factionRelationKind, reason); if (factionRelationKind == FactionRelationKind.Hostile) { Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_Hostile".Translate(new object[] { this.name }), empty, LetterDefOf.NegativeEvent, lookTarget, this, null); sentLetter = true; } else if (factionRelationKind == FactionRelationKind.Ally) { Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_Ally".Translate(new object[] { this.name }), empty, LetterDefOf.PositiveEvent, lookTarget, this, null); sentLetter = true; } else if (factionRelationKind == FactionRelationKind.Neutral) { if (previousKind == FactionRelationKind.Hostile) { Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_NeutralFromHostile".Translate(new object[] { this.name }), empty, LetterDefOf.PositiveEvent, lookTarget, this, null); sentLetter = true; } else { Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_NeutralFromAlly".Translate(new object[] { this.name }), empty, LetterDefOf.NeutralEvent, lookTarget, this, null); sentLetter = true; } } } if (Current.ProgramState == ProgramState.Playing) { List <Map> maps = Find.Maps; for (int m = 0; m < maps.Count; m++) { maps[m].attackTargetsCache.Notify_FactionHostilityChanged(this, other); LordManager lordManager = maps[m].lordManager; for (int n = 0; n < lordManager.lords.Count; n++) { Lord lord = lordManager.lords[n]; if (lord.faction == other) { lord.Notify_FactionRelationsChanged(this, previousKind); } else if (lord.faction == this) { lord.Notify_FactionRelationsChanged(other, previousKind); } } } } }
public void Notify_RelationKindChanged(Faction other, FactionRelationKind previousKind, bool canSendLetter, string reason, GlobalTargetInfo lookTarget, out bool sentLetter) { if (Current.ProgramState != ProgramState.Playing || other != OfPlayer) { canSendLetter = false; } sentLetter = false; ColoredText.ClearCache(); FactionRelationKind factionRelationKind = RelationKindWith(other); if (factionRelationKind == FactionRelationKind.Hostile) { if (Current.ProgramState == ProgramState.Playing) { foreach (Pawn item in PawnsFinder.AllMapsWorldAndTemporary_Alive.ToList()) { if ((item.Faction == this && item.HostFaction == other) || (item.Faction == other && item.HostFaction == this)) { item.guest.SetGuestStatus(item.HostFaction, prisoner: true); } } } if (other == OfPlayer) { QuestUtility.SendQuestTargetSignals(questTags, "BecameHostileToPlayer", this.Named("SUBJECT")); } } if (other == OfPlayer && !this.HostileTo(OfPlayer)) { List <Site> list = new List <Site>(); List <Site> sites = Find.WorldObjects.Sites; for (int i = 0; i < sites.Count; i++) { if (sites[i].factionMustRemainHostile && sites[i].Faction == this && !sites[i].HasMap) { list.Add(sites[i]); } } if (list.Any()) { string str; string str2; if (list.Count == 1) { str = "LetterLabelSiteNoLongerHostile".Translate(); str2 = "LetterSiteNoLongerHostile".Translate(NameColored, list[0].Label); } else { StringBuilder stringBuilder = new StringBuilder(); for (int j = 0; j < list.Count; j++) { if (stringBuilder.Length != 0) { stringBuilder.AppendLine(); } stringBuilder.Append(" - " + list[j].LabelCap); ImportantPawnComp component = list[j].GetComponent <ImportantPawnComp>(); if (component != null && component.pawn.Any) { stringBuilder.Append(" (" + component.pawn[0].LabelCap + ")"); } } str = "LetterLabelSiteNoLongerHostileMulti".Translate(); str2 = (string)("LetterSiteNoLongerHostileMulti".Translate(NameColored) + ":\n\n") + stringBuilder; } Find.LetterStack.ReceiveLetter(str, str2, LetterDefOf.NeutralEvent, new LookTargets(list.Select((Site x) => new GlobalTargetInfo(x.Tile)))); for (int k = 0; k < list.Count; k++) { list[k].Destroy(); } } } if (other == OfPlayer && this.HostileTo(OfPlayer)) { List <WorldObject> allWorldObjects = Find.WorldObjects.AllWorldObjects; for (int l = 0; l < allWorldObjects.Count; l++) { if (allWorldObjects[l].Faction == this) { TradeRequestComp component2 = allWorldObjects[l].GetComponent <TradeRequestComp>(); if (component2 != null && component2.ActiveRequest) { component2.Disable(); } } } foreach (Map map in Find.Maps) { map.passingShipManager.RemoveAllShipsOfFaction(this); } } if (canSendLetter) { TaggedString text = ""; TryAppendRelationKindChangedInfo(ref text, previousKind, factionRelationKind, reason); switch (factionRelationKind) { case FactionRelationKind.Hostile: Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_Hostile".Translate(Name), text, LetterDefOf.NegativeEvent, lookTarget, this); sentLetter = true; break; case FactionRelationKind.Ally: Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_Ally".Translate(Name), text, LetterDefOf.PositiveEvent, lookTarget, this); sentLetter = true; break; case FactionRelationKind.Neutral: if (previousKind == FactionRelationKind.Hostile) { Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_NeutralFromHostile".Translate(Name), text, LetterDefOf.PositiveEvent, lookTarget, this); sentLetter = true; } else { Find.LetterStack.ReceiveLetter("LetterLabelRelationsChange_NeutralFromAlly".Translate(Name), text, LetterDefOf.NeutralEvent, lookTarget, this); sentLetter = true; } break; } } if (Current.ProgramState != ProgramState.Playing) { return; } List <Map> maps = Find.Maps; for (int m = 0; m < maps.Count; m++) { maps[m].attackTargetsCache.Notify_FactionHostilityChanged(this, other); LordManager lordManager = maps[m].lordManager; for (int n = 0; n < lordManager.lords.Count; n++) { Lord lord = lordManager.lords[n]; if (lord.faction == other) { lord.Notify_FactionRelationsChanged(this, previousKind); } else if (lord.faction == this) { lord.Notify_FactionRelationsChanged(other, previousKind); } } } }