示例#1
0
        public virtual bool CanHitTarget(LocalTargetInfo target, bool sightCheck)
        {
            if (target.IsValid && target.Cell.DistanceTo(this.pawn.Position) < this.GetRangeForPawn())
            {
                if ((this.targetParams.canTargetLocations && this.targetParams.CanTarget(new TargetInfo(target.Cell, this.Caster.Map))) ||
                    this.targetParams.CanTarget(target.ToTargetInfo(this.Caster.Map)))
                {
                    if (!sightCheck)
                    {
                        return(true);
                    }

                    if (GenSight.LineOfSight(this.pawn.Position, target.Cell, this.pawn.Map))
                    {
                        return(true);
                    }
                    List <IntVec3> tempSourceList = new List <IntVec3>();
                    ShootLeanUtility.LeanShootingSourcesFromTo(this.pawn.Position, target.Cell, this.pawn.Map, tempSourceList);
                    if (tempSourceList.Any(ivc => GenSight.LineOfSight(ivc, target.Cell, this.pawn.Map)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 public static bool CanReachImmediate(IntVec3 start, LocalTargetInfo target, Map map, PathEndMode peMode, Actor actor)
 {
     if (!target.IsValid)
     {
         return(false);
     }
     target = (LocalTargetInfo)ActorGenPath.ResolvePathMode(actor, target.ToTargetInfo(map), ref peMode);
     if (target.HasThing)
     {
         Thing thing = target.Thing;
         if (thing.Spawned)
         {
             if (thing.Map != map)
             {
                 return(false);
             }
         }
         else
         {
             return(actor != null);
         }
     }
     if (!target.HasThing || target.Thing.def.size.x == 1 && target.Thing.def.size.z == 1)
     {
         if (start == target.Cell)
         {
             return(true);
         }
     }
     else if (start.IsInside(target.Thing))
     {
         return(true);
     }
     return(peMode == PathEndMode.Touch && TouchPathEndModeUtility.IsAdjacentOrInsideAndAllowedToTouch(start, target, map));
 }
示例#3
0
 public void StartPath(LocalTargetInfo dest, PathEndMode peMode)
 {
     dest = (LocalTargetInfo)GenPath.ResolvePathMode(this.pawn, dest.ToTargetInfo(this.pawn.Map), ref peMode);
     if (dest.HasThing && dest.ThingDestroyed)
     {
         Log.Error(this.pawn + " pathing to destroyed thing " + dest.Thing, false);
         this.PatherFailed();
     }
     else
     {
         if (!this.PawnCanOccupy(this.pawn.Position))
         {
             if (!this.TryRecoverFromUnwalkablePosition(true))
             {
                 return;
             }
         }
         if (!this.moving || this.curPath == null || !(this.destination == dest) || this.peMode != peMode)
         {
             if (!this.pawn.Map.reachability.CanReach(this.pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)))
             {
                 this.PatherFailed();
             }
             else
             {
                 this.peMode      = peMode;
                 this.destination = dest;
                 if (!this.IsNextCellWalkable())
                 {
                     this.nextCell = this.pawn.Position;
                 }
                 if (!this.destination.HasThing && this.pawn.Map.pawnDestinationReservationManager.MostRecentReservationFor(this.pawn) != this.destination.Cell)
                 {
                     this.pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(this.pawn);
                 }
                 if (this.AtDestinationPosition())
                 {
                     this.PatherArrived();
                 }
                 else if (this.pawn.Downed)
                 {
                     Log.Error(this.pawn.LabelCap + " tried to path while downed. This should never happen. curJob=" + this.pawn.CurJob.ToStringSafe <Job>(), false);
                     this.PatherFailed();
                 }
                 else
                 {
                     if (this.curPath != null)
                     {
                         this.curPath.ReleaseToPool();
                     }
                     this.curPath           = null;
                     this.moving            = true;
                     this.pawn.jobs.posture = PawnPosture.Standing;
                 }
             }
         }
     }
 }
 public override void OnGUI(LocalTargetInfo target)
 {
     if (CanHitTarget(target) && verbProps.targetParams.CanTarget(target.ToTargetInfo(caster.Map)))
     {
         base.OnGUI(target);
     }
     else
     {
         GenUI.DrawMouseAttachment(TexCommand.CannotShoot);
     }
 }
示例#5
0
		public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
		{
			if (target.Cell.Filled(parent.pawn.Map))
			{
				if (throwMessages)
				{
					Messages.Message("AbilityOccupiedCells".Translate(parent.def.LabelCap), target.ToTargetInfo(parent.pawn.Map), MessageTypeDefOf.RejectInput, historical: false);
				}
				return false;
			}
			return true;
		}
 // Token: 0x06000C53 RID: 3155 RVA: 0x0004605C File Offset: 0x0004425C
 public bool CanReachImmediate(IntVec3 start, LocalTargetInfo target, Map map, PathEndMode peMode, Pawn pawn)
 {
     if (!target.IsValid)
     {
         return(false);
     }
     target = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, target.ToTargetInfo(map), ref peMode);
     if (target.HasThing)
     {
         Thing thing = target.Thing;
         if (!thing.Spawned)
         {
             if (pawn != null)
             {
                 if (pawn.carryTracker.innerContainer.Contains(thing))
                 {
                     return(true);
                 }
                 if (pawn.inventory.innerContainer.Contains(thing))
                 {
                     return(true);
                 }
                 if (pawn.apparel != null && pawn.apparel.Contains(thing))
                 {
                     return(true);
                 }
                 if (pawn.equipment != null && pawn.equipment.Contains(thing))
                 {
                     return(true);
                 }
             }
             return(false);
         }
         if (thing.Map != map)
         {
             return(false);
         }
     }
     if (!target.HasThing || (target.Thing.def.size.x == 1 && target.Thing.def.size.z == 1))
     {
         if (start == target.Cell)
         {
             return(true);
         }
     }
     else if (start.IsInside(target.Thing))
     {
         return(true);
     }
     return(peMode == PathEndMode.Touch && IsAdjacentOrInsideAndAllowedToTouch(start, target, map));
 }
示例#7
0
 public void StartPath(LocalTargetInfo dest, PathEndMode peMode)
 {
     dest = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode);
     if (dest.HasThing && dest.ThingDestroyed)
     {
         Log.Error(string.Concat(pawn, " pathing to destroyed thing ", dest.Thing));
         PatherFailed();
     }
     else
     {
         if ((!PawnCanOccupy(pawn.Position) && !TryRecoverFromUnwalkablePosition()) || (moving && curPath != null && destination == dest && this.peMode == peMode))
         {
             return;
         }
         if (!pawn.Map.reachability.CanReach(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors)))
         {
             PatherFailed();
             return;
         }
         this.peMode = peMode;
         destination = dest;
         if (!IsNextCellWalkable() || NextCellDoorToWaitForOrManuallyOpen() != null || nextCellCostLeft == nextCellCostTotal)
         {
             ResetToCurrentPosition();
         }
         PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager.MostRecentReservationFor(pawn);
         if (pawnDestinationReservation != null && ((destination.HasThing && pawnDestinationReservation.target != destination.Cell) || (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != destination.Cell)))
         {
             pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn);
         }
         if (AtDestinationPosition())
         {
             PatherArrived();
             return;
         }
         if (pawn.Downed)
         {
             Log.Error(pawn.LabelCap + " tried to path while downed. This should never happen. curJob=" + pawn.CurJob.ToStringSafe());
             PatherFailed();
             return;
         }
         if (curPath != null)
         {
             curPath.ReleaseToPool();
         }
         curPath           = null;
         moving            = true;
         pawn.jobs.posture = PawnPosture.Standing;
     }
 }
