Example #1
0
        protected override void DrawPawnRow(Rect rect, Pawn p)
        {
            Rect rect2 = new Rect(rect.x + 175f, rect.y, rect.width - 175f, rect.height);
            Rect rect3 = new Rect(rect2.x, rect2.y + 2f, rect2.width * 0.333f, rect2.height - 4f);

            if (Widgets.TextButton(rect3, p.outfits.CurrentOutfit.label, true, false))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (Outfit current in Find.Map.outfitDatabase.AllOutfits)
                {
                    Outfit localOut = current;
                    list.Add(new FloatMenuOption(localOut.label, delegate
                    {
                        p.outfits.CurrentOutfit = localOut;
                    }, MenuOptionPriority.Medium, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list, false));
            }
            rect3 = new Rect(rect3.xMax + 4f, rect.y + 2f, 100f, rect.height - 4f);
            if (Widgets.TextButton(rect3, "OutfitEdit".Translate(), true, false))
            {
                Find.WindowStack.Add(new Dialog_ManageOutfitsAutoEquip(p.outfits.CurrentOutfit));
            }
            rect3 = new Rect(rect3.xMax + 4f, rect.y + 2f, 100f, rect.height - 4f);
            if (Widgets.TextButton(rect3, "AutoEquipStatus".Translate(), true, false))
            {
                Saveable_Pawn cx = MapComponent_AutoEquip.Get.GetCache(p);
                if (cx.stats == null)
                {
                    cx.stats = new List <Saveable_StatDef>();
                }
                Find.WindowStack.Add(new Dialog_ManagePawnOutfit(cx.stats));
            }
            rect3 = new Rect(rect3.xMax + 4f, rect.y + 2f, 100f, rect.height - 4f);
            if (p.outfits.forcedHandler.SomethingIsForced)
            {
                if (Widgets.TextButton(rect3, "ClearForcedApparel".Translate(), true, false))
                {
                    p.outfits.forcedHandler.Reset();
                }
                TooltipHandler.TipRegion(rect3, new TipSignal(delegate
                {
                    string text = "ForcedApparel".Translate() + ":\n";
                    foreach (Apparel current2 in p.outfits.forcedHandler.ForcedApparel)
                    {
                        text = text + "\n   " + current2.LabelCap;
                    }
                    return(text);
                }, p.GetHashCode() * 612));
            }
        }
        public Saveable_Pawn GetCache(Pawn pawn)
        {
            foreach (Saveable_Pawn c in this.pawnCache)
            {
                if (c.pawn == pawn)
                {
                    return(c);
                }
            }
            Saveable_Pawn n = new Saveable_Pawn();

            n.pawn = pawn;
            this.pawnCache.Add(n);
            return(n);
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            if (Find.TickManager.TicksGame < this.nextOptimization)
            {
                return;
            }

#if LOG
            MapComponent_AutoEquip.logMessage = new StringBuilder();
            MapComponent_AutoEquip.logMessage.AppendLine("Start Scaning Best Apparel");
            MapComponent_AutoEquip.logMessage.AppendLine();
#endif
            List <Saveable_Pawn>      newSaveableList = new List <Saveable_Pawn>();
            List <PawnCalcForApparel> newCalcList     = new List <PawnCalcForApparel>();

            List <Apparel> allApparels = new List <Apparel>(Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType <Apparel>());
            foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
            {
                this.InjectTab(pawn.def);
                Saveable_Pawn      newPawnSaveable = this.GetCache(pawn);
                PawnCalcForApparel newPawnCalc     = new PawnCalcForApparel(newPawnSaveable);

                newSaveableList.Add(newPawnSaveable);
                newCalcList.Add(newPawnCalc);

                newPawnCalc.InitializeFixedApparelsAndGetAvaliableApparels(allApparels);
            }

            this.pawnCache = newSaveableList;
            PawnCalcForApparel.DoOptimizeApparel(newCalcList, allApparels);

#if LOG
            this.nextOptimization = Find.TickManager.TicksGame + 500;
#else
            this.nextOptimization = Find.TickManager.TicksGame + 5000;
#endif
        }
