public static bool LordOf(LordManager __instance, ref Lord __result, Pawn p) { Lord lordResult = null; if (p != null) { if (!Lord_Patch.pawnsLord.TryGetValue(p, out lordResult)) { for (int i = 0; i < __instance.lords.Count; i++) { Lord lord = __instance.lords[i]; for (int j = 0; j < lord.ownedPawns.Count; j++) { if (lord.ownedPawns[j] == p) { lock (Lord_Patch.pawnsLord) { Lord_Patch.pawnsLord.SetOrAdd(p, lord); } __result = lord; return(false); } } } lock (Lord_Patch.pawnsLord) { Lord_Patch.pawnsLord.SetOrAdd(p, null); } } } __result = lordResult; return(false); }
public static bool RemoveLord(LordManager __instance, Lord oldLord) { for (int j = 0; j < oldLord.ownedPawns.Count; j++) { lock (Lord_Patch.pawnsLord) { Lord_Patch.pawnsLord.SetOrAdd(oldLord.ownedPawns[j], null); } } __instance.lords.Remove(oldLord); Find.SignalManager.DeregisterReceiver(oldLord); oldLord.Cleanup(); return(false); }
public void ConstructComponents() { this.spawnedThings = new ThingOwner <Thing>(this); this.cellIndices = new CellIndices(this); this.listerThings = new ListerThings(ListerThingsUse.Global); this.listerBuildings = new ListerBuildings(); this.mapPawns = new MapPawns(this); this.dynamicDrawManager = new DynamicDrawManager(this); this.mapDrawer = new MapDrawer(this); this.tooltipGiverList = new TooltipGiverList(); this.pawnDestinationReservationManager = new PawnDestinationReservationManager(); this.reservationManager = new ReservationManager(this); this.physicalInteractionReservationManager = new PhysicalInteractionReservationManager(); this.designationManager = new DesignationManager(this); this.lordManager = new LordManager(this); this.debugDrawer = new DebugCellDrawer(); this.passingShipManager = new PassingShipManager(this); this.haulDestinationManager = new HaulDestinationManager(this); this.gameConditionManager = new GameConditionManager(this); this.weatherManager = new WeatherManager(this); this.zoneManager = new ZoneManager(this); this.resourceCounter = new ResourceCounter(this); this.mapTemperature = new MapTemperature(this); this.temperatureCache = new TemperatureCache(this); this.areaManager = new AreaManager(this); this.attackTargetsCache = new AttackTargetsCache(this); this.attackTargetReservationManager = new AttackTargetReservationManager(this); this.lordsStarter = new VoluntarilyJoinableLordsStarter(this); this.thingGrid = new ThingGrid(this); this.coverGrid = new CoverGrid(this); this.edificeGrid = new EdificeGrid(this); this.blueprintGrid = new BlueprintGrid(this); this.fogGrid = new FogGrid(this); this.glowGrid = new GlowGrid(this); this.regionGrid = new RegionGrid(this); this.terrainGrid = new TerrainGrid(this); this.pathGrid = new PathGrid(this); this.roofGrid = new RoofGrid(this); this.fertilityGrid = new FertilityGrid(this); this.snowGrid = new SnowGrid(this); this.deepResourceGrid = new DeepResourceGrid(this); this.exitMapGrid = new ExitMapGrid(this); this.linkGrid = new LinkGrid(this); this.glowFlooder = new GlowFlooder(this); this.powerNetManager = new PowerNetManager(this); this.powerNetGrid = new PowerNetGrid(this); this.regionMaker = new RegionMaker(this); this.pathFinder = new PathFinder(this); this.pawnPathPool = new PawnPathPool(this); this.regionAndRoomUpdater = new RegionAndRoomUpdater(this); this.regionLinkDatabase = new RegionLinkDatabase(); this.moteCounter = new MoteCounter(); this.gatherSpotLister = new GatherSpotLister(); this.windManager = new WindManager(this); this.listerBuildingsRepairable = new ListerBuildingsRepairable(); this.listerHaulables = new ListerHaulables(this); this.listerMergeables = new ListerMergeables(this); this.listerFilthInHomeArea = new ListerFilthInHomeArea(this); this.reachability = new Reachability(this); this.itemAvailability = new ItemAvailability(this); this.autoBuildRoofAreaSetter = new AutoBuildRoofAreaSetter(this); this.roofCollapseBufferResolver = new RoofCollapseBufferResolver(this); this.roofCollapseBuffer = new RoofCollapseBuffer(); this.wildAnimalSpawner = new WildAnimalSpawner(this); this.wildPlantSpawner = new WildPlantSpawner(this); this.steadyEnvironmentEffects = new SteadyEnvironmentEffects(this); this.skyManager = new SkyManager(this); this.overlayDrawer = new OverlayDrawer(); this.floodFiller = new FloodFiller(this); this.weatherDecider = new WeatherDecider(this); this.fireWatcher = new FireWatcher(this); this.dangerWatcher = new DangerWatcher(this); this.damageWatcher = new DamageWatcher(); this.strengthWatcher = new StrengthWatcher(this); this.wealthWatcher = new WealthWatcher(this); this.regionDirtyer = new RegionDirtyer(this); this.cellsInRandomOrder = new MapCellsInRandomOrder(this); this.rememberedCameraPos = new RememberedCameraPos(this); this.mineStrikeManager = new MineStrikeManager(); this.storyState = new StoryState(this); this.retainedCaravanData = new RetainedCaravanData(this); this.components.Clear(); this.FillComponents(); }
// ===================== Goodwill management ===================== public static bool AffectGoodwillWith(Faction faction, Faction other, int goodwillChange, bool canSendMessage = true, bool canSendHostilityLetter = true, string reason = null, GlobalTargetInfo?lookTarget = null) { if (goodwillChange == 0) { return(true); } int num = faction.GoodwillWith(other); int num2 = Mathf.Clamp(num + goodwillChange, -100, 100); if (num == num2) { return(true); } FactionRelation factionRelation = faction.RelationWith(other, false); factionRelation.goodwill = num2; bool flag; factionRelation.CheckKindThresholds(faction, canSendHostilityLetter, reason, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, out flag); FactionRelation factionRelation2 = other.RelationWith(faction, false); FactionRelationKind kind = factionRelation2.kind; factionRelation2.goodwill = factionRelation.goodwill; factionRelation2.kind = factionRelation.kind; bool flag2; if (kind != factionRelation2.kind) { other.Notify_RelationKindChanged(faction, kind, canSendHostilityLetter, reason, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, out flag2); } if ((faction == Util_Faction.MiningCoFaction) && (other == Faction.OfPlayer) && (factionRelation.kind == FactionRelationKind.Hostile)) { Util_Misc.Partnership.globalGoodwillFeeInSilver = WorldComponent_Partnership.globalGoodwillCostInSilver; Util_Misc.OrbitalHealing.Notify_BecameHostileToColony(); foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { List <Building_Spaceship> takeOffRequestList = new List <Building_Spaceship>(); foreach (Thing thing in map.listerThings.AllThings) { if (thing is Building_Spaceship) { takeOffRequestList.Add(thing as Building_Spaceship); } } foreach (Building_Spaceship spaceship in takeOffRequestList) { spaceship.RequestTakeOff(); } } LordManager lordManager = map.lordManager; for (int j = 0; j < lordManager.lords.Count; j++) { Lord lord = lordManager.lords[j]; if (lord.faction == Util_Faction.MiningCoFaction) { lord.ReceiveMemo("BecameHostileToColony"); } } } } /*else * { * flag2 = false; * } * if (canSendMessage && !flag && !flag2 && Current.ProgramState == ProgramState.Playing && (faction.IsPlayer || other.IsPlayer)) * { * Faction faction = (!this.IsPlayer) ? this : other; * string text; * if (!reason.NullOrEmpty()) * { * text = "MessageGoodwillChangedWithReason".Translate(faction.name, num.ToString("F0"), factionRelation.goodwill.ToString("F0"), reason); * } * else * { * text = "MessageGoodwillChanged".Translate(faction.name, num.ToString("F0"), factionRelation.goodwill.ToString("F0")); * } * Messages.Message(text, (!lookTarget.HasValue) ? GlobalTargetInfo.Invalid : lookTarget.Value, ((float)goodwillChange <= 0f) ? MessageTypeDefOf.NegativeEvent : MessageTypeDefOf.PositiveEvent, true); * }*/ return(true); }
public void SetHostileTo(Faction other, bool hostile) { if (!this.def.hidden && !other.def.hidden) { FactionRelation factionRelation = this.RelationWith(other, false); if (hostile) { if (Current.ProgramState == ProgramState.Playing) { foreach (Pawn item in PawnsFinder.AllMapsWorldAndTemporary_Alive.ToList()) { if (item.Faction == this && item.HostFaction == other) { goto IL_0088; } if (item.Faction == other && item.HostFaction == this) { goto IL_0088; } continue; IL_0088: item.guest.SetGuestStatus(item.HostFaction, true); } } if (!factionRelation.hostile) { other.RelationWith(this, false).hostile = true; factionRelation.hostile = true; if (factionRelation.goodwill > -80.0) { factionRelation.goodwill = -80f; } } } else if (factionRelation.hostile) { other.RelationWith(this, false).hostile = false; factionRelation.hostile = false; if (factionRelation.goodwill < 0.0) { factionRelation.goodwill = 0f; } } if (Current.ProgramState == ProgramState.Playing) { List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { maps[i].attackTargetsCache.Notify_FactionHostilityChanged(this, other); LordManager lordManager = maps[i].lordManager; for (int j = 0; j < lordManager.lords.Count; j++) { Lord lord = lordManager.lords[j]; if (lord.faction == other) { lord.Notify_FactionRelationsChanged(this); } else if (lord.faction == this) { lord.Notify_FactionRelationsChanged(other); } } } } } }
public static void SetFactionHostileToOther(Faction faction, Faction other, bool hostile) { FactionRelation factionRelation = faction.RelationWith(other, false); if (hostile) { if ((faction == Util_Faction.MiningCoFaction) && (other == Faction.OfPlayer)) { Util_Misc.Partnership.globalGoodwillFeeInSilver = WorldComponent_Partnership.globalGoodwillCostInSilver; Util_Misc.OrbitalHealing.Notify_BecameHostileToColony(); foreach (Map map in Find.Maps) { if (map.IsPlayerHome) { List <Building_Spaceship> takeOffRequestList = new List <Building_Spaceship>(); foreach (Thing thing in map.listerThings.AllThings) { if (thing is Building_Spaceship) { takeOffRequestList.Add(thing as Building_Spaceship); } } foreach (Building_Spaceship spaceship in takeOffRequestList) { spaceship.RequestTakeOff(); } } } } if (Current.ProgramState == ProgramState.Playing) { foreach (Pawn current in PawnsFinder.AllMapsWorldAndTemporary_Alive.ToList <Pawn>()) { if ((current.Faction == faction && current.HostFaction == other) || (current.Faction == other && current.HostFaction == faction)) { current.guest.SetGuestStatus(current.HostFaction, true); } } } if (!factionRelation.hostile) { other.RelationWith(faction, false).hostile = true; factionRelation.hostile = true; if (factionRelation.goodwill > -80f) { factionRelation.goodwill = -80f; } } } else { if (factionRelation.hostile) { other.RelationWith(faction, false).hostile = false; factionRelation.hostile = false; if (factionRelation.goodwill < 0f) { factionRelation.goodwill = 0f; } } } if (Current.ProgramState == ProgramState.Playing) { List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { maps[i].attackTargetsCache.Notify_FactionHostilityChanged(faction, other); LordManager lordManager = maps[i].lordManager; for (int j = 0; j < lordManager.lords.Count; j++) { Lord lord = lordManager.lords[j]; if (lord.faction == other) { lord.Notify_FactionRelationsChanged(faction); } else { if (lord.faction == faction) { lord.Notify_FactionRelationsChanged(other); } } if ((lord.faction == Util_Faction.MiningCoFaction) && (other == Faction.OfPlayer)) { lord.ReceiveMemo("BecameHostileToColony"); } } } } }
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); } } } }