Exemple #1
0
        public static void GroupExclusionButton(Listing_Standard listing, Bill bill)
        {
            string label;

            switch (BillAssignationUtility.IsFor(bill))
            {
            case GroupMode.ColonistsOnly:
                label = "PrisonLabor_ColonistsOnlyShort".Translate();
                break;

            case GroupMode.PrisonersOnly:
                label = "PrisonLabor_PrisonersOnlyShort".Translate();
                break;

            case GroupMode.ColonyOnly:
                label = "PrisonLabor_ColonyOnlyShort".Translate();
                break;

            default:
                label = "no label";
                break;
            }

            if (listing.ButtonText(label))
            {
                MakeModeFloatMenu(bill);
            }

            listing.Gap(12f);
        }
        public static bool IsForCertainGroup(Pawn pawn, Bill bill)
        {
            var group = BillAssignationUtility.IsFor(bill);

            if (group == GroupMode.ColonyOnly)
            {
                return(true);
            }
            if (group == GroupMode.ColonistsOnly && !pawn.IsPrisoner && !pawn.IsSlave)
            {
                return(true);
            }
            if (group == GroupMode.PrisonersOnly && pawn.IsPrisoner)
            {
                return(true);
            }
            if (group == GroupMode.SlavesOnly && bill.SlavesOnly && pawn.IsSlave)
            {
                return(true);
            }

            if (group == GroupMode.CaptiveOnly && (pawn.IsPrisoner || (bill.SlavesOnly && pawn.IsSlave)))
            {
                return(true);
            }
            return(false);
        }
        public static string GetDropLabel(Dialog_BillConfig dialog)
        {
            Bill_Production bill      = Traverse.Create(dialog).Field("bill").GetValue <Bill_Production>();
            GroupMode       groupMode = BillAssignationUtility.IsFor(bill);

            switch (groupMode)
            {
            case GroupMode.ColonyOnly:
                return("PrisonLabor_ColonyOnly".Translate());

            case GroupMode.PrisonersOnly:
                return("PrisonLabor_PrisonersOnly".Translate());

            case GroupMode.ColonistsOnly:
                return("AnyWorker".Translate());

            case GroupMode.SlavesOnly:
                return("AnySlave".Translate());

            case GroupMode.CaptiveOnly:
                return("PrisonLabor_PrisonersAndSlaveOnly".Translate());

            default:
                return((!ModsConfig.IdeologyActive || !bill.SlavesOnly) ? ("AnyWorker".Translate()) : ("AnySlave".Translate()));
            }
        }
Exemple #4
0
        private static void MakeModeFloatMenu(Bill bill)
        {
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            list.Add(new FloatMenuOption("PrisonLabor_ColonyOnly".Translate(), delegate
            {
                BillAssignationUtility.SetFor(bill, GroupMode.ColonyOnly);
            }));
            list.Add(new FloatMenuOption("PrisonLabor_ColonistsOnly".Translate(), delegate
            {
                BillAssignationUtility.SetFor(bill, GroupMode.ColonistsOnly);
            }));
            list.Add(new FloatMenuOption("PrisonLabor_PrisonersOnly".Translate(), delegate
            {
                BillAssignationUtility.SetFor(bill, GroupMode.PrisonersOnly);
            }));
            Find.WindowStack.Add(new FloatMenu(list));
        }
        static bool Postfix(bool __result, Bill __instance, Pawn p)
        {
            if (__result == false && __instance.PawnRestriction == null)
            {
                GroupMode group = BillAssignationUtility.IsFor(__instance);

                if (group == GroupMode.ColonyOnly && __instance.SlavesOnly && p.IsSlave)
                {
                    return(true);
                }
                if (group == GroupMode.SlavesOnly && __instance.SlavesOnly && p.IsSlave)
                {
                    return(true);
                }

                if (group == GroupMode.CaptiveOnly && __instance.SlavesOnly && p.IsSlave)
                {
                    return(true);
                }
                if (__instance.recipe.workSkill != null)
                {
                    int level = p.skills.GetSkill(__instance.recipe.workSkill).Level;
                    if (level < __instance.allowedSkillRange.min)
                    {
                        JobFailReason.Is("UnderAllowedSkill".Translate(__instance.allowedSkillRange.min), __instance.Label);
                        return(false);
                    }
                    if (level > __instance.allowedSkillRange.max)
                    {
                        JobFailReason.Is("AboveAllowedSkill".Translate(__instance.allowedSkillRange.max), __instance.Label);
                        return(false);
                    }
                }
                if (group == GroupMode.ColonyOnly || (group == GroupMode.CaptiveOnly && p.IsPrisoner))
                {
                    return(true);
                }
            }
            return(__result);
        }
Exemple #6
0
 public static void Postfix(Bill bill)
 {
     BillAssignationUtility.Remove(bill);
 }