Example #4
0
        protected override Job TryGiveTerminalJob(Pawn pawn)
        {
            if (pawn.outfits == null)
            {
                Log.ErrorOnce(pawn + " tried to run JobGiver_OptimizeApparel without an OutfitTracker", 5643897);
                return(null);
            }
            if (pawn.Faction != Faction.OfColony)
            {
                Log.ErrorOnce("Non-colonist " + pawn + " tried to optimize apparel.", 764323);
                return(null);
            }

            if (Find.TickManager.TicksGame < pawn.mindState.nextApparelOptimizeTick)
            {
                return(null);
            }

            Saveable_Pawn configurarion = MapComponent_AutoEquip.Get.GetCache(pawn);
            Outfit        currentOutfit = pawn.outfits.CurrentOutfit;

            #region [  Wear Apparel  ]

            if (configurarion.toWearApparel.Count > 0)
            {
                List <Thing> list = Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel);
                if (list.Count > 0)
                {
                    foreach (Apparel ap in list)
                    {
                        if (configurarion.toWearApparel.Contains(ap))
                        {
                            if (pawn.CanReserveAndReach(ap, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1))
                            {
#if LOG && JOBS
                                Log.Message("Pawn " + pawn + " wear apparel: " + ap);
#endif
                                configurarion.toWearApparel.Remove(ap);
                                return(new Job(JobDefOf.Wear, ap));
                            }
                        }
                    }
                }
            }

            #endregion

            #region [  Drops unequiped  ]

            for (int i = configurarion.toDropApparel.Count - 1; i >= 0; i--)
            {
                Apparel a = configurarion.toDropApparel[i];
                configurarion.toDropApparel.Remove(a);

#if LOG && JOBS
                Log.Message("Pawn " + pawn + " drop apparel: " + a);
#endif

                if (pawn.apparel.WornApparel.Contains(a))
                {
                    Apparel t;
                    if (pawn.apparel.TryDrop(a, out t))
                    {
                        t.SetForbidden(false, true);

                        Job job = HaulAIUtility.HaulToStorageJob(pawn, t);

                        if (job != null)
                        {
                            return(job);
                        }
                        else
                        {
                            pawn.mindState.nextApparelOptimizeTick = Find.TickManager.TicksGame + 350;
                            return(null);
                        }
                    }
                }
            }

            #endregion

            pawn.mindState.nextApparelOptimizeTick = Find.TickManager.TicksGame + 350;
            return(null);
        }
