コード例 #1
0
        //public void DoForcedGeneration(bool disableFog)
        //{
        //    SettlementGeneration.DoSettlementGeneration(this.map, this.path, this.map.ParentFaction, disableFog);
        //    this.DoGeneration = false;
        //}

        public override void FinalizeInit()
        {
            base.FinalizeInit();
            if (!this.hasCavesBelow.HasValue)
            {
                if (Rand.Chance(0.5f) && (Find.WorldGrid[map.Tile].hilliness == Hilliness.SmallHills ||
                                          Find.WorldGrid[map.Tile].hilliness == Hilliness.LargeHills ||
                                          Find.WorldGrid[map.Tile].hilliness == Hilliness.Mountainous ||
                                          Find.WorldGrid[map.Tile].hilliness == Hilliness.Impassable))
                {
                    ZLogger.Message("The map has caves below now");
                    this.hasCavesBelow = true;
                }
            }

            var ZTracker = ZUtils.ZTracker;

            if (ZTracker.ZLevelsTracker == null)
            {
                ZLogger.Message("1 Resetting ZLevelsTracker");
                ZTracker.ZLevelsTracker = new Dictionary <int, ZLevelData>();
            }

            foreach (var tile in ZTracker.ZLevelsTracker)
            {
                foreach (var zData in ZTracker.ZLevelsTracker[tile.Key].ZLevels)
                {
                    ZLogger.Message("2 Tile: " + tile.Key + " - Map: " + ZTracker.GetMapInfo(zData.Value));
                    ZLogger.Message("Map null: " + (zData.Value == null).ToString());
                    ZLogger.Message("Map.Pawns null: " + (zData.Value.mapPawns == null).ToString());
                    ZLogger.Message("2 Map.Pawns null: " + (this.map.mapPawns == null).ToString());
                }
            }

            if (!ZTracker.ZLevelsTracker.ContainsKey(this.map.Tile) && ZTracker.TryRegisterMap(this.map, 0))
            {
                this.Z_LevelIndex = 0;
            }
        }
コード例 #2
0
 private static void Postfix(Skyfaller __result, ThingDef skyfaller, IEnumerable <Thing> things, IntVec3 pos, Map map)
 {
     ZLogger.Message("Spawning " + __result);
     if (pos.Roofed(map))
     {
         var ZTracker = ZUtils.ZTracker;
         var upperMap = ZTracker.ZLevelsTracker[map.Tile]
                        .ZLevels.Values.Where(x => !pos.Roofed(x) &&
                                              pos.GetTerrain(x) != ZLevelsDefOf.ZL_OutsideTerrain)
                        .OrderByDescending(x => ZTracker.GetZIndexFor(x)).FirstOrDefault();
         if (upperMap != null)
         {
             ZTracker.SimpleTeleportThing(__result, pos, upperMap);
             ZLogger.Message("Skyfaller: " + __result + " spawning in " + ZTracker.GetMapInfo(upperMap));
         }
         else
         {
             ZLogger.Message("Cant find unroofed map for " + __result);
         }
         ZLogger.Message("Roofed");
     }
 }
コード例 #3
0
ファイル: CombatPatches.cs プロジェクト: Proxyer/Z-Levels
 private static void JobGiver_AIGotoNearestHostilePostfix(JobGiver_AIGotoNearestHostile __instance, ref Job __result, Pawn pawn)
 {
     ZLogger.Message(pawn + " got response 4: " + __result, true);
     if (__result == null && !recursiveTrap)
     {
         recursiveTrap = true;
         CombatPatches_BestAttackTarget_Patch.multiMapSearch = true;
         var job = __instance.TryGiveJob(pawn);
         if (job != null)
         {
             ZLogger.Message("Second block: " + job, true);
             if (job.targetA.Thing?.Map != null && job.targetA.Thing.Map != pawn.Map)
             {
                 ZUtils.ZTracker.BuildJobListFor(pawn, job.targetA.Thing.Map, __result);
                 ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(job.targetA.Thing);
                 ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
                 __result = ZUtils.ZTracker.jobTracker[pawn].activeJobs[0];
                 ZUtils.ZTracker.jobTracker[pawn].activeJobs.RemoveAt(0);
             }
             else
             {
                 __result = job;
             }
         }
         recursiveTrap = false;
         CombatPatches_BestAttackTarget_Patch.multiMapSearch = false;
     }
     else if (__result != null && __result.targetA.Thing?.Map != null && __result.targetA.Thing.Map != pawn.Map)
     {
         ZLogger.Message("Second block: " + __result, true);
         ZUtils.ZTracker.BuildJobListFor(pawn, __result.targetA.Thing.Map, __result);
         ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(__result.targetA.Thing);
         ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
         __result = ZUtils.ZTracker.jobTracker[pawn].activeJobs[0];
         ZUtils.ZTracker.jobTracker[pawn].activeJobs.RemoveAt(0);
     }
     ZLogger.Message(pawn + " got result 4: " + __result + " in " + pawn.Map + " - " + __result?.targetA.Thing?.Map + " - mind enemy: " + pawn.mindState.enemyTarget, true);
 }
コード例 #4
0
 private static void JobGiver_ConfigurableHostilityResponsePostfix(JobGiver_ConfigurableHostilityResponse __instance, ref Job __result, Pawn pawn)
 {
     if (__result == null && !recursiveTrap)
     {
         recursiveTrap = true;
         CombatPatches_BestAttackTarget_Patch.multiMapSearch = true;
         var job = __instance.TryGiveJob(pawn);
         if (job != null)
         {
             ZLogger.Message("Second block: " + job, true);
             if (job.targetA.Thing?.Map != null && job.targetA.Thing.Map != pawn.Map)
             {
                 ZUtils.ZTracker.ResetJobTrackerFor(pawn);
                 ZUtils.ZTracker.BuildJobListFor(pawn, job.targetA.Thing.Map, __result);
                 ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(job.targetA.Thing);
                 ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
                 __result = ZUtils.ZTracker.jobTracker[pawn].activeJobs[0];
                 ZUtils.ZTracker.jobTracker[pawn].activeJobs.RemoveAt(0);
             }
             else
             {
                 __result = job;
             }
         }
         recursiveTrap = false;
         CombatPatches_BestAttackTarget_Patch.multiMapSearch = false;
     }
     else if (__result != null && __result.targetA.Thing?.Map != null && __result.targetA.Thing.Map != pawn.Map)
     {
         ZLogger.Message("Second block: " + __result, true);
         ZUtils.ZTracker.ResetJobTrackerFor(pawn);
         ZUtils.ZTracker.BuildJobListFor(pawn, __result.targetA.Thing.Map, __result);
         ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(__result.targetA.Thing);
         ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
         __result = ZUtils.ZTracker.jobTracker[pawn].activeJobs[0];
         ZUtils.ZTracker.jobTracker[pawn].activeJobs.RemoveAt(0);
     }
 }
コード例 #5
0
            private static void Postfix(FloatMenuOption __instance, bool colonistOrdering, FloatMenu floatMenu)
            {
                bool goDown = __instance.Label != "GoDown".Translate();

                if (goDown && __instance.Label != "GoUP".Translate())
                {
                    return;
                }
                if (Find.Selector.SelectedObjects.Count(x => x is Pawn) > 1)
                {
                    foreach (var pawn in Find.Selector.SelectedObjects.Where(x => x is Pawn))
                    {
                        Thing thing;
                        if (goDown)
                        {
                            thing = GenClosest.ClosestThing_Global_Reachable(UI.MouseMapPosition().ToIntVec3()
                                                                             , ((Pawn)pawn).Map, ((Pawn)pawn).Map.listerThings.AllThings
                                                                             .Where(x => x is Building_StairsDown), PathEndMode.OnCell,
                                                                             TraverseParms.For(TraverseMode.ByPawn, Danger.Deadly, false), 9999f);
                            Job job = JobMaker.MakeJob(ZLevelsDefOf.ZL_GoToStairs, thing);
                            ((Pawn)pawn).jobs.StartJob(job, JobCondition.InterruptForced);
                        }
                        else
                        {
                            thing = GenClosest.ClosestThing_Global_Reachable(UI.MouseMapPosition().ToIntVec3()
                                                                             , ((Pawn)pawn).Map, ((Pawn)pawn).Map.listerThings.AllThings
                                                                             .Where(x => x is Building_StairsUp), PathEndMode.OnCell,
                                                                             TraverseParms.For(TraverseMode.ByPawn, Danger.Deadly, false), 9999f);
                            Job job = JobMaker.MakeJob(ZLevelsDefOf.ZL_GoToStairs, thing);
                            ((Pawn)pawn).jobs.StartJob(job, JobCondition.InterruptForced);
                        }
                    }

                    ZLogger.Message("Chosen");
                }
            }
コード例 #6
0
ファイル: JobPatches - Copy.cs プロジェクト: sumghai/Z-Levels
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            try
            {
                ZLogger.Message("--------------------------");
                for (int i = job.targetQueueB.Count - 1; i >= 0; i--)
                {
                    var target = job.targetQueueB[i];

                    ZLogger.Message("-2 job.targetQueueB: " + target.Thing);
                    ZLogger.Message("-2 job.targetQueueB.Map: " + target.Thing.Map);
                    ZLogger.Message("-2 job.targetQueueB.stackCount: " + target.Thing.stackCount);
                    ZLogger.Message("-2 job.targetQueueB.countQueue: " + job.countQueue[i]);
                }
            }
            catch { }

            if (!pawn.Reserve(job.GetTarget(TargetIndex.A), job, 1, -1, null, errorOnFailed))
            {
                return(false);
            }
            pawn.ReserveAsManyAsPossible(job.GetTargetQueue(TargetIndex.B), job);
            return(true);
        }
コード例 #7
0
            public static FloatMenuOption AddArrestOption(Pawn pawn, Pawn victim)
            {
                if (!pawn.CanReach(victim, PathEndMode.OnCell, Danger.Deadly))
                {
                    return(new FloatMenuOption(
                               "CannotArrest".Translate() + ": " + "NoPath".Translate().CapitalizeFirst(), null));
                }
                else
                {
                    Pawn   pTarg2 = victim;
                    Action action = delegate
                    {
                        var  ZTracker     = ZUtils.ZTracker;
                        var  oldMap       = pawn.Map;
                        var  oldPosition1 = pawn.Position;
                        var  oldPosition2 = victim.Position;
                        bool select       = false;
                        if (Find.Selector.SelectedObjects.Contains(pawn))
                        {
                            select = true;
                        }

                        Building building_Bed3 = null;
                        foreach (var otherMap in ZUtils.GetAllMapsInClosestOrderForTwoThings(pawn, oldMap,
                                                                                             oldPosition1, victim, oldMap, oldPosition2))
                        {
                            building_Bed3 = RestUtility.FindBedFor(pTarg2, pawn, sleeperWillBePrisoner: true,
                                                                   checkSocialProperness: false);
                            if (building_Bed3 == null)
                            {
                                building_Bed3 = RestUtility.FindBedFor(pTarg2, pawn, sleeperWillBePrisoner: true,
                                                                       checkSocialProperness: false, ignoreOtherReservations: true);
                            }

                            if (building_Bed3 != null)
                            {
                                break;
                            }
                        }

                        ZUtils.TeleportThing(pawn, oldMap, oldPosition1);
                        ZUtils.TeleportThing(victim, oldMap, oldPosition2);

                        if (select)
                        {
                            Find.Selector.Select(pawn);
                        }

                        if (building_Bed3 == null)
                        {
                            Messages.Message("CannotArrest".Translate() + ": " + "NoPrisonerBed".Translate(),
                                             pTarg2, MessageTypeDefOf.RejectInput, historical: false);
                        }
                        else
                        {
                            Job job = JobMaker.MakeJob(JobDefOf.Arrest, pTarg2, building_Bed3);
                            job.count = 1;
                            ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                            ZLogger.Message(pawn + " taking first job 3");
                            pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);

                            if (pTarg2.Faction != null &&
                                ((pTarg2.Faction != Faction.OfPlayer && !pTarg2.Faction.def.hidden) ||
                                 pTarg2.IsQuestLodger()))
                            {
                                TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.ArrestingCreatesEnemies);
                            }
                        }
                    };
                    return(FloatMenuUtility.DecoratePrioritizedTask(
                               new FloatMenuOption(
                                   "TryToArrest".Translate(victim.LabelCap, victim,
                                                           pTarg2.GetAcceptArrestChance(pawn).ToStringPercent()), action,
                                   MenuOptionPriority.High, null, victim), pawn, pTarg2));
                }
            }