示例#8
0
 static bool Prefix(ref Pawn_PathFollower __instance, LocalTargetInfo dest, PathEndMode peMode, Pawn ___pawn)
 {
     if (___pawn.Map?.Parent is City)
     {
         dest = (LocalTargetInfo)GenPath.ResolvePathMode(___pawn, dest.ToTargetInfo(___pawn.Map), ref peMode);
         if (dest.HasThing && dest.ThingDestroyed)
         {
             Log.Warning(___pawn + " pathing to destroyed thing " + dest.Thing);
             // ReSharper disable once PossibleNullReferenceException
             typeof(Pawn_PathFollower).GetMethod("PatherFailed", BindingFlags.NonPublic).Invoke(__instance, new object[] { });
             return(false);
         }
     }
     return(true);
 }
 public void StartPath(LocalTargetInfo dest, PathEndMode peMode)
 {
     dest = (LocalTargetInfo)ActorGenPath.ResolvePathMode(actor, dest.ToTargetInfo(actor.Map), ref peMode);
     if (dest.HasThing && dest.ThingDestroyed)
     {
         Log.Error(actor + " pathing to destroyed thing " + dest.Thing, false);
         PatherFailed();
     }
     else
     {
         if (!PawnCanOccupy(actor.Position) && !TryRecoverFromUnwalkablePosition(true) || moving && curPath != null && (destination == dest && this.peMode == peMode))
         {
             return;
         }
         if (!actor.Map.reachability.CanReach(actor.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)))
         {
             PatherFailed();
         }
         else
         {
             this.peMode = peMode;
             destination = dest;
             if (!IsNextCellWalkable() || NextCellDoorToManuallyOpen() != null || nextCellCostLeft == (double)nextCellCostTotal)
             {
                 ResetToCurrentPosition();
             }
             if (AtDestinationPosition())
             {
                 PatherArrived();
             }
             else
             {
                 if (curPath != null)
                 {
                     curPath.ReleaseToPool();
                 }
                 curPath = null;
                 moving  = true;
             }
         }
     }
 }
