public static void AddDresser(Building_Dresser dresser)
 {
     if (!DressersToUse.Contains(dresser))
     {
         DressersToUse.AddLast(dresser);
     }
 }
Exemple #2
0
 public static bool RemoveDesser(Building_Dresser dresser)
 {
     if (DressersToUse.Remove(dresser))
     {
         return(true);
     }
     return(false);
 }
 public void AddDresser(Building_Dresser dresser)
 {
     if (this.AttachedDressers.Contains(dresser))
     {
         return;
     }
     this.AttachedDressers.AddLast(dresser);
 }
        private void OrderAttachedDressers()
        {
            bool isSorted = true;
            LinkedListNode <Building_Dresser> n = this.AttachedDressers.First;

            while (n != null)
            {
                var next = n.Next;
                if (!n.Value.Spawned)
                {
                    this.AttachedDressers.Remove(n);
                }
                else if (
                    n.Next != null &&
                    n.Value.settings.Priority < n.Next.Value.settings.Priority)
                {
                    isSorted = false;
                }
                n = next;
            }

            if (!isSorted)
            {
                LinkedList <Building_Dresser> ordered = new LinkedList <Building_Dresser>();
                for (n = this.AttachedDressers.First; n != null; n = n.Next)
                {
                    Building_Dresser d        = n.Value;
                    bool             inserted = false;
                    for (LinkedListNode <Building_Dresser> o = ordered.First; o != null; o = o.Next)
                    {
                        if (d.settings.Priority > o.Value.settings.Priority)
                        {
                            ordered.AddBefore(o, d);
                            inserted = true;
                            break;
                        }
                    }
                    if (!inserted)
                    {
                        ordered.AddLast(d);
                    }
                }
                this.AttachedDressers.Clear();
                this.AttachedDressers = ordered;
#if DEBUG
                Log.Warning("CD New Order:");
                foreach (Building_Dresser d in this.AttachedDressers)
                {
                    Log.Warning(" " + d.Label + " " + d.settings.Priority);
                }
#endif
            }
        }
        public static void AddDresser(Building_Dresser dresser)
        {
            if (dresser == null || dresser.Map == null)
            {
                Log.Error("Cannot add ChangeDresser that is either null or has a null map.");
                return;
            }

            if (!DressersToUse.Contains(dresser))
            {
                DressersToUse.AddLast(dresser);
            }
        }
        private void StartRepairing()
        {
#if AUTO_MENDER
            Log.Warning("Begin RepairChangeDresser.StartRepairing");
            Log.Message("    Currently Being Repaired:");
            foreach (Apparel a in AllApparelBeingRepaired)
            {
                Log.Message("        " + a.Label);
            }
#endif
            this.OrderAttachedDressers();
            foreach (PawnOutfitTracker po in WorldComp.PawnOutfits.Values)
            {
                foreach (Apparel a in po.CustomApparel)
                {
                    if (a.HitPoints < a.MaxHitPoints &&
                        !AllApparelBeingRepaired.Contains(a))
                    {
                        this.BeingRepaird = a;
                        AllApparelBeingRepaired.AddLast(a);
#if AUTO_MENDER
                        Log.Warning("End RepairChangeDresser.StartRepairing -- " + a.Label);
#endif
                        return;
                    }
                }
            }
            for (LinkedListNode <Building_Dresser> n = this.AttachedDressers.First; n != null; n = n.Next)
            {
                Building_Dresser d = n.Value;
                foreach (LinkedList <Apparel> l in d.StoredApparel.StoredApparelLookup.Values)
                {
                    foreach (Apparel a in l)
                    {
                        if (a.HitPoints < a.MaxHitPoints &&
                            !AllApparelBeingRepaired.Contains(a))
                        {
                            this.BeingRepaird = a;
                            AllApparelBeingRepaired.AddLast(a);
#if AUTO_MENDER
                            Log.Warning("End RepairChangeDresser.StartRepairing -- " + a.Label);
#endif
                            return;
                        }
                    }
                }
            }
#if AUTO_MENDER
            Log.Warning("End RepairChangeDresser.StartRepairing -- No new repairs to start");
#endif
        }
        static void Postfix(Pawn pawn, ref Job __result)
        {
            IEnumerable <Building_Dresser> dressers = pawn.Map.listerBuildings.AllBuildingsColonistOfClass <Building_Dresser>();

            if (!DoesDressersHaveApparel(dressers))
            {
                return;
            }

            Thing thing = null;

            if (__result != null)
            {
                thing = __result.targetA.Thing;
            }

            Building_Dresser containingDresser = null;
            Outfit           currentOutfit     = pawn.outfits.CurrentOutfit;
            float            baseApparelScore  = 0f;

            foreach (Building_Dresser dresser in dressers)
            {
                foreach (Apparel apparel in dresser.StoredApparel)
                {
                    if (currentOutfit.filter.Allows(apparel))
                    {
                        if (!apparel.IsForbidden(pawn))
                        {
                            float newApparelScore = JobGiver_OptimizeApparel.ApparelScoreGain(pawn, apparel);
                            if (newApparelScore >= 0.05f && newApparelScore >= baseApparelScore)
                            {
                                if (ApparelUtility.HasPartsToWear(pawn, apparel.def))
                                {
                                    if (ReservationUtility.CanReserveAndReach(pawn, dresser, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1))
                                    {
                                        containingDresser = dresser;
                                        thing             = apparel;
                                        baseApparelScore  = newApparelScore;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (thing != null && containingDresser != null)
            {
                __result = new Job(containingDresser.wearApparelFromStorageJobDef, containingDresser, thing);
            }
        }
Exemple #8
0
        public static void RemoveDressers(Map map)
        {
            LinkedListNode <Building_Dresser> n = DressersToUse.First;

            while (n != null)
            {
                var next           = n.Next;
                Building_Dresser d = n.Value;
                if (d.Map == null)
                {
                    DressersToUse.Remove(n);
                }
                n = next;
            }
        }
Exemple #9
0
        public void UpdateCustomApparel(Building_Dresser dresser)
        {
#if DRESSER_OUTFIT
            Log.Warning("Begin PawnOutfitTracker.UpdateCustomApparel(Dresser: " + ((dresser == null) ? "<null>" : dresser.Label) + ")");
#endif
            List <Apparel> stored = new List <Apparel>(this.customApparel);
            this.customApparel.Clear();

            foreach (CustomOutfit o in this.CustomOutfits)
            {
                foreach (Apparel a in o.Apparel)
                {
                    if (!this.customApparel.Contains(a))
                    {
#if DRESSER_OUTFIT
                        Log.Message("    Add CustomApparel: " + a.Label);
#endif
                        this.customApparel.Add(a);
                    }
                    stored.Remove(a);
                }
            }

            foreach (Apparel a in stored)
            {
#if DRESSER_OUTFIT
                Log.Message("    No Longer Used: " + a.Label);
#endif
                if (!WorldComp.AddApparel(a))
                {
                    if (dresser == null)
                    {
                        Log.Error("Unable to drop " + a.Label + " on ground.");
                    }
                    else
                    {
                        BuildingUtil.DropThing(a, dresser, dresser.Map, false);
                    }
                }
            }
#if DRESSER_OUTFIT
            Log.Warning("End PawnOutfitTracker.UpdateCustomApparel");
#endif
        }
Exemple #10
0
        public static void OptimizeApparel(Pawn pawn)
        {
            if (!WorldComp.HasDressers(pawn.Map))
            {
                // When pawns are not on the home map they will not get dressed using the game's normal method

                // This logic works but pawns will run back to the dresser to change cloths
                foreach (ThingDef def in pawn.outfits.CurrentOutfit.filter.AllowedThingDefs)
                {
#if TRACE && SWAP_APPAREL
                    Log.Warning("        Try Find Def " + def.label);
#endif
                    if (pawn.apparel.CanWearWithoutDroppingAnything(def))
                    {
#if TRACE && SWAP_APPAREL
                        Log.Warning("        Can Wear. Check Dressers for apparel:");
#endif
                        foreach (Building_Dresser d in WorldComp.DressersToUse)
                        {
#if TRACE && SWAP_APPAREL
                            Log.Warning("            " + d.Label);
#endif
                            Apparel apparel;
                            if (d.TryRemoveBestApparel(def, pawn.outfits.CurrentOutfit.filter, out apparel))
                            {
                                WorldComp.ApparelColorTracker.RemoveApparel(apparel);
#if TRACE && SWAP_APPAREL
                                Log.Warning("            Found : " + apparel.Label);
#endif
                                pawn.apparel.Wear(apparel);
                                break;
                            }
#if TRACE && SWAP_APPAREL
                            else
                            {
                                Log.Warning("            No matching apparel found");
                            }
#endif
                        }
                    }
#if TRACE && SWAP_APPAREL
                    else
                    {
                        Log.Warning("        Can't wear");
                    }
#endif
                }
                return;
            }

#if DRESSER_OUTFIT
            Log.Warning("Begin OptimizeApparelUtil.OptimizeApparel(Pawn: " + pawn.Name + ")");
#endif
            MethodInfo mi = typeof(JobGiver_OptimizeApparel).GetMethod("TryGiveJob", BindingFlags.Instance | BindingFlags.NonPublic);
            JobGiver_OptimizeApparel apparelOptimizer = new JobGiver_OptimizeApparel();
            object[] param = new object[] { pawn };

            for (int i = 0; i < 10; ++i)
            {
#if TRACE && DRESSER_OUTFIT
                Log.Message(i + " start equip for loop");
#endif
                Job job = mi.Invoke(apparelOptimizer, param) as Job;
#if TRACE && DRESSER_OUTFIT
                Log.Message(i + " job is null: " + (string)((job == null) ? "yes" : "no"));
#endif
                if (job == null)
                {
                    break;
                }
#if TRACE && DRESSER_OUTFIT
                Log.Message(job.def.defName);
#endif
                if (job.def == JobDefOf.Wear)
                {
                    Apparel a = ((job.targetB != null) ? job.targetB.Thing : null) as Apparel;
                    if (a == null)
                    {
                        Log.Warning("ChangeDresser: OptimizeApparelUtil.OptimizeApparel: Problem equiping pawn. Apparel is null.");
                        break;
                    }
#if TRACE && DRESSER_OUTFIT
                    Log.Message("Wear from ground " + a.Label);
#endif
                    pawn.apparel.Wear(a);
                }
                else if (job.def == Building_Dresser.WEAR_APPAREL_FROM_DRESSER_JOB_DEF)
                {
                    Building_Dresser d = ((job.targetA != null) ? job.targetA.Thing : null) as Building_Dresser;
                    Apparel          a = ((job.targetB != null) ? job.targetB.Thing : null) as Apparel;

                    if (d == null || a == null)
                    {
                        Log.Warning("ChangeDresser: OptimizeApparelUtil.OptimizeApparel: Problem equiping pawn. Dresser or Apparel is null.");
                        break;
                    }
#if TRACE && DRESSER_OUTFIT
                    Log.Message("Wear from dresser " + d.Label + " " + a.Label);
#endif
                    d.RemoveNoDrop(a);
                    pawn.apparel.Wear(a);
                }
#if TRACE && DRESSER_OUTFIT
                Log.Message(i + " end equip for loop");
#endif
            }
#if DRESSER_OUTFIT
            Log.Warning("End OptimizeApparelUtil.OptimizeApparel");
#endif
        }
 public void RemoveDresser(Building_Dresser dresser)
 {
     this.AttachedDressers.Remove(dresser);
 }
 public StoredApparel(Building_Dresser dresser, Apparel apparel)
 {
     this.Dresser = dresser;
     this.Apparel = apparel;
 }
Exemple #13
0
        static void Postfix(Pawn pawn, ref bool __state, ref Job __result)
        {
            if (!__state)
            {
                return;
            }

#if BETTER_OUTFIT
            Log.Warning("Begin JobGiver_OptimizeApparel.Postfix(Pawn: " + pawn.Name.ToStringShort + "     Job: " + ((__result == null) ? "<null>" : __result.ToString()) + ")");
#endif
            if (!DoDressersHaveApparel() || pawn.apparel?.LockedApparel?.Count > 0)
            {
                return;
            }

            Thing thing            = null;
            float baseApparelScore = 0f;
            if (__result != null && __result.targetA.Thing is Apparel)
            {
                thing            = __result.targetA.Thing;
                baseApparelScore = JobGiver_OptimizeApparel.ApparelScoreGain(pawn, thing as Apparel);
                if (thing == null)
                {
                    baseApparelScore = 0f;
                }
                else
                {
#if BETTER_OUTFIT
                    Log.Message("    Game Found Better Apparel: " + ((thing == null) ? "<null>" : thing.Label) + "    Score: " + baseApparelScore);
#endif
                }
            }

            Apparel          a = null;
            Building_Dresser containingDresser = null;

#if BETTER_OUTFIT
            Log.Message("    Loop Through Dressers:");
#endif
            foreach (Building_Dresser dresser in WorldComp.DressersToUse)
            {
#if TRACE && BETTER_OUTFIT
                Log.Message("        Dresser: " + dresser.Label);
#endif
                float score = baseApparelScore;
                if (dresser.FindBetterApparel(ref score, ref a, pawn, pawn.outfits.CurrentOutfit))
                {
                    thing             = a;
                    baseApparelScore  = score;
                    containingDresser = dresser;
#if BETTER_OUTFIT
                    Log.Message("    Dresser Found Better Apparel: " + ((a == null) ? "<null>" : a.Label) + "    Score: " + baseApparelScore);
#endif
                }
            }
#if BETTER_OUTFIT
            Log.Message("    Best Apparel: " + ((a == null) ? "<null>" : a.Label) + "    Score: " + baseApparelScore);
#endif
            if (a != null && containingDresser != null)
            {
                __result = new Job(containingDresser.wearApparelFromStorageJobDef, containingDresser, a);
            }
#if BETTER_OUTFIT
            Log.Warning("End JobGiver_OptimizeApparel.Postfix");
#endif
        }