コード例 #1
0
 private bool ShouldCeremonyBeCalledOff()
 {
     return(firstPawn.Destroyed || secondPawn.Destroyed ||
            !firstPawn.relations.DirectRelationExists(PawnRelationDefOf.Fiance, secondPawn) ||
            spot.GetDangerFor(firstPawn, Map) != Danger.None ||
            spot.GetDangerFor(secondPawn, Map) != Danger.None ||
            !MarriageCeremonyUtility.AcceptableGameConditionsToStartCeremony(Map) ||
            !MarriageCeremonyUtility.FianceCanContinueCeremony(firstPawn, secondPawn));
 }
コード例 #2
0
        /**
         * Move few stepf srom dispenser to avoid clustering in a single cell
         */
        public static Toil CarryIngestibleToChewSpot(Pawn pawn, TargetIndex ingestibleInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn    actor  = toil.actor;
                IntVec3 intVec = IntVec3.Invalid;
                Thing   thing  = null;
                Thing   thing2 = actor.CurJob.GetTarget(ingestibleInd).Thing;

                intVec = RCellFinder.SpotToChewStandingNear(actor, actor.CurJob.GetTarget(ingestibleInd).Thing);
                Danger chewSpotDanger = intVec.GetDangerFor(pawn, actor.Map);
                if (chewSpotDanger != Danger.None)
                {
                    thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor), thing2.def.ingestible.chairSearchRadius, (Thing t) => (int)t.Position.GetDangerFor(pawn, t.Map) <= (int)chewSpotDanger);
                }
                if (thing != null)
                {
                    intVec = thing.Position;
                    actor.Reserve(thing, actor.CurJob);
                }

                actor.Map.pawnDestinationReservationManager.Reserve(actor, actor.CurJob, intVec);
                actor.pather.StartPath(intVec, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            return(toil);
        }
コード例 #3
0
 private bool ShouldCeremonyBeCalledOff()
 {
     if (firstPawn.Destroyed || secondPawn.Destroyed)
     {
         return(true);
     }
     if (!firstPawn.relations.DirectRelationExists(PawnRelationDefOf.Fiance, secondPawn))
     {
         return(true);
     }
     if (spot.GetDangerFor(firstPawn, base.Map) != Danger.None || spot.GetDangerFor(secondPawn, base.Map) != Danger.None)
     {
         return(true);
     }
     if (!GatheringsUtility.AcceptableGameConditionsToContinueGathering(base.Map) || !MarriageCeremonyUtility.FianceCanContinueCeremony(firstPawn, secondPawn) || !MarriageCeremonyUtility.FianceCanContinueCeremony(secondPawn, firstPawn))
     {
         return(true);
     }
     return(false);
 }
コード例 #4
0
 public static bool SafeEnvironmentalConditions(Pawn pawn, IntVec3 cell, Map map)
 {
     if (map.gameConditionManager.ConditionIsActive(GameConditionDefOf.ToxicFallout) && !cell.Roofed(map))
     {
         return(false);
     }
     if (cell.GetDangerFor(pawn, map) != Danger.None)
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
        public static bool ValidateGatheringSpot(IntVec3 cell, GatheringDef gatheringDef, Pawn organizer, bool enjoyableOutside)
        {
            Map map = organizer.Map;

            if (!cell.Standable(map))
            {
                return(false);
            }
            if (cell.GetDangerFor(organizer, map) != Danger.None)
            {
                return(false);
            }
            if (!enjoyableOutside && !cell.Roofed(map))
            {
                return(false);
            }
            if (cell.IsForbidden(organizer))
            {
                return(false);
            }
            if (!organizer.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.None))
            {
                return(false);
            }
            bool flag = cell.GetRoom(map)?.isPrisonCell ?? false;

            if (organizer.IsPrisoner != flag)
            {
                return(false);
            }
            if (!EnoughPotentialGuestsToStartGathering(map, gatheringDef, cell))
            {
                return(false);
            }
            return(true);
        }
