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; } } }
private static void GetWarObjectsStandingAtOrAboutToStandAt(int tile, out int warObjectsCount, out int warObjectsWithLowerIdCount, WarObject forWarObject) { warObjectsCount = 0; warObjectsWithLowerIdCount = 0; List <WarObject> warObjects = Utility.RW_Find.WarObjects(); for (int i = 0; i < warObjects.Count; i++) { WarObject warObject = warObjects[i]; if (warObject.Tile != tile) { if (!warObject.pather.Moving || warObject.pather.nextTile != warObject.pather.Destination || warObject.pather.Destination != tile) { continue; } } else if (warObject.pather.Moving) { continue; } warObjectsCount++; if (warObject.ID < forWarObject.ID) { warObjectsWithLowerIdCount++; } } }
public static Vector3 WarObjectCollisionPosOffsetFor(WarObject warObject) { if (!warObject.Spawned) { return(Vector3.zero); } bool flag = warObject.Spawned && warObject.pather.Moving; float d = 0.15f * Verse.Find.WorldGrid.averageTileSize; if (!flag || warObject.pather.nextTile == warObject.pather.Destination) { int num = (!flag) ? warObject.Tile : warObject.pather.nextTile; int warObjectsCount = 0; int warObjectsWithLowerIdCount = 0; GetWarObjectsStandingAtOrAboutToStandAt(num, out warObjectsCount, out warObjectsWithLowerIdCount, warObject); if (warObjectsCount == 0) { return(Vector3.zero); } return(WorldRendererUtility.ProjectOnQuadTangentialToPlanet(Verse.Find.WorldGrid.GetTileCenter(num), GenGeo.RegularPolygonVertexPosition(warObjectsCount, warObjectsWithLowerIdCount) * d)); } if (DrawPosCollides(warObject)) { Rand.PushState(); Rand.Seed = warObject.ID; float f = Rand.Range(0f, 360f); Rand.PopState(); Vector2 point = new Vector2(Mathf.Cos(f), Mathf.Sin(f)) * d; return(WorldRendererUtility.ProjectOnQuadTangentialToPlanet(PatherTweenedPosRoot(warObject), point)); } return(Vector3.zero); }
public static void CallForAid(WarObject rwo, int pts, Map map, Faction faction, int callRelationsCost, RimWarData rwd, Settlement sendingSettlement) { Faction ofPlayer = Faction.OfPlayer; bool canSendMessage = false; string reason = "GoodwillChangedReason_RequestedMilitaryAid".Translate(); faction.TryAffectGoodwillWith(ofPlayer, -callRelationsCost, canSendMessage, true, reason); sendingSettlement.GetComponent <RimWarSettlementComp>().RimWarPoints -= pts; WorldUtility.CreateWarObjectOfType(rwo, pts, rwd, sendingSettlement, sendingSettlement.Tile, Find.WorldObjects.SettlementAt(map.Tile), WorldObjectDefOf.Settlement); }
public static int EstimatedTicksToArrive(int from, int to, WarObject warObject) { using (WorldPath worldPath = Verse.Find.WorldPathFinder.FindPath(from, to, null)) { if (!worldPath.Found) { return(0); } return(CaravanArrivalTimeEstimator.EstimatedTicksToArrive(from, to, worldPath, 0, warObject.TicksPerMove, Verse.Find.TickManager.TicksAbs)); } }
private static bool DrawPosCollides(WarObject warObject) { Vector3 a = PatherTweenedPosRoot(warObject); float num = Verse.Find.WorldGrid.averageTileSize * 0.2f; List <WarObject> warObjects = Utility.RW_Find.WarObjects(); for (int i = 0; i < warObjects.Count; i++) { WarObject warObject2 = warObjects[i]; if (warObject2 != warObject && Vector3.Distance(a, PatherTweenedPosRoot(warObject2)) < num) { return(true); } } return(false); }
public static Vector3 PatherTweenedPosRoot(WarObject warObject) { WorldGrid worldGrid = Verse.Find.WorldGrid; if (!warObject.Spawned) { return(worldGrid.GetTileCenter(warObject.Tile)); } if (warObject.pather.Moving) { float num = warObject.pather.IsNextTilePassable() ? (1f - warObject.pather.nextTileCostLeft / warObject.pather.nextTileCostTotal) : 0f; int tileID = (warObject.pather.nextTile != warObject.Tile || warObject.pather.previousTileForDrawingIfInDoubt == -1) ? warObject.Tile : warObject.pather.previousTileForDrawingIfInDoubt; return(worldGrid.GetTileCenter(warObject.pather.nextTile) * num + worldGrid.GetTileCenter(tileID) * (1f - num)); } return(worldGrid.GetTileCenter(warObject.Tile)); }
public bool PreExecuteWorker(IncidentParms parms, WarObject _wo) { this.wo = _wo; return(TryExecuteWorker(parms)); }
public void PreExecuteWorker(IncidentParms parms, WarObject _wo) { this.wo = _wo; TryExecuteWorker(parms); }
private static void LogWarObjectData() { int rwoCount = 0; int rwoPts = 0; StringBuilder str = new StringBuilder(); List <RimWarData> rwdList = WorldUtility.GetRimWarData(); if (rwdList != null) { if (rwdList.Count > 0) { List <WorldObject> woList = Find.WorldObjects.AllWorldObjects; if (woList != null && woList.Count > 0) { for (int i = 0; i < woList.Count; i++) { str.Clear(); if (woList[i] is WarObject) { rwoCount++; WarObject rwo = woList[i] as WarObject; str.Append(rwo.Name + " ID: " + rwo.ID); if (rwo.rimwarData == null || rwo.rimwarData.WorldSettlements == null || rwo.rimwarData.WorldSettlements.Count <= 0) { Log.Warning("Invalid Rim War Data!"); } if (rwo.ParentSettlement != null) { rwoPts += rwo.RimWarPoints; if (rwo.ParentSettlement != null) { str.Append(" Parent: " + rwo.ParentSettlement.Label + " ID " + rwo.ParentSettlement.ID); if (rwo.ParentSettlement.Destroyed) { Log.Warning("Parent Settlement is Destroyed!"); } } else { Log.Warning("Parent Settlement has Null World Object!"); } } else { Log.Warning("No Parent Settlement!"); } if (rwo.UseDestinationTile) { if (Find.WorldObjects.AnySettlementAt(rwo.DestinationTile)) { Log.Warning("Settlement detected at destination!"); } } else if (rwo.DestinationTarget != null) { str.Append(" Destination " + rwo.DestinationTarget.Label + " ID " + rwo.DestinationTarget.ID); if (!rwo.DestinationTarget.Destroyed) { if (!rwo.canReachDestination) { Log.Warning("Pather unable to reach destination!"); } int distance = Mathf.RoundToInt(Find.WorldGrid.ApproxDistanceInTiles(rwo.Tile, rwo.DestinationTarget.Tile)); if (distance > 100) { Log.Warning("Object travel distance is " + distance); } } else { Log.Warning("Destination destroyed!"); } } else { Log.Warning("No Destination or Destination is Null!"); } Log.Message("" + str); } } } else { Log.Warning("Debug: no world objects found"); } } else { Log.Warning("Debug: RWD count = 0"); } Log.Message("Total objects: " + rwoCount); Log.Message("Total points: " + rwoPts); } else { Log.Warning("Debug: Rim War Data was null."); } }