コード例 #8
0
        private void GenerateRiverLookupTexture(Map map, RiverMaker riverMaker)
        {
            int num = Mathf.CeilToInt((from rd in DefDatabase <RiverDef> .AllDefs
                                       select rd.widthOnMap / 2f + 8f).Max());
            int num2 = Mathf.Max(4, num) * 2;
            Dictionary <int, GenStep_TerrainUpper.GRLT_Entry> dictionary  = new Dictionary <int, GenStep_TerrainUpper.GRLT_Entry>();
            Dictionary <int, GenStep_TerrainUpper.GRLT_Entry> dictionary2 = new Dictionary <int, GenStep_TerrainUpper.GRLT_Entry>();
            Dictionary <int, GenStep_TerrainUpper.GRLT_Entry> dictionary3 = new Dictionary <int, GenStep_TerrainUpper.GRLT_Entry>();

            for (int i = -num2; i < map.Size.z + num2; i++)
            {
                for (int j = -num2; j < map.Size.x + num2; j++)
                {
                    IntVec3 intVec  = new IntVec3(j, 0, i);
                    Vector3 vector  = riverMaker.WaterCoordinateAt(intVec);
                    int     entryId = Mathf.FloorToInt(vector.z / 4f);
                    this.UpdateRiverAnchorEntry(dictionary, intVec, entryId, (vector.z + Mathf.Abs(vector.x)) / 4f);
                    this.UpdateRiverAnchorEntry(dictionary2, intVec, entryId, (vector.z + Mathf.Abs(vector.x - (float)num)) / 4f);
                    this.UpdateRiverAnchorEntry(dictionary3, intVec, entryId, (vector.z + Mathf.Abs(vector.x + (float)num)) / 4f);
                }
            }
            int num3 = Mathf.Max(new int[]
            {
                dictionary.Keys.Min(),
                dictionary2.Keys.Min(),
                dictionary3.Keys.Min()
            });
            int num4 = Mathf.Min(new int[]
            {
                dictionary.Keys.Max(),
                dictionary2.Keys.Max(),
                dictionary3.Keys.Max()
            });

            for (int k = num3; k < num4; k++)
            {
                WaterInfo waterInfo = map.waterInfo;
                if (dictionary2.ContainsKey(k) && dictionary2.ContainsKey(k + 1))
                {
                    List <Vector3> riverDebugData = waterInfo.riverDebugData;
                    GenStep_TerrainUpper.GRLT_Entry grlt_Entry = dictionary2[k];
                    riverDebugData.Add(grlt_Entry.bestNode.ToVector3Shifted());
                    List <Vector3> riverDebugData2 = waterInfo.riverDebugData;
                    grlt_Entry = dictionary2[k + 1];
                    riverDebugData2.Add(grlt_Entry.bestNode.ToVector3Shifted());
                }
                if (dictionary.ContainsKey(k) && dictionary.ContainsKey(k + 1))
                {
                    List <Vector3> riverDebugData3             = waterInfo.riverDebugData;
                    GenStep_TerrainUpper.GRLT_Entry grlt_Entry = dictionary[k];
                    riverDebugData3.Add(grlt_Entry.bestNode.ToVector3Shifted());
                    List <Vector3> riverDebugData4 = waterInfo.riverDebugData;
                    grlt_Entry = dictionary[k + 1];
                    riverDebugData4.Add(grlt_Entry.bestNode.ToVector3Shifted());
                }
                if (dictionary3.ContainsKey(k) && dictionary3.ContainsKey(k + 1))
                {
                    List <Vector3> riverDebugData5             = waterInfo.riverDebugData;
                    GenStep_TerrainUpper.GRLT_Entry grlt_Entry = dictionary3[k];
                    riverDebugData5.Add(grlt_Entry.bestNode.ToVector3Shifted());
                    List <Vector3> riverDebugData6 = waterInfo.riverDebugData;
                    grlt_Entry = dictionary3[k + 1];
                    riverDebugData6.Add(grlt_Entry.bestNode.ToVector3Shifted());
                }
                if (dictionary2.ContainsKey(k) && dictionary.ContainsKey(k))
                {
                    List <Vector3> riverDebugData7             = waterInfo.riverDebugData;
                    GenStep_TerrainUpper.GRLT_Entry grlt_Entry = dictionary2[k];
                    riverDebugData7.Add(grlt_Entry.bestNode.ToVector3Shifted());
                    List <Vector3> riverDebugData8 = waterInfo.riverDebugData;
                    grlt_Entry = dictionary[k];
                    riverDebugData8.Add(grlt_Entry.bestNode.ToVector3Shifted());
                }
                if (dictionary.ContainsKey(k) && dictionary3.ContainsKey(k))
                {
                    List <Vector3> riverDebugData9             = waterInfo.riverDebugData;
                    GenStep_TerrainUpper.GRLT_Entry grlt_Entry = dictionary[k];
                    riverDebugData9.Add(grlt_Entry.bestNode.ToVector3Shifted());
                    List <Vector3> riverDebugData10 = waterInfo.riverDebugData;
                    grlt_Entry = dictionary3[k];
                    riverDebugData10.Add(grlt_Entry.bestNode.ToVector3Shifted());
                }
            }
            CellRect cellRect = new CellRect(-2, -2, map.Size.x + 4, map.Size.z + 4);

            float[] array = new float[cellRect.Area * 2];
            int     num5  = 0;

            for (int l = cellRect.minZ; l <= cellRect.maxZ; l++)
            {
                for (int m = cellRect.minX; m <= cellRect.maxX; m++)
                {
                    IntVec3 a    = new IntVec3(m, 0, l);
                    bool    flag = true;
                    for (int n = 0; n < GenAdj.AdjacentCellsAndInside.Length; n++)
                    {
                        if (riverMaker.TerrainAt(a + GenAdj.AdjacentCellsAndInside[n], false) != null)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        Vector2 p    = a.ToIntVec2.ToVector2();
                        int     num6 = int.MinValue;
                        Vector2 zero = Vector2.zero;
                        for (int num7 = num3; num7 < num4; num7++)
                        {
                            if (dictionary2.ContainsKey(num7) && dictionary2.ContainsKey(num7 + 1) && dictionary.ContainsKey(num7) && dictionary.ContainsKey(num7 + 1) && dictionary3.ContainsKey(num7) && dictionary3.ContainsKey(num7 + 1))
                            {
                                GenStep_TerrainUpper.GRLT_Entry grlt_Entry = dictionary2[num7];
                                Vector2 p2 = grlt_Entry.bestNode.ToIntVec2.ToVector2();
                                grlt_Entry = dictionary2[num7 + 1];
                                Vector2 p3 = grlt_Entry.bestNode.ToIntVec2.ToVector2();
                                grlt_Entry = dictionary[num7];
                                Vector2 p4 = grlt_Entry.bestNode.ToIntVec2.ToVector2();
                                grlt_Entry = dictionary[num7 + 1];
                                Vector2 p5 = grlt_Entry.bestNode.ToIntVec2.ToVector2();
                                grlt_Entry = dictionary3[num7];
                                Vector2 p6 = grlt_Entry.bestNode.ToIntVec2.ToVector2();
                                grlt_Entry = dictionary3[num7 + 1];
                                Vector2 p7      = grlt_Entry.bestNode.ToIntVec2.ToVector2();
                                Vector2 vector2 = GenGeo.InverseQuadBilinear(p, p4, p2, p5, p3);
                                if (vector2.x >= -0.0001f && vector2.x <= 1.0001f && vector2.y >= -0.0001f && vector2.y <= 1.0001f)
                                {
                                    zero = new Vector2(-vector2.x * (float)num, (vector2.y + (float)num7) * 4f);
                                    num6 = num7;
                                    break;
                                }
                                Vector2 vector3 = GenGeo.InverseQuadBilinear(p, p4, p6, p5, p7);
                                if (vector3.x >= -0.0001f && vector3.x <= 1.0001f && vector3.y >= -0.0001f && vector3.y <= 1.0001f)
                                {
                                    zero = new Vector2(vector3.x * (float)num, (vector3.y + (float)num7) * 4f);
                                    num6 = num7;
                                    break;
                                }
                            }
                        }
                        if (num6 == -2147483648)
                        {
                            ZLogger.ErrorOnce("Failed to find all necessary river flow data", true);
                        }
                        array[num5]     = zero.x;
                        array[num5 + 1] = zero.y;
                    }
                    num5 += 2;
                }
            }
            float[] array2 = new float[cellRect.Area * 2];
            float[] array3 = new float[]
            {
                0.123317f,
                0.123317f,
                0.123317f,
                0.123317f,
                0.077847f,
                0.077847f,
                0.077847f,
                0.077847f,
                0.195346f
            };
            int num8 = 0;

            for (int num9 = cellRect.minZ; num9 <= cellRect.maxZ; num9++)
            {
                for (int num10 = cellRect.minX; num10 <= cellRect.maxX; num10++)
                {
                    IntVec3 a2    = new IntVec3(num10, 0, num9);
                    float   num11 = 0f;
                    float   num12 = 0f;
                    float   num13 = 0f;
                    for (int num14 = 0; num14 < GenAdj.AdjacentCellsAndInside.Length; num14++)
                    {
                        IntVec3 c = a2 + GenAdj.AdjacentCellsAndInside[num14];
                        if (cellRect.Contains(c))
                        {
                            int num15 = num8 + (GenAdj.AdjacentCellsAndInside[num14].x + GenAdj.AdjacentCellsAndInside[num14].z * cellRect.Width) * 2;
                            if (array[num15] != 0f || array[num15 + 1] != 0f)
                            {
                                num11 += array[num15] * array3[num14];
                                num12 += array[num15 + 1] * array3[num14];
                                num13 += array3[num14];
                            }
                        }
                    }
                    if (num13 > 0f)
                    {
                        array2[num8]     = num11 / num13;
                        array2[num8 + 1] = num12 / num13;
                    }
                    num8 += 2;
                }
            }
            array = array2;
            for (int num16 = 0; num16 < array.Length; num16 += 2)
            {
                if (array[num16] != 0f || array[num16 + 1] != 0f)
                {
                    Vector2 vector4 = Rand.InsideUnitCircle * 0.4f;
                    array[num16]     += vector4.x;
                    array[num16 + 1] += vector4.y;
                }
            }
            byte[] array4 = new byte[array.Length * 4];
            Buffer.BlockCopy(array, 0, array4, 0, array.Length * 4);
            map.waterInfo.riverOffsetMap = array4;
            map.waterInfo.GenerateRiverFlowMap();
        }