コード例 #6
0
        public static Toil CarryIngestibleToChewSpot(Pawn pawn, TargetIndex ingestibleInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn              actor              = toil.actor;
                IntVec3           intVec             = IntVec3.Invalid;
                Thing             thing              = null;
                Thing             thing2             = actor.CurJob.GetTarget(ingestibleInd).Thing;
                Predicate <Thing> baseChairValidator = delegate(Thing t)
                {
                    bool result;
                    if (t.def.building == null || !t.def.building.isSittable)
                    {
                        result = false;
                    }
                    else if (t.IsForbidden(pawn))
                    {
                        result = false;
                    }
                    else if (!actor.CanReserve(t, 1, -1, null, false))
                    {
                        result = false;
                    }
                    else if (!t.IsSociallyProper(actor))
                    {
                        result = false;
                    }
                    else if (t.IsBurning())
                    {
                        result = false;
                    }
                    else if (t.HostileTo(pawn))
                    {
                        result = false;
                    }
                    else
                    {
                        bool flag = false;
                        for (int i = 0; i < 4; i++)
                        {
                            IntVec3  c       = t.Position + GenAdj.CardinalDirections[i];
                            Building edifice = c.GetEdifice(t.Map);
                            if (edifice != null && edifice.def.surfaceType == SurfaceType.Eat)
                            {
                                flag = true;
                                break;
                            }
                        }
                        result = flag;
                    }
                    return(result);
                };
                if (thing2.def.ingestible.chairSearchRadius > 0f)
                {
                    thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), thing2.def.ingestible.chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) == Danger.None, null, 0, -1, false, RegionType.Set_Passable, false);
                }
                if (thing == null)
                {
                    intVec = RCellFinder.SpotToChewStandingNear(actor, actor.CurJob.GetTarget(ingestibleInd).Thing);
                    Danger chewSpotDanger = intVec.GetDangerFor(pawn, actor.Map);
                    if (chewSpotDanger != Danger.None)
                    {
                        thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), thing2.def.ingestible.chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) <= chewSpotDanger, null, 0, -1, false, RegionType.Set_Passable, false);
                    }
                }
                if (thing != null)
                {
                    intVec = thing.Position;
                    actor.Reserve(thing, actor.CurJob, 1, -1, null);
                }
                actor.Map.pawnDestinationReservationManager.Reserve(actor, actor.CurJob, intVec);
                actor.pather.StartPath(intVec, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            return(toil);
        }
コード例 #7
0
ファイル: RCellFinder.cs プロジェクト: KraigXu/GameProject
        private static bool CanWanderToCell(IntVec3 c, Pawn pawn, IntVec3 root, Func <Pawn, IntVec3, IntVec3, bool> validator, int tryIndex, Danger maxDanger)
        {
            bool flag = false;

            if (!c.Walkable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0f, "walk");
                }
                return(false);
            }
            if (c.IsForbidden(pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "forbid");
                }
                return(false);
            }
            if (tryIndex < 10 && !c.Standable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "stand");
                }
                return(false);
            }
            if (!pawn.CanReach(c, PathEndMode.OnCell, maxDanger))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.6f, "reach");
                }
                return(false);
            }
            if (PawnUtility.KnownDangerAt(c, pawn.Map, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.1f, "trap");
                }
                return(false);
            }
            if (tryIndex < 10)
            {
                if (c.GetTerrain(pawn.Map).avoidWander)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.39f, "terr");
                    }
                    return(false);
                }
                if (pawn.Map.pathGrid.PerceivedPathCostAt(c) > 20)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "pcost");
                    }
                    return(false);
                }
                if ((int)c.GetDangerFor(pawn, pawn.Map) > 1)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "danger");
                    }
                    return(false);
                }
            }
            else if (tryIndex < 15 && c.GetDangerFor(pawn, pawn.Map) == Danger.Deadly)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.4f, "deadly");
                }
                return(false);
            }
            if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.75f, "resvd");
                }
                return(false);
            }
            if (validator != null && !validator(pawn, c, root))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.15f, "valid");
                }
                return(false);
            }
            if (c.GetDoor(pawn.Map) != null)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.32f, "door");
                }
                return(false);
            }
            if (c.ContainsStaticFire(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.9f, "fire");
                }
                return(false);
            }
            return(true);
        }
