Example #1
0
        public static bool CacheWorkGiversInOrder(Pawn_WorkSettings __instance)
        {
            //Pawn_WorkSettings.wtsByPrio.Clear();
            List <WorkTypeDef> wtsByPrio          = new List <WorkTypeDef>(); //ADD
            List <WorkTypeDef> defsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;
            int num1 = 999;

            for (int index = 0; index < defsListForReading.Count; ++index)
            {
                WorkTypeDef w        = defsListForReading[index];
                int         priority = __instance.GetPriority(w);
                if (priority > 0)
                {
                    if (priority < num1 && w.workGiversByPriority.Any(wg => !wg.emergency))
                    {
                        num1 = priority;
                    }
                    wtsByPrio.Add(w); //FIND REPLACE
                }
            }
            //FIND REPLACE
            wtsByPrio.InsertionSort((a, b) =>
            {
                float num2 = a.naturalPriority + (4 - __instance.GetPriority(a)) * 100000;
                return(((float)(b.naturalPriority + (4 - __instance.GetPriority(b)) * 100000)).CompareTo(num2));
            });
            WorkGiverListClear(workGiversInOrderEmerg(__instance));
            for (int index1 = 0; index1 < wtsByPrio.Count; ++index1) //FIND REPLACE
            {
                WorkTypeDef workTypeDef = wtsByPrio[index1];         ////FIND REPLACE
                for (int index2 = 0; index2 < workTypeDef.workGiversByPriority.Count; ++index2)
                {
                    WorkGiver worker = workTypeDef.workGiversByPriority[index2].Worker;
                    if (worker.def.emergency && __instance.GetPriority(worker.def.workType) <= num1)
                    {
                        WorkGiverListAdd(workGiversInOrderEmerg(__instance), worker);
                    }
                }
            }
            WorkGiverListClear(workGiversInOrderNormal(__instance));
            for (int index1 = 0; index1 < wtsByPrio.Count; ++index1) //FIND REPLACE
            {
                WorkTypeDef workTypeDef = wtsByPrio[index1];         //FIND REPLACE
                for (int index2 = 0; index2 < workTypeDef.workGiversByPriority.Count; ++index2)
                {
                    WorkGiver worker = workTypeDef.workGiversByPriority[index2].Worker;
                    if (!worker.def.emergency || __instance.GetPriority(worker.def.workType) > num1)
                    {
                        WorkGiverListAdd(workGiversInOrderNormal(__instance), worker);
                    }
                }
            }
            workGiversDirty(__instance) = false;
            return(false);
        }
Example #2
0
        public PawnSurface(Pawn pawn)
        {
            this.pawn = pawn;

            Pawn_WorkSettings workSettings = this.pawn.workSettings;

            for (int i = 0; i < Controller.GetPrimaries.PrimaryWorkList.Count; i++)
            {
                WorkTypeDef def               = Controller.GetPrimaries.PrimaryWorkList[i].def;
                bool        incapablePawn     = this.pawn.story.WorkTypeIsDisabled(def);
                bool        currentlyDisabled = workSettings.GetPriority(def) == 0;          //Account for pre-existing priorities

                DraggableWork newWork = new DraggableWork(def, incapablePawn, this, currentlyDisabled);

                this.children.Add(newWork);
            }

            this.RefreshChildrenDictionary();

            this.children = this.children.OrderByDescending(d => !d.CompletelyDisabled).ThenByDescending(d => workSettings.GetPriority(d.Def) != 0).ThenBy(d => workSettings.GetPriority(d.Def)).ToList();             //Account for pre-existing priorities

            this.UpdatePawnPriorities();
        }
Example #3
0
        static bool CacheWorkGiversInOrder(ref Pawn_WorkSettings __instance)
        {
            List <WorkTypeDef> wtsByPrio = new List <WorkTypeDef>();
            List <WorkGiver>   workGiversInOrderEmerg  = ((List <WorkGiver>)__instance.GetField("workGiversInOrderEmerg"));
            List <WorkGiver>   workGiversInOrderNormal = ((List <WorkGiver>)__instance.GetField("workGiversInOrderNormal"));

            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;

            int num = 999;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                WorkTypeDef workTypeDef = allDefsListForReading[i];
                int         priority    = __instance.GetPriority(workTypeDef);
                if (priority > 0)
                {
                    if (priority < num)
                    {
                        if (workTypeDef.workGiversByPriority.Any((WorkGiverDef wg) => !wg.emergency))
                        {
                            num = priority;
                        }
                    }
                    wtsByPrio.Add(workTypeDef);
                }
            }
            var tmp = __instance;

            wtsByPrio.InsertionSort(delegate(WorkTypeDef a, WorkTypeDef b)
            {
                float value = (float)(a.naturalPriority + (4 - tmp.GetPriority(a)) * 100000);
                return(((float)(b.naturalPriority + (4 - tmp.GetPriority(b)) * 100000)).CompareTo(value));
            });
            workGiversInOrderEmerg.Clear();
            for (int j = 0; j < wtsByPrio.Count; j++)
            {
                WorkTypeDef workTypeDef2 = wtsByPrio[j];
                for (int k = 0; k < workTypeDef2.workGiversByPriority.Count; k++)
                {
                    WorkGiver worker = workTypeDef2.workGiversByPriority[k].Worker;
                    if (worker.def.emergency && __instance.GetPriority(worker.def.workType) <= num)
                    {
                        workGiversInOrderEmerg.Add(worker);
                    }
                }
            }
            workGiversInOrderNormal.Clear();
            for (int l = 0; l < wtsByPrio.Count; l++)
            {
                WorkTypeDef workTypeDef3 = wtsByPrio[l];
                for (int m = 0; m < workTypeDef3.workGiversByPriority.Count; m++)
                {
                    WorkGiver worker2 = workTypeDef3.workGiversByPriority[m].Worker;
                    if (!worker2.def.emergency || __instance.GetPriority(worker2.def.workType) > num)
                    {
                        workGiversInOrderNormal.Add(worker2);
                    }
                }
            }
            __instance.SetField("workGiversDirty", false);
            return(false);
        }