示例#10
0
        public void StartRefreshing(Pawn pawn, LocalTargetInfo targetInfo)
        {
            //if (pawn.ThingID != this.PodOwnerId)
            if (this.PodOwner != pawn)
            {
                return;
            }
            this.SaveNeeds(pawn.needs.AllNeeds);
            pawn.DeSpawn(DestroyMode.Vanish);
            if (this.TryAcceptThing(pawn))
            {
                this.CurrentTicksLeft = this.CurrentMaxTicks = this.TotalTicksPerAction;
                this.JobState         = PS_Conditioning_JobState.Refreshing;


                EffecterDef progressBar = EffecterDefOf.ProgressBar;
                ProgressBarEffector = progressBar.Spawn();
                ProgressBarEffector.EffectTick(targetInfo.ToTargetInfo(this.Map), TargetInfo.Invalid);
            }
        }
 public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
 {
     if (target.Cell.Filled(parent.pawn.Map) || (target.Cell.GetFirstBuilding(parent.pawn.Map) != null && !Props.allowOnBuildings))
     {
         if (throwMessages)
         {
             Messages.Message("AbilityOccupiedCells".Translate(parent.def.LabelCap), target.ToTargetInfo(parent.pawn.Map), MessageTypeDefOf.RejectInput, historical: false);
         }
         return(false);
     }
     return(true);
 }
示例#12
0
        public static bool CanReach(Reachability __instance, ref bool __result, IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams)
        {
            Map map = __instance.map;

            //if (working)
            //{
            //Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233);
            //return false;
            //}

            if (traverseParams.pawn != null)
            {
                if (!traverseParams.pawn.Spawned)
                {
                    __result = false;
                    return(false);
                }

                if (traverseParams.pawn.Map != map)
                {
                    Log.Error(string.Concat("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParams.pawn, " pawn.Map=", traverseParams.pawn.Map, " map=", map));
                    __result = false;
                    return(false);
                }
            }

            if (ReachabilityImmediate.CanReachImmediate(start, dest, map, peMode, traverseParams.pawn))
            {
                __result = true;
                return(false);
            }

            if (!dest.IsValid)
            {
                __result = false;
                return(false);
            }

            if (dest.HasThing && dest.Thing.Map != map)
            {
                __result = false;
                return(false);
            }

            if (!start.InBounds(map) || !dest.Cell.InBounds(map))
            {
                __result = false;
                return(false);
            }

            if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
            {
#if RW12
                Room room = RegionAndRoomQuery.RoomAtFast(start, map);
                if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, map))
#endif
#if RW13
                District district = RegionAndRoomQuery.DistirctAtFast(start, map);
                if (district != null && district == RegionAndRoomQuery.DistirctAtFast(dest.Cell, map))
#endif
                {
                    __result = true;
                    return(false);
                }
            }

            if (traverseParams.mode == TraverseMode.PassAllDestroyableThings)
            {
                TraverseParms traverseParams2 = traverseParams;
                traverseParams2.mode = TraverseMode.PassDoors;
                bool canReachResult = false;
                CanReach(__instance, ref canReachResult, start, dest, peMode, traverseParams2);
                if (canReachResult)
                {
                    __result = true;
                    return(false);
                }
            }

            dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(map), ref peMode);
            //working = true;
            try
            {
#if RW12
                __instance.pathGrid = map.pathGrid;
                PathGrid pathGrid = map.pathGrid;
#endif
#if RW13
                __instance.pathGrid = map.pathing.For(traverseParams).pathGrid;
                PathGrid pathGrid = __instance.pathGrid;
#endif
                __instance.regionGrid = map.regionGrid;
                RegionGrid regionGrid = map.regionGrid;

                destRegions.Clear();

                switch (peMode)
                {
                case PathEndMode.OnCell:
                {
                    Region region = dest.Cell.GetRegion(map);
                    if (region != null && region.Allows(traverseParams, isDestination: true))
                    {
                        destRegions.Add(region);
                    }
                    break;
                }

                case PathEndMode.Touch:
                    TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, map, destRegions);
                    break;
                }

                if (destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    __result = false;
                    return(false);
                }

                destRegions.RemoveDuplicates();
                regionsReached.Clear();
                openQueue.Clear();
                startingRegions.Clear();

                DetermineStartRegions(map, start, startingRegions, pathGrid, regionGrid, openQueue, regionsReached);
                if (openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    __result = false;
                    return(false);
                }

                if (startingRegions.Any() && destRegions.Any() && __instance.CanUseCache(traverseParams.mode))
                {
                    switch (GetCachedResult(__instance, traverseParams, startingRegions, destRegions))
                    {
                    case BoolUnknown.True:
                        __result = true;
                        return(false);

                    case BoolUnknown.False:
                        __result = false;
                        return(false);
                    }
                }
                if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater)
                {
                    bool result = __instance.CheckCellBasedReachability(start, dest, peMode, traverseParams);
                    __result = result;
                    return(false);
                }

                bool result2 = CheckRegionBasedReachability(__instance, traverseParams, openQueue, regionsReached, startingRegions, destRegions);
                __result = result2;
                return(false);
            }
            finally
            {
                //working = false;
            }
        }
