/// <summary> /// Disable the ability to attack a settlement when docked there. Breaks immersion and can cause an entry cell error. (Boats Only) /// </summary> /// <param name="caravan"></param> /// <param name="__result"></param> /// <param name="__instance"></param> public static void NoAttackSettlementWhenDocked(Caravan caravan, ref IEnumerable <Gizmo> __result, Settlement __instance) { if (caravan.HasBoat() && !caravan.pather.Moving) { List <Gizmo> gizmos = __result.ToList(); if (caravan.PawnsListForReading.NotNullAndAny(p => !p.IsBoat())) { int index = gizmos.FindIndex(x => (x as Command_Action).icon == Settlement.AttackCommand); if (index >= 0 && index < gizmos.Count) { gizmos[index].Disable("CommandAttackDockDisable".Translate(__instance.LabelShort)); } } else { int index2 = gizmos.FindIndex(x => (x as Command_Action).icon == ContentFinder <Texture2D> .Get("UI/Commands/Trade", false)); if (index2 >= 0 && index2 < gizmos.Count) { gizmos[index2].Disable("CommandTradeDockDisable".Translate(__instance.LabelShort)); } int index3 = gizmos.FindIndex(x => (x as Command_Action).icon == ContentFinder <Texture2D> .Get("UI/Commands/OfferGifts", false)); if (index3 >= 0 && index3 < gizmos.Count) { gizmos[index3].Disable("CommandTradeDockDisable".Translate(__instance.LabelShort)); } } __result = gizmos; } }
/// <summary> /// Spawn DockedBoat object to store boats on World map /// </summary> /// <param name="caravan"></param> public static void SpawnDockedBoatObject(Caravan caravan) { if (!caravan.HasBoat()) { Log.Error("Attempted to dock boats with no boats in caravan. This could have serious errors in the future. - Smash Phil"); } ToggleDocking(caravan, true); Find.WindowStack.Add(new Dialog_DockBoat(caravan)); }
/// <summary> /// Toggle state of caravan between land and sea /// </summary> /// <param name="caravan"></param> /// <param name="dock"></param> public static void ToggleDocking(Caravan caravan, bool dock = false) { if (caravan.HasBoat()) { if (!dock) { BoardAllCaravanPawns(caravan); } else { List <VehiclePawn> ships = caravan.PawnsListForReading.Where(p => p.IsBoat()).Cast <VehiclePawn>().ToList(); ships.ForEach(b => b.DisembarkAll()); } } }
public static void EnterAndSpawn(Caravan caravan, Map map, CaravanEnterMode enterMode, CaravanDropInventoryMode dropInventoryMode = CaravanDropInventoryMode.DoNotDrop, bool draftColonists = false, Predicate <IntVec3> extraValidator = null) { bool coastalSpawn = caravan.HasBoat(); if (enterMode == CaravanEnterMode.None) { Log.Error(string.Concat(new object[] { "Caravan ", caravan, " tried to enter map ", map, " with no enter mode. Defaulting to edge." })); enterMode = CaravanEnterMode.Edge; } List <Pawn> pawns = new List <Pawn>(caravan.PawnsListForReading).ToList(); IntVec3 enterCell = pawns.NotNullAndAny(v => v.IsBoat()) ? GetWaterCell(caravan, map, CaravanEnterMode.Edge) : GetEnterCellVehicle(caravan, map, enterMode, extraValidator); Rot4 edge = enterMode == CaravanEnterMode.Edge ? CellRect.WholeMap(map).GetClosestEdge(enterCell) : Rot4.North; Predicate <IntVec3> validator = (IntVec3 c) => coastalSpawn?GenGridVehicles.Standable(c, map) : GenGrid.Standable(c, map); Func <Pawn, IntVec3> spawnCellGetter = (Pawn p) => CellFinderExtended.RandomSpawnCellForPawnNear(enterCell, map, p, validator); SpawnVehicles(caravan, pawns, map, spawnCellGetter, edge, draftColonists); }