コード例 #9
0
        public override void Tick()
        {
            base.Tick();
            var baseComp = this.GetComp <CompPowerZTransmitter>();

            if (baseComp.PowerNet != null)
            {
                //if (baseComp.PowerNet.powerComps.Where(x => x is CompPowerZTransmitter).Count() > 1
                //    && this.lowerPowerComp == null && this.upperPowerComp == null)
                //{
                //    ZLogger.Message("1 Removing " + baseComp + " - " + baseComp.GetHashCode(), true);
                //    baseComp.PowerNet.powerComps.Remove(baseComp);
                //}

                if (baseComp != null && baseComp.PowerNet.powerComps.Contains(baseComp))
                {
                    if (!baseComp.PowerNet.powerComps.Contains(baseComp))
                    {
                        ZLogger.Message("1 Adding " + baseComp + " - " + baseComp.GetHashCode(), true);
                        baseComp.PowerNet.powerComps.Add(baseComp);
                    }
                    var powerComps = new List <CompPowerZTransmitter>();
                    if (connectedPowerNets.powerNets == null)
                    {
                        ZLogger.Message("2 Adding " + baseComp + " - " + baseComp.GetHashCode(), true);
                        powerComps.Add(baseComp);
                        connectedPowerNets.powerNets = new Dictionary <int, List <CompPowerZTransmitter> >
                        {
                            { 0, powerComps }
                        };
                    }
                    else if (connectedPowerNets.powerNets.Count == 0)
                    {
                        ZLogger.Message("3 Adding " + baseComp + " - " + baseComp.GetHashCode(), true);
                        powerComps.Add(baseComp);
                        connectedPowerNets.powerNets.Add(0, powerComps);
                    }
                    else if (connectedPowerNets.powerNets.Values.Where(x => x.Where(y => y.PowerNet == baseComp.PowerNet &&
                                                                                    y.PowerNet.powerComps.Exists(c => c is CompPowerZTransmitter)).Any()).Count() == 0)
                    {
                        ZLogger.Message("4 Adding " + baseComp + " - " + baseComp.GetHashCode(), true);
                        powerComps.Add(baseComp);
                        int maxKey = connectedPowerNets.powerNets.Max(x => x.Key);
                        connectedPowerNets.powerNets.Add(maxKey + 1, powerComps);
                    }
                    else
                    {
                        powerComps = connectedPowerNets.powerNets.Values.Where(x => x
                                                                               .Where(y => y.PowerNet == baseComp.PowerNet).Count() == 1).ToList().First();
                    }

                    var upperMap = ZTracker.GetUpperLevel(this.Map.Tile, this.Map);
                    var lowerMap = ZTracker.GetLowerLevel(this.Map.Tile, this.Map);

                    if (Find.TickManager.TicksGame % 60 == 0)
                    {
                        ZLogger.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.upperTransmitter: " + this.upperTransmitter);
                        ZLogger.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.upperTransmitter.Spawned: " + this.upperTransmitter?.Spawned);
                        ZLogger.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.upperPowerComp: " + this.upperPowerComp);
                        ZLogger.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.lowerTransmitter: " + this.lowerTransmitter);
                        ZLogger.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.lowerTransmitter.Spawned: " + this.lowerTransmitter?.Spawned);
                        ZLogger.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.lowerPowerComp: " + this.lowerPowerComp);
                    }

                    if (this.upperPowerComp != null && (upperTransmitter == null || !upperTransmitter.Spawned))
                    {
                        this.upperPowerComp = null;
                        upperTransmitter    = null;
                    }
                    if (this.lowerPowerComp != null && (lowerTransmitter == null || !lowerTransmitter.Spawned))
                    {
                        this.lowerPowerComp = null;
                        lowerTransmitter    = null;
                    }
                    if (upperMap != null && this.upperPowerComp == null && Find.TickManager.TicksGame % 200 == 0)
                    {
                        foreach (var pos in GenRadial.RadialCellsAround(this.Position, 3f, true))
                        {
                            foreach (var t in pos.GetThingList(upperMap))
                            {
                                ZLogger.Message("Power candidate: " + t);
                                if (t.TryGetComp <CompPowerTransmitter>() != null)
                                {
                                    upperTransmitter = t;
                                    var upperComp = upperTransmitter.TryGetComp <CompPowerTransmitter>();
                                    upperPowerComp = (CompPowerZTransmitter)upperComp.PowerNet.powerComps
                                                     .Where(x => x is CompPowerZTransmitter).FirstOrDefault();
                                    if (upperPowerComp == null)
                                    {
                                        upperPowerComp = new CompPowerZTransmitter
                                        {
                                            parent         = this,
                                            powerOutputInt = 0,
                                            transNet       = upperComp.transNet
                                        };
                                        upperPowerComp.Initialize(new CompProperties_PowerZTransmitter());
                                        ZLogger.Message("5 Adding " + upperPowerComp + " - " + upperPowerComp.GetHashCode(), true);
                                        upperComp.PowerNet.powerComps.Add(upperPowerComp);
                                    }
                                    if (upperPowerComp != null && !powerComps.Contains(upperPowerComp))
                                    {
                                        ZLogger.Message("6 Adding " + upperPowerComp + " - " + upperPowerComp.GetHashCode(), true);
                                        powerComps.Add(upperPowerComp);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (lowerMap != null && this.lowerPowerComp == null && Find.TickManager.TicksGame % 200 == 0)
                    {
                        foreach (var pos in GenRadial.RadialCellsAround(this.Position, 3f, true))
                        {
                            foreach (var t in pos.GetThingList(lowerMap))
                            {
                                if (t.TryGetComp <CompPowerTransmitter>() != null)
                                {
                                    lowerTransmitter = t;
                                    var lowerComp = lowerTransmitter.TryGetComp <CompPowerTransmitter>();
                                    lowerPowerComp = (CompPowerZTransmitter)lowerComp.PowerNet
                                                     .powerComps.Where(x => x is CompPowerZTransmitter).FirstOrDefault();
                                    if (lowerPowerComp == null)
                                    {
                                        lowerPowerComp = new CompPowerZTransmitter
                                        {
                                            parent         = this,
                                            powerOutputInt = 0,
                                            transNet       = lowerComp.transNet,
                                        };
                                        lowerPowerComp.Initialize(new CompProperties_PowerZTransmitter());
                                        ZLogger.Message("7 Adding " + lowerPowerComp + " - " + lowerPowerComp.GetHashCode(), true);
                                        lowerComp.PowerNet.powerComps.Add(lowerPowerComp);
                                    }
                                    if (lowerPowerComp != null && !powerComps.Contains(lowerPowerComp))
                                    {
                                        ZLogger.Message(this + " Lower add " + lowerPowerComp);
                                        ZLogger.Message("8 Adding " + lowerPowerComp + " - " + lowerPowerComp.GetHashCode(), true);
                                        powerComps.Add(lowerPowerComp);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (this.ticksToExplode > 0)
            {
                if (this.wickSustainer == null)
                {
                    this.StartWickSustainer();
                }
                else
                {
                    this.wickSustainer.Maintain();
                }
                this.ticksToExplode--;
                if (this.ticksToExplode == 0)
                {
                    IntVec3 randomCell = this.OccupiedRect().RandomCell;
                    float   radius     = Rand.Range(0.5f, 1f) * 3f;
                    GenExplosion.DoExplosion(randomCell, base.Map, radius, DamageDefOf.Flame, null, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false, null, null);
                }
            }
        }
コード例 #10
0
        public override IEnumerable <Toil> MakeNewToils()
        {
            Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var ZTracker = ZUtils.ZTracker; - 5", true);
            var ZTracker = ZUtils.ZTracker;

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Log.Message("pawn.Map: " + pawn.Map);
                    Log.Message("this.job.targetA.Thing.Map: " + this.job.targetA.Thing?.Map);
                    Log.Message("ZTracker.jobTracker[pawn].targetDest.Map: " + ZTracker.jobTracker[pawn].targetDest.Map);

                    if (pawn.Map == this.job.targetA.Thing?.Map && pawn.Map == ZTracker.jobTracker[pawn].targetDest.Map)
                    {
                        ZLogger.Message("pawn map and thing map and dest map are same, yield breaking in JobDriver_HaulThingToDest");
                        this.EndJobWith(JobCondition.InterruptForced);
                    }
                    this.savedThing = this.job.targetA.Thing;
                }
            });

            Toil reserveItem = Toils_Reserve.Reserve(TargetIndex.A);

            Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (TargetA.Thing?.Map != null) - 12", true);
            if (TargetA.Thing?.Map != null)
            {
                Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), new TargetInfo(TargetA.Thing).Map, this)) - 13", true);
                foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), new TargetInfo(TargetA.Thing).Map, this))
                {
                    yield return(new Toil {
                        initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return toil; - 14", true); }
                    });

                    yield return(toil);
                }
            }

            Toil toilGoto = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch);

            yield return(new Toil {
                initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return reserveItem.FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A); - 16", true); }
            });

            yield return(reserveItem.FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            yield return(new Toil {
                initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return toilGoto; - 17", true); }
            });

            yield return(toilGoto);

            yield return(new Toil {
                initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true).FailOnDestroyedNullOrForbidden(TargetIndex.A); - 18", true); }
            });

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true).FailOnDestroyedNullOrForbidden(TargetIndex.A));

            Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (job.haulOpportunisticDuplicates) - 19", true);
            if (job.haulOpportunisticDuplicates)
            {
                yield return(new Toil {
                    initAction = delegate() { Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - yield return Toils_Haul.CheckForGetOpportunityDuplicate(reserveItem, TargetIndex.A, TargetIndex.None, takeFromValidStorage: true); - 20", true); }
                });

                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveItem, TargetIndex.A, TargetIndex.None, takeFromValidStorage: true));
            }
            yield return(Toils_Haul.JumpIfAlsoCollectingNextTargetInQueue(toilGoto, TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Log.Message("Pawn: " + pawn);
                    Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (ZTracker.jobTracker.TryGetValue(pawn, out JobTracker jobTracker)) - 23", true);
                    if (ZTracker.jobTracker.TryGetValue(pawn, out JobTracker jobTracker))
                    {
                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetA.Thing != null && jobTracker.mainJob.targetA.Thing == this.savedThing && jobTracker.mainJob.targetA.Thing != TargetA.Thing) - 24", true);
                        if (jobTracker.mainJob.targetA.Thing != null && jobTracker.mainJob.targetA.Thing == this.savedThing && jobTracker.mainJob.targetA.Thing != TargetA.Thing)
                        {
                            Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetA = new LocalTargetInfo(TargetA.Thing); - 25", true);
                            jobTracker.mainJob.targetA = new LocalTargetInfo(TargetA.Thing);
                        }
                        else if (jobTracker.mainJob.targetB.Thing != null && jobTracker.mainJob.targetB.Thing == this.savedThing && jobTracker.mainJob.targetB.Thing != TargetA.Thing)
                        {
                            Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetB = new LocalTargetInfo(TargetA.Thing); - 27", true);
                            jobTracker.mainJob.targetB = new LocalTargetInfo(TargetA.Thing);
                        }
                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetQueueA != null) - 28", true);
                        if (jobTracker.mainJob.targetQueueA != null)
                        {
                            for (int i = jobTracker.mainJob.targetQueueA.Count - 1; i >= 0; i--)
                            {
                                Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var target = jobTracker.mainJob.targetQueueA[i]; - 29", true);
                                var target = jobTracker.mainJob.targetQueueA[i];
                                Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) - 30", true);
                                if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing)
                                {
                                    Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueA[i] = new LocalTargetInfo(TargetA.Thing); - 31", true);
                                    jobTracker.mainJob.targetQueueA[i] = new LocalTargetInfo(TargetA.Thing);
                                }
                            }
                        }
                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetQueueB != null) - 32", true);
                        if (jobTracker.mainJob.targetQueueB != null)
                        {
                            for (int i = jobTracker.mainJob.targetQueueB.Count - 1; i >= 0; i--)
                            {
                                Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var target = jobTracker.mainJob.targetQueueB[i]; - 33", true);
                                var target = jobTracker.mainJob.targetQueueB[i];
                                Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing) - 34", true);
                                if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing)
                                {
                                    Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - if (jobTracker.mainJob.targetQueueB[i].Thing.stackCount == 0) - 35", true);
                                    if (jobTracker.mainJob.targetQueueB[i].Thing.stackCount == 0)
                                    {
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueB[i] = new LocalTargetInfo(TargetA.Thing); - 36", true);
                                        jobTracker.mainJob.targetQueueB[i] = new LocalTargetInfo(TargetA.Thing);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.countQueue[i] = TargetA.Thing.stackCount; - 37", true);
                                        jobTracker.mainJob.countQueue[i] = TargetA.Thing.stackCount;
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - break; - 38", true);
                                        break;
                                    }
                                    else if (!jobTracker.mainJob.targetQueueB.Any(x => x.Thing == TargetA.Thing))
                                    {
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - var newTarget = new LocalTargetInfo(TargetA.Thing); - 40", true);
                                        var newTarget = new LocalTargetInfo(TargetA.Thing);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueB.Add(newTarget); - 41", true);
                                        jobTracker.mainJob.targetQueueB.Add(newTarget);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.countQueue.Add(newTarget.Thing.stackCount); - 42", true);
                                        jobTracker.mainJob.countQueue.Add(newTarget.Thing.stackCount);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - int ind = jobTracker.mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing); - 43", true);
                                        int ind = jobTracker.mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.targetQueueB.RemoveAt(ind); - 44", true);
                                        jobTracker.mainJob.targetQueueB.RemoveAt(ind);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - jobTracker.mainJob.countQueue.RemoveAt(ind); - 45", true);
                                        jobTracker.mainJob.countQueue.RemoveAt(ind);
                                        Log.Message("JobDriver_HaulThingToDest : JobDriver_ZLevels - MakeNewToils - break; - 46", true);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            });