コード例 #8
0
 public static bool IsValidMarriageSpotFor(IntVec3 cell, Pawn firstFiance, Pawn secondFiance, StringBuilder outFailReason = null)
 {
     if (!firstFiance.Spawned || !secondFiance.Spawned)
     {
         Log.Warning("Can't check if a marriage spot is valid because one of the fiances isn't spawned.", false);
         return(false);
     }
     if (firstFiance.Map != secondFiance.Map)
     {
         return(false);
     }
     if (!MarriageSpotUtility.IsValidMarriageSpot(cell, firstFiance.Map, outFailReason))
     {
         return(false);
     }
     if (!cell.Roofed(firstFiance.Map))
     {
         if (!JoyUtility.EnjoyableOutsideNow(firstFiance, outFailReason))
         {
             return(false);
         }
         if (!JoyUtility.EnjoyableOutsideNow(secondFiance, outFailReason))
         {
             return(false);
         }
     }
     if (cell.GetDangerFor(firstFiance, firstFiance.Map) != Danger.None)
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotDangerous".Translate(new object[]
             {
                 firstFiance.LabelShort
             }));
         }
         return(false);
     }
     if (cell.GetDangerFor(secondFiance, secondFiance.Map) != Danger.None)
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotDangerous".Translate(new object[]
             {
                 secondFiance.LabelShort
             }));
         }
         return(false);
     }
     if (cell.IsForbidden(firstFiance))
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotForbidden".Translate(new object[]
             {
                 firstFiance.LabelShort
             }));
         }
         return(false);
     }
     if (cell.IsForbidden(secondFiance))
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotForbidden".Translate(new object[]
             {
                 secondFiance.LabelShort
             }));
         }
         return(false);
     }
     if (!firstFiance.CanReserve(cell, 1, -1, null, false) || !secondFiance.CanReserve(cell, 1, -1, null, false))
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotReserved".Translate());
         }
         return(false);
     }
     if (!firstFiance.CanReach(cell, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn))
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotUnreachable".Translate(new object[]
             {
                 firstFiance.LabelShort
             }));
         }
         return(false);
     }
     if (!secondFiance.CanReach(cell, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn))
     {
         if (outFailReason != null)
         {
             outFailReason.Append("MarriageSpotUnreachable".Translate(new object[]
             {
                 secondFiance.LabelShort
             }));
         }
         return(false);
     }
     if (!firstFiance.IsPrisoner && !secondFiance.IsPrisoner)
     {
         Room room = cell.GetRoom(firstFiance.Map, RegionType.Set_Passable);
         if (room != null && room.isPrisonCell)
         {
             if (outFailReason != null)
             {
                 outFailReason.Append("MarriageSpotInPrisonCell".Translate());
             }
             return(false);
         }
     }
     return(true);
 }
