private static void DebugResetAllMobileUnits() { int resetCount = 0; List <WorldObject> woList = Find.WorldObjects.AllWorldObjects; if (woList != null && woList.Count > 0) { for (int i = 0; i < woList.Count; i++) { WarObject rwo = woList[i] as WarObject; if (rwo != null) { RimWarData rwd = WorldUtility.GetRimWarDataForFaction(rwo.Faction); if (rwd != null && rwd.WorldSettlements != null && rwd.WorldSettlements.Count > 0) { resetCount++; RimWorld.Planet.Settlement settlement = rwd.WorldSettlements.RandomElement(); if (settlement != null) { if (settlement.Destroyed) { Log.Warning("Detected destroyed settlement in Rim War data for " + rwd.RimWarFaction.Name); } else { RimWarSettlementComp rwsc = settlement.GetComponent <RimWarSettlementComp>(); if (rwsc != null) { rwsc.RimWarPoints += rwo.RimWarPoints; } else { Log.Warning("Found no Rim War component for settlement " + settlement.Label); Log.Warning("Settlement in faction " + settlement.Faction); Log.Warning("Settlement defname " + settlement.def.defName); } } } else { Log.Warning("Detected null settlement in Rim War data for " + rwd.RimWarFaction.Name); } if (!rwo.Destroyed) { rwo.Destroy(); } } else { Log.Warning("Tried to reset unit but no Faction data exists - cleaning up object."); if (!rwo.Destroyed) { rwo.Destroy(); } } } } Log.Message("Reset " + resetCount + " Rim War units."); } }
public void FindParentSettlement() { RimWorld.Planet.Settlement wos = null; wos = WorldUtility.GetClosestSettlementInRWDTo(WorldUtility.GetRimWarDataForFaction(this.Faction), this.Tile); if (wos != null) { this.parentSettlementTile = wos.Tile; ParentSettlement = wos; } //List<Settlement> rwdTownList = WorldUtility.GetFriendlyRimWarSettlementsInRange(this.Tile, 30, this.Faction, WorldUtility.GetRimWarData(), WorldUtility.GetRimWarDataForFaction(this.Faction)); //if(rwdTownList != null && rwdTownList.Count <= 0) //{ // Log.Message("initial check did not find nearby settlement"); // rwdTownList = WorldUtility.GetFriendlyRimWarSettlementsInRange(this.Tile, 100, this.Faction, WorldUtility.GetRimWarData(), WorldUtility.GetRimWarDataForFaction(this.Faction)); //} //if(rwdTownList != null && rwdTownList.Count > 0) //{ // this.ParentSettlement = rwdTownList.RandomElement(); //WorldUtility.GetFriendlyRimWarSettlementsInRange(this.Tile, 100, this.Faction, WorldUtility.GetRimWarData(), WorldUtility.GetRimWarDataForFaction(this.Faction)).RandomElement(); // Log.Message("found parent at " + this.ParentSettlement.Tile + " current tile is " + this.Tile); // PathToTarget(Find.World.worldObjects.WorldObjectAt(this.ParentSettlement.Tile, WorldObjectDefOf.Settlement)); //} if (this.parentSettlement == null) { //warband is lost, no nearby parent settlement this.Destroy(); if (Find.WorldObjects.Contains(this)) { Find.WorldObjects.Remove(this); } } }
private static void Add1000RWP() { int tile = GenWorld.MouseTile(); if (tile < 0 || Find.World.Impassable(tile)) { Messages.Message("Impassable", MessageTypeDefOf.RejectInput, historical: false); } else { RimWorld.Planet.Settlement s = Find.WorldObjects.SettlementAt(tile); if (s != null && s.Faction != Faction.OfPlayer) { RimWarSettlementComp rwsc = WorldUtility.GetRimWarSettlementAtTile(tile); if (rwsc != null && rwsc.parent.Faction != Faction.OfPlayer) { rwsc.RimWarPoints += 1000; } } WarObject rwo = Find.WorldObjects.WorldObjectAt(tile, RimWarDefOf.RW_WarObject) as WarObject; if (rwo != null) { rwo.RimWarPoints += 1000; } } }
public void ValidateParentSettlement() { if (this.ParentSettlement != null) { RimWorld.Planet.Settlement settlement = Find.World.worldObjects.SettlementAt(this.ParentSettlement.Tile); if (settlement == null || settlement.Faction != this.Faction) { if (WorldUtility.GetRimWarDataForFaction(this.Faction).FactionSettlements.Contains(this.ParentSettlement)) { WorldUtility.GetRimWarDataForFaction(this.Faction).FactionSettlements.Remove(this.ParentSettlement); } this.ParentSettlement = null; } } }
public void ValidateParentSettlement() { if (this.ParentSettlement != null) { RimWorld.Planet.Settlement settlement = Find.WorldObjects.SettlementAt(this.ParentSettlement.Tile); if (settlement == null || settlement.Faction != this.Faction || settlement.Destroyed) { ////RimWar.Planet.Settlement rws = null; ////if (WorldUtility.GetRimWarDataForFaction(this.Faction).HasFactionSettlementFor(settlement, out rws)) ////{ //// WorldUtility.GetRimWarDataForFaction(this.Faction).FactionSettlements.Remove(rws); ////} this.ParentSettlement = null; } } }
public bool HasWarSettlementFor(RimWorld.Planet.Settlement wos, out RimWarSettlementComp rwsc) { rwsc = null; if (this.WorldSettlements != null && this.WorldSettlements.Count > 0) { for (int i = 0; i < WorldSettlements.Count; i++) { if (wos == WorldSettlements[i]) { rwsc = WorldSettlements[i].GetComponent <RimWarSettlementComp>(); if (rwsc != null) { return(true); } } } } return(false); }
//private static void DrawFactionRow_WithFactionPoints_Postfix(Faction faction, float rowY, Rect fillRect, ref float __result) //{ // if (!Prefs.DevMode) // { // Rect rect = new Rect(35f, rowY + __result, 250f, 80f); // StringBuilder stringBuilder = new StringBuilder(); // string text = stringBuilder.ToString(); // float width = fillRect.width - rect.xMax; // float num = Text.CalcHeight(text, width); // float num2 = Mathf.Max(80f, num); // Rect position = new Rect(10f, rowY + 10f, 15f, 15f); // Rect rect2 = new Rect(0f, rowY + __result, fillRect.width, num2); // if (Mouse.IsOver(rect2)) // { // GUI.DrawTexture(rect2, TexUI.HighlightTex); // } // Text.Font = GameFont.Small; // Text.Anchor = TextAnchor.UpperLeft; // Widgets.DrawRectFast(position, faction.Color); // string label = "RW_FactionPower".Translate(WorldUtility.GetRimWarDataForFaction(faction) == null ? 0 : WorldUtility.GetRimWarDataForFaction(faction).TotalFactionPoints); // label += "\n" + "RW_FactionBehavior".Translate(WorldUtility.GetRimWarDataForFaction(faction).behavior.ToString()); // Widgets.Label(rect, label); // if (!faction.IsPlayer) // { // } // __result += num2; // } //} private static void Settlement_InspectString_WithPoints_Postfix(RimWorld.Planet.Settlement __instance, ref string __result) { if (!__instance.Faction.def.hidden) { RimWarSettlementComp rwsc = __instance.GetComponent <RimWarSettlementComp>(); RimWarData rwd = WorldUtility.GetRimWarDataForFaction(__instance.Faction); if (rwsc != null && rwd != null) { string text = ""; if (!__result.NullOrEmpty()) { text += "\n"; } text += "RW_SettlementPoints".Translate(rwsc.RimWarPoints + "\n" + "RW_FactionBehavior".Translate(rwd.behavior.ToString())); __result += text; } } }
private static void SpawnScout() { int tile = GenWorld.MouseTile(); if (tile < 0 || Find.World.Impassable(tile)) { Messages.Message("Impassable", MessageTypeDefOf.RejectInput, historical: false); } else { RimWorld.Planet.Settlement s = Find.WorldObjects.SettlementAt(tile); if (s != null) { RimWarSettlementComp rwsc = WorldUtility.GetRimWarSettlementAtTile(tile); if (rwsc != null) { WorldUtility.Get_WCPT().AttemptScoutMission(WorldUtility.GetRimWarDataForFaction(s.Faction), s, rwsc, false, false, true); } } } }
public static void GiveGift(List <ActiveDropPodInfo> pods, Settlement giveTo) { int goodwillChange = GetGoodwillChange(pods.Cast <IThingHolder>(), giveTo); for (int i = 0; i < pods.Count; i++) { ThingOwner innerContainer = pods[i].innerContainer; for (int num = innerContainer.Count - 1; num >= 0; num--) { GiveGiftInternal(innerContainer[num], innerContainer[num].stackCount, giveTo.Faction); if (num < innerContainer.Count) { innerContainer.RemoveAt(num); } } } if (!giveTo.Faction.TryAffectGoodwillWith(Faction.OfPlayer, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, "GoodwillChangedReason_ReceivedGift".Translate(), giveTo)) { SendGiftNotAppreciatedMessage(giveTo.Faction, giveTo); } }
public static void AppendProximityGoodwillOffsets(int tile, List <Pair <Settlement, int> > outOffsets, bool ignoreIfAlreadyMinGoodwill, bool ignorePermanentlyHostile) { int maxDist = MaxDist; List <Settlement> settlements = Find.WorldObjects.Settlements; for (int i = 0; i < settlements.Count; i++) { Settlement settlement = settlements[i]; if (settlement.Faction != null && settlement.Faction != Faction.OfPlayer && (!ignorePermanentlyHostile || !settlement.Faction.def.permanentEnemy) && (!ignoreIfAlreadyMinGoodwill || settlement.Faction.PlayerGoodwill != -100)) { int num = Find.WorldGrid.TraversalDistanceBetween(tile, settlement.Tile, passImpassable: false, maxDist); if (num != 2147483647) { int num2 = Mathf.RoundToInt(DiplomacyTuning.Goodwill_PerQuadrumFromSettlementProximity.Evaluate((float)num)); if (num2 != 0) { outOffsets.Add(new Pair <Settlement, int>(settlement, num2)); } } } } }
public static bool IsPlayerAttackingAnySettlementOf(Faction faction) { if (faction == Faction.OfPlayer) { return(false); } if (!faction.HostileTo(Faction.OfPlayer)) { return(false); } List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { Settlement settlement = maps[i].info.parent as Settlement; if (settlement != null && settlement.Faction == faction) { return(true); } } return(false); }
public static void AffectRelationsOnAttacked(Settlement settlement, ref TaggedString letterText) { if (settlement.Faction == null || settlement.Faction == Faction.OfPlayer) { return; } FactionRelationKind playerRelationKind = settlement.Faction.PlayerRelationKind; if (!settlement.Faction.HostileTo(Faction.OfPlayer)) { settlement.Faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, canSendLetter: false); } else if (settlement.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -50, canSendMessage: false, canSendHostilityLetter: false)) { if (!letterText.NullOrEmpty()) { letterText += "\n\n"; } letterText += "RelationsWith".Translate(settlement.Faction.Name.ApplyTag(settlement.Faction)) + ": " + (-50).ToStringWithSign(); } settlement.Faction.TryAppendRelationKindChangedInfo(ref letterText, playerRelationKind, settlement.Faction.PlayerRelationKind); }
public static void Settle(Caravan caravan) { Faction faction = caravan.Faction; if (faction != Faction.OfPlayer) { Log.Error("Cannot settle with non-player faction.", false); } else { Settlement newHome = SettleUtility.AddNewHome(caravan.Tile, faction); Action action = delegate() { GetOrGenerateMapUtility.GetOrGenerateMap(caravan.Tile, Find.World.info.initialMapSize, null); }; string textKey = "GeneratingMap"; bool doAsynchronously = true; if (SettleInEmptyTileUtility.< > f__mg$cache0 == null) { SettleInEmptyTileUtility.< > f__mg$cache0 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap); } LongEventHandler.QueueLongEvent(action, textKey, doAsynchronously, SettleInEmptyTileUtility.< > f__mg$cache0); Action action2 = 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); }; string textKey2 = "SpawningColonists"; bool doAsynchronously2 = true; if (SettleInEmptyTileUtility.< > f__mg$cache1 == null) { SettleInEmptyTileUtility.< > f__mg$cache1 = new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap); } LongEventHandler.QueueLongEvent(action2, textKey2, doAsynchronously2, SettleInEmptyTileUtility.< > f__mg$cache1); } }
public static string GenerateSettlementName(Settlement factionBase, RulePackDef rulePack = null) { if (rulePack == null) { if (factionBase.Faction == null || factionBase.Faction.def.settlementNameMaker == null) { return(factionBase.def.label); } rulePack = factionBase.Faction.def.settlementNameMaker; } SettlementNameGenerator.usedNames.Clear(); List <Settlement> settlements = Find.WorldObjects.Settlements; for (int i = 0; i < settlements.Count; i++) { Settlement settlement = settlements[i]; if (settlement.Name != null) { SettlementNameGenerator.usedNames.Add(settlement.Name); } } return(NameGenerator.GenerateName(rulePack, SettlementNameGenerator.usedNames, true, null)); }
public static void Settle(Caravan caravan) { Faction faction = caravan.Faction; if (faction != Faction.OfPlayer) { Log.Error("Cannot settle with non-player faction.", false); return; } Settlement 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)); }
//private static void DrawFactionRow_WithFactionPoints_Postfix(Faction faction, float rowY, Rect fillRect, ref float __result) //{ // if (!Prefs.DevMode) // { // Rect rect = new Rect(35f, rowY + __result, 250f, 80f); // StringBuilder stringBuilder = new StringBuilder(); // string text = stringBuilder.ToString(); // float width = fillRect.width - rect.xMax; // float num = Text.CalcHeight(text, width); // float num2 = Mathf.Max(80f, num); // Rect position = new Rect(10f, rowY + 10f, 15f, 15f); // Rect rect2 = new Rect(0f, rowY + __result, fillRect.width, num2); // if (Mouse.IsOver(rect2)) // { // GUI.DrawTexture(rect2, TexUI.HighlightTex); // } // Text.Font = GameFont.Small; // Text.Anchor = TextAnchor.UpperLeft; // Widgets.DrawRectFast(position, faction.Color); // string label = "RW_FactionPower".Translate(WorldUtility.GetRimWarDataForFaction(faction) == null ? 0 : WorldUtility.GetRimWarDataForFaction(faction).TotalFactionPoints); // label += "\n" + "RW_FactionBehavior".Translate(WorldUtility.GetRimWarDataForFaction(faction).behavior.ToString()); // Widgets.Label(rect, label); // if (!faction.IsPlayer) // { // } // __result += num2; // } //} private static void Settlement_InspectString_WithPoints_Postfix(RimWorld.Planet.Settlement __instance, ref string __result) { if (!__instance.Faction.def.hidden) { RimWarData rwData = WorldUtility.GetRimWarDataForFaction(__instance.Faction); if (rwData != null) { string text = ""; if (!__result.NullOrEmpty()) { text += "\n"; } for (int i = 0; i < rwData.FactionSettlements.Count; i++) { if (rwData.FactionSettlements[i].Tile == __instance.Tile) { text += "RW_SettlementPoints".Translate(rwData.FactionSettlements[i].RimWarPoints + "\n" + rwData.behavior.ToString()); break; } } __result += text; } } }
public static void Settle(Map map) { MapParent parent = map.Parent; Settlement settlement = SettleUtility.AddNewHome(map.Tile, Faction.OfPlayer); map.info.parent = settlement; if (parent != null) { Find.WorldObjects.Remove(parent); } Messages.Message("MessageSettledInExistingMap".Translate(), settlement, MessageTypeDefOf.PositiveEvent, false); 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(); } }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(Caravan caravan, Settlement settlement) { return(CaravanArrivalActionUtility.GetFloatMenuOptions(() => CanOfferGiftsTo(caravan, settlement), () => new CaravanArrivalAction_OfferGifts(settlement), "OfferGifts".Translate(), caravan, settlement.Tile, settlement)); }
public static FloatMenuAcceptanceReport CanVisit(IEnumerable <IThingHolder> pods, Settlement settlement) { if (settlement == null || !settlement.Spawned || !settlement.Visitable) { return(false); } if (!TransportPodsArrivalActionUtility.AnyPotentialCaravanOwner(pods, Faction.OfPlayer)) { return(false); } return(true); }
public CaravanArrivalAction_OfferGifts(Settlement settlement) { this.settlement = settlement; }
public static FloatMenuAcceptanceReport CanOfferGiftsTo(Caravan caravan, Settlement settlement) { return(settlement != null && settlement.Spawned && !settlement.HasMap && settlement.Faction != null && settlement.Faction != Faction.OfPlayer && !settlement.Faction.def.permanentEnemy && settlement.Faction.HostileTo(Faction.OfPlayer) && settlement.CanTradeNow && HasNegotiator(caravan)); }
public static FloatMenuAcceptanceReport CanVisit(Caravan caravan, Settlement settlement) { return(settlement != null && settlement.Spawned && settlement.Visitable); }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(Caravan caravan, Settlement settlement) { return(CaravanArrivalActionUtility.GetFloatMenuOptions(() => CanVisit(caravan, settlement), () => new CaravanArrivalAction_VisitSettlement(settlement), "VisitSettlement".Translate(settlement.Label), caravan, settlement.Tile, settlement)); }
public Settlement_TraderTracker(Settlement settlement) { this.settlement = settlement; }
public CaravanArrivalAction_VisitSettlement(Settlement settlement) { this.settlement = settlement; }
public static bool IsValidTileForNewSettlement(int tile, StringBuilder reason = null) { Tile tile2 = Find.WorldGrid[tile]; if (!tile2.biome.canBuildBase) { if (reason != null) { reason.Append("CannotLandBiome".Translate(new object[] { tile2.biome.label })); } return(false); } if (!tile2.biome.implemented) { if (reason != null) { reason.Append("BiomeNotImplemented".Translate() + ": " + tile2.biome.label); } return(false); } if (tile2.hilliness == Hilliness.Impassable) { if (reason != null) { reason.Append("CannotLandImpassableMountains".Translate()); } return(false); } Settlement settlement = Find.WorldObjects.SettlementAt(tile); if (settlement != null) { if (reason != null) { if (settlement.Faction == null) { reason.Append("TileOccupied".Translate()); } else if (settlement.Faction == Faction.OfPlayer) { reason.Append("YourBaseAlreadyThere".Translate()); } else { reason.Append("BaseAlreadyThere".Translate(new object[] { settlement.Faction.Name })); } } return(false); } if (Find.WorldObjects.AnySettlementAtOrAdjacent(tile)) { if (reason != null) { reason.Append("FactionBaseAdjacent".Translate()); } return(false); } if (Find.WorldObjects.AnyMapParentAt(tile) || Current.Game.FindMap(tile) != null || Find.WorldObjects.AnyWorldObjectOfDefAt(WorldObjectDefOf.AbandonedFactionBase, tile)) { if (reason != null) { reason.Append("TileOccupied".Translate()); } return(false); } return(true); }
public TransportPodsArrivalAction_VisitSettlement(Settlement settlement) { this.settlement = settlement; }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(Caravan caravan, Settlement settlement) { return(CaravanArrivalActionUtility.GetFloatMenuOptions(() => CanAttack(caravan, settlement), () => new CaravanArrivalAction_AttackSettlement(settlement), "AttackSettlement".Translate(settlement.Label), caravan, settlement.Tile, settlement, settlement.Faction.AllyOrNeutralTo(Faction.OfPlayer) ? ((Action <Action>) delegate(Action action) { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmAttackFriendlyFaction".Translate(settlement.LabelCap, settlement.Faction.Name), delegate { action(); })); }) : null)); }
public CaravanArrivalAction_AttackSettlement(Settlement settlement) { this.settlement = settlement; }
public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(CompLaunchable representative, IEnumerable <IThingHolder> pods, Settlement settlement) { return(TransportPodsArrivalActionUtility.GetFloatMenuOptions(() => CanVisit(pods, settlement), () => new TransportPodsArrivalAction_VisitSettlement(settlement), "VisitSettlement".Translate(settlement.Label), representative, settlement.Tile)); }