コード例 #11
0
        private static void Postfix(ref bool __result, Pawn claimant, LocalTargetInfo target, bool __state, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
        {
            if (__state)
            {
                ZUtils.TeleportThing(claimant, oldMap, oldPosition);
            }
            if (__result)
            {
                var ZTracker = ZUtils.ZTracker;
                if (claimant.RaceProps.Humanlike && ZTracker.jobTracker != null)
                {
                    var thing = target.thingInt;
                    if (thing != null)
                    {
                        foreach (var data in ZTracker.jobTracker)
                        {
                            var otherPawn           = data.Key;
                            var otherPawnJobTracker = data.Value;
                            if (otherPawn != claimant && otherPawnJobTracker.reservedThings != null)
                            {
                                foreach (var reservation in otherPawnJobTracker.reservedThings)
                                {
                                    if (reservation.thingInt == target.thingInt)
                                    {
                                        var shouldChangeResult = !(otherPawn.jobs?.curDriver is JobDriver_TakeToBed);// || !(data.Key.jobs?.curDriver is JobDriver_LayDown));
                                        if (shouldChangeResult)
                                        {
                                            try
                                            {
                                                ZLogger.Message("reservation.thingInt: " + reservation.thingInt + " - target.thingInt: " + target.thingInt);
                                                ZLogger.Message(data.Key + " - 1 data.Value.mainJob: " + data.Value.mainJob);
                                                ZLogger.Message(data.Key + " - 1 data.Key.CurJob: " + data.Key.CurJob);
                                                ZLogger.Message(data.Key + " - 1 thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key): " + thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key));
                                            }
                                            catch
                                            {
                                            }
                                            if (otherPawn.Map == thing.Map && !thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == otherPawn))
                                            {
                                                ZLogger.Message($"PREVENTED ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                                continue;
                                            }
                                            __result = false;
                                            ZLogger.Message($"shouldChangeResult Detected ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                            return;
                                        }
                                    }
                                    //Log.Message($"ZTracker reservation: map: Reservation: {data.Key}, target: {reservation}, {data.Key.Map} - {reservation.Thing?.Map}");
                                }
                            }
                        }
                    }
                    else if (ZTracker.jobTracker.TryGetValue(claimant, out var jobTracker) && jobTracker.lookedAtLocalCellMap.TryGetValue(target.cellInt, out var mapDest) && mapDest != null)
                    {
                        var cell = target.cellInt;
                        foreach (var data in ZTracker.jobTracker)
                        {
                            var otherPawn           = data.Key;
                            var otherPawnJobTracker = data.Value;
                            if (otherPawn != claimant && otherPawnJobTracker.reservedCells != null)
                            {
                                foreach (var reservation in otherPawnJobTracker.reservedCells)
                                {
                                    if (reservation.cellInt == cell && otherPawnJobTracker.mapDest == jobTracker.mapDest)
                                    {
                                        try
                                        {
                                            ZLogger.Message("claimant: " + claimant + " - " + otherPawn + " - 2 data.Value.mainJob: " + data.Value.mainJob);
                                            ZLogger.Message("claimant: " + claimant + " - " + otherPawn + " - 2 data.Key.CurJob: " + data.Key.CurJob);
                                            ZLogger.Message("claimant: " + claimant + " - " + otherPawn + " - 2 jobTracker.lookedAtMap.reservationManager.reservations.Any(x => !x.Target.HasThing && x.Target.cellInt == cell && x.claimant == data.Key)): " + jobTracker.mapDest.reservationManager.reservations.Any(x => !x.Target.HasThing && x.Target.cellInt == cell && x.claimant == data.Key));
                                        }
                                        catch { }
                                        if (otherPawn.Map == jobTracker.mapDest && !jobTracker.mapDest.reservationManager.reservations.Any(x => !x.Target.HasThing && x.Target.cellInt == cell && x.claimant == otherPawn))
                                        {
                                            ZLogger.Message($"2 PREVENTED ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, cell: {cell}");
                                            continue;
                                        }
                                        __result = false;
                                        ZLogger.Message($"reservation.cellInt == cell 2 Detected ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, cell: {cell}");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (ZLogger.DebugEnabled)
            {
                if (!__result)
                {
                    ZLogger.Error($"claimant {claimant} can't reserve target: {target}");
                }
            }
        }
コード例 #12
0
        public override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            //this.FailOnBurningImmobile(TargetIndex.B);
            if (!forbiddenInitially)
            {
                this.FailOnForbidden(TargetIndex.A);
            }
            var ZTracker = ZUtils.ZTracker;

            if (pawn.Map == this.job.targetA.Thing.Map && pawn.Map == ZTracker.jobTracker[pawn].targetDest.Map)
            {
                ZLogger.Message("pawn map and thing map and dest map are same, yield breaking in JobDriver_HaulThingToDest");
                yield break;
            }
            ZLogger.Message($"JobDriver HaulThingToDestAndCell1 About to call findRouteWithStairs, with pawn {GetActor()}, dest {new TargetInfo(TargetA.Thing)}, instance {this}");
            Log.Message("1 - pawn.Map: " + pawn.Map + " - dest: " + new TargetInfo(TargetA.Thing).Map);
            foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), new TargetInfo(TargetA.Thing).Map, this))
            {
                yield return(toil);
            }
            Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A);
            Toil toilGoto       = null;

            toilGoto = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A).FailOn((Func <bool>) delegate
            {
                Pawn actor = toilGoto.actor;
                Job curJob = actor.jobs.curJob;
                if (curJob.haulMode == HaulMode.ToCellStorage)
                {
                    Thing thing = curJob.GetTarget(TargetIndex.A).Thing;
                    if (!actor.jobs.curJob.GetTarget(TargetIndex.B).Cell.IsValidStorageFor(base.Map, thing))
                    {
                        return(true);
                    }
                }
                return(false);
            });

            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("JobDriver_HaulThingToDestAndToCell 1: " + pawn + " trying to reserve: " + TargetA);
                }
            });

            yield return(reserveTargetA);

            yield return(toilGoto);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    this.savedThing = TargetA.Thing;
                }
            });

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true));

            if (job.haulOpportunisticDuplicates)
            {
                yield return(new Toil
                {
                    initAction = delegate()
                    {
                        ZLogger.Message("JobDriver_HaulThingToDestAndToCell 2: " + pawn + " trying to reserve other things: " + TargetA);
                    }
                });

                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveTargetA, TargetIndex.A, TargetIndex.B));
            }
            ZLogger.Message($"JobDriver HaulThingToDestAndCell2 About to call findRouteWithStairs, with pawn {GetActor()}, dest {ZTracker.jobTracker[pawn].targetDest}, instance {this}");
            Log.Message("2 - pawn.Map: " + pawn.Map + " - dest: " + ZTracker.jobTracker[pawn].targetDest.Map);
            foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), ZTracker.jobTracker[pawn].targetDest.Map, this))
            {
                yield return(toil);
            }
            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (TargetB.Cell.GetFirstItem(pawn.Map) != null)
                    {
                        IntVec3 newPosition = IntVec3.Invalid;

                        IntVec3 center = (from x in GenRadial.RadialCellsAround(pawn.Position, 3f, useCenter: true)
                                          where x.InBounds(pawn.Map) && x.GetFirstItem(pawn.Map) == null
                                          select x).FirstOrDefault();
                        if (center != null)
                        {
                            job.targetB = new LocalTargetInfo(center);
                        }
                        else if (CellFinder.TryFindRandomCellNear(TargetB.Cell, pawn.Map, 3,
                                                                  (IntVec3 c) => c.GetFirstItem(pawn.Map)?.def != TargetA.Thing.def, out newPosition))
                        {
                            job.targetB = new LocalTargetInfo(newPosition);
                        }
                    }
                }
            });

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, false));
        }
コード例 #13
0
            public static FloatMenuOption AddCaptureOption(Pawn pawn, Pawn victim)
            {
                var floatOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Capture".Translate
                                                                                                   (victim.LabelCap, victim), delegate()
                {
                    var ZTracker     = ZUtils.ZTracker;
                    var oldMap       = pawn.Map;
                    var oldPosition1 = pawn.Position;
                    var oldPosition2 = victim.Position;
                    bool select      = false;
                    if (Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        select = true;
                    }

                    Building building_Bed = null;
                    foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
                    {
                        ZLogger.Message("Searching rest job for " + pawn + " in " + ZTracker.GetMapInfo(otherMap)
                                        + " for " + ZTracker.GetMapInfo(oldMap));

                        var stairs = new List <Thing>();

                        if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap))
                        {
                            Map lowerMap = ZTracker.GetLowerLevel(otherMap.Tile, otherMap);
                            if (lowerMap != null)
                            {
                                stairs = ZTracker.stairsUp[lowerMap];
                            }
                            else
                            {
                                ZLogger.Message("Lower map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }
                        else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap))
                        {
                            Map upperMap = ZTracker.GetUpperLevel(otherMap.Tile, otherMap);
                            if (upperMap != null)
                            {
                                stairs = ZTracker.stairsDown[upperMap];
                            }
                            else
                            {
                                ZLogger.Message("Upper map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }

                        if (stairs != null && stairs.Count() > 0)
                        {
                            var selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position));
                            var position       = selectedStairs.Position;

                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(position);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(position);
                        }
                        else if (pawn.Map != oldMap && otherMap == oldMap)
                        {
                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(oldPosition1);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(oldPosition2);
                        }


                        building_Bed = RestUtility.FindBedFor(victim, pawn, true, false, false);
                        if (building_Bed == null)
                        {
                            building_Bed = RestUtility.FindBedFor(victim, pawn, true, false, true);
                        }
                        if (building_Bed != null)
                        {
                            break;
                        }
                    }

                    Traverse.Create(pawn).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(pawn).Field("positionInt")
                    .SetValue(oldPosition1);

                    Traverse.Create(victim).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(victim).Field("positionInt")
                    .SetValue(oldPosition2);

                    if (select)
                    {
                        Find.Selector.Select(pawn);
                    }

                    if (building_Bed == null)
                    {
                        Messages.Message("CannotCapture".Translate() + ": " + "NoPrisonerBed".Translate(), victim, MessageTypeDefOf.RejectInput, false);
                        return;
                    }
                    Job job   = JobMaker.MakeJob(JobDefOf.Capture, victim, building_Bed);
                    job.count = 1;
                    ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                    ZLogger.Message(pawn + " taking first job 3");
                    pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Capturing, KnowledgeAmount.Total);
                    if (victim.Faction != null && victim.Faction != Faction.OfPlayer && !victim.Faction.def.hidden && !victim.Faction.HostileTo(Faction.OfPlayer) && !victim.IsPrisonerOfColony)
                    {
                        Messages.Message("MessageCapturingWillAngerFaction".Translate(victim.Named("PAWN"))
                                         .AdjustedFor(victim, "PAWN", true), victim, MessageTypeDefOf.CautionInput, false);
                    }
                }, MenuOptionPriority.RescueOrCapture, null, victim, 0f, null, null), pawn, victim, "ReservedBy");

                return(floatOption);
            }
コード例 #14
0
        public static void TryFixPawnError(Pawn pawn)
        {
            if (pawn.rotationTracker == null)
            {
                ZLogger.Pause(pawn + " Pawn_RotationTracker IS NULL. FIXING");
                pawn.rotationTracker = new Pawn_RotationTracker(pawn);
            }
            if (pawn.pather == null)
            {
                ZLogger.Pause(pawn + " Pawn_PathFollower IS NULL. FIXING");
                pawn.pather = new Pawn_PathFollower(pawn);
            }
            if (pawn.thinker == null)
            {
                ZLogger.Pause(pawn + " Pawn_Thinker IS NULL. FIXING");
                pawn.thinker = new Pawn_Thinker(pawn);
            }
            if (pawn.jobs == null)
            {
                ZLogger.Pause(pawn + " Pawn_JobTracker IS NULL. FIXING");
                pawn.jobs = new Pawn_JobTracker(pawn);
            }
            if (pawn.stances == null)
            {
                ZLogger.Pause(pawn + " Pawn_StanceTracker IS NULL. FIXING");
                pawn.stances = new Pawn_StanceTracker(pawn);
            }
            if (pawn.natives == null)
            {
                ZLogger.Pause(pawn + " Pawn_NativeVerbs IS NULL. FIXING");
                pawn.natives = new Pawn_NativeVerbs(pawn);
            }
            if (pawn.filth == null)
            {
                ZLogger.Pause(pawn + " Pawn_FilthTracker IS NULL. FIXING");
                pawn.filth = new Pawn_FilthTracker(pawn);
            }
            if ((int)pawn.RaceProps.intelligence <= 1 && pawn.caller == null)
            {
                ZLogger.Pause(pawn + " Pawn_CallTracker IS NULL. FIXING");
                pawn.caller = new Pawn_CallTracker(pawn);
            }
            if (pawn.RaceProps.IsFlesh)
            {
                if (pawn.interactions == null)
                {
                    ZLogger.Pause(pawn + " Pawn_InteractionsTracker IS NULL. FIXING");
                    pawn.interactions = new Pawn_InteractionsTracker(pawn);
                }
                if (pawn.psychicEntropy == null)
                {
                    ZLogger.Pause(pawn + " Pawn_PsychicEntropyTracker IS NULL. FIXING");
                    pawn.psychicEntropy = new Pawn_PsychicEntropyTracker(pawn);
                }
                if (pawn.abilities == null)
                {
                    ZLogger.Pause(pawn + " Pawn_AbilityTracker IS NULL. FIXING");
                    pawn.abilities = new Pawn_AbilityTracker(pawn);
                }
            }

            bool flag  = pawn.Faction != null && pawn.Faction.IsPlayer;
            bool flag2 = pawn.HostFaction != null && pawn.HostFaction.IsPlayer;

            if (pawn.RaceProps.Humanlike && !pawn.Dead)
            {
                if (pawn.mindState.wantsToTradeWithColony)
                {
                    if (pawn.trader == null)
                    {
                        ZLogger.Pause(pawn + " Pawn_TraderTracker IS NULL. FIXING");
                        pawn.trader = new Pawn_TraderTracker(pawn);
                    }
                }
            }
            if (pawn.RaceProps.Humanlike)
            {
                if ((flag || flag2) && pawn.foodRestriction == null)
                {
                    ZLogger.Pause(pawn + " Pawn_FoodRestrictionTracker IS NULL. FIXING");

                    pawn.foodRestriction = new Pawn_FoodRestrictionTracker(pawn);
                }
                if (flag)
                {
                    if (pawn.outfits == null)
                    {
                        ZLogger.Pause(pawn + " Pawn_OutfitTracker IS NULL. FIXING");

                        pawn.outfits = new Pawn_OutfitTracker(pawn);
                    }
                    if (pawn.drugs == null)
                    {
                        ZLogger.Pause(pawn + " Pawn_DrugPolicyTracker IS NULL. FIXING");

                        pawn.drugs = new Pawn_DrugPolicyTracker(pawn);
                    }
                    if (pawn.timetable == null)
                    {
                        ZLogger.Pause(pawn + " Pawn_TimetableTracker IS NULL. FIXING");

                        pawn.timetable = new Pawn_TimetableTracker(pawn);
                    }
                    if (pawn.drafter == null)
                    {
                        ZLogger.Pause(pawn + " Pawn_DraftController IS NULL. FIXING");

                        pawn.drafter = new Pawn_DraftController(pawn);
                    }
                }
            }
            if ((flag || flag2) && pawn.playerSettings == null)
            {
                ZLogger.Pause(pawn + " Pawn_PlayerSettings IS NULL. FIXING");
                pawn.playerSettings = new Pawn_PlayerSettings(pawn);
            }
            if ((int)pawn.RaceProps.intelligence <= 1 && pawn.Faction != null && !pawn.RaceProps.IsMechanoid && pawn.training == null)
            {
                ZLogger.Pause(pawn + " Pawn_TrainingTracker IS NULL. FIXING");
                pawn.training = new Pawn_TrainingTracker(pawn);
            }
        }