示例#13
0
 public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
 {
     if (this.AffectedCells(target, this.parent.pawn.Map).Any((IntVec3 c) => c.Filled(this.parent.pawn.Map)))
     {
         if (throwMessages)
         {
             Messages.Message("AbilityOccupiedCells".Translate(this.parent.def.LabelCap), target.ToTargetInfo(this.parent.pawn.Map), MessageTypeDefOf.RejectInput, false);
         }
         return(false);
     }
     return(true);
 }
 public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
 {
     if (AffectedCells(target, parent.pawn.Map).Any((IntVec3 c) => c.Filled(parent.pawn.Map)))
     {
         if (throwMessages)
         {
             Messages.Message("AbilityOccupiedCells".Translate(parent.def.LabelCap), target.ToTargetInfo(parent.pawn.Map), MessageTypeDefOf.RejectInput, historical: false);
         }
         return(false);
     }
     if (AffectedCells(target, parent.pawn.Map).Any((IntVec3 c) => !c.Standable(parent.pawn.Map)))
     {
         if (throwMessages)
         {
             Messages.Message("AbilityUnwalkable".Translate(parent.def.LabelCap), target.ToTargetInfo(parent.pawn.Map), MessageTypeDefOf.RejectInput, historical: false);
         }
         return(false);
     }
     return(true);
 }
