Beispiel #1
0
        private IEnumerable <object> SelectableObjectsUnderMouse()
        {
            Vector2 mousePos         = UI.MousePositionOnUIInverted;
            Thing   colonistOrCorpse = Find.ColonistBar.ColonistOrCorpseAt(mousePos);

            if (colonistOrCorpse != null && colonistOrCorpse.Spawned)
            {
                yield return(colonistOrCorpse);

                yield break;
            }
            if (!UI.MouseCell().InBounds(Find.CurrentMap))
            {
                yield break;
            }
            TargetingParameters selectParams = new TargetingParameters();

            selectParams.mustBeSelectable   = true;
            selectParams.canTargetPawns     = true;
            selectParams.canTargetBuildings = true;
            selectParams.canTargetItems     = true;
            selectParams.mapObjectTargetsMustBeAutoAttackable = false;
            List <Thing> selectableList = GenUI.ThingsUnderMouse(UI.MouseMapPosition(), 1f, selectParams);

            if (selectableList.Count > 0 && selectableList[0] is Pawn)
            {
                if ((selectableList[0].DrawPos - UI.MouseMapPosition()).MagnitudeHorizontal() < 0.4f)
                {
                    for (int j = selectableList.Count - 1; j >= 0; j--)
                    {
                        Thing thing = selectableList[j];
                        if (thing.def.category == ThingCategory.Pawn && (thing.DrawPos - UI.MouseMapPosition()).MagnitudeHorizontal() > 0.4f)
                        {
                            selectableList.Remove(thing);
                        }
                    }
                }
            }
            for (int i = 0; i < selectableList.Count; i++)
            {
                yield return(selectableList[i]);
            }
            Zone z = Find.CurrentMap.zoneManager.ZoneAt(UI.MouseCell());

            if (z != null)
            {
                yield return(z);
            }
            yield break;
        }
        private IEnumerable <object> SelectableObjectsUnderMouse()
        {
            Vector2 mousePos         = UI.MousePositionOnUIInverted;
            Thing   colonistOrCorpse = Find.ColonistBar.ColonistOrCorpseAt(mousePos);

            if (colonistOrCorpse != null && colonistOrCorpse.Spawned)
            {
                yield return((object)colonistOrCorpse);

                /*Error: Unable to find new state assignment for yield return*/;
            }
            if (UI.MouseCell().InBounds(Find.VisibleMap))
            {
                TargetingParameters selectParams = new TargetingParameters
                {
                    mustBeSelectable   = true,
                    canTargetPawns     = true,
                    canTargetBuildings = true,
                    canTargetItems     = true,
                    mapObjectTargetsMustBeAutoAttackable = false
                };
                List <Thing> selectableList = GenUI.ThingsUnderMouse(UI.MouseMapPosition(), 1f, selectParams);
                if (selectableList.Count > 0 && selectableList[0] is Pawn && (selectableList[0].DrawPos - UI.MouseMapPosition()).MagnitudeHorizontal() < 0.40000000596046448)
                {
                    for (int num = selectableList.Count - 1; num >= 0; num--)
                    {
                        Thing thing = selectableList[num];
                        if (thing.def.category == ThingCategory.Pawn && (thing.DrawPos - UI.MouseMapPosition()).MagnitudeHorizontal() > 0.40000000596046448)
                        {
                            selectableList.Remove(thing);
                        }
                    }
                }
                int i = 0;
                if (i < selectableList.Count)
                {
                    yield return((object)selectableList[i]);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
                Zone z = Find.VisibleMap.zoneManager.ZoneAt(UI.MouseCell());
                if (z == null)
                {
                    yield break;
                }
                yield return((object)z);

                /*Error: Unable to find new state assignment for yield return*/;
            }
        }
Beispiel #3
0
            private static void Postfix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts, bool drafted, FloatMenuOption[] ___equivalenceGroupTempStorage)
            {
                if (pawn.thinker.TryGetMainTreeThinkNode <JobGiver_Work>() != null)
                {
                    IntVec3             clickCell           = IntVec3.FromVector3(clickPos);
                    TargetingParameters targetingParameters = new TargetingParameters();
                    targetingParameters.canTargetPawns     = true;
                    targetingParameters.canTargetBuildings = true;
                    targetingParameters.canTargetItems     = true;
                    targetingParameters.mapObjectTargetsMustBeAutoAttackable = false;
                    var ZTracker = ZUtils.ZTracker;
                    foreach (Thing item in GenUI.ThingsUnderMouse(clickPos, 1f, targetingParameters))
                    {
                        bool flag = false;
                        foreach (WorkTypeDef item2 in DefDatabase <WorkTypeDef> .AllDefsListForReading)
                        {
                            for (int i = 0; i < item2.workGiversByPriority.Count; i++)
                            {
                                WorkGiverDef workGiver2 = item2.workGiversByPriority[i];
                                if (!drafted || workGiver2.canBeDoneWhileDrafted)
                                {
                                    WorkGiver_Scanner workGiver_Scanner = workGiver2.Worker as WorkGiver_Scanner;
                                    if (workGiver_Scanner != null && workGiver_Scanner.def.directOrderable)
                                    {
                                        JobFailReason.Clear();
                                        if ((workGiver_Scanner.PotentialWorkThingRequest.Accepts(item) || (workGiver_Scanner.PotentialWorkThingsGlobal(pawn) != null && workGiver_Scanner.PotentialWorkThingsGlobal(pawn).Contains(item))) && !workGiver_Scanner.ShouldSkip(pawn, forced: true))
                                        {
                                            string          text            = null;
                                            Action          action          = null;
                                            PawnCapacityDef pawnCapacityDef = workGiver_Scanner.MissingRequiredCapacity(pawn);
                                            if (pawnCapacityDef != null)
                                            {
                                                text = "CannotMissingHealthActivities".Translate(pawnCapacityDef.label);
                                            }
                                            else
                                            {
                                                Map oldMap = pawn.Map;
                                                Job job    = null;
                                                Map dest   = null;
                                                foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
                                                {
                                                    if (workGiver_Scanner is WorkGiver_Refuel scanner1)
                                                    {
                                                        job = JobPatches.TryIssueJobPackagePatch.JobOnThing(
                                                            scanner1, pawn, item, true);
                                                    }
                                                    else if (workGiver_Scanner.def.defName == "HaulGeneral" ||
                                                             workGiver_Scanner.def.defName == "HaulCorpses")
                                                    {
                                                        job = JobPatches.TryIssueJobPackagePatch.JobOnThing(pawn,
                                                                                                            item, ref dest);
                                                    }
                                                    else if (workGiver_Scanner is WorkGiver_DoBill scanner2)
                                                    {
                                                        job = JobPatches.TryIssueJobPackagePatch.JobOnThing(
                                                            scanner2, pawn, item);
                                                    }
                                                    else if (workGiver_Scanner is
                                                             WorkGiver_ConstructDeliverResourcesToBlueprints scanner3)
                                                    {
                                                        job = JobPatches.TryIssueJobPackagePatch.JobOnThing(
                                                            scanner3, pawn, item);
                                                    }
                                                    else if (workGiver_Scanner is
                                                             WorkGiver_ConstructDeliverResourcesToFrames scanner4)
                                                    {
                                                        job = JobPatches.TryIssueJobPackagePatch.JobOnThing(
                                                            scanner4, pawn, item);
                                                    }
                                                    else
                                                    {
                                                        job = workGiver_Scanner.HasJobOnThing(pawn, item,
                                                                                              forced: true)
                                                            ? workGiver_Scanner.JobOnThing(pawn, item, forced: true)
                                                            : null;
                                                    }

                                                    if (job != null)
                                                    {
                                                        break;
                                                    }
                                                }
                                                if (job == null)
                                                {
                                                    if (JobFailReason.HaveReason)
                                                    {
                                                        text = (JobFailReason.CustomJobString.NullOrEmpty() ? ((string)"CannotGenericWork".Translate(workGiver_Scanner.def.verb, item.LabelShort, item)) : ((string)"CannotGenericWorkCustom".Translate(JobFailReason.CustomJobString)));
                                                        text = text + ": " + JobFailReason.Reason.CapitalizeFirst();
                                                    }
                                                    else
                                                    {
                                                        if (!item.IsForbidden(pawn))
                                                        {
                                                            continue;
                                                        }
                                                        text = (item.Position.InAllowedArea(pawn) ? ((string)"CannotPrioritizeForbidden".Translate(item.Label, item)) : ((string)("CannotPrioritizeForbiddenOutsideAllowedArea".Translate() + ": " + pawn.playerSettings.EffectiveAreaRestriction.Label)));
                                                    }
                                                }
                                                else
                                                {
                                                    WorkTypeDef workType = workGiver_Scanner.def.workType;
                                                    if (pawn.WorkTagIsDisabled(workGiver_Scanner.def.workTags))
                                                    {
                                                        text = "CannotPrioritizeWorkGiverDisabled".Translate(workGiver_Scanner.def.label);
                                                    }
                                                    else if (pawn.jobs.curJob != null && pawn.jobs.curJob.JobIsSameAs(job))
                                                    {
                                                        text = "CannotGenericAlreadyAm".Translate(workGiver_Scanner.PostProcessedGerund(job), item.LabelShort, item);
                                                    }
                                                    else if (pawn.workSettings.GetPriority(workType) == 0)
                                                    {
                                                        text = (pawn.WorkTypeIsDisabled(workType) ? ((string)"CannotPrioritizeWorkTypeDisabled".Translate(workType.gerundLabel)) : ((!"CannotPrioritizeNotAssignedToWorkType".CanTranslate()) ? ((string)"CannotPrioritizeWorkTypeDisabled".Translate(workType.pawnLabel)) : ((string)"CannotPrioritizeNotAssignedToWorkType".Translate(workType.gerundLabel))));
                                                    }
                                                    else if (job.def == JobDefOf.Research && item is Building_ResearchBench)
                                                    {
                                                        text = "CannotPrioritizeResearch".Translate();
                                                    }
                                                    else if (item.IsForbidden(pawn))
                                                    {
                                                        text = (item.Position.InAllowedArea(pawn) ? ((string)"CannotPrioritizeForbidden".Translate(item.Label, item)) : ((string)("CannotPrioritizeForbiddenOutsideAllowedArea".Translate() + ": " + pawn.playerSettings.EffectiveAreaRestriction.Label)));
                                                    }
                                                    else if (!pawn.CanReach(item, workGiver_Scanner.PathEndMode, Danger.Deadly))
                                                    {
                                                        text = (item.Label + ": " + "NoPath".Translate().CapitalizeFirst()).CapitalizeFirst();
                                                    }
                                                    else
                                                    {
                                                        text = "PrioritizeGeneric".Translate(workGiver_Scanner.PostProcessedGerund(job), item.Label);
                                                        Job localJob2 = job;
                                                        WorkGiver_Scanner localScanner2 = workGiver_Scanner;
                                                        job.workGiverDef = workGiver_Scanner.def;
                                                        action           = delegate
                                                        {
                                                            if (!ZTracker.jobTracker.ContainsKey(pawn))
                                                            {
                                                                ZTracker.jobTracker[pawn] = new JobTracker();
                                                            }
                                                            if (dest != null)
                                                            {
                                                                ZTracker.BuildJobListFor(pawn, dest, job);
                                                            }
                                                            else
                                                            {
                                                                ZTracker.BuildJobListFor(pawn, oldMap, job);
                                                            }
                                                            pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                                                            if (workGiver2.forceMote != null)
                                                            {
                                                                MoteMaker.MakeStaticMote(clickCell, pawn.Map,
                                                                                         workGiver2.forceMote);
                                                            }
                                                        };
                                                    }
                                                }
                                            }
                                            if (DebugViewSettings.showFloatMenuWorkGivers)
                                            {
                                                text += $" (from {workGiver2.defName})";
                                            }
                                            FloatMenuOption menuOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, action), pawn, item);
                                            if (drafted && workGiver2.autoTakeablePriorityDrafted != -1)
                                            {
                                                menuOption.autoTakeable         = true;
                                                menuOption.autoTakeablePriority = workGiver2.autoTakeablePriorityDrafted;
                                            }
                                            if (!opts.Any((FloatMenuOption op) => op.Label == menuOption.Label))
                                            {
                                                if (workGiver2.equivalenceGroup != null)
                                                {
                                                    if (___equivalenceGroupTempStorage[workGiver2.equivalenceGroup.index] == null ||
                                                        (___equivalenceGroupTempStorage[workGiver2.equivalenceGroup.index].Disabled && !menuOption.Disabled))
                                                    {
                                                        ___equivalenceGroupTempStorage[workGiver2.equivalenceGroup.index] = menuOption;
                                                        flag = true;
                                                    }
                                                }
                                                else
                                                {
                                                    opts.Add(menuOption);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            for (int j = 0; j < ___equivalenceGroupTempStorage.Length; j++)
                            {
                                if (___equivalenceGroupTempStorage[j] != null)
                                {
                                    opts.Add(___equivalenceGroupTempStorage[j]);
                                    ___equivalenceGroupTempStorage[j] = null;
                                }
                            }
                        }
                    }
                    foreach (WorkTypeDef item3 in DefDatabase <WorkTypeDef> .AllDefsListForReading)
                    {
                        for (int k = 0; k < item3.workGiversByPriority.Count; k++)
                        {
                            WorkGiverDef workGiver = item3.workGiversByPriority[k];
                            if (!drafted || workGiver.canBeDoneWhileDrafted)
                            {
                                WorkGiver_Scanner workGiver_Scanner2 = workGiver.Worker as WorkGiver_Scanner;
                                if (workGiver_Scanner2 != null && workGiver_Scanner2.def.directOrderable)
                                {
                                    JobFailReason.Clear();
                                    if (workGiver_Scanner2.PotentialWorkCellsGlobal(pawn).Contains(clickCell) && !workGiver_Scanner2.ShouldSkip(pawn, forced: true))
                                    {
                                        Action          action2          = null;
                                        string          label            = null;
                                        PawnCapacityDef pawnCapacityDef2 = workGiver_Scanner2.MissingRequiredCapacity(pawn);
                                        if (pawnCapacityDef2 != null)
                                        {
                                            label = "CannotMissingHealthActivities".Translate(pawnCapacityDef2.label);
                                        }
                                        else
                                        {
                                            Job job2 = workGiver_Scanner2.HasJobOnCell(pawn, clickCell, forced: true) ? workGiver_Scanner2.JobOnCell(pawn, clickCell, forced: true) : null;
                                            if (job2 == null)
                                            {
                                                if (JobFailReason.HaveReason)
                                                {
                                                    if (!JobFailReason.CustomJobString.NullOrEmpty())
                                                    {
                                                        label = "CannotGenericWorkCustom".Translate(JobFailReason.CustomJobString);
                                                    }
                                                    else
                                                    {
                                                        label = "CannotGenericWork".Translate(workGiver_Scanner2.def.verb, "AreaLower".Translate());
                                                    }
                                                    label = label + ": " + JobFailReason.Reason.CapitalizeFirst();
                                                }
                                                else
                                                {
                                                    if (!clickCell.IsForbidden(pawn))
                                                    {
                                                        continue;
                                                    }
                                                    if (!clickCell.InAllowedArea(pawn))
                                                    {
                                                        label = "CannotPrioritizeForbiddenOutsideAllowedArea".Translate() + ": " + pawn.playerSettings.EffectiveAreaRestriction.Label;
                                                    }
                                                    else
                                                    {
                                                        label = "CannotPrioritizeCellForbidden".Translate();
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                WorkTypeDef workType2 = workGiver_Scanner2.def.workType;
                                                if (pawn.jobs.curJob != null && pawn.jobs.curJob.JobIsSameAs(job2))
                                                {
                                                    label = "CannotGenericAlreadyAmCustom".Translate(workGiver_Scanner2.PostProcessedGerund(job2));
                                                }
                                                else if (pawn.workSettings.GetPriority(workType2) == 0)
                                                {
                                                    if (pawn.WorkTypeIsDisabled(workType2))
                                                    {
                                                        label = "CannotPrioritizeWorkTypeDisabled".Translate(workType2.gerundLabel);
                                                    }
                                                    else if ("CannotPrioritizeNotAssignedToWorkType".CanTranslate())
                                                    {
                                                        label = "CannotPrioritizeNotAssignedToWorkType".Translate(workType2.gerundLabel);
                                                    }
                                                    else
                                                    {
                                                        label = "CannotPrioritizeWorkTypeDisabled".Translate(workType2.pawnLabel);
                                                    }
                                                }
                                                else if (clickCell.IsForbidden(pawn))
                                                {
                                                    if (!clickCell.InAllowedArea(pawn))
                                                    {
                                                        label = "CannotPrioritizeForbiddenOutsideAllowedArea".Translate() + ": " + pawn.playerSettings.EffectiveAreaRestriction.Label;
                                                    }
                                                    else
                                                    {
                                                        label = "CannotPrioritizeCellForbidden".Translate();
                                                    }
                                                }
                                                else if (!pawn.CanReach(clickCell, PathEndMode.Touch, Danger.Deadly))
                                                {
                                                    label = "AreaLower".Translate().CapitalizeFirst() + ": " + "NoPath".Translate().CapitalizeFirst();
                                                }
                                                else
                                                {
                                                    label = "PrioritizeGeneric".Translate(workGiver_Scanner2.PostProcessedGerund(job2), "AreaLower".Translate());
                                                    Job localJob = job2;
                                                    WorkGiver_Scanner localScanner = workGiver_Scanner2;
                                                    job2.workGiverDef = workGiver_Scanner2.def;
                                                    action2           = delegate
                                                    {
                                                        if (pawn.jobs.TryTakeOrderedJobPrioritizedWork(localJob, localScanner, clickCell) && workGiver.forceMote != null)
                                                        {
                                                            MoteMaker.MakeStaticMote(clickCell, pawn.Map, workGiver.forceMote);
                                                        }
                                                    };
                                                }
                                            }
                                        }
                                        if (!opts.Any((FloatMenuOption op) => op.Label == label.TrimEnd()))
                                        {
                                            FloatMenuOption floatMenuOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(label, action2), pawn, clickCell);
                                            if (drafted && workGiver.autoTakeablePriorityDrafted != -1)
                                            {
                                                floatMenuOption.autoTakeable         = true;
                                                floatMenuOption.autoTakeablePriority = workGiver.autoTakeablePriorityDrafted;
                                            }
                                            opts.Add(floatMenuOption);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
//        public static List<FloatMenuOption> floatingList=new List<FloatMenuOption>();
        static void GeneratePawnOptionsFor(Pawn p, Thing t, List <FloatMenuOption> opts)
        {
            Utils.Mess(RightClickMenu, "Generating Options for " + p + " using " + t);
//            if (!t.Spawned) return null;
            if (!t.Spawned)
            {
                return;
            }
            // if not cached, build
            Map map = p.Map;
            /*** Step 1: Clear ThingsList ***/
            var index = map.cellIndices.CellToIndex(t.Position);

            if (mapOfCachedThingGrid != map)
            {
                mapOfCachedThingGrid     = map;
                cachedThingGridThingList = (List <Thing>[])thingGridThingList.GetValue(map.thingGrid);
            }
            List <Thing> origList = cachedThingGridThingList[index];

            cachedThingGridThingList[index] = tmpEmpty;
            // Add the thing we are interested in to the new thinglist:
            tmpEmpty.Add(t); // (remember to empty afterwards)

/*            IntVec3 c=t.Position;
 *          var list=t.Map.thingGrid.ThingsListAtFast(c);
 *          foreach (Thing bye in list) {
 *              if (bye==t) continue;
 *              SendToFaerie(bye);
 *          }
 *          // get rid of non-item things (e.g., pawns?)
 */

            //XXX:
            // We are doing UI stuff, which often uses the click-position
            //    instead of the map position, so that's annoying and may
            //    be risky, but I'm not sure there's much choice. We also
            //    grab everything via TargetingParameters, which includes
            //    all the Things on the ground as well as pawns, fire, &c
            Vector3             clickPos     = t.Position.ToVector3();
            TargetingParameters TPeverything = new TargetingParameters();

            TPeverything.canTargetBuildings = true;  // be thorough here
            TPeverything.canTargetItems     = false; // We already moved the thingsList
            TPeverything.canTargetFires     = true;  // not that pawns SHOULD be able to grab things from burning lockers...
            TPeverything.canTargetPawns     = true;
            TPeverything.canTargetSelf      = true;  // are we sure?

            foreach (LocalTargetInfo anotherT in GenUI.ThingsUnderMouse(clickPos,
                                                                        0.8f /*see TargetsAt*/, TPeverything))
            {
                Thing tmpT = anotherT.Thing;
                if (tmpT != null && tmpT != t)
                {
//                    Utils.Mess(RightClickMenu, "  moving away "+tmpT);
//                    SendToFaerie(tmpT);
                }
            }

            /*var index = pawn.Map.cellIndices.CellToIndex(cpos.ToIntVec3());
             * var listArray = (List<Thing>[]) thingListTG.GetValue(pawn.Map.thingGrid);
             * var origList = listArray[index];
             *
             * listArray[index] = new List<Thing> {thingList[i]};
             * rows[i] = new DSGUI_ListItem(pawn, thingList[i], cpos, boxHeight);
             * listArray[index] = origList;
             */
            // get orders for Thing t!
//            List<Thing> thingList=t.Position.GetThingList(t.Map);
//            List<Thing> tmpList=new List<Thing>(thingList);
//            thingList.Clear();
//            thingList.Add(t);
            runVanillaAHlO    = true;
            blockAHlONonItems = true;
//            floatingList.Clear();
            Utils.Mess(RightClickMenu, "  running vanilla (but target-blocked) AHlO");
            AHlO(clickPos, p, opts);
            blockAHlONonItems = false;
//            AHlO(clickPos,p,floatingList);
//            AHlO.Invoke(null, new object[] { clickPos, p, floatingList}); //todo
            runVanillaAHlO = false;
            // Restore Things:
            Utils.Mess(RightClickMenu, "  returning things");
            ReturnThingsFromFaerie();
            // Restor ThingList:
            cachedThingGridThingList[index] = origList;
            tmpEmpty.Clear(); // clean up after ourselves!
//            thingList.Clear();
//            thingList.AddRange(tmpList);
//      Log.Warning("List size: "+floatingList.Count);
//            return floatingList;
//            Log.Warning("List size: "+opts.Count);
        }