コード例 #15
0
        public static void Prefix(ColonistBar __instance, ref List <ColonistBar.Entry> ___cachedEntries,
                                  ref List <Vector2> ___cachedDrawLocs)
        {
            try
            {
                if (___cachedDrawLocs.Count == ___cachedEntries.Count)
                {
                    for (int i = 0; i < ___cachedDrawLocs.Count; i++)
                    {
                        if (___cachedEntries[i].pawn == null && ___cachedEntries[i].map.Parent is MapParent_ZLevel)
                        {
                            //ZLogger.Message("Rect: " + ___cachedDrawLocs[i].x + " - " + ___cachedDrawLocs[i].y + " - "
                            //      + __instance.Size.x + " - " + __instance.Size.y);
                            Rect rect = new Rect(___cachedDrawLocs[i].x + (__instance.Size.x / 1.25f),
                                                 ___cachedDrawLocs[i].y + (__instance.Size.y / 1.25f),
                                                 __instance.Size.x / 3, __instance.Size.y / 3);
                            GUI.DrawTexture(rect, AbandonButtonTex);
                            if (Mouse.IsOver(rect))
                            {
                                if (Input.GetMouseButtonDown(0) && ___cachedEntries[i].map != null)
                                {
                                    Map map = ___cachedEntries[i].map;
                                    Find.WindowStack.Add(new Dialog_MessageBox("ZAbandonConfirmation".Translate(), "Yes".Translate(), delegate()
                                    {
                                        var comp        = map.GetComponent <MapComponentZLevel>();
                                        var pathToWrite = Path.Combine(Path.Combine(GenFilePaths.ConfigFolderPath,
                                                                                    "SavedMaps"), map.Tile + " - " + comp.Z_LevelIndex + ".xml");
                                        if (map.listerThings.AllThings.Count > 0)
                                        {
                                            BlueprintUtility.SaveEverything(pathToWrite, map, "SavedMap");
                                            ZLogger.Message("Removing map: " + map);
                                        }
                                        var parent   = map.Parent as MapParent_ZLevel;
                                        var ZTracker = ZUtils.ZTracker;
                                        parent.Abandon();
                                        ZTracker.ZLevelsTracker[map.Tile].ZLevels.Remove(comp.Z_LevelIndex);

                                        foreach (var map2 in Find.Maps)
                                        {
                                            var comp2 = map2.GetComponent <MapComponentZLevel>();
                                            if (ZTracker.ZLevelsTracker[map2.Tile] != null)
                                            {
                                                foreach (var d in ZTracker.ZLevelsTracker[map2.Tile].ZLevels)
                                                {
                                                    ZLogger.Message(map2 + ": " + d.Key + " - " + d.Value);
                                                }
                                            }
                                        }
                                    }, "No".Translate(), null, null, false, null, null));
                                }
                                else if (Input.GetMouseButtonDown(1) && ___cachedEntries[i].map != null)
                                {
                                    Map map = ___cachedEntries[i].map;
                                    Find.WindowStack.Add(new Dialog_MessageBox("ZAbandonPermanentlyConfirmation".Translate(), "Yes".Translate(), delegate()
                                    {
                                        var comp = map.GetComponent <MapComponentZLevel>();
                                        try
                                        {
                                            var pathToDelete = Path.Combine(Path.Combine(GenFilePaths.ConfigFolderPath,
                                                                                         "SavedMaps"), map.Tile + " - " + comp.Z_LevelIndex + ".xml");
                                            var file = new FileInfo(pathToDelete);
                                            file.Delete();
                                        }
                                        catch
                                        {
                                        }

                                        var parent   = map.Parent as MapParent_ZLevel;
                                        var ZTracker = ZUtils.ZTracker;
                                        parent.Abandon();
                                        ZTracker.ZLevelsTracker[map.Tile].ZLevels.Remove(comp.Z_LevelIndex);

                                        foreach (var map2 in Find.Maps)
                                        {
                                            var comp2 = map2.GetComponent <MapComponentZLevel>();
                                            if (ZTracker.ZLevelsTracker[map2.Tile] != null)
                                            {
                                                foreach (var d in ZTracker.ZLevelsTracker[map2.Tile].ZLevels)
                                                {
                                                    ZLogger.Message(map2 + ": " + d.Key + " - " + d.Value);
                                                }
                                            }
                                        }
                                    }, "No".Translate(), null, null, false, null, null));
                                }
                            }
                        }
                    }
                }
            }
            catch { };
        }
コード例 #16
0
        private static bool Prefix(ref bool __result, Reachability __instance, IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams, out bool __state)
        {
            __state = false;
            var pawn = traverseParams.pawn;

            if (pawn != null && pawn.Map != null)
            {
                if (dest.HasThing && dest.thingInt.Map != null)
                {
                    if (dest.thingInt.Map != pawn.Map)
                    {
                        var cellToTeleport = ZUtils.GetCellToTeleportFrom(pawn.Map, pawn.Position, dest.thingInt.Map);
                        var cell           = cellToTeleport.IsValid ? cellToTeleport : pawn.Position;

                        __state     = true;
                        oldMap      = pawn.Map;
                        oldPosition = pawn.Position;
                        ZUtils.TeleportThing(pawn, dest.thingInt.Map, cell);
                        if (dest.thingInt.Map != __instance.map)
                        {
                            __result = dest.thingInt.Map.reachability.CanReach(start, dest, peMode, traverseParams);
                            ZLogger.Message($"1 CanReach: Used dest thing map reachability: __instance.map: {__instance.map}, pawn: {pawn}, thing: {dest.thingInt}, pawn.Map: {pawn.Map}, thing.Map: {dest.thingInt.Map}, result: {__result}");
                            return(false);
                        }
                    }
                    else if (dest.thingInt.Map != __instance.map)
                    {
                        __result = dest.thingInt.Map.reachability.CanReach(start, dest, peMode, traverseParams);
                        ZLogger.Message($"2 CanReach: Used dest thing map reachability: __instance.map: {__instance.map}, pawn: {pawn}, thing: {dest.thingInt}, pawn.Map: {pawn.Map}, thing.Map: {dest.thingInt.Map}, result: {__result}");
                        return(false);
                    }
                }
                else if (ZUtils.ZTracker.jobTracker.TryGetValue(pawn, out var jobTracker) && jobTracker.lookedAtLocalCellMap != null &&
                         jobTracker.lookedAtLocalCellMap.TryGetValue(dest.cellInt, out var mapDest) && mapDest != null)
                {
                    if (mapDest != pawn.Map)
                    {
                        var cellToTeleport = ZUtils.GetCellToTeleportFrom(pawn.Map, pawn.Position, mapDest);
                        var cell           = cellToTeleport.IsValid ? cellToTeleport : pawn.Position;

                        __state     = true;
                        oldMap      = pawn.Map;
                        oldPosition = pawn.Position;
                        ZUtils.TeleportThing(pawn, mapDest, cell);
                        if (mapDest != __instance.map)
                        {
                            __result = mapDest.reachability.CanReach(start, dest, peMode, traverseParams);
                            ZLogger.Message($"3 CanReach: Used mapDest map reachability: __instance.map: {__instance.map}, pawn: {pawn}, mapDest: {mapDest}, pawn.Map: {pawn.Map}, result: {__result}");
                            return(false);
                        }
                    }
                    else if (mapDest != __instance.map)
                    {
                        __result = mapDest.reachability.CanReach(start, dest, peMode, traverseParams);
                        ZLogger.Message($"4 CanReach: Used mapDest map reachability: __instance.map: {__instance.map}, pawn: {pawn}, mapDest: {mapDest}, pawn.Map: {pawn.Map}, result: {__result}");
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #17
0
ファイル: CombatPatches.cs プロジェクト: Proxyer/Z-Levels
 public static void Postfix(ref Building_TurretGun __instance, ref LocalTargetInfo __result)
 {
     ZLogger.Message(__instance + " got target " + __result, true);
 }
コード例 #18
0
            public static void Postfix(IntVec3 clickCell, Pawn pawn, ref List <FloatMenuOption> opts, bool drafted, FloatMenuOption[] ___equivalenceGroupTempStorage)
            {
                var ZTracker = ZUtils.ZTracker;

                if (pawn.thinker.TryGetMainTreeThinkNode <JobGiver_Work>() != null)
                {
                    foreach (Thing item in pawn.Map.thingGrid.ThingsAt(clickCell))
                    {
                        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 && !workGiver_Scanner.ShouldSkip(pawn, forced: true))
                                    {
                                        JobFailReason.Clear();
                                        if (workGiver_Scanner.PotentialWorkThingRequest.Accepts(item) || (workGiver_Scanner.PotentialWorkThingsGlobal(pawn) != null && workGiver_Scanner.PotentialWorkThingsGlobal(pawn).Contains(item)))
                                        {
                                            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();
                                                    }
                                                    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;
                                            }
                                            ZLogger.Message("workGiver_Scanner: " + workGiver_Scanner
                                                            + " - menuOption.Label: " + menuOption.Label);
                                            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 && !workGiver_Scanner2.ShouldSkip(pawn, forced: true))
                                {
                                    JobFailReason.Clear();
                                    if (workGiver_Scanner2.PotentialWorkCellsGlobal(pawn).Contains(clickCell))
                                    {
                                        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();
                                                }
                                                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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
コード例 #19
0
            public static FloatMenuOption AddRescueOption(Pawn pawn, Pawn victim)
            {
                var floatOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Rescue".Translate
                                                                                                   (victim.LabelCap, victim), delegate()
                {
                    var ZTracker     = ZUtils.ZTracker;
                    var oldMap       = pawn.Map;
                    var oldPosition1 = pawn.Position;
                    var oldPosition2 = victim.Position;
                    bool select      = false;
                    if (Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        select = true;
                    }

                    Building building_Bed = null;
                    foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
                    {
                        ZLogger.Message("Searching rest job for " + pawn + " in " + ZTracker.GetMapInfo(otherMap)
                                        + " for " + ZTracker.GetMapInfo(oldMap));

                        var stairs = new List <Thing>();

                        if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap))
                        {
                            Map lowerMap = ZTracker.GetLowerLevel(otherMap.Tile, otherMap);
                            if (lowerMap != null)
                            {
                                stairs = ZTracker.stairsUp[lowerMap];
                            }
                            else
                            {
                                ZLogger.Message("Lower map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }
                        else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap))
                        {
                            Map upperMap = ZTracker.GetUpperLevel(otherMap.Tile, otherMap);
                            if (upperMap != null)
                            {
                                stairs = ZTracker.stairsDown[upperMap];
                            }
                            else
                            {
                                ZLogger.Message("Upper map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }

                        if (stairs != null && stairs.Count() > 0)
                        {
                            var selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position));
                            var position       = selectedStairs.Position;

                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(position);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(position);
                        }
                        else if (pawn.Map != oldMap && otherMap == oldMap)
                        {
                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(oldPosition1);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(oldPosition2);
                        }

                        building_Bed = RestUtility.FindBedFor(victim, pawn, sleeperWillBePrisoner: false, checkSocialProperness: false);
                        if (building_Bed == null)
                        {
                            building_Bed = RestUtility.FindBedFor(victim, pawn, sleeperWillBePrisoner: false, checkSocialProperness: false, ignoreOtherReservations: true);
                        }
                        if (building_Bed != null)
                        {
                            break;
                        }
                    }
                    if (select)
                    {
                        Find.Selector.Select(pawn);
                    }
                    Traverse.Create(pawn).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(pawn).Field("positionInt")
                    .SetValue(oldPosition1);

                    Traverse.Create(victim).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(victim).Field("positionInt")
                    .SetValue(oldPosition2);

                    if (building_Bed == null)
                    {
                        string t3 = (!victim.RaceProps.Animal) ? ((string)"NoNonPrisonerBed".Translate()) : ((string)"NoAnimalBed".Translate());
                        Messages.Message("CannotRescue".Translate() + ": " + t3, victim, MessageTypeDefOf.RejectInput, historical: false);
                    }
                    else
                    {
                        Job job   = JobMaker.MakeJob(JobDefOf.Rescue, victim, building_Bed);
                        job.count = 1;
                        ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                        Log.Message(pawn + " taking first job 2");
                        pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Rescuing, KnowledgeAmount.Total);
                    }
                }, MenuOptionPriority.RescueOrCapture, null, victim, 0f, null, null), pawn, victim, "ReservedBy");

                return(floatOption);
            }
コード例 #20
0
            public static FloatMenuOption AddRescueOption(Pawn pawn, Pawn victim)
            {
                var floatOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Rescue".Translate
                                                                                                   (victim.LabelCap, victim), delegate()
                {
                    var ZTracker     = ZUtils.ZTracker;
                    var oldMap       = pawn.Map;
                    var oldPosition1 = pawn.Position;
                    var oldPosition2 = victim.Position;
                    bool select      = false;
                    if (Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        select = true;
                    }
                    Building building_Bed = null;

                    foreach (var otherMap in ZUtils.GetAllMapsInClosestOrderForTwoThings(pawn, oldMap, oldPosition1,
                                                                                         victim, oldMap, oldPosition2))
                    {
                        ZLogger.Message("Searching rest job for " + pawn + " in " + ZTracker.GetMapInfo(otherMap)
                                        + " for " + ZTracker.GetMapInfo(oldMap));
                        building_Bed = RestUtility.FindBedFor(victim, pawn, sleeperWillBePrisoner: false,
                                                              checkSocialProperness: false);
                        if (building_Bed == null)
                        {
                            building_Bed = RestUtility.FindBedFor(victim, pawn, sleeperWillBePrisoner: false,
                                                                  checkSocialProperness: false, ignoreOtherReservations: true);
                        }

                        if (building_Bed != null)
                        {
                            break;
                        }
                    }

                    if (select)
                    {
                        Find.Selector.Select(pawn);
                    }
                    ZUtils.TeleportThing(pawn, oldMap, oldPosition1);
                    ZUtils.TeleportThing(victim, oldMap, oldPosition2);

                    if (building_Bed == null)
                    {
                        string t3 = (!victim.RaceProps.Animal)
                            ? ((string)"NoNonPrisonerBed".Translate())
                            : ((string)"NoAnimalBed".Translate());
                        Messages.Message("CannotRescue".Translate() + ": " + t3, victim,
                                         MessageTypeDefOf.RejectInput, historical: false);
                    }
                    else
                    {
                        Job job   = JobMaker.MakeJob(JobDefOf.Rescue, victim, building_Bed);
                        job.count = 1;
                        ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                        Log.Message(pawn + " taking first job 2");
                        pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Rescuing, KnowledgeAmount.Total);
                    }
                }, MenuOptionPriority.RescueOrCapture, null, victim, 0f, null, null), pawn, victim, "ReservedBy");

                return(floatOption);
            }
