Beispiel #1
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)
            {
                if (pawn.RaceProps.Humanlike)
                {
                    if (dest.HasThing && dest.thingInt.Map != null && dest.thingInt.Map != pawn.Map)
                    {
                        var cell = ZUtils.GetCellToTeleportFrom(pawn.Map, pawn.Position, dest.thingInt.Map);
                        if (cell.IsValid)
                        {
                            __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($"CanReach: Used other's map reachability: pawn: {pawn}, thing: {dest.thingInt}, pawn.Map: {pawn.Map}, thing.Map: {dest.thingInt.Map}, result: {__result}");
                                return(false);
                            }
                        }
                        else
                        {
                            ZLogger.Pause($"CanReach: Detected reachability disfunction: pawn: {pawn}, thing: {dest.thingInt}, pawn.Map: {pawn.Map}, thing.Map: {dest.thingInt.Map}");
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
 private static bool Prefix(ref bool __result, ReservationManager __instance, Pawn claimant, LocalTargetInfo target, out bool __state, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
 {
     __state = false;
     if (claimant.RaceProps.Humanlike)
     {
         if (target.HasThing && target.thingInt.Map != null && target.thingInt.Map != claimant.Map)
         {
             var cell = ZUtils.GetCellToTeleportFrom(claimant.Map, claimant.Position, target.thingInt.Map);
             if (cell.IsValid)
             {
                 __state     = true;
                 oldMap      = claimant.Map;
                 oldPosition = claimant.Position;
                 ZUtils.TeleportThing(claimant, target.thingInt.Map, cell);
                 ZLogger.Message($"Teleporting claimaint {claimant} to {target.thingInt.Map}");
                 __result = claimant.CanReserve(target, maxPawns, stackCount, layer, ignoreOtherReservations);
                 return(false);
             }
             else
             {
                 ZLogger.Pause($"CanReserve: Detected reservation disfunction: pawn: {claimant}, thing: {target.thingInt}, pawn.Map: {claimant.Map}, thing.Map: {target.thingInt.Map}");
             }
         }
     }
     return(true);
 }
Beispiel #3
0
        public static Toil ExtractNextTargetFromQueue(TargetIndex ind, bool failIfCountFromQueueTooBig = true)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                try
                {
                    ZLogger.Message("--------------------------");
                    for (int i = curJob.targetQueueB.Count - 1; i >= 0; i--)
                    {
                        var target = curJob.targetQueueB[i];

                        ZLogger.Message("4 job.targetQueueB: " + target.Thing);
                        ZLogger.Message("4 job.targetQueueB.Map: " + target.Thing.Map);
                        ZLogger.Message("4 job.targetQueueB.stackCount: " + target.Thing.stackCount);
                        ZLogger.Message("4 job.targetQueueB.countQueue: " + curJob.countQueue[i]);
                    }
                }
                catch { }
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (!targetQueue.NullOrEmpty())
                {
                    if (failIfCountFromQueueTooBig && !curJob.countQueue.NullOrEmpty() && targetQueue[0].HasThing &&
                        curJob.countQueue[0] > targetQueue[0].Thing.stackCount)
                    {
                        Log.Message("targetQueue[0].Thing: " + targetQueue[0].Thing, true);
                        Log.Message("failIfCountFromQueueTooBig: " + failIfCountFromQueueTooBig, true);
                        Log.Message("!curJob.countQueue.NullOrEmpty(): " + (!curJob.countQueue.NullOrEmpty()).ToString(), true);
                        Log.Message("targetQueue[0].HasThing: " + (targetQueue[0].HasThing).ToString(), true);
                        Log.Message("curJob.countQueue[0] > targetQueue[0].Thing.stackCount: " + (curJob.countQueue[0] > targetQueue[0].Thing.stackCount).ToString(), true);
                        Log.Message("targetQueue[0].Thing.stackCount: " + (targetQueue[0].Thing.stackCount).ToString(), true);
                        Log.Message("curJob.countQueue[0]: " + (curJob.countQueue[0]).ToString(), true);
                        ZLogger.Pause("Stack count of thing is lesser than countQueue");
                        actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                    }
                    else
                    {
                        curJob.SetTarget(ind, targetQueue[0]);
                        targetQueue.RemoveAt(0);
                        if (!curJob.countQueue.NullOrEmpty())
                        {
                            curJob.count = curJob.countQueue[0];
                            curJob.countQueue.RemoveAt(0);
                        }
                    }
                }
            };
            return(toil);
        }
Beispiel #4
0
 public static bool Prefix(Rect rect, Pawn colonist)
 {
     try
     {
         if (colonist.CurJob != null && colonist.jobs.curDriver.asleep)
         {
         }
     }
     catch
     {
         ZLogger.Pause("Error in JobDriver of " + colonist);
         colonist.jobs.EndCurrentJob(JobCondition.Errored);
     }
     return(true);
 }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        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);
        }
    }
Beispiel #7
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)
            {
                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($"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($"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))
                {
                    if (mapDest is null)
                    {
                        ZLogger.Pause($"mapDest: {mapDest} is 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($"CanReach: Used lookedAtLocalCellMap 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($"CanReach: Used lookedAtLocalCellMap map reachability: __instance.map: {__instance.map}, pawn: {pawn}, mapDest: {mapDest}, pawn.Map: {pawn.Map}, result: {__result}");
                        return(false);
                    }
                }
            }
            return(true);
        }