public static void RemovePawnFromCaravan(Pawn pawn, Lord lord, bool removeFromDowned = true)
        {
            bool flag = false;

            for (int i = 0; i < lord.ownedPawns.Count; i++)
            {
                Pawn pawn2 = lord.ownedPawns[i];
                if (pawn2 != pawn && CaravanUtility.IsOwner(pawn2, Faction.OfPlayer))
                {
                    flag = true;
                    break;
                }
            }
            bool   flag2 = true;
            string text  = "MessagePawnLostWhileFormingCaravan".Translate(pawn).CapitalizeFirst();

            if (!flag)
            {
                CaravanFormingUtility.StopFormingCaravan(lord);
                text = text + " " + "MessagePawnLostWhileFormingCaravan_AllLost".Translate();
            }
            else
            {
                pawn.inventory.UnloadEverything = true;
                if (lord.ownedPawns.Contains(pawn))
                {
                    lord.Notify_PawnLost(pawn, PawnLostCondition.ForcedByPlayerAction, null);
                    flag2 = false;
                }
                LordJob_FormAndSendCaravan lordJob_FormAndSendCaravan = lord.LordJob as LordJob_FormAndSendCaravan;
                if (lordJob_FormAndSendCaravan != null && lordJob_FormAndSendCaravan.downedPawns.Contains(pawn))
                {
                    if (!removeFromDowned)
                    {
                        flag2 = false;
                    }
                    else
                    {
                        lordJob_FormAndSendCaravan.downedPawns.Remove(pawn);
                    }
                }
            }
            if (flag2)
            {
                Messages.Message(text, pawn, MessageTypeDefOf.NegativeEvent, true);
            }
        }
        public static void RemovePawnFromCaravan(Pawn pawn, Lord lord)
        {
            bool flag = false;

            for (int i = 0; i < lord.ownedPawns.Count; i++)
            {
                Pawn pawn2 = lord.ownedPawns[i];
                if (pawn2 != pawn && CaravanUtility.IsOwner(pawn2, Faction.OfPlayer))
                {
                    flag = true;
                    break;
                }
            }
            bool   flag2 = true;
            string text  = "MessagePawnLostWhileFormingCaravan".Translate(new object[]
            {
                pawn.LabelIndefinite()
            }).CapitalizeFirst();

            if (!flag)
            {
                CaravanFormingUtility.StopFormingCaravan(lord);
                text = text + " " + "MessagePawnLostWhileFormingCaravan_AllLost".Translate();
            }
            else
            {
                pawn.inventory.UnloadEverything = true;
                if (lord.ownedPawns.Contains(pawn))
                {
                    lord.Notify_PawnLost(pawn, PawnLostCondition.ForcedByPlayerAction);
                    flag2 = false;
                }
            }
            if (flag2)
            {
                Messages.Message(text, pawn, MessageTypeDefOf.NegativeEvent, true);
            }
        }
Esempio n. 3
0
 public static void StopFormingCaravan(Lord lord)
 {
     CaravanFormingUtility.SetToUnloadEverything(lord);
     lord.lordManager.RemoveLord(lord);
 }