コード例 #21
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.B);
            if (!forbiddenInitially)
            {
                this.FailOnForbidden(TargetIndex.A);
            }
            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("200 TargetA.Thing: " + TargetA.Thing);
                    ZLogger.Message("200 TargetA.Thing.Position: " + TargetA.Thing?.Position);
                    ZLogger.Message("200 TargetA.Thing.Map: " + TargetA.Thing?.Map);
                    ZLogger.Message("200 TargetA.Thing.stackCount: " + TargetA.Thing?.stackCount);
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();

                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                    {
                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB: " + target.Thing);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.Map: " + target.Thing.Map);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.stackCount: " + target.Thing.stackCount);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                    }
                }
            });

            Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.A);

            yield return(reserveTargetA);

            Toil toilGoto = null;

            toilGoto = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A).FailOn((Func <bool>) delegate
            {
                Pawn actor = toilGoto.actor;
                Job curJob = actor.jobs.curJob;
                if (curJob.haulMode == HaulMode.ToCellStorage)
                {
                    Thing thing = curJob.GetTarget(TargetIndex.A).Thing;
                    if (!actor.jobs.curJob.GetTarget(TargetIndex.B).Cell.IsValidStorageFor(base.Map, thing))
                    {
                        return(true);
                    }
                }
                return(false);
            });
            yield return(toilGoto);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("200.3 TargetA.Thing: " + TargetA.Thing);
                    ZLogger.Message("200.3 TargetA.Thing.Position: " + TargetA.Thing?.Position);
                    ZLogger.Message("200.3 TargetA.Thing.Map: " + TargetA.Thing?.Map);
                    ZLogger.Message("200.3 TargetA.Thing.stackCount: " + TargetA.Thing?.stackCount);
                    this.savedThing = TargetA.Thing;
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();

                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                    {
                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB: " + target.Thing);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.Map: " + target.Thing.Map);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.stackCount: " + target.Thing.stackCount);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                    }
                }
            });

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true));

            if (job.haulOpportunisticDuplicates)
            {
                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveTargetA, TargetIndex.A, TargetIndex.B));
            }
            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("10 savedThing: " + this.savedThing);
                    ZLogger.Message("10 carried Thing: " + pawn.carryTracker?.CarriedThing);
                    ZLogger.Message("200.5 TargetA.Thing: " + TargetA.Thing);
                    ZLogger.Message("200.5 TargetA.Thing.Position: " + TargetA.Thing?.Position);
                    ZLogger.Message("200.5 TargetA.Thing.Map: " + TargetA.Thing?.Map);
                    ZLogger.Message("200.5 TargetA.Thing.stackCount: " + TargetA.Thing?.stackCount);
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();

                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                    {
                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB: " + target.Thing);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.Map: " + target.Thing.Map);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.stackCount: " + target.Thing.stackCount);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                    }
                }
            });

            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("Pawn: " + pawn);
                    ZLogger.Message("pawn.Map: " + pawn.Map);
                    ZLogger.Message("TargetB: " + TargetB);
                }
            });

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (TargetB.Cell.GetFirstItem(pawn.Map) != null)
                    {
                        IntVec3 newPosition = IntVec3.Invalid;

                        IntVec3 center = (from x in GenRadial.RadialCellsAround(pawn.Position, 3f, useCenter: true)
                                          where x.InBounds(pawn.Map) && x.GetFirstItem(pawn.Map) == null select x).FirstOrDefault();
                        if (center != null)
                        {
                            job.targetB = new LocalTargetInfo(center);
                        }

                        else if (CellFinder.TryFindRandomCellNear(TargetB.Cell, pawn.Map, 3,
                                                                  (IntVec3 c) => c.GetFirstItem(pawn.Map)?.def != TargetA.Thing.def, out newPosition))
                        {
                            job.targetB = new LocalTargetInfo(newPosition);
                        }
                    }
                }
            });

            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("2 Pawn: " + pawn);
                    ZLogger.Message("2 pawn.Map: " + pawn.Map);
                    ZLogger.Message("2 TargetB: " + TargetB);
                }
            });

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, false));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    ZLogger.Message("201 TargetA.Thing: " + TargetA.Thing);
                    ZLogger.Message("201 TargetA.Thing.Position: " + TargetA.Thing?.Position);
                    ZLogger.Message("201 TargetA.Thing.Map: " + TargetA.Thing?.Map);
                    ZLogger.Message("201 TargetA.Thing.stackCount: " + TargetA.Thing?.stackCount);
                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                    {
                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB: " + target.Thing);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.Map: " + target.Thing.Map);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.stackCount: " + target.Thing.stackCount);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                    }
                    if (ZTracker.jobTracker.ContainsKey(this.pawn) && ZTracker.jobTracker[this.pawn].mainJob != null)
                    {
                        if (ZTracker.jobTracker[this.pawn].mainJob.targetQueueB != null &&
                            ZTracker.jobTracker[this.pawn].mainJob.targetQueueB
                            .Where(x => x.Thing == TargetA.Thing).Count() == 0)
                        {
                            //var newTarget = new LocalTargetInfo(TargetA.Thing);
                            //ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.Add(newTarget);
                            //ZTracker.jobTracker[this.pawn].mainJob.countQueue.Add(newTarget.Thing.stackCount);
                            //ZLogger.Message("1 Adding " + newTarget + " to " + ZTracker.jobTracker[this.pawn].mainJob);
                            //int ind = ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing);
                            //ZLogger.Message("1 Removing " + ZTracker.jobTracker[this.pawn].mainJob.targetQueueB[ind] + " from " + ZTracker.jobTracker[this.pawn].mainJob);
                            //
                            //ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.RemoveAt(ind);
                            //ZTracker.jobTracker[this.pawn].mainJob.countQueue.RemoveAt(ind);
                        }
                    }

                    ZLogger.Message("202 TargetA.Thing: " + TargetA.Thing);
                    ZLogger.Message("202 TargetA.Thing.Position: " + TargetA.Thing?.Position);
                    ZLogger.Message("202 TargetA.Thing.Map: " + TargetA.Thing?.Map);
                    ZLogger.Message("202 TargetA.Thing.stackCount: " + TargetA.Thing?.stackCount);
                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                    {
                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB: " + target.Thing);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.Map: " + target.Thing.Map);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.stackCount: " + target.Thing.stackCount);
                        ZLogger.Message("JobDriver_ZHaulToCell job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                    }
                }
            });
        }
コード例 #22
0
        private static void Postfix(ref bool __result, Pawn claimant, LocalTargetInfo target, bool __state, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
        {
            if (__state)
            {
                ZUtils.TeleportThing(claimant, oldMap, oldPosition);
            }
            if (__result)
            {
                var thing = target.Thing;
                if (thing != null)
                {
                    if (claimant.RaceProps.Humanlike && target.HasThing)
                    {
                        var ZTracker = ZUtils.ZTracker;
                        //foreach (var map in ZTracker.GetAllMaps(claimant.Map.Tile))
                        //{
                        //    foreach (var reservation in map.reservationManager.reservations)
                        //    {
                        //        Log.Message($"map: {map}, Reservation: {reservation.claimant}, target: {reservation.target}, {reservation.claimant.Map} - {reservation.target.Thing?.Map}");
                        //    }
                        //}

                        if (ZTracker.jobTracker != null)
                        {
                            foreach (var data in ZTracker.jobTracker)
                            {
                                if (data.Key != claimant && data.Value.reservedThings != null)
                                {
                                    foreach (var reservation in data.Value.reservedThings)
                                    {
                                        if (reservation.HasThing && reservation.thingInt == target.thingInt)
                                        {
                                            var shouldChangeResult = !((data.Key.jobs?.curDriver is JobDriver_TakeToBed) || (data.Key.jobs?.curDriver is JobDriver_LayDown));
                                            if (shouldChangeResult)
                                            {
                                                Log.Message(data.Key + " - data.Value.mainJob: " + data.Value.mainJob);
                                                Log.Message(data.Key + " - data.Key.CurJob: " + data.Key.CurJob);
                                                Log.Message(data.Key + " - thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key): " + thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key));
                                                if (data.Key.Map == thing.Map && !thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key))
                                                {
                                                    ZLogger.Error($"PREVENTED ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                                    continue;
                                                }
                                                __result = false;
                                                ZLogger.Message($"Detected ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                                return;
                                            }
                                        }
                                        //Log.Message($"ZTracker reservation: map: Reservation: {data.Key}, target: {reservation}, {data.Key.Map} - {reservation.Thing?.Map}");
                                    }
                                }
                            }
                        }
                        //Log.Message($"---------------------");
                    }
                    //Log.Message($"{claimant} can reserve {target}: {__result}, {claimant.Map} - {target.Thing?.Map}");

                    //if (claimant.Map != thing.Map)
                    //{
                    //    ZLogger.Pause($"CanReserve: {__result}, Detected reservation disfunction: claimant.Map != thing.Map, claimant: {claimant}, thing: {thing}");
                    //    var ZTracker = ZUtils.ZTracker;
                    //    foreach (var map in ZTracker.GetAllMaps(thing.Map.Tile))
                    //    {
                    //        var pawn = map.reservationManager.FirstRespectedReserver(target, claimant);
                    //        if (pawn != null && pawn != claimant)
                    //        {
                    //            ZLogger.Pause($"CanReserve: {__result}, Detected reservation disfunction: claimant: {claimant}, pawn: {pawn}, thing: {thing}");
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    var ZTracker = ZUtils.ZTracker;
                    //    foreach (var map in ZTracker.GetAllMaps(thing.Map.Tile))
                    //    {
                    //        var pawn = map.reservationManager.FirstRespectedReserver(target, claimant);
                    //        if (pawn != null && pawn != claimant)
                    //        {
                    //            ZLogger.Pause($"CanReserve: {__result}, Detected other claimant: first claimant: {claimant}, second claimant: {pawn}, thing: {thing}");
                    //        }
                    //    }
                    //}
                }
            }
            else if (ZLogger.DebugEnabled)
            {
                ZLogger.Message($"claimant {claimant} can't reserve target: {target}");
                //var ZTracker = ZUtils.ZTracker;
                //if (target.HasThing)
                //{
                //    foreach (var map in ZTracker.GetAllMaps(claimant.Map.Tile))
                //    {
                //        foreach (var reservation in map.reservationManager.reservations)
                //        {
                //            Log.Message($"Vanilla reservation: map: {map}, Reservation: {reservation.claimant}, target: {reservation.target}, {reservation.claimant.Map} - {reservation.target.Thing?.Map}");
                //        }
                //    }
                //    if (ZTracker.jobTracker != null)
                //    {
                //        foreach (var data in ZTracker.jobTracker)
                //        {
                //            if (data.Value.reservedThings != null)
                //            {
                //                foreach (var reservation in data.Value.reservedThings)
                //                {
                //                    Log.Message($"ZTracker reservation: map: Reservation: {data.Key}, target: {reservation}, {data.Key.Map} - {reservation.Thing?.Map}");
                //                }
                //            }
                //        }
                //    }
                //}
            }
        }
コード例 #23
0
        public static IEnumerable <Map> GetAllMapsInClosestOrderForTwoThings(Thing thing, Map oldMap, IntVec3 oldPosition, Thing thing2, Map oldMap2, IntVec3 oldPosition2)
        {
            bool cantGoDown = false;
            bool cantGoUP   = false;

            foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
            {
                var stairs = new List <Building_Stairs>();
                if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap) && !cantGoUP)
                {
                    Map lowerMap = ZTracker.GetLowerLevel(otherMap.Tile, otherMap);
                    if (lowerMap != null)
                    {
                        stairs = ZTracker.stairsUp[lowerMap];
                    }
                    else
                    {
                        ZLogger.Message("Lower map is null in " + ZTracker.GetMapInfo(otherMap));
                    }
                }
                else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap) && !cantGoDown)
                {
                    Map upperMap = ZTracker.GetUpperLevel(otherMap.Tile, otherMap);
                    if (upperMap != null)
                    {
                        stairs = ZTracker.stairsDown[upperMap];
                    }
                    else
                    {
                        ZLogger.Message("Upper map is null in " + ZTracker.GetMapInfo(otherMap));
                    }
                }
                if (stairs != null && stairs.Count > 0)
                {
                    var selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position));
                    var position       = selectedStairs.Position;
                    TeleportThing(thing, otherMap, position);
                    TeleportThing(thing2, otherMap, position);
                    currentLookedIntoMap = otherMap;
                    yield return(otherMap);
                }
                else if (otherMap == oldMap)
                {
                    TeleportThing(thing, oldMap, oldPosition);
                    TeleportThing(thing2, oldMap2, oldPosition2);
                    currentLookedIntoMap = otherMap;
                    yield return(otherMap);
                }
                else
                {
                    if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap))
                    {
                        ZLogger.Message(thing + " cant go up in " + ZTracker.GetMapInfo(otherMap));
                        cantGoUP = true;
                    }
                    else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap))
                    {
                        ZLogger.Message(thing + " cant go down in " + ZTracker.GetMapInfo(otherMap));
                        cantGoDown = true;
                    }
                }
            }
        }