Exemple #7
0
 private static void Postfix(Bill __instance)
 {
     BillAssignationUtility.GetData(__instance).ExposeData();
 }
        static IEnumerable <Widgets.DropdownMenuElement <Pawn> > Postfix_GenerateFields(IEnumerable <Widgets.DropdownMenuElement <Pawn> > values, Dialog_BillConfig __instance)
        {
            int             check = ModsConfig.IdeologyActive ? 1 : 0;
            int             i     = 0;
            Bill_Production bill  = Traverse.Create(__instance).Field("bill").GetValue <Bill_Production>();

            Widgets.DropdownMenuElement <Pawn> anyone = new Widgets.DropdownMenuElement <Pawn>
            {
                option = new FloatMenuOption("PrisonLabor_ColonyOnly".Translate(), delegate
                {
                    Traverse.Create(bill).Field("slavesOnly").SetValue(true);
                    Traverse.Create(bill).Field("pawnRestriction").SetValue(null);
                    BillAssignationUtility.SetFor(bill, GroupMode.ColonyOnly);
                }),
                payload = null
            };
            yield return(anyone);

            foreach (Widgets.DropdownMenuElement <Pawn> value in values)
            {
                yield return(value);

                if (check == i)
                {
                    Widgets.DropdownMenuElement <Pawn> prisonerMenu = new Widgets.DropdownMenuElement <Pawn>
                    {
                        option = new FloatMenuOption("PrisonLabor_PrisonersOnly".Translate(), delegate
                        {
                            bill.SetAnyPawnRestriction();
                            BillAssignationUtility.SetFor(bill, GroupMode.PrisonersOnly);
                        }),
                        payload = null
                    };
                    yield return(prisonerMenu);

                    Widgets.DropdownMenuElement <Pawn> anyCaptive = new Widgets.DropdownMenuElement <Pawn>
                    {
                        option = new FloatMenuOption("PrisonLabor_PrisonersAndSlaveOnly".Translate(), delegate
                        {
                            bill.SetAnySlaveRestriction();
                            BillAssignationUtility.SetFor(bill, GroupMode.CaptiveOnly);
                        }),
                        payload = null
                    };
                    yield return(anyCaptive);
                }
                i++;
            }
            WorkGiverDef       workGiver            = bill.billStack.billGiver.GetWorkgiver();
            SkillDef           workSkill            = bill.recipe.workSkill;
            IEnumerable <Pawn> allPrisonersOfColony = PawnsFinder.AllMaps_PrisonersOfColony;

            allPrisonersOfColony = allPrisonersOfColony.OrderBy((Pawn pawn) => pawn.LabelShortCap);
            if (workSkill != null)
            {
                allPrisonersOfColony = allPrisonersOfColony.OrderByDescending((Pawn pawn) => pawn.skills.GetSkill(bill.recipe.workSkill).Level);
            }
            if (workGiver == null)
            {
                Log.ErrorOnce("Generating pawn restrictions for a BillGiver without a Workgiver", 96455148);
                yield break;
            }
            allPrisonersOfColony = allPrisonersOfColony.OrderByDescending((Pawn pawn) => pawn.workSettings.WorkIsActive(workGiver.workType));
            allPrisonersOfColony = allPrisonersOfColony.OrderBy((Pawn pawn) => pawn.WorkTypeIsDisabled(workGiver.workType));

            Widgets.DropdownMenuElement <Pawn> dropdownMenuElement;
            foreach (Pawn pawn in allPrisonersOfColony)
            {
                if (PrisonLaborUtility.LaborEnabled(pawn))
                {
                    if (pawn.WorkTypeIsDisabled(workGiver.workType))
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option  = new FloatMenuOption(string.Format("P: {0} ({1})", pawn.LabelShortCap, "WillNever".Translate(workGiver.verb)), null),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else if (bill.recipe.workSkill != null && !pawn.workSettings.WorkIsActive(workGiver.workType))
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption(string.Format("P: {0} ({1} {2}, {3})", pawn.LabelShortCap, pawn.skills.GetSkill(bill.recipe.workSkill).Level, bill.recipe.workSkill.label, "NotAssigned".Translate()), delegate
                            {
                                bill.SetPawnRestriction(pawn);
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else if (!pawn.workSettings.WorkIsActive(workGiver.workType))
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption(string.Format("P: {0} ({1})", pawn.LabelShortCap, "NotAssigned".Translate()), delegate
                            {
                                bill.SetPawnRestriction(pawn);
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else if (bill.recipe.workSkill != null)
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption($"P: {pawn.LabelShortCap} ({pawn.skills.GetSkill(bill.recipe.workSkill).Level} {bill.recipe.workSkill.label})", delegate
                            {
                                bill.SetPawnRestriction(pawn);
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption($"P: {pawn.LabelShortCap}", delegate
                            {
                                bill.SetPawnRestriction(pawn);
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                }
            }
        }
 static void SlavePostFix(Bill __instance)
 {
     BillAssignationUtility.SetFor(__instance, GroupMode.SlavesOnly);
 }
 static void ColonistPostFix(Bill __instance)
 {
     BillAssignationUtility.SetFor(__instance, GroupMode.ColonistsOnly);
 }