示例#15
0
 public override bool ValidateTarget(LocalTargetInfo target)
 {
     if (verbProps.range > 0f)
     {
         if (!CanHitTarget(target))
         {
             if (target.IsValid)
             {
                 Messages.Message(ability.def.LabelCap + ": " + "AbilityCannotHitTarget".Translate(), new LookTargets(ability.pawn, target.ToTargetInfo(ability.pawn.Map)), MessageTypeDefOf.RejectInput, historical: false);
             }
             return(false);
         }
     }
     else if (!ability.pawn.CanReach(target, PathEndMode.Touch, ability.pawn.NormalMaxDanger()))
     {
         if (target.IsValid)
         {
             Messages.Message(ability.def.LabelCap + ": " + "AbilityCannotReachTarget".Translate(), new LookTargets(ability.pawn, target.ToTargetInfo(ability.pawn.Map)), MessageTypeDefOf.RejectInput, historical: false);
         }
         return(false);
     }
     if (!IsApplicableTo(target, showMessages: true))
     {
         return(false);
     }
     for (int i = 0; i < ability.EffectComps.Count; i++)
     {
         if (!ability.EffectComps[i].Valid(target, throwMessages: true))
         {
             return(false);
         }
     }
     return(true);
 }
        public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
        {
            Pawn pawn = target.Pawn;

            if (pawn != null && pawn.InMentalState)
            {
                if (throwMessages)
                {
                    Messages.Message("AbilityCantApplyToMentallyBroken".Translate(pawn.LabelShort), target.ToTargetInfo(parent.pawn.Map), MessageTypeDefOf.RejectInput, historical: false);
                }
                return(false);
            }
            return(true);
        }
        public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams)
        {
            if (this.working)
            {
                Log.ErrorOnce("Called ReachableBetween while working. This should never happen. Suppressing further errors.", 7312233);
                return(false);
            }
            if (traverseParams.pawn != null)
            {
                if (!traverseParams.pawn.Spawned)
                {
                    return(false);
                }
                if (traverseParams.pawn.Map != this.map)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=",
                        traverseParams.pawn,
                        " pawn.Map=",
                        traverseParams.pawn.Map,
                        " map=",
                        this.map
                    }));
                    return(false);
                }
            }
            if (ReachabilityImmediate.CanReachImmediate(start, dest, this.map, peMode, traverseParams.pawn))
            {
                return(true);
            }
            if (!dest.IsValid)
            {
                return(false);
            }
            if (dest.HasThing && dest.Thing.Map != this.map)
            {
                return(false);
            }
            if (!start.InBounds(this.map) || !dest.Cell.InBounds(this.map))
            {
                return(false);
            }
            if (peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch)
            {
                Room room = RegionAndRoomQuery.RoomAtFast(start, this.map, RegionType.Set_Passable);
                if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, this.map, RegionType.Set_Passable))
                {
                    return(true);
                }
            }
            if (traverseParams.mode == TraverseMode.PassAllDestroyableThings)
            {
                TraverseParms traverseParams2 = traverseParams;
                traverseParams2.mode = TraverseMode.PassDoors;
                if (this.CanReach(start, dest, peMode, traverseParams2))
                {
                    return(true);
                }
            }
            dest         = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(this.map), ref peMode);
            this.working = true;
            bool result;

            try
            {
                this.pathGrid      = this.map.pathGrid;
                this.regionGrid    = this.map.regionGrid;
                this.reachedIndex += 1u;
                this.destRegions.Clear();
                if (peMode == PathEndMode.OnCell)
                {
                    Region region = dest.Cell.GetRegion(this.map, RegionType.Set_Passable);
                    if (region != null && region.Allows(traverseParams, true))
                    {
                        this.destRegions.Add(region);
                    }
                }
                else if (peMode == PathEndMode.Touch)
                {
                    TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, this.map, this.destRegions);
                }
                if (this.destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings)
                {
                    this.FinalizeCheck();
                    result = false;
                }
                else
                {
                    this.destRegions.RemoveDuplicates <Region>();
                    this.openQueue.Clear();
                    this.numRegionsOpened = 0;
                    this.DetermineStartRegions(start);
                    if (this.openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings)
                    {
                        this.FinalizeCheck();
                        result = false;
                    }
                    else
                    {
                        if (this.startingRegions.Any <Region>() && this.destRegions.Any <Region>())
                        {
                            BoolUnknown cachedResult = this.GetCachedResult(traverseParams);
                            if (cachedResult == BoolUnknown.True)
                            {
                                this.FinalizeCheck();
                                result = true;
                                return(result);
                            }
                            if (cachedResult == BoolUnknown.False)
                            {
                                this.FinalizeCheck();
                                result = false;
                                return(result);
                            }
                            if (cachedResult != BoolUnknown.Unknown)
                            {
                            }
                        }
                        if (traverseParams.mode == TraverseMode.PassAllDestroyableThings)
                        {
                            bool flag = this.CheckCellBasedReachability(start, dest, peMode, traverseParams);
                            this.FinalizeCheck();
                            result = flag;
                        }
                        else
                        {
                            bool flag2 = this.CheckRegionBasedReachability(traverseParams);
                            this.FinalizeCheck();
                            result = flag2;
                        }
                    }
                }
            }
            finally
            {
                this.working = false;
            }
            return(result);
        }