コード例 #9
0
        public static Toil CarryIngestibleToChewSpot(Pawn pawn, TargetIndex ingestibleInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn              actor              = toil.actor;
                IntVec3           cell2              = IntVec3.Invalid;
                Thing             thing              = null;
                Thing             thing2             = actor.CurJob.GetTarget(ingestibleInd).Thing;
                Predicate <Thing> baseChairValidator = delegate(Thing t)
                {
                    if (t.def.building == null || !t.def.building.isSittable)
                    {
                        return(false);
                    }
                    if (!TryFindFreeSittingSpotOnThing(t, out var _))
                    {
                        return(false);
                    }
                    if (t.IsForbidden(pawn))
                    {
                        return(false);
                    }
                    if (!actor.CanReserve(t))
                    {
                        return(false);
                    }
                    if (!t.IsSociallyProper(actor))
                    {
                        return(false);
                    }
                    if (t.IsBurning())
                    {
                        return(false);
                    }
                    if (t.HostileTo(pawn))
                    {
                        return(false);
                    }
                    bool flag = false;
                    for (int i = 0; i < 4; i++)
                    {
                        Building edifice = (t.Position + GenAdj.CardinalDirections[i]).GetEdifice(t.Map);
                        if (edifice != null && edifice.def.surfaceType == SurfaceType.Eat)
                        {
                            flag = true;
                            break;
                        }
                    }
                    return(flag ? true : false);
                };
                if (thing2.GetIngestibleProperties().chairSearchRadius > 0f)
                {
                    thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor), thing2.GetIngestibleProperties().chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) == Danger.None);
                }
                if (thing == null)
                {
                    cell2 = RCellFinder.SpotToChewStandingNear(actor, actor.CurJob.GetTarget(ingestibleInd).Thing, (IntVec3 c) => actor.CanReserveSittableOrSpot(c));
                    Danger chewSpotDanger = cell2.GetDangerFor(pawn, actor.Map);
                    if (chewSpotDanger != Danger.None)
                    {
                        thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor), thing2.GetIngestibleProperties().chairSearchRadius, (Thing t) => baseChairValidator(t) && (int)t.Position.GetDangerFor(pawn, t.Map) <= (int)chewSpotDanger);
                    }
                }
                if (thing != null && !TryFindFreeSittingSpotOnThing(thing, out cell2))
                {
                    Log.Error("Could not find sitting spot on chewing chair! This is not supposed to happen - we looked for a free spot in a previous check!");
                }
                actor.ReserveSittableOrSpot(cell2, actor.CurJob);
                actor.Map.pawnDestinationReservationManager.Reserve(actor, actor.CurJob, cell2);
                actor.pather.StartPath(cell2, PathEndMode.OnCell);
                bool TryFindFreeSittingSpotOnThing(Thing t, out IntVec3 cell)
                {
                    foreach (IntVec3 item in t.OccupiedRect())
                    {
                        if (actor.CanReserveSittableOrSpot(item))
                        {
                            cell = item;
                            return(true);
                        }
                    }
                    cell = default(IntVec3);
                    return(false);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            return(toil);
        }