コード例 #24
0
 private static void Postfix(ref JobGiver_AIDefendPawn __instance, ref Job __result, ref Pawn pawn)
 {
     ZLogger.Message(pawn + " got response 4: " + __result);
 }
コード例 #25
0
        public static IEnumerable <Map> GetAllMapsInClosestOrder(Thing thing, Map oldMap, IntVec3 oldPosition, bool skipOldMap = false, bool dontCheckForStairs = false)
        {
            bool cantGoDown = false;
            bool cantGoUP   = false;
            var  zTracker   = ZTracker;
            var  jobTracker = thing is Pawn p?zTracker.jobTracker.TryGetValue(p, out var value) ? value : null : null;

            foreach (var otherMap in zTracker.GetAllMapsInClosestOrder(oldMap))
            {
                if (!dontCheckForStairs)
                {
                    var stairs         = new List <Building_Stairs>();
                    var otherMapZIndex = zTracker.GetZIndexFor(otherMap);
                    var oldMapZIndex   = zTracker.GetZIndexFor(oldMap);

                    if (otherMapZIndex > oldMapZIndex && !cantGoUP) // old map is lower than other map
                    {
                        Map lowerMap = zTracker.GetLowerLevel(otherMap.Tile, otherMap);
                        if (lowerMap != null)
                        {
                            stairs = zTracker.stairsUp[lowerMap]; // fetching stairs from lower map, in this case from map below than other map
                        }
                        else
                        {
                            ZLogger.Error("Lower map is null in " + zTracker.GetMapInfo(otherMap));
                        }
                    }
                    else if (otherMapZIndex < oldMapZIndex && !cantGoDown) // other map is lower than old map
                    {
                        Map upperMap = zTracker.GetUpperLevel(otherMap.Tile, otherMap);
                        if (upperMap != null)
                        {
                            stairs = zTracker.stairsDown[upperMap]; // fetching stairs from upper map, in this case from map upper than other map
                        }
                        else
                        {
                            ZLogger.Error("Upper map is null in " + zTracker.GetMapInfo(otherMap));
                        }
                    }

                    if (stairs != null && stairs.Count > 0)
                    {
                        if (!skipOldMap || skipOldMap && otherMap != oldMap)
                        {
                            IntVec3 newPosition = IntVec3.Invalid;// stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position)).Position;
                            if (thing is Pawn pawn)
                            {
                                foreach (var stair in stairs.OrderBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position)))
                                {
                                    //ZLogger.Message($"CHECK: {pawn} is from {zTracker.GetMapInfo(pawn.Map)}, can reach {stair} - {pawn.CanReach(stair, Verse.AI.PathEndMode.OnCell, Danger.Deadly)}," +
                                    //    $" stair is from {zTracker.GetMapInfo(stair.Map)}");
                                    if (pawn.CanReach(stair, Verse.AI.PathEndMode.OnCell, Danger.Deadly))
                                    {
                                        newPosition = stair.Position;
                                        break;
                                    }
                                }
                            }

                            if (newPosition.IsValid)
                            {
                                TeleportThing(thing, otherMap, newPosition);
                                //ZLogger.Message($"1 CHECK: {thing} is going to {zTracker.GetMapInfo(otherMap)}");
                                currentLookedIntoMap = otherMap;
                                yield return(otherMap);
                            }
                            else
                            {
                                var firstStairs = stairs.FirstOrDefault();
                                var map         = firstStairs?.Map;
                                if (map != null)
                                {
                                    //ZLogger.Message($"3 CHECK: stairs map: {zTracker.GetMapInfo(map)} - other map: {zTracker.GetMapInfo(otherMap)} - pawn map: {zTracker.GetMapInfo(thing.Map)}");
                                    if (map != oldMap)
                                    {
                                        var stairsMapIndex = zTracker.GetZIndexFor(map);
                                        if (stairsMapIndex > oldMapZIndex)
                                        {
                                            cantGoUP = true;
                                        }
                                        else if (oldMapZIndex > stairsMapIndex)
                                        {
                                            cantGoDown = true;
                                        }
                                    }
                                    else if (firstStairs is Building_StairsUp)
                                    {
                                        cantGoUP = true;
                                    }
                                    else if (firstStairs is Building_StairsDown)
                                    {
                                        cantGoDown = true;
                                    }
                                }
                            }
                        }
                    }
                    else if (otherMap == oldMap && !skipOldMap)
                    {
                        TeleportThing(thing, oldMap, oldPosition);
                        //ZLogger.Message($"2 CHECK: {thing} is going to {zTracker.GetMapInfo(otherMap)}");
                        currentLookedIntoMap = otherMap;
                        yield return(otherMap);
                    }
                    else
                    {
                        if (otherMapZIndex > oldMapZIndex)
                        {
                            //ZLogger.Message(thing + " cant go up in " + zTracker.GetMapInfo(otherMap));
                            cantGoUP = true;
                        }
                        else if (otherMapZIndex < oldMapZIndex)
                        {
                            //ZLogger.Message(thing + " cant go down in " + zTracker.GetMapInfo(otherMap));
                            cantGoDown = true;
                        }
                    }
                }
                else
                {
                    TeleportThing(thing, otherMap, oldPosition);
                    currentLookedIntoMap = otherMap;
                    yield return(otherMap);
                }
            }
        }
コード例 #26
0
        private static void Postfix(ref JobGiver_AIFightEnemy __instance, ref Job __result, ref Pawn pawn)
        {
            if (__result == null && !recursiveTrap)
            {
                recursiveTrap = true;
                CombatPatches_BestAttackTarget_Patch.multiMapSearch = true;
                var job = __instance.TryGiveJob(pawn);
                if (job != null)
                {
                    ZLogger.Message("Second block: " + job, true);
                    if (job.targetA.Thing?.Map != null && job.targetA.Thing.Map != pawn.Map)
                    {
                        if (!ZUtils.ZTracker.jobTracker.ContainsKey(pawn))
                        {
                            ZUtils.ZTracker.jobTracker[pawn] = new JobTracker
                            {
                                activeJobs = new List <Job>()
                            }
                        }
                        ;
                        ZUtils.ZTracker.ResetJobTrackerFor(pawn);
                        ZUtils.ZTracker.BuildJobListFor(pawn, job.targetA.Thing.Map, __result);
                        ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(job.targetA.Thing);
                        ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
                        __result = ZUtils.ZTracker.jobTracker[pawn].activeJobs[0];
                        ZUtils.ZTracker.jobTracker[pawn].activeJobs.RemoveAt(0);
                    }
                    else
                    {
                        __result = job;
                    }
                }
                recursiveTrap = false;
                CombatPatches_BestAttackTarget_Patch.multiMapSearch = false;
            }
            else if (__result != null && __result.targetA.Thing?.Map != null && __result.targetA.Thing.Map != pawn.Map)
            {
                ZLogger.Message("Second block: " + __result, true);
                if (!ZUtils.ZTracker.jobTracker.ContainsKey(pawn))
                {
                    ZUtils.ZTracker.jobTracker[pawn] = new JobTracker
                    {
                        activeJobs = new List <Job>()
                    }
                }
                ;
                ZUtils.ZTracker.ResetJobTrackerFor(pawn);
                ZUtils.ZTracker.BuildJobListFor(pawn, __result.targetA.Thing.Map, __result);
                ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(__result.targetA.Thing);
                ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
                __result = ZUtils.ZTracker.jobTracker[pawn].activeJobs[0];
                ZUtils.ZTracker.jobTracker[pawn].activeJobs.RemoveAt(0);
            }
            else if (__result == null && pawn.mindState.enemyTarget?.Map != null && pawn.mindState.enemyTarget.Map != pawn.Map)
            {
                ZLogger.Message("Third block: " + __result, true);
                if (!ZUtils.ZTracker.jobTracker.ContainsKey(pawn))
                {
                    ZUtils.ZTracker.jobTracker[pawn] = new JobTracker
                    {
                        activeJobs = new List <Job>()
                    }
                }
                ;
                ZUtils.ZTracker.jobTracker[pawn].targetDest       = new TargetInfo(pawn.mindState.enemyTarget);
                ZUtils.ZTracker.jobTracker[pawn].forceGoToDestMap = true;
                __result = JobMaker.MakeJob(ZLevelsDefOf.ZL_GoToMap);
                ZUtils.ZTracker.jobTracker[pawn].mainJob = __result;
                ZUtils.ZTracker.jobTracker[pawn].failIfTargetMapIsNotDest = true;
                ZUtils.ZTracker.jobTracker[pawn].target = pawn.mindState.enemyTarget;
            }
            ZLogger.Message(pawn + " got result 5: " + __result + " in " + pawn.Map + " - " + __result?.targetA.Thing?.Map + " - mind enemy: " + pawn.mindState.enemyTarget, true);
        }
    }
}
コード例 #27
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            var ZTracker = ZUtils.ZTracker;

            if (ZTracker.totalStairsDown == null)
            {
                ZTracker.totalStairsDown = new HashSet <Thing>();
            }
            ZTracker.totalStairsDown.Add(this);

            if (!ZTracker.stairsDown.ContainsKey(this.Map))
            {
                ZTracker.stairsDown[this.Map] = new List <Thing>();
            }
            if (!ZTracker.stairsDown[this.Map].Contains(this))
            {
                ZTracker.stairsDown[this.Map].Add(this);
            }
            ZLogger.Message("Spawning " + this);
            if (!respawningAfterLoad)
            {
                if (this.Position.GetTerrain(this.Map) == ZLevelsDefOf.ZL_OutsideTerrain)
                {
                    this.Map.terrainGrid.SetTerrain(this.Position, ZLevelsDefOf.ZL_OutsideTerrainTwo);
                }
                Map mapBelow = ZTracker.GetLowerLevel(this.Map.Tile, this.Map);
                if (mapBelow != null && mapBelow != this.Map && this.def.defName == "FC_StairsDown")
                {
                    for (int i = mapBelow.thingGrid.ThingsListAt(this.Position).Count - 1; i >= 0; i--)
                    {
                        Thing thing = mapBelow.thingGrid.ThingsListAt(this.Position)[i];
                        if (thing is Mineable)
                        {
                            if (thing.Spawned)
                            {
                                thing.DeSpawn(DestroyMode.WillReplace);
                            }
                        }
                    }
                    if (this.Position.GetThingList(mapBelow).Where(x => x.def == ZLevelsDefOf.ZL_StairsUp).Count() == 0)
                    {
                        var stairsToSpawn = ThingMaker.MakeThing(ZLevelsDefOf.ZL_StairsUp, this.Stuff);
                        mapBelow.terrainGrid.SetTerrain(this.Position, ZLevelsDefOf.ZL_OutsideTerrainTwo);
                        GenPlace.TryPlaceThing(stairsToSpawn, this.Position, mapBelow, ThingPlaceMode.Direct);
                        stairsToSpawn.SetFaction(this.Faction);
                    }
                    FloodFillerFog.FloodUnfog(this.Position, mapBelow);
                    AccessTools.Method(typeof(FogGrid), "FloodUnfogAdjacent").Invoke(mapBelow.fogGrid, new object[]
                                                                                     { this.Position });
                }
                else if (mapBelow == this.Map)
                {
                    Log.Error("There was a mismatch of ZLevels indices. This is a serious error, report it to the mod developers");
                    foreach (var map2 in ZTracker.GetAllMaps(this.Map.Tile))
                    {
                        ZLogger.Message("Index: " + ZTracker.GetMapInfo(map2));
                    }
                }
            }
        }