示例#18
0
        public bool CanReachShip(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParms)
        {
            if (this.working)
            {
                Log.ErrorOnce("Called CanReach() while working for Ships. This should never happen. Suppressing further errors.", 7312233, false);
                return(false);
            }
            if (!this.map.terrainGrid.TerrainAt(dest.Cell).IsWater)
            {
                return(false);
            }
            if (!(traverseParms.pawn is null))
            {
                if (!traverseParms.pawn.Spawned)
                {
                    return(false);
                }
                if (traverseParms.pawn.Map != this.map)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Called CanReach() with a ship spawned not on this map. This means that we can't check its reachability here. Pawn's" +
                        "current map should have been used instead of this one. pawn=", traverseParms.pawn,
                        " pawn.Map=", traverseParms.pawn.Map,
                        " map=", this.map
                    }), false);
                    return(false);
                }
            }
            if (!dest.IsValid)
            {
                return(false);
            }
            if (dest.HasThing && dest.Thing.Map != this.map)
            {
                return(false);
            }
            if (!start.InBoundsShip(this.map) || !dest.Cell.InBoundsShip(this.map))
            {
                return(false);
            }
            if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater &&
                traverseParms.mode != TraverseMode.PassAllDestroyableThingsNotWater)
            {
                WaterRoom room = WaterRegionAndRoomQuery.RoomAtFast(start, this.map, RegionType.Set_Passable);
                if (!(room is null) && room == WaterRegionAndRoomQuery.RoomAtFast(dest.Cell, this.map, RegionType.Set_Passable))
                {
                    return(true);
                }
            }
            if (traverseParms.mode == TraverseMode.PassAllDestroyableThings)
            {
                TraverseParms traverseParms2 = traverseParms;
                traverseParms.mode = TraverseMode.PassDoors;
                if (this.CanReachShip(start, dest, peMode, traverseParms2))
                {
                    return(true);
                }
            }
            dest         = (LocalTargetInfo)GenPathShip.ResolvePathMode(traverseParms.pawn, dest.ToTargetInfo(this.map), ref peMode, this.mapExt);
            this.working = true;
            bool result;

            try
            {
                this.pathGrid      = mapExt.getShipPathGrid;
                this.regionGrid    = this.mapExt.getWaterRegionGrid;
                this.reachedIndex += 1u;
                this.destRegions.Clear();
                if (peMode == PathEndMode.OnCell)
                {
                    WaterRegion region = WaterGridsUtility.GetRegion(dest.Cell, this.map, RegionType.Set_Passable);
                    if (!(region is null) && region.Allows(traverseParms, true))
                    {
                        this.destRegions.Add(region);
                    }
                }
                else if (peMode == PathEndMode.Touch)
                {
                    TouchPathEndModeUtilityShips.AddAllowedAdjacentRegions(dest, traverseParms, this.map, this.destRegions);
                }
                if (this.destRegions.Count == 0 && traverseParms.mode != TraverseMode.PassAllDestroyableThings && traverseParms.mode !=
                    TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    this.FinalizeCheck();
                    result = false;
                }
                else
                {
                    this.destRegions.RemoveDuplicates <WaterRegion>();
                    this.openQueue.Clear();
                    this.numRegionsOpened = 0;
                    this.DetermineStartRegions(start);
                    if (this.openQueue.Count == 0 && traverseParms.mode != TraverseMode.PassAllDestroyableThings && traverseParms.mode !=
                        TraverseMode.PassAllDestroyableThingsNotWater)
                    {
                        this.FinalizeCheck();
                        result = false;
                    }
                    else
                    {
                        if (this.startingRegions.Any <WaterRegion>() && this.destRegions.Any <WaterRegion>() && this.CanUseCache(traverseParms.mode))
                        {
                            BoolUnknown cachedResult = this.GetCachedResult(traverseParms);
                            if (cachedResult == BoolUnknown.True)
                            {
                                this.FinalizeCheck();
                                return(true);
                            }
                            if (cachedResult == BoolUnknown.False)
                            {
                                this.FinalizeCheck();
                                return(false);
                            }
                        }
                        if (traverseParms.mode == TraverseMode.PassAllDestroyableThings || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater ||
                            traverseParms.mode == TraverseMode.NoPassClosedDoorsOrWater)
                        {
                            bool flag = this.CheckCellBasedReachability(start, dest, peMode, traverseParms);
                            this.FinalizeCheck();
                            result = flag;
                        }
                        else
                        {
                            //bool flag2 = this.CheckRegionBasedReachability(traverseParms);
                            bool flag2 = this.CheckCellBasedReachability(start, dest, peMode, traverseParms); //Change back to region based later
                            this.FinalizeCheck();
                            result = flag2;
                        }
                    }
                }
            }
            finally
            {
                this.working = false;
            }
            return(result);
        }