コード例 #10
0
        public static bool __Prefix(Pawn pawn, TargetIndex ingestibleInd, ref Toil __result)
        {
            if (!TableDiner.settings.useExtraFeatures)
            {
                return(true);
            }
            Toil toil = new Verse.AI.Toil();

            toil.initAction = delegate
            {
                Pawn              actor              = toil.actor;
                IntVec3           intVec             = IntVec3.Invalid;
                Thing             thing              = null;
                Thing             thing2             = actor.CurJob.GetTarget(ingestibleInd).Thing;
                Predicate <Thing> baseChairValidator = delegate(Thing t)
                {
                    bool result;
                    if (t.def.building == null || !t.def.building.isSittable)
                    {
                        result = false;
                    }
                    else if (t.IsForbidden(pawn))
                    {
                        result = false;
                    }
                    else if (!actor.CanReserve(t, 1, -1, null, false))
                    {
                        result = false;
                    }
                    else if (!t.IsSociallyProper(actor))
                    {
                        result = false;
                    }
                    else if (t.IsBurning())
                    {
                        result = false;
                    }
                    else if (t.HostileTo(pawn))
                    {
                        result = false;
                    }
                    else
                    {
                        bool flag = false;
                        for (int i = 0; i < 4; i++)
                        {
                            IntVec3  c       = t.Position + GenAdj.CardinalDirections[i];
                            Building edifice = c.GetEdifice(t.Map);
                            if (edifice != null && edifice.def.surfaceType == SurfaceType.Eat)
                            {
                                float tr = TableDinerGlobal.GetTableRadius(edifice.ThingID);
                                float pr = TableDinerGlobal.GetTableRadius(actor.ThingID);

                                if (tr >= 1 || pr >= 1)
                                {
                                    float r2 = (edifice.TrueCenter() - actor.TrueCenter()).sqrMagnitude;
                                    if (tr < 1)
                                    {
                                        if (r2 <= Mathf.Pow(pr, 2))
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    else if (pr < 1)
                                    {
                                        if (r2 <= Mathf.Pow(tr, 2))
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        if (r2 <= Mathf.Pow(Mathf.Min(tr, pr), 2))
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        result = flag;
                    }
                    return(result);
                };
                if (thing2.def.ingestible.chairSearchRadius > 0f)
                {
                    thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), thing2.def.ingestible.chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) == Danger.None, null, 0, -1, false, RegionType.Set_Passable, false);
                }
                if (thing == null)
                {
                    intVec = RCellFinder.SpotToChewStandingNear(actor, actor.CurJob.GetTarget(ingestibleInd).Thing);
                    Danger chewSpotDanger = intVec.GetDangerFor(pawn, actor.Map);
                    if (chewSpotDanger != Danger.None)
                    {
                        thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), thing2.def.ingestible.chairSearchRadius, (Thing t) => baseChairValidator(t) && t.Position.GetDangerFor(pawn, t.Map) <= chewSpotDanger, null, 0, -1, false, RegionType.Set_Passable, false);
                    }
                }
                if (thing != null)
                {
                    intVec = thing.Position;
                    actor.Reserve(thing, actor.CurJob, 1, -1, null);
                }
                actor.Map.pawnDestinationReservationManager.Reserve(actor, actor.CurJob, intVec);
                actor.pather.StartPath(intVec, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            __result = toil;
            return(false);
        }
コード例 #11
0
            internal bool <> m__0(IntVec3 x)
            {
                if (!x.InBounds(this.map))
                {
                    return(false);
                }
                if (!x.Standable(this.map))
                {
                    return(false);
                }
                if (x.Fogged(this.map))
                {
                    return(false);
                }
                if (this.rectWithMargin.Contains(x))
                {
                    return(false);
                }
                if ((x.z <= this.rectWithMargin.maxZ || (this.allowedSides & SpectateRectSide.Up) != SpectateRectSide.Up) && (x.x <= this.rectWithMargin.maxX || (this.allowedSides & SpectateRectSide.Right) != SpectateRectSide.Right) && (x.z >= this.rectWithMargin.minZ || (this.allowedSides & SpectateRectSide.Down) != SpectateRectSide.Down) && (x.x >= this.rectWithMargin.minX || (this.allowedSides & SpectateRectSide.Left) != SpectateRectSide.Left))
                {
                    return(false);
                }
                IntVec3 intVec = this.spectateRect.ClosestCellTo(x);

                if ((float)intVec.DistanceToSquared(x) > 210.25f)
                {
                    return(false);
                }
                if (!GenSight.LineOfSight(intVec, x, this.map, true, null, 0, 0))
                {
                    return(false);
                }
                if (x.GetThingList(this.map).Find((Thing y) => y is Pawn && y != this.p) != null)
                {
                    return(false);
                }
                if (this.p != null)
                {
                    if (!this.p.CanReserveAndReach(x, PathEndMode.OnCell, Danger.Some, 1, -1, null, false))
                    {
                        return(false);
                    }
                    Building edifice = x.GetEdifice(this.map);
                    if (edifice != null && edifice.def.category == ThingCategory.Building && edifice.def.building.isSittable && !this.p.CanReserve(edifice, 1, -1, null, false))
                    {
                        return(false);
                    }
                    if (x.IsForbidden(this.p))
                    {
                        return(false);
                    }
                    if (x.GetDangerFor(this.p, this.map) != Danger.None)
                    {
                        return(false);
                    }
                }
                if (this.extraDisallowedCells != null && this.extraDisallowedCells.Contains(x))
                {
                    return(false);
                }
                if (!SpectatorCellFinder.CorrectlyRotatedChairAt(x, this.map, this.spectateRect))
                {
                    int num = 0;
                    for (int i = 0; i < GenAdj.AdjacentCells.Length; i++)
                    {
                        IntVec3 x2 = x + GenAdj.AdjacentCells[i];
                        if (SpectatorCellFinder.CorrectlyRotatedChairAt(x2, this.map, this.spectateRect))
                        {
                            num++;
                        }
                    }
                    if (num >= 3)
                    {
                        return(false);
                    }
                    int num2 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(-1, 0, 0), this.map, 4, this.spectateRect);
                    if (num2 >= 0)
                    {
                        int num3 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(1, 0, 0), this.map, 4, this.spectateRect);
                        if (num3 >= 0 && Mathf.Abs(num2 - num3) <= 1)
                        {
                            return(false);
                        }
                    }
                    int num4 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, 1), this.map, 4, this.spectateRect);
                    if (num4 >= 0)
                    {
                        int num5 = SpectatorCellFinder.DistanceToClosestChair(x, new IntVec3(0, 0, -1), this.map, 4, this.spectateRect);
                        if (num5 >= 0 && Mathf.Abs(num4 - num5) <= 1)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
コード例 #12
0
        public static Toil GoToDineSpot(Pawn pawn, TargetIndex dineSpotInd)
        {
            var toil = new Toil();

            toil.initAction = () => {
                Pawn    actor          = toil.actor;
                IntVec3 targetPosition = IntVec3.Invalid;
                var     diningSpot     = (DiningSpot)actor.CurJob.GetTarget(dineSpotInd).Thing;

                bool BaseChairValidator(Thing t)
                {
                    if (t.def.building == null || !t.def.building.isSittable)
                    {
                        return(false);
                    }

                    if (t.IsForbidden(pawn))
                    {
                        return(false);
                    }

                    if (!actor.CanReserve(t))
                    {
                        return(false);
                    }

                    if (!t.IsSociallyProper(actor))
                    {
                        return(false);
                    }

                    if (t.IsBurning())
                    {
                        return(false);
                    }

                    if (t.HostileTo(pawn))
                    {
                        return(false);
                    }

                    if (t.Position.GetDangerFor(pawn, t.Map) > JobUtility.MaxDangerDining)
                    {
                        return(false);
                    }
                    return(true);
                }

                var chair = GenClosest.ClosestThingReachable(diningSpot.Position, diningSpot.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.OnCell, TraverseParms.For(actor), 2, BaseChairValidator);
                if (chair == null)
                {
                    Log.Message($"{pawn.NameShortColored} could not find a chair around {diningSpot.Position}.");
                    if (diningSpot.MayDineStanding)
                    {
                        targetPosition = RCellFinder.SpotToChewStandingNear(actor, diningSpot);
                        var chewSpotDanger = targetPosition.GetDangerFor(pawn, actor.Map);
                        if (chewSpotDanger != JobUtility.MaxDangerDining)
                        {
                            Log.Message($"{pawn.NameShortColored} could not find a save place around {diningSpot.Position} ({chewSpotDanger}).");
                            actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                            return;
                        }
                    }
                }

                if (chair != null)
                {
                    targetPosition = chair.Position;
                    actor.Reserve(chair, actor.CurJob);
                }

                actor.Map.pawnDestinationReservationManager.Reserve(actor, actor.CurJob, targetPosition);
                actor.pather.StartPath(targetPosition, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            return(toil);
        }
コード例 #13
0
        private static bool CanWanderToCell(IntVec3 c, Pawn pawn, IntVec3 root, Func <Pawn, IntVec3, bool> validator, int tryIndex, Danger maxDanger)
        {
            bool flag = UnityData.isDebugBuild && DebugViewSettings.drawDestSearch;

            if (!c.Walkable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0f, "walk", 50);
                }
                return(false);
            }
            if (c.IsForbidden(pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "forbid", 50);
                }
                return(false);
            }
            if (tryIndex < 10 && !c.Standable(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.25f, "stand", 50);
                }
                return(false);
            }
            if (!pawn.CanReach(c, PathEndMode.OnCell, maxDanger, false, TraverseMode.ByPawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.6f, "reach", 50);
                }
                return(false);
            }
            if (RCellFinder.ContainsKnownTrap(c, pawn.Map, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.1f, "trap", 50);
                }
                return(false);
            }
            if (tryIndex < 10)
            {
                if (c.GetTerrain(pawn.Map).avoidWander)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.39f, "terr", 50);
                    }
                    return(false);
                }
                if (pawn.Map.pathGrid.PerceivedPathCostAt(c) > 20)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "pcost", 50);
                    }
                    return(false);
                }
                if ((int)c.GetDangerFor(pawn, pawn.Map) > 1)
                {
                    if (flag)
                    {
                        pawn.Map.debugDrawer.FlashCell(c, 0.4f, "danger", 50);
                    }
                    return(false);
                }
            }
            else if (tryIndex < 15 && c.GetDangerFor(pawn, pawn.Map) == Danger.Deadly)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.4f, "deadly", 50);
                }
                return(false);
            }
            if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.75f, "resvd", 50);
                }
                return(false);
            }
            if (validator != null && !validator(pawn, c))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.15f, "valid", 50);
                }
                return(false);
            }
            if (c.GetDoor(pawn.Map) != null)
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.32f, "door", 50);
                }
                return(false);
            }
            if (c.ContainsStaticFire(pawn.Map))
            {
                if (flag)
                {
                    pawn.Map.debugDrawer.FlashCell(c, 0.9f, "fire", 50);
                }
                return(false);
            }
            return(true);
        }