Esempio n. 4
0
        public static IEnumerable <Gizmo> GetGizmos(Pawn pawn)
        {
            if (pawn.IsFormingCaravan())
            {
                Lord lord = pawn.GetLord();
                yield return(new Command_Action
                {
                    defaultLabel = "CommandCancelFormingCaravan".Translate(),
                    defaultDesc = "CommandCancelFormingCaravanDesc".Translate(),
                    icon = TexCommand.ClearPrioritizedWork,
                    activateSound = SoundDefOf.Tick_Low,
                    action = delegate()
                    {
                        CaravanFormingUtility.StopFormingCaravan(lord);
                    },
                    hotKey = KeyBindingDefOf.Designator_Cancel
                });

                yield return(new Command_Action
                {
                    defaultLabel = "CommandRemoveFromCaravan".Translate(),
                    defaultDesc = "CommandRemoveFromCaravanDesc".Translate(),
                    icon = CaravanFormingUtility.RemoveFromCaravanCommand,
                    action = delegate()
                    {
                        CaravanFormingUtility.RemovePawnFromCaravan(pawn, lord);
                    },
                    hotKey = KeyBindingDefOf.Misc6
                });
            }
            else if (pawn.Spawned)
            {
                bool anyCaravanToJoin = false;
                for (int i = 0; i < pawn.Map.lordManager.lords.Count; i++)
                {
                    Lord lord2 = pawn.Map.lordManager.lords[i];
                    if (lord2.faction == Faction.OfPlayer && lord2.LordJob is LordJob_FormAndSendCaravan)
                    {
                        anyCaravanToJoin = true;
                        break;
                    }
                }
                if (anyCaravanToJoin && Dialog_FormCaravan.AllSendablePawns(pawn.Map, false).Contains(pawn))
                {
                    yield return(new Command_Action
                    {
                        defaultLabel = "CommandAddToCaravan".Translate(),
                        defaultDesc = "CommandAddToCaravanDesc".Translate(),
                        icon = CaravanFormingUtility.AddToCaravanCommand,
                        action = delegate()
                        {
                            List <Lord> list = new List <Lord>();
                            for (int j = 0; j < pawn.Map.lordManager.lords.Count; j++)
                            {
                                Lord lord3 = pawn.Map.lordManager.lords[j];
                                if (lord3.faction == Faction.OfPlayer && lord3.LordJob is LordJob_FormAndSendCaravan)
                                {
                                    list.Add(lord3);
                                }
                            }
                            if (list.Count == 0)
                            {
                                return;
                            }
                            if (list.Count == 1)
                            {
                                CaravanFormingUtility.LateJoinFormingCaravan(pawn, list[0]);
                                SoundDefOf.Click.PlayOneShotOnCamera(null);
                            }
                            else
                            {
                                List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                                for (int k = 0; k < list.Count; k++)
                                {
                                    Lord caravanLocal = list[k];
                                    string label = "Caravan".Translate() + " " + (k + 1);
                                    list2.Add(new FloatMenuOption(label, delegate()
                                    {
                                        if (pawn.Spawned && pawn.Map.lordManager.lords.Contains(caravanLocal) && Dialog_FormCaravan.AllSendablePawns(pawn.Map, false).Contains(pawn))
                                        {
                                            CaravanFormingUtility.LateJoinFormingCaravan(pawn, caravanLocal);
                                        }
                                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                                }
                                Find.WindowStack.Add(new FloatMenu(list2));
                            }
                        },
                        hotKey = KeyBindingDefOf.Misc7
                    });
                }
            }
            yield break;
        }
Esempio n. 5
0
        public static List <Pawn> AllSendablePawns(Map map, bool allowEvenIfDownedOrInMentalState = false, bool allowEvenIfPrisonerNotSecure = false, bool allowCapturableDownedPawns = false)
        {
            List <Pawn> list            = new List <Pawn>();
            List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < allPawnsSpawned.Count; i++)
            {
                Pawn pawn = allPawnsSpawned[i];
                if (allowEvenIfDownedOrInMentalState || (!pawn.Downed && !pawn.InMentalState))
                {
                    if (pawn.Faction == Faction.OfPlayer || pawn.IsPrisonerOfColony || (allowCapturableDownedPawns && CaravanFormingUtility.CanListAsAutoCapturable(pawn)))
                    {
                        if ((allowEvenIfPrisonerNotSecure || !pawn.IsPrisoner || pawn.guest.PrisonerIsSecure) && (pawn.GetLord() == null || pawn.GetLord().LordJob is LordJob_VoluntarilyJoinable))
                        {
                            list.Add(pawn);
                        }
                    }
                }
            }
            return(list);
        }
Esempio n. 6
0
 public static void Notify_FormAndSendCaravanLordFailed(Lord lord)
 {
     CaravanFormingUtility.SetToUnloadEverything(lord);
 }
 public static bool IsFormingCaravanOrDownedPawnToBeTakenByCaravan(Pawn p)
 {
     return(CaravanFormingUtility.GetFormAndSendCaravanLord(p) != null);
 }