示例#19
0
 public override bool IsApplicableTo(LocalTargetInfo target, bool showMessages = false)
 {
     if (!ModLister.RoyaltyInstalled)
     {
         Log.ErrorOnce("Psycasts are a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 324345647);
         return(false);
     }
     if (!base.IsApplicableTo(target, showMessages))
     {
         return(false);
     }
     if (!Psycast.def.HasAreaOfEffect && !Psycast.CanApplyPsycastTo(target))
     {
         if (showMessages)
         {
             Messages.Message(ability.def.LabelCap + ": " + "AbilityTargetPsychicallyDeaf".Translate(), target.ToTargetInfo(ability.pawn.Map), MessageTypeDefOf.RejectInput, historical: false);
         }
         return(false);
     }
     return(true);
 }
示例#20
0
        public static bool CanReach(Reachability __instance, ref bool __result,
                                    IntVec3 start,
                                    LocalTargetInfo dest,
                                    PathEndMode peMode,
                                    TraverseParms traverseParams)
        {
            /*
             * if (working)
             * {
             *  Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233);
             *  return false;
             * }
             */

            Map this_map = map(__instance);

            if (traverseParams.pawn != null)
            {
                if (!traverseParams.pawn.Spawned)
                {
                    __result = false;
                    return(false);
                }
                if (traverseParams.pawn.Map != this_map)
                {
                    Log.Error("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=" +
                              (object)traverseParams.pawn + " pawn.Map=" + (object)traverseParams.pawn.Map + " map=" + (object)map(__instance), false);
                    __result = false;
                    return(false);
                }
            }
            if (ReachabilityImmediate.CanReachImmediate(start, dest, this_map, peMode, traverseParams.pawn))
            {
                __result = true;
                return(false);
            }
            if (!dest.IsValid || dest.HasThing && dest.Thing.Map != this_map || (!start.InBounds(this_map) || !dest.Cell.InBounds(this_map)))
            {
                __result = false;
                return(false);
            }
            if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && (traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater))
            {
                Room room = RegionAndRoomQuery.RoomAtFast(start, this_map, RegionType.Set_Passable);
                if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, this_map, RegionType.Set_Passable))
                {
                    __result = true;
                    return(false);
                }
            }
            if (traverseParams.mode == TraverseMode.PassAllDestroyableThings)
            {
                TraverseParms traverseParams1 = traverseParams;
                traverseParams1.mode = TraverseMode.PassDoors;
                if (__instance.CanReach(start, dest, peMode, traverseParams1))
                {
                    __result = true;
                    return(false);
                }
            }
            dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(this_map), ref peMode);
            //working = true;
            try
            {
                uint this_reachedIndex;                                   //Replaced reachedIndex
                lock (reachedIndexLock)                                   //Added
                {
                    this_reachedIndex   = offsetReachedIndex;             //Added
                    offsetReachedIndex += 100000;                         //Added
                }
                HashSet <Region> regionsReached = new HashSet <Region>(); //Added
                PathGrid         pathGrid       = this_map.pathGrid;      //Replaced pathGrid
                RegionGrid       regionGrid     = this_map.regionGrid;    //Replaced regionGrid
                ++this_reachedIndex;                                      //Replaced reachedIndex

                //this_destRegions.Clear();
                List <Region> this_destRegions = new List <Region>(); //Replaced destRegions
                switch (peMode)
                {
                case PathEndMode.OnCell:
                    Region region = dest.Cell.GetRegion(this_map, RegionType.Set_Passable);
                    if (region != null && region.Allows(traverseParams, true))
                    {
                        this_destRegions.Add(region);
                        break;
                    }
                    break;

                case PathEndMode.Touch:
                    TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, this_map, this_destRegions);
                    break;
                }
                if (this_destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    //this.FinalizeCheck();
                    __result = false;
                    return(false);
                }
                this_destRegions.RemoveDuplicates <Region>();
                //this_openQueue.Clear();
                Queue <Region> this_openQueue        = new Queue <Region>(); //Replaced openQueue
                int            this_numRegionsOpened = 0;                    //Replaced numRegionsOpened
                List <Region>  this_startingRegions  = new List <Region>();
                DetermineStartRegions2(__instance, start, this_startingRegions, pathGrid, regionGrid, this_reachedIndex, this_openQueue, ref this_numRegionsOpened, regionsReached);
                if (this_openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)
                {
                    //this.FinalizeCheck();
                    __result = false;
                    return(false);
                }
                ReachabilityCache this_cache = cache(__instance);
                if (this_startingRegions.Any <Region>() && this_destRegions.Any <Region>() && CanUseCache(traverseParams.mode))
                {
                    switch (GetCachedResult2(traverseParams, this_startingRegions, this_destRegions, this_cache))
                    {
                    case BoolUnknown.True:
                        //this.FinalizeCheck();
                        __result = true;
                        return(false);

                    case BoolUnknown.False:
                        //this.FinalizeCheck();
                        __result = false;
                        return(false);
                    }
                }
                if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater)
                {
                    int num = CheckCellBasedReachability(start, dest, peMode, traverseParams,
                                                         regionGrid, __instance, this_startingRegions, this_cache, this_destRegions
                                                         ) ? 1 : 0;
                    //this.FinalizeCheck();
                    __result = num != 0;
                    return(false);
                }
                int num1 = CheckRegionBasedReachability(traverseParams,
                                                        this_openQueue, this_reachedIndex,
                                                        this_destRegions, this_startingRegions, this_cache, ref this_numRegionsOpened, regionsReached
                                                        ) ? 1 : 0;
                //this.FinalizeCheck();
                __result = num1 != 0;
                return(false);
            }
            finally
            {
            }
        }