コード例 #14
0
        // Token: 0x0600002A RID: 42 RVA: 0x00002E28 File Offset: 0x00001028
        internal bool FlightCellCheck(Pawn pilot, IntVec3 tCell, int fuel, float fRate, float minJump, float maxJump,
                                      out string cantReason)
        {
            cantReason = "";
            if (!tCell.InBounds(pilot.Map))
            {
                cantReason = "JetPack.JumpReasonInvalid".Translate();
                return(false);
            }

            if (JPOnCooldown)
            {
                cantReason = "JetPack.JumpReasonOnCooldown".Translate();
                return(false);
            }

            if (!pilot.CanReserve(tCell))
            {
                cantReason = "JetPack.JumpReasonReserved".Translate();
                return(false);
            }

            if (tCell.Roofed(pilot.Map))
            {
                if (!Settings.RoofPunch)
                {
                    cantReason = "JetPack.JumpReasonRoofed".Translate();
                    return(false);
                }

                var chkSKF = DefDatabase <ThingDef> .GetNamed(JPSkyFallType, false);

                if (chkSKF == null || !chkSKF.skyfaller.hitRoof)
                {
                    cantReason =
                        "JetPack.JumpReasonSFNotRPunch".Translate(
                            chkSKF?.label.CapitalizeFirst());
                    return(false);
                }
            }

            if (!tCell.Walkable(pilot.Map))
            {
                cantReason = "JetPack.JumpReasonNotWalk".Translate();
                return(false);
            }

            if (tCell.GetDangerFor(pilot, pilot.Map) == Danger.Deadly)
            {
                cantReason = "JetPack.JumpReasonDeadly".Translate();
                return(false);
            }

            var distance = pilot.Position.DistanceTo(tCell);

            if (distance < minJump)
            {
                cantReason = "JetPack.JumpReasonMinRange".Translate(((int)minJump).ToString());
                return(false);
            }

            if (distance > maxJump)
            {
                cantReason = "JetPack.JumpReasonMaxRange".Translate(((int)maxJump).ToString());
                return(false);
            }

            if (fRate <= 0f)
            {
                cantReason = "JetPack.JumpFuelRateInvalid".Translate(fRate.ToString());
                return(false);
            }

            float distCanJump;

            if (Settings.UseCarry)
            {
                distCanJump = fuel / fRate * JPWeightUtility.JPCarryFactor(pilot, def, JPFuelItem);
            }
            else
            {
                distCanJump = fuel / fRate;
            }

            if (distCanJump > maxJump)
            {
                distCanJump = maxJump;
            }

            if (!(distCanJump < distance))
            {
                return(true);
            }

            cantReason = "JetPack.JumpNotEnoughfuel".Translate();
            return(false);
        }