Esempio n. 1
0
 public override void PostClose()
 {
     base.PostClose();
     if (caravan.PawnsListForReading.NotNullAndAny(p => p.IsBoat()))
     {
         CaravanHelper.ToggleDocking(caravan, false);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Find Vehicle (Not pack animal) with usable free space for caravan packing
 /// </summary>
 /// <param name="pawn"></param>
 /// <param name="__result"></param>
 public static bool UsableVehicleWithMostFreeSpace(Pawn pawn, ref Pawn __result)
 {
     if (CaravanHelper.IsFormingCaravanShipHelper(pawn) || pawn.Map.mapPawns.SpawnedPawnsInFaction(pawn.Faction).HasVehicle())
     {
         __result = CaravanHelper.UsableVehicleWithTheMostFreeSpace(pawn);
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
 protected virtual Toil FindNearestVehicle()
 {
     return(new Toil
     {
         initAction = delegate()
         {
             Pawn pawn = CaravanHelper.UsableVehicleWithTheMostFreeSpace(this.pawn);
             if (pawn is null)
             {
                 this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
             }
             else
             {
                 this.job.SetTarget(TargetIndex.B, pawn);
             }
         }
     });
Esempio n. 4
0
        public void Notify_CaravanArrived(Caravan caravan)
        {
            if (caravan.PawnsListForReading.Where(p => !p.IsBoat()).Count() > TotalAvailableSeats)
            {
                Messages.Message("CaravanMustHaveEnoughSpaceOnShip".Translate(), this, MessageTypeDefOf.RejectInput, false);
                return;
            }
            caravan.pawns.TryAddRangeOrTransfer(dockedBoats);
            List <Pawn> boats = caravan.PawnsListForReading.Where(p => p.IsBoat()).ToList();

            foreach (Pawn p in caravan.pawns)
            {
                if (!p.IsBoat())
                {
                    for (int i = p.inventory.innerContainer.Count - 1; i >= 0; i--)
                    {
                        Thing t = p.inventory.innerContainer[i];
                        p.inventory.innerContainer.TryTransferToContainer(t, boats.Find(x => !MassUtility.IsOverEncumbered(x)).inventory.innerContainer, true);
                    }
                }
            }
            CaravanHelper.ToggleDocking(caravan, false);
            Find.WorldObjects.Remove(this);
        }
Esempio n. 5
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            if (Find.WorldSelector.SingleSelectedObject == this)
            {
                yield return(new Gizmo_CaravanInfo(this));
            }
            foreach (Gizmo gizmo in base.GetGizmos().Where(g => g is Command_Action && (g as Command_Action).defaultLabel != "Dev: Mental break" &&
                                                           (g as Command_Action).defaultLabel != "Dev: Make random pawn hungry" && (g as Command_Action).defaultLabel != "Dev: Kill random pawn" &&
                                                           (g as Command_Action).defaultLabel != "Dev: Harm random pawn" && (g as Command_Action).defaultLabel != "Dev: Down random pawn" &&
                                                           (g as Command_Action).defaultLabel != "Dev: Plague on random pawn" && (g as Command_Action).defaultLabel != "Dev: Teleport to destination"))
            {
                yield return(gizmo);
            }

            if (IsPlayerControlled)
            {
                if (vPather.Moving)
                {
                    yield return(new Command_Toggle
                    {
                        hotKey = KeyBindingDefOf.Misc1,
                        isActive = (() => vPather.Paused),
                        toggleAction = delegate()
                        {
                            if (!vPather.Moving)
                            {
                                return;
                            }
                            vPather.Paused = !vPather.Paused;
                        },
                        defaultDesc = "CommandToggleCaravanPauseDesc".Translate(2f.ToString("0.#"), 0.3f.ToStringPercent()),
                        icon = TexCommand.PauseCaravan,
                        defaultLabel = "CommandPauseCaravan".Translate()
                    });
                }
                if (CaravanMergeUtility.ShouldShowMergeCommand)
                {
                    yield return(CaravanMergeUtility.MergeCommand(this));
                }
                foreach (Gizmo gizmo2 in this.forage.GetGizmos())
                {
                    yield return(gizmo2);
                }

                foreach (WorldObject worldObject in Find.WorldObjects.ObjectsAt(base.Tile))
                {
                    foreach (Gizmo gizmo3 in worldObject.GetCaravanGizmos(this))
                    {
                        yield return(gizmo3);
                    }
                }
            }
            if (Prefs.DevMode)
            {
                yield return(new Command_Action
                {
                    defaultLabel = "Vehicle Dev: Teleport to destination",
                    action = delegate()
                    {
                        Tile = vPather.Destination;
                        vPather.StopDead();
                    }
                });
            }
            if (this.HasBoat() && (Find.World.CoastDirectionAt(Tile).IsValid || WorldHelper.RiverIsValid(Tile, PawnsListForReading.Where(p => p.IsBoat()).ToList())))
            {
                if (!vPather.Moving && !PawnsListForReading.NotNullAndAny(p => !p.IsBoat()))
                {
                    Command_Action dock = new Command_Action();
                    dock.icon         = VehicleTex.Anchor;
                    dock.defaultLabel = Find.WorldObjects.AnySettlementBaseAt(Tile) ? "CommandDockShip".Translate() : "CommandDockShipDisembark".Translate();
                    dock.defaultDesc  = Find.WorldObjects.AnySettlementBaseAt(Tile) ? "CommandDockShipDesc".Translate(Find.WorldObjects.SettlementBaseAt(Tile)) : "CommandDockShipObjectDesc".Translate();
                    dock.action       = delegate()
                    {
                        List <WorldObject> objects = Find.WorldObjects.ObjectsAt(Tile).ToList();
                        if (!objects.All(x => x is Caravan))
                        {
                            CaravanHelper.ToggleDocking(this, true);
                        }
                        else
                        {
                            CaravanHelper.SpawnDockedBoatObject(this);
                        }
                    };

                    yield return(dock);
                }
                else if (!vPather.Moving && PawnsListForReading.NotNullAndAny(p => !p.IsBoat()))
                {
                    Command_Action undock = new Command_Action
                    {
                        icon         = VehicleTex.UnloadAll,
                        defaultLabel = "CommandUndockShip".Translate(),
                        defaultDesc  = "CommandUndockShipDesc".Translate(Label),
                        action       = delegate()
                        {
                            CaravanHelper.ToggleDocking(this, false);
                        }
                    };

                    yield return(undock);
                }
            }
        }