Esempio n. 1
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            var prisoner = t as Pawn;
            var need     = prisoner?.needs.TryGetNeed <Need_Motivation>();

            if (need == null || prisoner == null)
            {
                return(null);
            }
            if (!ShouldTakeCareOfPrisoner(pawn, prisoner))
            {
                return(null);
            }
            if (prisoner.Downed || !pawn.CanReserve(t, 1, -1, null, false) || !prisoner.Awake())
            {
                return(null);
            }
            if (pawn.IsPrisoner)
            {
                return(null);
            }
            var prisonerComp = prisoner.TryGetComp <PrisonerComp>();;

            if (!PrisonLaborUtility.LaborEnabled(prisoner) && prisonerComp != null && !prisonerComp.EscapeTracker.CanEscape)
            {
                return(null);
            }
            if ((!PrisonLaborUtility.WorkTime(prisoner) || !need.ShouldBeMotivated) && prisonerComp != null && !prisonerComp.EscapeTracker.CanEscape)
            {
                return(null);
            }

            return(new Job(DefDatabase <JobDef> .GetNamed("PrisonLabor_PrisonerSupervise"), prisoner));
        }
        protected override bool Satisfied(Pawn pawn)
        {
            if (pawn.IsPrisoner)
            {
                //show tutorials
                Tutorials.Introduction();
                Tutorials.Management();

                IntVec3 c;

                var need = pawn.needs.TryGetNeed <Need_Motivation>();
                if (need == null)
                {
                    if (!pawn.guest.PrisonerIsSecure || RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
                    {
                        return(false);
                    }
                    else if (PrisonLaborUtility.LaborEnabled(pawn))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                // Prisoner will escape if get ready to run.
                // If he can run he will start ticking impatient, once complete he will get ready.

                var prisonerComp = pawn.TryGetComp <PrisonerComp>();
                if (pawn.guest.PrisonerIsSecure && RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
                {
                    if (prisonerComp.escapeTracker.ReadyToEscape)
                    {
                        return(false);
                    }
                    else
                    {
                        prisonerComp.escapeTracker.CanEscape = true;
                    }
                }
                else
                {
                    prisonerComp.escapeTracker.CanEscape = false;
                }


                if (PrisonLaborUtility.LaborEnabled(pawn))
                {
                    return(true);
                }

                need.IsPrisonerWorking = false;
            }
            return(false);
        }
Esempio n. 3
0
        private float GetChangePoints()
        {
            if (pawn.IsPrisoner && pawn.IsPrisonerOfColony)
            {
                if (pawn.GetRoomGroup() != null)
                {
                    var value = InspirationTracker.GetInsiprationValue(pawn, true);

                    if (PrisonLaborUtility.LaborEnabled(pawn))
                    {
                        if (IsPrisonerWorking)
                        {
                            value -= BGP.Laziness_LazyRate;
                            if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
                            {
                                value -= BGP.Laziness_HealthRate;
                            }
                            if (pawn.needs.food != null)
                            {
                                //warforged
                                value -= (int)pawn.needs.food.CurCategory * BGP.Laziness_HungryRate;
                            }
                            // Some pawns have no rest need (e.g. Pawns with Circadian Half Cycler or androids from other mods)
                            if (pawn.needs.rest != null)
                            {
                                value -= (int)pawn.needs.rest.CurCategory * BGP.Laziness_TiredRate;
                            }
                        }
                        else if (pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Joy)
                        {
                            value += BGP.Laziness_JoyRate;
                        }
                    }

                    _GUIChangeArrow = value.CompareTo(0.0f);
                    return(value);
                }
                else
                {
                    _GUIChangeArrow = 0;
                    return(0.0f);
                }
            }
            else
            {
                _GUIChangeArrow = 1;
                return(+0.01f);
            }
        }
Esempio n. 4
0
        public override void MapComponentOnGUI()
        {
            try
            {
                if (!PrisonLaborPrefs.EnableMotivationIcons)
                {
                    return;
                }

                if (map.mapPawns == null)
                {
                    return;
                }

                foreach (var pawn in map.mapPawns.AllPawns)
                {
                    if (pawn == null)
                    {
                        continue;
                    }
                    if (pawn.RaceProps == null)
                    {
                        continue;
                    }

                    if (pawn.IsPrisonerOfColony && pawn.CarriedBy == null)
                    {
                        var need = pawn.needs.TryGetNeed <Need_Motivation>();
                        if (pawn.health.hediffSet.HasTemperatureInjury(TemperatureInjuryStage.Serious) && PrisonLaborUtility.WorkTime(pawn))
                        {
                            DrawIcon(freezingTexture, pawn.DrawPos);
                        }
                        else if (pawn.IsWatched())
                        {
                            DrawIcon(watchedTexture, pawn.DrawPos);
                        }
                        else if (need != null && need.IsLazy && PrisonLaborUtility.LaborEnabled(pawn) && PrisonLaborUtility.WorkTime(pawn))
                        {
                            DrawIcon(lazyTexture, pawn.DrawPos);
                        }
                    }
                }
            }
            catch (NullReferenceException e)
            {
                Log.ErrorOnce("PrisonLaborError: null reference in OnGui() : " + e.Message + " trace: " + e.StackTrace, typeof(PawnIcons).GetHashCode());
            }
        }
Esempio n. 5
0
 public static IEnumerable <Pawn> Pawns(MainTabWindow mainTabWindow)
 {
     foreach (var p in Find.VisibleMap.mapPawns.FreeColonists)
     {
         yield return(p);
     }
     if (mainTabWindow is MainTabWindow_Work || mainTabWindow is MainTabWindow_Restrict ||
         mainTabWindow.GetType().ToString().Contains("MainTabWindow_WorkTab"))
     {
         foreach (var pawn in Find.VisibleMap.mapPawns.PrisonersOfColony)
         {
             if (PrisonLaborUtility.LaborEnabled(pawn))
             {
                 WorkSettings.InitWorkSettings(pawn);
                 yield return(pawn);
             }
         }
     }
 }
Esempio n. 6
0
 public override void PostDraw()
 {
     if (Active && PrisonLaborPrefs.EnableMotivationIcons)
     {
         Pawn pawn = this.parent as Pawn;
         var  need = pawn.needs.TryGetNeed <Need_Motivation>();
         if (pawn.health.hediffSet.HasTemperatureInjury(TemperatureInjuryStage.Serious) && PrisonLaborUtility.WorkTime(pawn))
         {
             DrawIcon(TexturePool.freezingTexture);
         }
         else if (pawn.IsWatched())
         {
             DrawIcon(TexturePool.watchedTexture);
         }
         else if (need != null && need.IsLazy && PrisonLaborUtility.LaborEnabled(pawn) && PrisonLaborUtility.WorkTime(pawn))
         {
             DrawIcon(TexturePool.lazyTexture);
         }
     }
 }
Esempio n. 7
0
        private float GetChangePoints()
        {
            if (pawn.IsPrisoner && pawn.IsPrisonerOfColony)
            {
                if (pawn.GetRoomGroup() != null)
                {
                    var value = InspirationTracker.GetInsiprationValue(pawn, true);

                    if (PrisonLaborUtility.LaborEnabled(pawn))
                    {
                        if (IsPrisonerWorking)
                        {
                            value -= BGP.Laziness_LazyRate;
                            if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
                            {
                                value -= BGP.Laziness_HealthRate;
                            }
                            value -= (int)pawn.needs.food.CurCategory * BGP.Laziness_HungryRate;
                            value -= (int)pawn.needs.rest.CurCategory * BGP.Laziness_TiredRate;
                        }
                        else if (pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Joy)
                        {
                            value += BGP.Laziness_JoyRate;
                        }
                    }

                    _GUIChangeArrow = value.CompareTo(0.0f);
                    return(value);
                }
                else
                {
                    _GUIChangeArrow = 0;
                    return(0.0f);
                }
            }
            else
            {
                _GUIChangeArrow = 1;
                return(+0.01f);
            }
        }
        static IEnumerable <Widgets.DropdownMenuElement <Pawn> > Postfix(IEnumerable <Widgets.DropdownMenuElement <Pawn> > values, Dialog_BillConfig __instance)
        {
            foreach (Widgets.DropdownMenuElement <Pawn> value in values)
            {
                yield return(value);
            }
            Bill_Production bill                 = Traverse.Create(__instance).Field("bill").GetValue <Bill_Production>();
            WorkGiverDef    workGiver            = bill.billStack.billGiver.GetWorkgiver();
            List <Pawn>     allPrisonersOfColony = PawnsFinder.AllMaps_PrisonersOfColony;

            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("{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("{0} ({1} {2}, {3})", pawn.LabelShortCap, pawn.skills.GetSkill(bill.recipe.workSkill).Level, bill.recipe.workSkill.label, "NotAssigned".Translate()), delegate
                            {
                                bill.pawnRestriction = pawn;
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else if (!pawn.workSettings.WorkIsActive(workGiver.workType))
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption(string.Format("{0} ({1})", pawn.LabelShortCap, "NotAssigned".Translate()), delegate
                            {
                                bill.pawnRestriction = pawn;
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else if (bill.recipe.workSkill != null)
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption($"{pawn.LabelShortCap} ({pawn.skills.GetSkill(bill.recipe.workSkill).Level} {bill.recipe.workSkill.label})", delegate
                            {
                                bill.pawnRestriction = pawn;
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                    else
                    {
                        dropdownMenuElement = new Widgets.DropdownMenuElement <Pawn>
                        {
                            option = new FloatMenuOption($"{pawn.LabelShortCap}", delegate
                            {
                                bill.pawnRestriction = pawn;
                            }),
                            payload = pawn
                        };
                        yield return(dropdownMenuElement);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }