public Settlement ClosestSettlementTo(int tile, int minPoints) { float closestDistance = 0f; RimWarSettlementComp closest = null; if (WarSettlementComps != null && WarSettlementComps.Count > 0) { for (int i = 0; i < WarSettlementComps.Count; i++) { if (closest != null) { if (WarSettlementComps[i].RimWarPoints >= minPoints && Find.WorldGrid.ApproxDistanceInTiles(tile, WarSettlementComps[i].parent.Tile) < closestDistance) { closestDistance = Find.WorldGrid.TraversalDistanceBetween(tile, WarSettlementComps[i].parent.Tile); closest = WarSettlementComps[i]; } } else if (WarSettlementComps[i].RimWarPoints >= minPoints) { closestDistance = Find.WorldGrid.TraversalDistanceBetween(tile, WarSettlementComps[i].parent.Tile); closest = WarSettlementComps[i]; } } if (closest != null) { return(closest.parent as Settlement); } } return(null); }
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."); } }
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 static bool CallForAid_Replacement_Patch(Map map, Faction faction) { Faction ofPlayer = Faction.OfPlayer; int goodwillChange = -25; bool canSendMessage = false; string reason = "GoodwillChangedReason_RequestedMilitaryAid".Translate(); faction.TryAffectGoodwillWith(ofPlayer, goodwillChange, canSendMessage, true, reason); IncidentParms incidentParms = new IncidentParms(); incidentParms.target = map; incidentParms.faction = faction; incidentParms.raidArrivalModeForQuickMilitaryAid = true; incidentParms.points = DiplomacyTuning.RequestedMilitaryAidPointsRange.RandomInRange; faction.lastMilitaryAidRequestTick = Find.TickManager.TicksGame; RimWarData rwd = WorldUtility.GetRimWarDataForFaction(faction); RimWarSettlementComp rwdTown = rwd.WorldSettlements.RandomElement().GetComponent <RimWarSettlementComp>(); if (rwdTown != null) { int pts = Mathf.RoundToInt(rwdTown.RimWarPoints / 2); if (rwd.CanLaunch) { WorldUtility.CreateLaunchedWarband(pts, rwd, rwdTown.parent as RimWorld.Planet.Settlement, rwdTown.parent.Tile, Find.WorldObjects.SettlementAt(map.Tile), WorldObjectDefOf.Settlement); } else { WorldUtility.CreateWarband(pts, rwd, rwdTown.parent as RimWorld.Planet.Settlement, rwdTown.parent.Tile, Find.WorldObjects.SettlementAt(map.Tile), WorldObjectDefOf.Settlement); } rwdTown.RimWarPoints = pts; return(false); } return(true); }
public static bool IncidentQueueAdd_Replacement_Prefix(IncidentQueue __instance, IncidentDef def, int fireTick, IncidentParms parms = null, int retryDurationTicks = 0) { if (def == IncidentDefOf.TraderCaravanArrival && fireTick == (Find.TickManager.TicksGame + 120000)) { RimWarSettlementComp rwdTown = WorldUtility.GetClosestSettlementOfFaction(parms.faction, parms.target.Tile, 40); if (rwdTown != null) { WorldUtility.CreateTrader(Mathf.RoundToInt(rwdTown.RimWarPoints / 2), WorldUtility.GetRimWarDataForFaction(rwdTown.parent.Faction), rwdTown.parent as RimWorld.Planet.Settlement, rwdTown.parent.Tile, Find.WorldObjects.SettlementAt(parms.target.Tile), WorldObjectDefOf.Settlement); rwdTown.RimWarPoints = Mathf.RoundToInt(rwdTown.RimWarPoints / 2); return(false); } } return(true); }
public static void AttackNow_SettlementReinforcement_Postfix(RimWorld.Planet.SettlementUtility __instance, Caravan caravan, RimWorld.Planet.Settlement settlement) { RimWarSettlementComp rwsc = settlement.GetComponent <RimWarSettlementComp>(); if (rwsc != null && rwsc.ReinforcementPoints > 0) { //if(rwsc.parent.def.defName == "City_Faction" || rwsc.parent.def.defName == "City_Citadel") //{ // Warband b = WorldUtility.CreateWarband((rwsc.ReinforcementPoints), WorldUtility.GetRimWarDataForFaction(rwsc.parent.Faction), settlement, settlement.Tile, settlement, WorldObjectDefOf.Settlement); // b.launched = true; //} //else //{ WorldUtility.CreateWarband((rwsc.ReinforcementPoints), WorldUtility.GetRimWarDataForFaction(rwsc.parent.Faction), settlement, settlement.Tile, settlement, WorldObjectDefOf.Settlement); //} } }
private static void Postfix(WorldObject __instance) { if (__instance is RimWorld.Planet.Settlement) { RimWarSettlementComp rwsc = __instance.GetComponent <RimWarSettlementComp>(); if (rwsc != null && rwsc.isCapitol) { for (int i = 0; i < Find.WorldObjects.AllWorldObjects.Count; i++) { WorldObject wo = Find.WorldObjects.AllWorldObjects[i]; if (wo is CapitolBuilding && wo.Tile == __instance.Tile) { wo.Destroy(); } } } } }
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 Debug_FixRimWarSettlements(bool generateReport = false, bool cleanupErrors = false) { int rwsCount = 0; int wosCount = 0; int rws_no_wosCount = 0; int wos_no_rwsCount = 0; int factionMismatchCount = 0; List <WorldObject> woList = Find.WorldObjects.AllWorldObjects; List <WorldObject> wosList = new List <WorldObject>(); wosList.Clear(); for (int i = 0; i < woList.Count; i++) { RimWorld.Planet.Settlement wos = woList[i] as RimWorld.Planet.Settlement; if (wos != null) { wosList.Add(wos); wosCount++; RimWarSettlementComp rws = WorldUtility.GetRimWarSettlementAtTile(wos.Tile); if (rws != null) { if (wos.Destroyed) { if (generateReport) { Log.Warning(wos.Label + " destroyed but has RWSC"); } if (cleanupErrors) { if (generateReport) { Log.Message("Cleaning RWS..."); } //WorldUtility.GetRimWarDataForFaction(wos.Faction)?.WorldSettlements?.Remove(rws); } } else if (wos.Faction != rws.parent.Faction) { factionMismatchCount++; if (generateReport) { Log.Warning(wos.Label + " of Faction " + wos.Faction + " different from RWS Faction " + rws.parent.Faction); } if (cleanupErrors) { if (generateReport) { Log.Message("Removing RWS from " + rws.parent.Faction + "..."); } //WorldUtility.GetRimWarDataForFaction(rws.parent.Faction)?.WorldSettlements?.Remove(rws); if (generateReport) { Log.Message("Adding RWS to " + wos.Faction + "..."); } //rws.Faction = wos.Faction; //WorldUtility.GetRimWarDataForFaction(wos.Faction)?.WorldSettlements?.Add(rws); } } } else { wos_no_rwsCount++; if (generateReport) { Log.Warning("" + wos.Label + " has no RWS"); } if (cleanupErrors) { if (generateReport) { Log.Message("Generating RWS for " + wos.Label + "..."); } WorldUtility.CreateRimWarSettlement(WorldUtility.GetRimWarDataForFaction(wos.Faction), wos); } } } } List <RimWarData> rwdList = WorldUtility.Get_WCPT().RimWarData; for (int i = 0; i < rwdList.Count; i++) { RimWarData rwd = rwdList[i]; if (rwd.WorldSettlements != null) { for (int j = 0; j < rwd.WorldSettlements.Count; j++) { RimWarSettlementComp rws = rwd.WorldSettlements[j].GetComponent <RimWarSettlementComp>(); rwsCount++; int wosHere = 0; List <RimWorld.Planet.Settlement> wosHereList = new List <RimWorld.Planet.Settlement>(); wosHereList.Clear(); for (int k = 0; k < wosList.Count; k++) { if (wosList[k].Tile == rws.parent.Tile) { wosHere++; wosHereList.Add(wosList[k] as RimWorld.Planet.Settlement); if (wosList[k].Faction != rws.parent.Faction) { factionMismatchCount++; if (generateReport) { Log.Warning(wosList[k].Label + " of Faction " + wosList[k].Faction + " different from RWS Faction " + rws.parent.Faction); } if (cleanupErrors) { if (generateReport) { Log.Message("Removing RWS from " + rws.parent.Faction + "..."); } //WorldUtility.GetRimWarDataForFaction(rws.parent.Faction)?.WorldSettlements?.Remove(rws); if (generateReport) { Log.Message("Adding RWS to " + wosList[k].Faction + "..."); } //rws.Faction = wosList[k].Faction; //WorldUtility.GetRimWarDataForFaction(wosList[k].Faction)?.WorldSettlements?.Add(rws); } } } } if (wosHere == 0) { rws_no_wosCount++; if (generateReport) { Log.Warning("No settlement found at " + Find.WorldGrid.LongLatOf(rws.parent.Tile)); } if (cleanupErrors) { if (generateReport) { Log.Warning("Removing RWS..."); } //rwd.FactionSettlements.Remove(rws); } } if (wosHere > 1) { if (generateReport) { Log.Warning("Stacked settlements (" + wosHere + ") found at " + Find.WorldGrid.LongLatOf(rws.parent.Tile)); } if (cleanupErrors) { while (wosHereList.Count > 1) { if (generateReport) { Log.Message("Destroying settlement..."); } RimWorld.Planet.Settlement wosHereDes = wosHereList[0]; wosHereList.Remove(wosHereDes); if (!wosHereDes.Destroyed) { wosHereDes.Destroy(); } } } } } } else { if (generateReport) { Log.Warning("Found null RWD"); } if (cleanupErrors) { if (generateReport) { Log.Message("Removing RWD..."); } rwdList.Remove(rwd); } } } if (generateReport) { bool errors = wos_no_rwsCount != 0 || rws_no_wosCount != 0 || factionMismatchCount != 0; Log.Message("Rim War Settlement Count: " + rwsCount); Log.Message("World Settlement Count: " + wosCount); if (!errors) { Log.Message("No errors found."); } if (wos_no_rwsCount > 0) { Log.Warning("Settlements without RWS component: " + wos_no_rwsCount); } if (rws_no_wosCount > 0) { Log.Warning("Rim War components without Settlement: " + rws_no_wosCount); } if (factionMismatchCount > 0) { Log.Warning("Faction mismatches: " + factionMismatchCount); } } }