Example #5
0
        public PawnCalcForApparel(Saveable_Pawn saveablePawn, Month month, float temperatureAjust)
        {
            this.saveablePawn = saveablePawn;
            this.pawn         = saveablePawn.pawn;
            this.outfit       = pawn.outfits.CurrentOutfit;
            this.stats        = saveablePawn.NormalizeCalculedStatDef().ToArray();

            float targetTemperature = GenTemperature.AverageTemperatureAtWorldCoordsForMonth(Find.Map.WorldCoords, month) + temperatureAjust;

            #region [  needWarmCurve  ]

            float stat = this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null);

            stat = targetTemperature - stat;

            Log.Message("Target: " + targetTemperature + "     Stat: " + this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null) + "    Value: " + stat);


            if (stat > 10f)
            {
                this.needWarmCurve = new SimpleCurve {
                    new CurvePoint(0f, 1f)
                }
            }
            ;
            else
            if (stat > 3f)
            {
                this.needWarmCurve = new SimpleCurve
                {
                    new CurvePoint(+10f, -1.00f),
                    new CurvePoint(+03f, +0.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(-03f, +1.10f)
                }
            }
            ;
            else
            if (stat > 0)
            {
                this.needWarmCurve = new SimpleCurve
                {
                    new CurvePoint(+03f, -1.00f),
                    new CurvePoint(+01f, -1.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(-03f, +1.20f),
                    new CurvePoint(-10f, +1.50f)
                }
            }
            ;
            else
            if (stat > -3)
            {
                this.needWarmCurve = new SimpleCurve
                {
                    new CurvePoint(+03f, -1.00f),
                    new CurvePoint(+01f, -1.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(-03f, +1.20f),
                    new CurvePoint(-100f, +2.00f)
                }
            }
            ;
            else
            {
                this.needWarmCurve = new SimpleCurve
                {
                    new CurvePoint(+01f, -1.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(-03f, +1.50f),
                    new CurvePoint(-100f, +20.00f)
                }
            };

            #endregion

            #region [  needCoolCurve  ]

            stat = this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null);

            stat = targetTemperature - stat;

            if (stat < -10)
            {
                this.needCoolCurve = new SimpleCurve {
                    new CurvePoint(0f, 1f)
                }
            }
            ;
            else
            if (stat < -3)
            {
                this.needCoolCurve = new SimpleCurve
                {
                    new CurvePoint(-10f, -1.00f),
                    new CurvePoint(-03f, +0.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(+03f, +1.10f)
                }
            }
            ;
            else
            if (stat < 0)
            {
                this.needCoolCurve = new SimpleCurve
                {
                    new CurvePoint(-03f, -1.00f),
                    new CurvePoint(-01f, -1.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(+03f, +1.20f),
                    new CurvePoint(+10f, +1.50f)
                }
            }
            ;
            else
            {
                this.needCoolCurve = new SimpleCurve
                {
                    new CurvePoint(-01f, -1.00f),
                    new CurvePoint(+00f, +1.00f),
                    new CurvePoint(+03f, +1.50f),
                    new CurvePoint(+100f, +20.00f)
                }
            };

            #endregion
        }
Example #6
0
 public PawnCalcForApparel(Saveable_Pawn saveablePawn)
     : this(saveablePawn, GenDate.CurrentMonth, 0f)
 {
 }
Example #7
0
        private void DrawThingRow(ref float y, float width, Thing thing, bool equiped, Color thingColor, Saveable_Pawn pawnSave, PawnCalcForApparel pawnCalc)
        {
            Rect rect = new Rect(0f, y, width, 28f);
            if (Mouse.IsOver(rect))
            {
                GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }
            if (Widgets.InvisibleButton(rect) && Event.current.button == 1)
            {
                List<FloatMenuOption> list = new List<FloatMenuOption>();
                list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }, MenuOptionPriority.Medium, null, null));
                if (this.CanEdit && equiped)
                {
                    Action action = null;
                    ThingWithComps eq = thing as ThingWithComps;
                    Apparel ap = thing as Apparel;
                    if (ap != null)
                    {
                        Apparel unused;
                        action = delegate
                        {
                            this.SelPawnForGear.apparel.TryDrop(ap, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (eq != null && this.SelPawnForGear.equipment.AllEquipment.Contains(eq))
                    {
                        ThingWithComps unused;
                        action = delegate
                        {
                            this.SelPawnForGear.equipment.TryDropEquipment(eq, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (!thing.def.destroyOnDrop)
                    {
                        Thing unused;
                        action = delegate
                        {
                            this.SelPawnForGear.inventory.container.TryDrop(thing, this.SelPawnForGear.Position, ThingPlaceMode.Near, out unused);
                        };
                    }
                    list.Add(new FloatMenuOption("DropThing".Translate(), action, MenuOptionPriority.Medium, null, null));
                }

                if ((pawnSave != null) &&
                    (thing is Apparel))
                {
                    if (!equiped)
                        list.Add(new FloatMenuOption("Locate", delegate
                        {
                            Pawn apparelEquipedThing = null;

                            foreach (Pawn p in Find.ListerPawns.FreeColonists)
                            {
                                foreach (Apparel a in p.apparel.WornApparel)
                                    if (a == thing)
                                    {
                                        apparelEquipedThing = p;
                                        break;
                                    }
                                if (apparelEquipedThing != null)
                                    break;
                            }

                            if (apparelEquipedThing != null)
                            {
                                Find.CameraMap.JumpTo(apparelEquipedThing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (apparelEquipedThing.SpawnedInWorld)
                                    Find.Selector.Select(apparelEquipedThing, true, true);
                            }
                            else
                            {
                                Find.CameraMap.JumpTo(thing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (thing.SpawnedInWorld)
                                    Find.Selector.Select(thing, true, true);
                            }
                        }, MenuOptionPriority.Medium, null, null));
                    list.Add(new FloatMenuOption("AutoEquip Details", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelDetail(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));

                    list.Add(new FloatMenuOption("AutoEquip Comparer", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelComparer(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));
                }

                FloatMenu window = new FloatMenu(list, thing.LabelCap, false, false);
                Find.WindowStack.Add(window);
            }
            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color = thingColor;
            Rect rect2 = new Rect(36f, y, width - 36f, 28f);
            string text = thing.LabelCap;
            if (thing is Apparel)
            {
                if ((pawnSave != null) &&
                    (pawnSave.targetApparel != null))
                    text = pawnCalc.CalculateApparelScoreRaw((Apparel)thing).ToString("N5") + "   " + text;

                if (this.SelPawnForGear.outfits != null && this.SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing))
                    text = text + ", " + "ApparelForcedLower".Translate();
            }
            Widgets.Label(rect2, text);
            y += 28f;
        }
Example #8
0
        private void DrawThingRow(ref float y, float width, Thing thing, bool equiped, Color thingColor, Saveable_Pawn pawnSave, PawnCalcForApparel pawnCalc)
        {
            Rect rect = new Rect(0f, y, width, 28f);

            if (Mouse.IsOver(rect))
            {
                GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }
            if (Widgets.InvisibleButton(rect) && Event.current.button == 1)
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }, MenuOptionPriority.Medium, null, null));
                if (this.CanEdit && equiped)
                {
                    Action         action = null;
                    ThingWithComps eq     = thing as ThingWithComps;
                    Apparel        ap     = thing as Apparel;
                    if (ap != null)
                    {
                        Apparel unused;
                        action = delegate
                        {
                            this.SelPawnForGear.apparel.TryDrop(ap, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (eq != null && this.SelPawnForGear.equipment.AllEquipment.Contains(eq))
                    {
                        ThingWithComps unused;
                        action = delegate
                        {
                            this.SelPawnForGear.equipment.TryDropEquipment(eq, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (!thing.def.destroyOnDrop)
                    {
                        Thing unused;
                        action = delegate
                        {
                            this.SelPawnForGear.inventory.container.TryDrop(thing, this.SelPawnForGear.Position, ThingPlaceMode.Near, out unused);
                        };
                    }
                    list.Add(new FloatMenuOption("DropThing".Translate(), action, MenuOptionPriority.Medium, null, null));
                }

                if ((pawnSave != null) &&
                    (thing is Apparel))
                {
                    if (!equiped)
                    {
                        list.Add(new FloatMenuOption("Locate", delegate
                        {
                            Pawn apparelEquipedThing = null;

                            foreach (Pawn p in Find.ListerPawns.FreeColonists)
                            {
                                foreach (Apparel a in p.apparel.WornApparel)
                                {
                                    if (a == thing)
                                    {
                                        apparelEquipedThing = p;
                                        break;
                                    }
                                }
                                if (apparelEquipedThing != null)
                                {
                                    break;
                                }
                            }

                            if (apparelEquipedThing != null)
                            {
                                Find.CameraMap.JumpTo(apparelEquipedThing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (apparelEquipedThing.SpawnedInWorld)
                                {
                                    Find.Selector.Select(apparelEquipedThing, true, true);
                                }
                            }
                            else
                            {
                                Find.CameraMap.JumpTo(thing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (thing.SpawnedInWorld)
                                {
                                    Find.Selector.Select(thing, true, true);
                                }
                            }
                        }, MenuOptionPriority.Medium, null, null));
                    }
                    list.Add(new FloatMenuOption("AutoEquip Details", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelDetail(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));

                    list.Add(new FloatMenuOption("AutoEquip Comparer", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelComparer(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));
                }

                FloatMenu window = new FloatMenu(list, thing.LabelCap, false, false);
                Find.WindowStack.Add(window);
            }
            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = thingColor;
            Rect   rect2 = new Rect(36f, y, width - 36f, 28f);
            string text  = thing.LabelCap;

            if (thing is Apparel)
            {
                if ((pawnSave != null) &&
                    (pawnSave.targetApparel != null))
                {
                    text = pawnCalc.CalculateApparelScoreRaw((Apparel)thing).ToString("N5") + "   " + text;
                }

                if (this.SelPawnForGear.outfits != null && this.SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing))
                {
                    text = text + ", " + "ApparelForcedLower".Translate();
                }
            }
            Widgets.Label(rect2, text);
            y += 28f;
        }
Example #9
0
        public PawnCalcForApparel(Saveable_Pawn saveablePawn, Month month, float temperatureAjust)
        {
            this.saveablePawn = saveablePawn;
            this.pawn = saveablePawn.pawn;
            this.outfit = pawn.outfits.CurrentOutfit;
            this.stats = saveablePawn.NormalizeCalculedStatDef().ToArray();

            float targetTemperature = GenTemperature.AverageTemperatureAtWorldCoordsForMonth(Find.Map.WorldCoords, month) + temperatureAjust;

            #region [  needWarmCurve  ]

            float stat = this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null);

            stat = targetTemperature - stat;

            Log.Message("Target: " + targetTemperature + "     Stat: " + this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null) + "    Value: " + stat);

            if (stat > 10f)
                this.needWarmCurve = new SimpleCurve { new CurvePoint(0f, 1f) };
            else
                if (stat > 3f)
                    this.needWarmCurve = new SimpleCurve
                        {
                            new CurvePoint(+10f, -1.00f),
                            new CurvePoint(+03f, +0.00f),
                            new CurvePoint(+00f, +1.00f),
                            new CurvePoint(-03f, +1.10f)
                        };
                else
                    if (stat > 0)
                        this.needWarmCurve = new SimpleCurve
                            {
                                new CurvePoint(+03f, -1.00f),
                                new CurvePoint(+01f, -1.00f),
                                new CurvePoint(+00f, +1.00f),
                                new CurvePoint(-03f, +1.20f),
                                new CurvePoint(-10f, +1.50f)
                            };
                    else
                        if (stat > -3)
                            this.needWarmCurve = new SimpleCurve
                            {
                                new CurvePoint(+03f, -1.00f),
                                new CurvePoint(+01f, -1.00f),
                                new CurvePoint(+00f, +1.00f),
                                new CurvePoint(-03f, +1.20f),
                                new CurvePoint(-100f, +2.00f)
                            };
                        else
                            this.needWarmCurve = new SimpleCurve
                                {
                                    new CurvePoint(+01f, -1.00f),
                                    new CurvePoint(+00f, +1.00f),
                                    new CurvePoint(-03f, +1.50f),
                                    new CurvePoint(-100f, +20.00f)
                                };

            #endregion

            #region [  needCoolCurve  ]

            stat = this.pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null);

            stat = targetTemperature - stat;

            if (stat < -10)
                this.needCoolCurve = new SimpleCurve { new CurvePoint(0f, 1f) };
            else
                if (stat < -3)
                    this.needCoolCurve = new SimpleCurve
                        {
                            new CurvePoint(-10f, -1.00f),
                            new CurvePoint(-03f, +0.00f),
                            new CurvePoint(+00f, +1.00f),
                            new CurvePoint(+03f, +1.10f)
                        };
                else
                    if (stat < 0)
                        this.needCoolCurve = new SimpleCurve
                            {
                                new CurvePoint(-03f, -1.00f),
                                new CurvePoint(-01f, -1.00f),
                                new CurvePoint(+00f, +1.00f),
                                new CurvePoint(+03f, +1.20f),
                                new CurvePoint(+10f, +1.50f)
                            };
                    else
                        this.needCoolCurve = new SimpleCurve
                            {
                                new CurvePoint(-01f, -1.00f),
                                new CurvePoint(+00f, +1.00f),
                                new CurvePoint(+03f, +1.50f),
                                new CurvePoint(+100f, +20.00f)
                            };

            #endregion
        }
Example #10
0
 public PawnCalcForApparel(Saveable_Pawn saveablePawn)
     : this(saveablePawn, GenDate.CurrentMonth, 0f)
 {
 }
 public Saveable_Pawn GetCache(Pawn pawn)
 {
     foreach (Saveable_Pawn c in this.pawnCache)
         if (c.pawn == pawn)
             return c;
     Saveable_Pawn n = new Saveable_Pawn();
     n.pawn = pawn;
     this.pawnCache.Add(n);
     return n;
 }