コード例 #28
0
ファイル: Toils_ZLevels.cs プロジェクト: absnormal/Z-Levels
        public static IEnumerable <Toil> GoToMap(Pawn pawn, Map dest, JobDriver instance)
        {
            Toil end = new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("if (pawn.Map == dest): " + pawn.Map + " - " + dest);
                }
            };

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (pawn.Map == dest)
                    {
                        instance.JumpToToil(end);
                    }
                }
            });

            Toil setStairs = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    ZLogger.Message("Pawn.map: " + pawn.Map);
                    ZLogger.Message("Dest Map: " + dest);
                    ZTracker.ReCheckStairs();
                    ZLogger.Message("1 Total count of stairs up: "
                                    + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsUp).Count());
                    ZLogger.Message("1 Total count of stairs down: "
                                    + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsDown).Count());

                    ZLogger.Message("2 Total count of stairs up: " + ZTracker.stairsUp[pawn.Map].Count);
                    ZLogger.Message("2 Total count of stairs down: " + ZTracker.stairsDown[pawn.Map].Count);
                    if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(dest))
                    {
                        var stairs = ZTracker.stairsDown[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position)));
                        }
                        else
                        {
                            ZLogger.Pause(pawn + " cant find stairs down");
                        }
                    }
                    else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(dest))
                    {
                        var stairs = ZTracker.stairsUp[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(y => IntVec3Utility.DistanceTo(pawn.Position, y.Position)));
                        }
                        else
                        {
                            ZLogger.Pause(pawn + " cant find stairs up");
                        }
                    }
                    else
                    {
                        pawn.CurJob.targetC = null;
                    }
                }
            };
            var  goToStairs = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell);
            Toil useStairs  = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f);
            //ToilFailConditions.FailOnDespawnedNullOrForbidden<Toil>(useStairs, TargetIndex.C);
            //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell);

            Toil teleport = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    if (pawn.CurJob.targetC.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }
                    else if (pawn.CurJob.targetC.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }

                    if (pawn.Map != dest)
                    {
                        instance.JumpToToil(setStairs);
                    }
                }
            };

            yield return(setStairs);

            yield return(goToStairs);

            yield return(useStairs);

            yield return(teleport);

            yield return(end);
        }
    }
コード例 #29
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    if (ZTracker.jobTracker.ContainsKey(pawn))
                    {
                        this.savedThing = this.TargetB.Thing;
                    }
                }
            });

            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnBurningImmobile(TargetIndex.B);
            this.FailOnForbidden(TargetIndex.B);
            Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null);

            yield return(reserveTargetA);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (this.pawn.jobs.curJob.count == -1)
                    {
                        this.pawn.jobs.curJob.count = Mathf.Min(TargetB.Thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity, true) / TargetB.Thing.def.VolumePerUnit));
                        if (this.pawn.jobs.curJob.count < 0)
                        {
                            this.pawn.jobs.curJob.count = TargetB.Thing.stackCount;
                        }
                    }
                    ZLogger.Message(this.pawn + " haul count: " + this.pawn.jobs.curJob.count);
                }
            });

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, true, false));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveTargetA, TargetIndex.B, TargetIndex.A,
                                                                    false, null));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.A);

            yield return(carryToCell);

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

            Toil useStairs = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(useStairs, TargetIndex.A, PathEndMode.OnCell);
            //yield return new Toil
            //{
            //    initAction = delegate () {
            //        ZLogger.Message("this.pawn.CanReachImmediate(TargetA.Thing, PathEndMode.OnCell): "
            //            + this.pawn.CanReachImmediate(TargetA.Thing, PathEndMode.OnCell), true);
            //    }
            //};
            yield return(useStairs);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    try
                    {
                        var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                        if (ZTracker.jobTracker.ContainsKey(pawn))
                        {
                            if (ZTracker.jobTracker[pawn].mainJob.targetA.Thing != null &&
                                ZTracker.jobTracker[pawn].mainJob.targetA.Thing == this.savedThing &&
                                ZTracker.jobTracker[pawn].mainJob.targetA.Thing != TargetB.Thing)
                            {
                                ZLogger.Message("1 Pawns carried thing not the same: " + ZTracker.jobTracker[pawn].mainJob.targetA.Thing);
                                ZTracker.jobTracker[pawn].mainJob.targetA = new LocalTargetInfo(TargetB.Thing);
                            }
                            else if (ZTracker.jobTracker[pawn].mainJob.targetB.Thing != null &&
                                     ZTracker.jobTracker[pawn].mainJob.targetB.Thing == this.savedThing &&
                                     ZTracker.jobTracker[pawn].mainJob.targetB.Thing != TargetB.Thing)
                            {
                                ZLogger.Message("2 Pawns carried thing not the same: " + ZTracker.jobTracker[pawn].mainJob.targetB.Thing);
                                ZTracker.jobTracker[pawn].mainJob.targetB = new LocalTargetInfo(TargetB.Thing);
                            }

                            try
                            {
                                for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueA.Count - 1; i >= 0; i--)
                                {
                                    var target = ZTracker.jobTracker[pawn].mainJob.targetQueueA[i];
                                    if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetB.Thing)
                                    {
                                        ZLogger.Message("3 Pawns carried thing not the same: " + target.Thing);
                                        ZTracker.jobTracker[pawn].mainJob.targetQueueA[i] = new LocalTargetInfo(TargetB.Thing);
                                    }
                                }
                            }
                            catch { }
                            try
                            {
                                try
                                {
                                    ZLogger.Message("--------------------------");
                                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                    {
                                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB: " + target.Thing);
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB.Map: " + target.Thing.Map);
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB.stackCount: " + target.Thing.stackCount);
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                                    }
                                }
                                catch { }

                                for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                {
                                    var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                                    if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetB.Thing)
                                    {
                                        ZLogger.Message("4 Pawns carried thing not the same");
                                        ZLogger.Message("4 Pawns target.Thing: " + target.Thing);
                                        ZLogger.Message("4 Pawns target.Thing.Map: " + target.Thing.Map);
                                        ZLogger.Message("4 Pawns this.savedThing: " + this.savedThing);
                                        ZLogger.Message("4 Pawns this.savedThing.Map: " + this.savedThing.Map);
                                        ZLogger.Message("4 Pawns TargetB.Thing: " + TargetB.Thing);
                                        ZLogger.Message("4 Pawns TargetB.Thing.Map: " + TargetB.Thing.Map);

                                        //ZLogger.Message("Replacing " + ZTracker.jobTracker[this.pawn].mainJob.targetQueueB[i] + " by " + TargetB);
                                        //
                                        //ZTracker.jobTracker[pawn].mainJob.targetQueueB[i] = new LocalTargetInfo(TargetB.Thing);
                                        //ZTracker.jobTracker[pawn].mainJob.countQueue[i] = TargetB.Thing.stackCount;
                                        //

                                        if (ZTracker.jobTracker[pawn].mainJob.targetQueueB[i].Thing.stackCount == 0)
                                        {
                                            ZTracker.jobTracker[pawn].mainJob.targetQueueB[i] = new LocalTargetInfo(TargetB.Thing);
                                            ZTracker.jobTracker[pawn].mainJob.countQueue[i] = TargetB.Thing.stackCount;
                                            ZLogger.Message("Altering " + ZTracker.jobTracker[this.pawn].mainJob);
                                            break;
                                        }
                                        else
                                        {
                                            if (ZTracker.jobTracker[pawn].mainJob.targetQueueB
                                                .Where(x => x.Thing == TargetB.Thing).Count() == 0)
                                            {
                                                var newTarget = new LocalTargetInfo(TargetB.Thing);
                                                ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.Add(newTarget);
                                                ZTracker.jobTracker[this.pawn].mainJob.countQueue.Add(newTarget.Thing.stackCount);
                                                ZLogger.Message("2 Adding " + newTarget + " to " + ZTracker.jobTracker[this.pawn].mainJob);
                                                int ind = ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing);
                                                ZLogger.Message("2 Removing " + ZTracker.jobTracker[this.pawn].mainJob.targetQueueB[ind] + " from " + ZTracker.jobTracker[this.pawn].mainJob);

                                                ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.RemoveAt(ind);
                                                ZTracker.jobTracker[this.pawn].mainJob.countQueue.RemoveAt(ind);
                                                break;
                                            }
                                            else
                                            {
                                                ZLogger.Message("Cant add  " + TargetB.Thing + " to " + ZTracker.jobTracker[this.pawn].mainJob);
                                            }
                                        }
                                    }
                                }

                                try
                                {
                                    ZLogger.Message("--------------------------");
                                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                    {
                                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB: " + target.Thing);
                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB.Map: " + target.Thing.Map);
                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB.stackCount: " + target.Thing.stackCount);
                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                                    }
                                }
                                catch { }
                            }
                            catch { }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Z-Tracker produced an error in JobDriver_HaulThingToStairs class. Report about it to devs. Error: " + ex);
                    }
                }
            });

            yield return(new Toil()
            {
                initAction = () =>
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(this.pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }
                    if (TargetA.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(this.pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map);
                        }
                    }

                    try
                    {
                        for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                        {
                            var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB: " + target.Thing);
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB.Map: " + target.Thing.Map);
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB.stackCount: " + target.Thing.stackCount);
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                        }
                    }
                    catch { }
                }
            });
コード例 #30
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            var ZTracker = ZUtils.ZTracker;

            if (pawn.Map == this.job.targetA.Thing.Map && pawn.Map == ZTracker.jobTracker[pawn].dest)
            {
                ZLogger.Message("pawn map and thing map and dest map are same, yield breaking in JobDriver_HaulThingToDest");
                yield break;
            }
            yield return(new Toil
            {
                initAction = delegate()
                {
                    this.savedThing = this.job.targetA.Thing;
                    ZLogger.Message("1111111111111: " + this.savedThing);
                    ZLogger.Message("Saved thing: " + this.savedThing);
                    ZLogger.Message("TargetA: " + this.job.targetA.Thing);
                }
            });

            Toil reserveItem = Toils_Reserve.Reserve(TargetIndex.A);

            ZLogger.Message(pawn + " 8 ZUtils.ZTracker.jobTracker[pawn].dest: " + TargetA.Thing.Map);
            foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), TargetA.Thing.Map, this))
            {
                ZLogger.Message(pawn + " 9 ZUtils.ZTracker.jobTracker[pawn].dest: " + TargetA.Thing.Map);
                yield return(toil);
            }
            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("Trying to reserve " + job.targetA + " for " + pawn + " - " + job);
                }
            });

            yield return(reserveItem.FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, putRemainderInQueue: false, subtractNumTakenFromJobCount: true).FailOnDestroyedNullOrForbidden(TargetIndex.A));

            if (job.haulOpportunisticDuplicates)
            {
                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveItem, TargetIndex.A, TargetIndex.None, takeFromValidStorage: true));
            }
            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("22222222222222: " + this.savedThing);
                    ZLogger.Message("Saved thing: " + this.savedThing);
                    ZLogger.Message("TargetA: " + this.job.targetA.Thing);
                }
            });

            yield return(new Toil
            {
                initAction = delegate()
                {
                    try
                    {
                        if (ZTracker.jobTracker.ContainsKey(pawn))
                        {
                            if (ZTracker.jobTracker[pawn].mainJob.targetA.Thing != null &&
                                ZTracker.jobTracker[pawn].mainJob.targetA.Thing == this.savedThing &&
                                ZTracker.jobTracker[pawn].mainJob.targetA.Thing != TargetA.Thing)
                            {
                                ZTracker.jobTracker[pawn].mainJob.targetA = new LocalTargetInfo(TargetA.Thing);
                            }
                            else if (ZTracker.jobTracker[pawn].mainJob.targetB.Thing != null &&
                                     ZTracker.jobTracker[pawn].mainJob.targetB.Thing == this.savedThing &&
                                     ZTracker.jobTracker[pawn].mainJob.targetB.Thing != TargetA.Thing)
                            {
                                ZTracker.jobTracker[pawn].mainJob.targetB = new LocalTargetInfo(TargetA.Thing);
                            }

                            try
                            {
                                for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueA.Count - 1; i >= 0; i--)
                                {
                                    var target = ZTracker.jobTracker[pawn].mainJob.targetQueueA[i];
                                    if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing)
                                    {
                                        ZTracker.jobTracker[pawn].mainJob.targetQueueA[i] = new LocalTargetInfo(TargetA.Thing);
                                    }
                                }
                            }
                            catch { }
                            try
                            {
                                for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                {
                                    var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                                    if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetA.Thing)
                                    {
                                        if (ZTracker.jobTracker[pawn].mainJob.targetQueueB[i].Thing.stackCount == 0)
                                        {
                                            ZTracker.jobTracker[pawn].mainJob.targetQueueB[i] = new LocalTargetInfo(TargetA.Thing);
                                            ZTracker.jobTracker[pawn].mainJob.countQueue[i] = TargetA.Thing.stackCount;
                                            break;
                                        }
                                        else
                                        {
                                            if (ZTracker.jobTracker[pawn].mainJob.targetQueueB
                                                .Where(x => x.Thing == TargetA.Thing).Count() == 0)
                                            {
                                                var newTarget = new LocalTargetInfo(TargetA.Thing);
                                                ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.Add(newTarget);
                                                ZTracker.jobTracker[this.pawn].mainJob.countQueue.Add(newTarget.Thing.stackCount);
                                                int ind = ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing);
                                                ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.RemoveAt(ind);
                                                ZTracker.jobTracker[this.pawn].mainJob.countQueue.RemoveAt(ind);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Z-Tracker produced an error in JobDriver_HaulThingToStairs class. Report about it to devs. Error: " + ex);
                    }
                }
            });

            yield return(new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("33333333333333: " + this.savedThing);
                    ZLogger.Message("Saved thing: " + this.savedThing);
                    ZLogger.Message("TargetA: " + this.job.targetA.Thing);
                }
            });

            ZLogger.Message(pawn + " 6 ZUtils.ZTracker.jobTracker[pawn].dest: " + ZTracker.jobTracker[pawn].dest);

            foreach (var toil in Toils_ZLevels.GoToMap(GetActor(), ZTracker.jobTracker[pawn].dest, this))
            {
                ZLogger.Message(pawn + " 7 ZUtils.ZTracker.jobTracker[pawn].dest: " + ZTracker.jobTracker[pawn].dest);

                yield return(toil);
            }
        }