示例#21
0
        public void StartPath(LocalTargetInfo dest, PathEndMode peMode)
        {
            if (!pawn.Drafted)
            {
                PatherFailed();
                return;
            }

            if (pawn.IsBoat())
            {
                dest = (LocalTargetInfo)GenPathVehicles.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode);
                if (dest.HasThing && dest.ThingDestroyed)
                {
                    Log.Error(pawn + " pathing to destroyed thing " + dest.Thing);
                    PatherFailed();
                    return;
                }
                //Add Building and Position Recoverable extras
                if (!GenGridVehicles.Walkable(pawn.Position, pawn.Map.GetCachedMapComponent <VehicleMapping>()))
                {
                    return;
                }
                if (Moving && curPath != null && destination == dest && this.peMode == peMode)
                {
                    return;
                }
                if (!pawn.Map.GetCachedMapComponent <VehicleMapping>().VehicleReachability?.CanReachShip(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)) ?? false)
                {
                    PatherFailed();
                    return;
                }
                this.peMode = peMode;
                destination = dest;
                if ((GenGridVehicles.Walkable(nextCell, pawn.Map.GetCachedMapComponent <VehicleMapping>()) || WillCollideWithPawnOnNextPathCell()) || nextCellCostLeft == nextCellCostTotal)
                {
                    ResetToCurrentPosition();
                }
                PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager.
                                                                                                          MostRecentReservationFor(pawn);
                if (!(pawnDestinationReservation is null) && ((Destination.HasThing && pawnDestinationReservation.target != Destination.Cell) ||
                                                              (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != Destination.Cell)))
                {
                    pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn);
                }
                if (VehicleReachabilityImmediate.CanReachImmediateShip(pawn, dest, peMode))
                {
                    PatherArrived();
                    return;
                }
                if (curPath != null)
                {
                    curPath.ReleaseToPool();
                }
                curPath           = null;
                moving            = true;
                pawn.jobs.posture = PawnPosture.Standing;

                return;
            }
            else
            {
                dest = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode);
                if (dest.HasThing && dest.ThingDestroyed)
                {
                    Log.Error(pawn + " pathing to destroyed thing " + dest.Thing);
                    PatherFailed();
                    return;
                }
                if (!PawnCanOccupy(pawn.Position) && !TryRecoverFromUnwalkablePosition(true))
                {
                    return;
                }
                if (moving && curPath != null && destination == dest && this.peMode == peMode)
                {
                    return;
                }
                if (!pawn.Map.reachability.CanReach(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)))
                {
                    PatherFailed();
                    return;
                }
                this.peMode = peMode;
                destination = dest;
                if (!IsNextCellWalkable() || NextCellDoorToWaitForOrManuallyOpen() != null || nextCellCostLeft == nextCellCostTotal)
                {
                    ResetToCurrentPosition();
                }
                PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager.MostRecentReservationFor(pawn);
                if (pawnDestinationReservation != null && ((destination.HasThing && pawnDestinationReservation.target != destination.Cell) || (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != destination.Cell)))
                {
                    pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn);
                }
                if (AtDestinationPosition())
                {
                    PatherArrived();
                    return;
                }
                if (pawn.Downed)
                {
                    Log.Error(pawn.LabelCap + " tried to path while downed. This should never happen. curJob=" + pawn.CurJob.ToStringSafe());
                    PatherFailed();
                    return;
                }
                if (curPath != null)
                {
                    curPath.ReleaseToPool();
                }
                curPath           = null;
                moving            = true;
                pawn.jobs.posture = PawnPosture.Standing;
            }
        }