コード例 #1
0
        public override IEnumerable <Toil> MakeNewToils()
        {
            var ZTracker = ZUtils.ZTracker;

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Log.Message("Test -1");
                    if (this.job is null)
                    {
                        ZLogger.Error("JobDriver_HaulThingToDest: job is null, this should never happen.");
                    }
                    else if (this.job.targetA.Thing is null)
                    {
                        ZLogger.Error("JobDriver_HaulThingToDest: targetA.Thing is null, this should never happen.");
                    }
                    Log.Message("Test 0");
                    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);
                    }
                    else
                    {
                        Log.Message("Test 1");
                        this.savedThing = this.job.targetA.Thing;
                        Log.Message("Test 2");
                    }
                }
            });
コード例 #2
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);
                }
            }
        }
コード例 #3
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}");
                //                }
                //            }
                //        }
                //    }
                //}
            }
        }
コード例 #4
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}");
                }
            }
        }