Exemplo n.º 1
0
        public static IntVec3 FinalWalkableNonDoorCell(this PawnPath path, Map map)
        {
            IntVec3 result;

            if (path.NodesReversed.Count == 1)
            {
                result = path.NodesReversed[0];
            }
            else
            {
                List <IntVec3> nodesReversed = path.NodesReversed;
                for (int i = 0; i < nodesReversed.Count; i++)
                {
                    Building edifice = nodesReversed[i].GetEdifice(map);
                    if (edifice == null || edifice.def.passability != Traversability.Impassable)
                    {
                        Building_Door building_Door = edifice as Building_Door;
                        if (building_Door == null || building_Door.FreePassage)
                        {
                            return(nodesReversed[i]);
                        }
                    }
                }
                result = nodesReversed[0];
            }
            return(result);
        }
Exemplo n.º 2
0
        public static PawnPath NewNotFound()
        {
            PawnPath pawnPath = new PawnPath();

            pawnPath.totalCostInt = -1f;
            return(pawnPath);
        }
        // Token: 0x06000055 RID: 85 RVA: 0x0000428C File Offset: 0x0000248C
        public override void Notify_PatherFailed()
        {
            bool attackDoorIfTargetLost = this.job.attackDoorIfTargetLost;

            if (attackDoorIfTargetLost)
            {
                Thing thing;
                using (PawnPath pawnPath = base.Map.pathFinder.FindPath(this.pawn.Position, base.TargetA.Cell, TraverseParms.For(this.pawn, Danger.Deadly, TraverseMode.PassDoors, false), PathEndMode.OnCell))
                {
                    bool flag = !pawnPath.Found;
                    if (flag)
                    {
                        return;
                    }
                    IntVec3 intVec;
                    thing = pawnPath.FirstBlockingBuilding(out intVec, this.pawn);
                }
                bool flag2 = thing != null;
                if (flag2)
                {
                    bool flag3 = thing.Position.InHorDistOf(this.pawn.Position, 6f);
                    if (flag3)
                    {
                        this.job.targetA            = thing;
                        this.job.maxNumMeleeAttacks = Rand.RangeInclusive(2, 5);
                        this.job.expiryInterval     = Rand.Range(2000, 4000);
                        return;
                    }
                }
            }
            base.Notify_PatherFailed();
        }
Exemplo n.º 4
0
        public static bool TryFindLastCellBeforeBlockingDoor(this PawnPath path, Pawn pawn, out IntVec3 result)
        {
            bool result2;

            if (path.NodesReversed.Count == 1)
            {
                result  = path.NodesReversed[0];
                result2 = false;
            }
            else
            {
                List <IntVec3> nodesReversed = path.NodesReversed;
                for (int i = nodesReversed.Count - 2; i >= 1; i--)
                {
                    Building_Door building_Door = nodesReversed[i].GetEdifice(pawn.Map) as Building_Door;
                    if (building_Door != null)
                    {
                        if (!building_Door.CanPhysicallyPass(pawn))
                        {
                            result = nodesReversed[i + 1];
                            return(true);
                        }
                    }
                }
                result  = nodesReversed[0];
                result2 = false;
            }
            return(result2);
        }
Exemplo n.º 5
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag = forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig && !pawn.CanReachMapEdge()) || (forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, countDormantPawnsAsHostile: true));

            if (!TryFindGoodExitDest(pawn, flag, out IntVec3 dest))
            {
                return(null);
            }
            if (flag)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, dest, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings)))
                {
                    IntVec3 cellBefore;
                    Thing   thing = path.FirstBlockingBuilding(out cellBefore, pawn);
                    if (thing != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBefore, canMineMineables: true, canMineNonMineables: true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            Job job2 = JobMaker.MakeJob(JobDefOf.Goto, dest);

            job2.exitMapOnArrival = true;
            job2.failIfCantJoinOrCreateCaravan = failIfCantJoinOrCreateCaravan;
            job2.locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, defaultLocomotion, LocomotionUrgency.Jog);
            job2.expiryInterval = jobMaxDuration;
            job2.canBash        = canBash;
            return(job2);
        }
        public override void Notify_PatherFailed()
        {
            if (base.job.attackDoorIfTargetLost)
            {
                Thing thing = default(Thing);
                using (PawnPath pawnPath = base.Map.pathFinder.FindPath(base.pawn.Position, base.TargetA.Cell, TraverseParms.For(base.pawn, Danger.Deadly, TraverseMode.PassDoors, false), PathEndMode.OnCell))
                {
                    if (pawnPath.Found)
                    {
                        IntVec3 intVec = default(IntVec3);
                        thing = pawnPath.FirstBlockingBuilding(out intVec, base.pawn);
                        goto end_IL_004e;
                    }
                    return;

                    end_IL_004e :;
                }
                if (thing != null)
                {
                    base.job.targetA            = thing;
                    base.job.maxNumMeleeAttacks = Rand.RangeInclusive(2, 5);
                    base.job.expiryInterval     = Rand.Range(2000, 4000);
                    return;
                }
            }
            base.Notify_PatherFailed();
        }
        public static IntVec3 LastCellBeforeBlockerOrFinalCell(this PawnPath path, Map map)
        {
            if (path.NodesReversed.Count == 1)
            {
                return(path.NodesReversed[0]);
            }
            List <IntVec3> nodesReversed = path.NodesReversed;

            for (int num = nodesReversed.Count - 2; num >= 1; num--)
            {
                Building edifice = nodesReversed[num].GetEdifice(map);
                if (edifice != null)
                {
                    if (edifice.def.passability == Traversability.Impassable)
                    {
                        return(nodesReversed[num + 1]);
                    }
                    Building_Door building_Door = edifice as Building_Door;
                    if (building_Door != null && !building_Door.FreePassage)
                    {
                        return(nodesReversed[num + 1]);
                    }
                }
            }
            return(nodesReversed[0]);
        }
Exemplo n.º 8
0
        private bool TrySetNewPath()
        {
            PawnPath pawnPath = this.GenerateNewPath();

            if (!pawnPath.Found)
            {
                this.PatherFailed();
                return(false);
            }
            if (this.curPath != null)
            {
                this.curPath.ReleaseToPool();
            }
            this.curPath = pawnPath;
            int num = 0;

            while (num < 20 && num < this.curPath.NodesLeftCount)
            {
                IntVec3 c = this.curPath.Peek(num);
                if (PawnUtility.ShouldCollideWithPawns(this.pawn) && PawnUtility.AnyPawnBlockingPathAt(c, this.pawn, false, false, false))
                {
                    this.foundPathWhichCollidesWithPawns = Find.TickManager.TicksGame;
                }
                if (PawnUtility.KnownDangerAt(c, this.pawn.Map, this.pawn))
                {
                    this.foundPathWithDanger = Find.TickManager.TicksGame;
                }
                if (this.foundPathWhichCollidesWithPawns == Find.TickManager.TicksGame && this.foundPathWithDanger == Find.TickManager.TicksGame)
                {
                    break;
                }
                num++;
            }
            return(true);
        }
Exemplo n.º 9
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;
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
        public static Thing FirstBlockingBuilding(this PawnPath path, out IntVec3 cellBefore, Pawn pawn = null)
        {
            Thing result;

            if (!path.Found)
            {
                cellBefore = IntVec3.Invalid;
                result     = null;
            }
            else
            {
                List <IntVec3> nodesReversed = path.NodesReversed;
                if (nodesReversed.Count == 1)
                {
                    cellBefore = nodesReversed[0];
                    result     = null;
                }
                else
                {
                    Building building = null;
                    IntVec3  intVec   = IntVec3.Invalid;
                    for (int i = nodesReversed.Count - 2; i >= 0; i--)
                    {
                        Building edifice = nodesReversed[i].GetEdifice(pawn.Map);
                        if (edifice != null)
                        {
                            Building_Door building_Door = edifice as Building_Door;
                            if ((building_Door != null && !building_Door.FreePassage && (pawn == null || !building_Door.PawnCanOpen(pawn))) || edifice.def.passability == Traversability.Impassable)
                            {
                                if (building != null)
                                {
                                    cellBefore = intVec;
                                    return(building);
                                }
                                cellBefore = nodesReversed[i + 1];
                                return(edifice);
                            }
                        }
                        if (edifice != null && edifice.def.passability == Traversability.PassThroughOnly && edifice.def.Fillage == FillCategory.Full)
                        {
                            if (building == null)
                            {
                                building = edifice;
                                intVec   = nodesReversed[i + 1];
                            }
                        }
                        else if (edifice == null || edifice.def.passability != Traversability.PassThroughOnly)
                        {
                            building = null;
                        }
                    }
                    cellBefore = nodesReversed[0];
                    result     = null;
                }
            }
            return(result);
        }
Exemplo n.º 11
0
 public void StopDead()
 {
     if (curPath != null)
     {
         curPath.ReleaseToPool();
     }
     curPath  = null;
     moving   = false;
     nextCell = pawn.Position;
 }
 public static bool TryFindCellAtIndex(PawnPath path, int index, out IntVec3 result)
 {
     if (path.NodesReversed.Count <= index || index < 0)
     {
         result = IntVec3.Invalid;
         return(false);
     }
     result = path.NodesReversed[path.NodesReversed.Count - 1 - index];
     return(true);
 }
Exemplo n.º 13
0
 public void StopDead()
 {
     if (this.curPath != null)
     {
         this.curPath.ReleaseToPool();
     }
     this.curPath  = null;
     this.moving   = false;
     this.nextCell = this.pawn.Position;
 }
		public static bool TryFindCellAtIndex(PawnPath path, int index, out IntVec3 result)
		{
			if (path.NodesReversed.Count > index && index >= 0)
			{
				result = path.NodesReversed[path.NodesReversed.Count - 1 - index];
				return true;
			}
			result = IntVec3.Invalid;
			return false;
		}
        // Token: 0x06003DA3 RID: 15779 RVA: 0x0016D63C File Offset: 0x0016B83C
        protected override Job TryGiveJob(Pawn pawn)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room.PsychologicallyOutdoors && room.TouchesMapEdge)
            {
                return(null);
            }
            if (!pawn.CanReachMapEdge())
            {
                return(null);
            }
            bool    flag = this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig && !pawn.CanReachMapEdge()) || (this.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (this.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, true));
            IntVec3 c;

            if (!this.TryFindGoodExitDest(pawn, flag, out c))
            {
                return(null);
            }
            if (flag)
            {
                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                {
                    IntVec3 cellBeforeBlocker;
                    Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                    if (thing.def == XenomorphDefOf.RRY_Xenomorph_Hive_Wall)
                    {
                        CellRect rect = new CellRect(thing.Position.x - 1, thing.Position.y - 1, 3, 3);
                        foreach (IntVec3 cell in rect)
                        {
                            if (cell.InBounds(thing.Map))
                            {
                                if (cell.GetThingList(thing.Map).All(x => x.def != XenomorphDefOf.RRY_Xenomorph_Hive_Wall))
                                {
                                    thing = cell.GetFirstMineable(thing.Map);
                                    break;
                                }
                            }
                        }
                    }
                    if (thing != null && thing.def != XenomorphDefOf.RRY_Xenomorph_Hive_Wall)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                        if (job != null)
                        {
                            return(job);
                        }
                    }
                }
            }
            return(null);
        }
		public static Thing FirstBlockingBuilding(this PawnPath path, out IntVec3 cellBefore, Pawn pawn = null)
		{
			if (!path.Found)
			{
				cellBefore = IntVec3.Invalid;
				return null;
			}
			List<IntVec3> nodesReversed = path.NodesReversed;
			if (nodesReversed.Count == 1)
			{
				cellBefore = nodesReversed[0];
				return null;
			}
			Building building = null;
			IntVec3 intVec = IntVec3.Invalid;
			for (int num = nodesReversed.Count - 2; num >= 0; num--)
			{
				Building edifice = nodesReversed[num].GetEdifice(pawn.Map);
				if (edifice != null)
				{
					Building_Door building_Door = edifice as Building_Door;
					if ((building_Door == null || building_Door.FreePassage || (pawn != null && building_Door.PawnCanOpen(pawn))) && edifice.def.passability != Traversability.Impassable)
					{
						goto IL_00da;
					}
					if (building != null)
					{
						cellBefore = intVec;
						return building;
					}
					cellBefore = nodesReversed[num + 1];
					return edifice;
				}
				goto IL_00da;
				IL_00da:
				if (edifice != null && edifice.def.passability == Traversability.PassThroughOnly && edifice.def.Fillage == FillCategory.Full)
				{
					if (building == null)
					{
						building = edifice;
						intVec = nodesReversed[num + 1];
					}
				}
				else if (edifice == null || edifice.def.passability != Traversability.PassThroughOnly)
				{
					building = null;
				}
			}
			cellBefore = nodesReversed[0];
			return null;
		}
Exemplo n.º 17
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;
     }
 }
Exemplo n.º 18
0
        private PawnPath FinalizedPath(int finalIndex, bool usedRegionHeuristics)
        {
            PawnPath emptyPawnPath = map.pawnPathPool.GetEmptyPawnPath();
            int      num           = finalIndex;

            while (true)
            {
                int parentIndex = calcGrid[num].parentIndex;
                emptyPawnPath.AddNode(map.cellIndices.IndexToCell(num));
                if (num == parentIndex)
                {
                    break;
                }
                num = parentIndex;
            }
            emptyPawnPath.SetupFound(calcGrid[finalIndex].knownCost, usedRegionHeuristics);
            return(emptyPawnPath);
        }
Exemplo n.º 19
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag = false;

            if (this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig) || (this.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (this.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction)))
            {
                flag = true;
            }
            IntVec3 c;
            Job     result;

            if (!this.TryFindGoodExitDest(pawn, flag, out c))
            {
                result = null;
            }
            else
            {
                if (flag)
                {
                    using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                    {
                        IntVec3 cellBeforeBlocker;
                        Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                        if (thing != null)
                        {
                            Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                            if (job != null)
                            {
                                return(job);
                            }
                        }
                    }
                }
                result = new Job(JobDefOf.Goto, c)
                {
                    exitMapOnArrival = true,
                    failIfCantJoinOrCreateCaravan = this.failIfCantJoinOrCreateCaravan,
                    locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, this.defaultLocomotion, LocomotionUrgency.Jog),
                    expiryInterval = this.jobMaxDuration,
                    canBash        = this.canBash
                };
            }
            return(result);
        }
        private PawnPath FinalizedPath(int finalIndex)
        {
            PawnPath emptyPawnPath = pathPool.GetEmptyPawnPath();
            int      num           = finalIndex;

            while (true)
            {
                newPathFinder.PathFinderNodeFast pathFinderNodeFast = this.calcGrid[num];
                int parentIndex = pathFinderNodeFast.parentIndex;
                emptyPawnPath.AddNode(this.map.cellIndices.IndexToCell(num));
                if (num == parentIndex)
                {
                    break;
                }
                num = parentIndex;
            }
            emptyPawnPath.SetupFound((float)this.calcGrid[finalIndex].knownCost);
            return(emptyPawnPath);
        }
Exemplo n.º 21
0
        private PawnPath FinalizedPath(int finalIndex, bool usedRegionHeuristics)
        {
            PawnPath emptyPawnPath = this.map.pawnPathPool.GetEmptyPawnPath();
            int      num           = finalIndex;

            for (;;)
            {
                PathFinder.PathFinderNodeFast pathFinderNodeFast = this.calcGrid[num];
                int parentIndex = pathFinderNodeFast.parentIndex;
                emptyPawnPath.AddNode(this.map.cellIndices.IndexToCell(num));
                if (num == parentIndex)
                {
                    break;
                }
                num = parentIndex;
            }
            emptyPawnPath.SetupFound((float)this.calcGrid[finalIndex].knownCost, usedRegionHeuristics);
            return(emptyPawnPath);
        }
		public static bool TryFindLastCellBeforeBlockingDoor(this PawnPath path, Pawn pawn, out IntVec3 result)
		{
			if (path.NodesReversed.Count == 1)
			{
				result = path.NodesReversed[0];
				return false;
			}
			List<IntVec3> nodesReversed = path.NodesReversed;
			for (int num = nodesReversed.Count - 2; num >= 1; num--)
			{
				Building_Door building_Door = nodesReversed[num].GetEdifice(pawn.Map) as Building_Door;
				if (building_Door != null && !building_Door.CanPhysicallyPass(pawn))
				{
					result = nodesReversed[num + 1];
					return true;
				}
			}
			result = nodesReversed[0];
			return false;
		}
Exemplo n.º 23
0
        public PawnPath GetEmptyPawnPath()
        {
            for (int i = 0; i < paths.Count; i++)
            {
                if (!paths[i].inUse)
                {
                    paths[i].inUse = true;
                    return(paths[i]);
                }
            }
            if (paths.Count > map.mapPawns.AllPawnsSpawnedCount + 2)
            {
                Log.ErrorOnce("PawnPathPool leak: more paths than spawned pawns. Force-recovering.", 664788);
                paths.Clear();
            }
            PawnPath pawnPath = new PawnPath();

            paths.Add(pawnPath);
            pawnPath.inUse = true;
            return(pawnPath);
        }
		public static IntVec3 FinalWalkableNonDoorCell(this PawnPath path, Map map)
		{
			if (path.NodesReversed.Count == 1)
			{
				return path.NodesReversed[0];
			}
			List<IntVec3> nodesReversed = path.NodesReversed;
			for (int i = 0; i < nodesReversed.Count; i++)
			{
				Building edifice = nodesReversed[i].GetEdifice(map);
				if (edifice != null && edifice.def.passability == Traversability.Impassable)
				{
					continue;
				}
				Building_Door building_Door = edifice as Building_Door;
				if (building_Door != null && !building_Door.FreePassage)
				{
					continue;
				}
				return nodesReversed[i];
			}
			return nodesReversed[0];
		}
 public override void Notify_PatherFailed()
 {
     if (job.attackDoorIfTargetLost)
     {
         Thing thing;
         using (PawnPath pawnPath = base.Map.pathFinder.FindPath(pawn.Position, base.TargetA.Cell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassDoors)))
         {
             if (!pawnPath.Found)
             {
                 return;
             }
             thing = pawnPath.FirstBlockingBuilding(out var _, pawn);
         }
         if (thing != null && thing.Position.InHorDistOf(pawn.Position, 6f))
         {
             job.targetA            = thing;
             job.maxNumMeleeAttacks = Rand.RangeInclusive(2, 5);
             job.expiryInterval     = Rand.Range(2000, 4000);
             return;
         }
     }
     base.Notify_PatherFailed();
 }
Exemplo n.º 26
0
        public PawnPath FindPath(IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode = PathEndMode.OnCell)
        {
            if (DebugSettings.pathThroughWalls)
            {
                traverseParms.mode = TraverseMode.PassAllDestroyableThings;
            }
            Pawn pawn = traverseParms.pawn;

            if (pawn != null && pawn.Map != this.map)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath for pawn which is spawned in another map. His map PathFinder should have been used, not this one. pawn=",
                    pawn,
                    " pawn.Map=",
                    pawn.Map,
                    " map=",
                    this.map
                }), false);
                return(PawnPath.NotFound);
            }
            if (!start.IsValid)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid start ",
                    start,
                    ", pawn= ",
                    pawn
                }), false);
                return(PawnPath.NotFound);
            }
            if (!dest.IsValid)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid dest ",
                    dest,
                    ", pawn= ",
                    pawn
                }), false);
                return(PawnPath.NotFound);
            }
            if (traverseParms.mode == TraverseMode.ByPawn)
            {
                if (!pawn.CanReach(dest, peMode, Danger.Deadly, traverseParms.canBash, traverseParms.mode))
                {
                    return(PawnPath.NotFound);
                }
            }
            else if (!this.map.reachability.CanReach(start, dest, peMode, traverseParms))
            {
                return(PawnPath.NotFound);
            }
            this.PfProfilerBeginSample(string.Concat(new object[]
            {
                "FindPath for ",
                pawn,
                " from ",
                start,
                " to ",
                dest,
                (!dest.HasThing) ? string.Empty : (" at " + dest.Cell)
            }));
            this.cellIndices   = this.map.cellIndices;
            this.pathGrid      = this.map.pathGrid;
            this.edificeGrid   = this.map.edificeGrid.InnerArray;
            this.blueprintGrid = this.map.blueprintGrid.InnerArray;
            int      x        = dest.Cell.x;
            int      z        = dest.Cell.z;
            int      num      = this.cellIndices.CellToIndex(start);
            int      num2     = this.cellIndices.CellToIndex(dest.Cell);
            ByteGrid byteGrid = (pawn == null) ? null : pawn.GetAvoidGrid(true);
            bool     flag     = traverseParms.mode == TraverseMode.PassAllDestroyableThings || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag2    = traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParms.mode != TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag3    = !flag;
            CellRect cellRect = this.CalculateDestinationRect(dest, peMode);
            bool     flag4    = cellRect.Width == 1 && cellRect.Height == 1;

            int[]        array       = this.map.pathGrid.pathGrid;
            TerrainDef[] topGrid     = this.map.terrainGrid.topGrid;
            EdificeGrid  edificeGrid = this.map.edificeGrid;
            int          num3        = 0;
            int          num4        = 0;
            Area         allowedArea = this.GetAllowedArea(pawn);
            bool         flag5       = pawn != null && PawnUtility.ShouldCollideWithPawns(pawn);
            bool         flag6       = true && DebugViewSettings.drawPaths;
            bool         flag7       = !flag && start.GetRegion(this.map, RegionType.Set_Passable) != null && flag2;
            bool         flag8       = !flag || !flag3;
            bool         flag9       = false;
            bool         flag10      = pawn != null && pawn.Drafted;
            bool         flag11      = pawn != null && pawn.IsColonist;
            int          num5        = (!flag11) ? 2000 : 100000;
            int          num6        = 0;
            int          num7        = 0;
            float        num8        = this.DetermineHeuristicStrength(pawn, start, dest);
            int          num9;
            int          num10;

            if (pawn != null)
            {
                num9  = pawn.TicksPerMoveCardinal;
                num10 = pawn.TicksPerMoveDiagonal;
            }
            else
            {
                num9  = 13;
                num10 = 18;
            }
            this.CalculateAndAddDisallowedCorners(traverseParms, peMode, cellRect);
            this.InitStatusesAndPushStartNode(ref num, start);
            while (true)
            {
                this.PfProfilerBeginSample("Open cell");
                if (this.openList.Count <= 0)
                {
                    break;
                }
                num6 += this.openList.Count;
                num7++;
                PathFinder.CostNode costNode = this.openList.Pop();
                num = costNode.index;
                if (costNode.cost != this.calcGrid[num].costNodeCost)
                {
                    this.PfProfilerEndSample();
                }
                else if (this.calcGrid[num].status == this.statusClosedValue)
                {
                    this.PfProfilerEndSample();
                }
                else
                {
                    IntVec3 c  = this.cellIndices.IndexToCell(num);
                    int     x2 = c.x;
                    int     z2 = c.z;
                    if (flag6)
                    {
                        this.DebugFlash(c, (float)this.calcGrid[num].knownCost / 1500f, this.calcGrid[num].knownCost.ToString());
                    }
                    if (flag4)
                    {
                        if (num == num2)
                        {
                            goto Block_32;
                        }
                    }
                    else if (cellRect.Contains(c) && !this.disallowedCornerIndices.Contains(num))
                    {
                        goto Block_34;
                    }
                    if (num3 > 160000)
                    {
                        goto Block_35;
                    }
                    this.PfProfilerEndSample();
                    this.PfProfilerBeginSample("Neighbor consideration");
                    for (int i = 0; i < 8; i++)
                    {
                        uint num11 = (uint)(x2 + PathFinder.Directions[i]);
                        uint num12 = (uint)(z2 + PathFinder.Directions[i + 8]);
                        if ((ulong)num11 < (ulong)((long)this.mapSizeX) && (ulong)num12 < (ulong)((long)this.mapSizeZ))
                        {
                            int num13 = (int)num11;
                            int num14 = (int)num12;
                            int num15 = this.cellIndices.CellToIndex(num13, num14);
                            if (this.calcGrid[num15].status != this.statusClosedValue || flag9)
                            {
                                int  num16  = 0;
                                bool flag12 = false;
                                if (flag2 || !new IntVec3(num13, 0, num14).GetTerrain(this.map).HasTag("Water"))
                                {
                                    if (!this.pathGrid.WalkableFast(num15))
                                    {
                                        if (!flag)
                                        {
                                            if (flag6)
                                            {
                                                this.DebugFlash(new IntVec3(num13, 0, num14), 0.22f, "walk");
                                            }
                                            goto IL_E3A;
                                        }
                                        flag12 = true;
                                        num16 += 70;
                                        Building building = edificeGrid[num15];
                                        if (building == null)
                                        {
                                            goto IL_E3A;
                                        }
                                        if (!PathFinder.IsDestroyable(building))
                                        {
                                            goto IL_E3A;
                                        }
                                        num16 += (int)((float)building.HitPoints * 0.2f);
                                    }
                                    if (i > 3)
                                    {
                                        switch (i)
                                        {
                                        case 4:
                                            if (this.BlocksDiagonalMovement(num - this.mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2, 0, z2 - 1), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            if (this.BlocksDiagonalMovement(num + 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2 + 1, 0, z2), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            break;

                                        case 5:
                                            if (this.BlocksDiagonalMovement(num + this.mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2, 0, z2 + 1), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            if (this.BlocksDiagonalMovement(num + 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2 + 1, 0, z2), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            break;

                                        case 6:
                                            if (this.BlocksDiagonalMovement(num + this.mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2, 0, z2 + 1), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            if (this.BlocksDiagonalMovement(num - 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2 - 1, 0, z2), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            break;

                                        case 7:
                                            if (this.BlocksDiagonalMovement(num - this.mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2, 0, z2 - 1), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            if (this.BlocksDiagonalMovement(num - 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.DebugFlash(new IntVec3(x2 - 1, 0, z2), 0.9f, "corn");
                                                    }
                                                    goto IL_E3A;
                                                }
                                                num16 += 70;
                                            }
                                            break;
                                        }
                                    }
                                    int num17 = (i <= 3) ? num9 : num10;
                                    num17 += num16;
                                    if (!flag12)
                                    {
                                        num17 += array[num15];
                                        if (flag10)
                                        {
                                            num17 += topGrid[num15].extraDraftedPerceivedPathCost;
                                        }
                                        else
                                        {
                                            num17 += topGrid[num15].extraNonDraftedPerceivedPathCost;
                                        }
                                    }
                                    if (byteGrid != null)
                                    {
                                        num17 += (int)(byteGrid[num15] * 8);
                                    }
                                    if (allowedArea != null && !allowedArea[num15])
                                    {
                                        num17 += 600;
                                    }
                                    if (flag5 && PawnUtility.AnyPawnBlockingPathAt(new IntVec3(num13, 0, num14), pawn, false, false, true))
                                    {
                                        num17 += 175;
                                    }
                                    Building building2 = this.edificeGrid[num15];
                                    if (building2 != null)
                                    {
                                        this.PfProfilerBeginSample("Edifices");
                                        int buildingCost = PathFinder.GetBuildingCost(building2, traverseParms, pawn);
                                        if (buildingCost == 2147483647)
                                        {
                                            this.PfProfilerEndSample();
                                            goto IL_E3A;
                                        }
                                        num17 += buildingCost;
                                        this.PfProfilerEndSample();
                                    }
                                    List <Blueprint> list = this.blueprintGrid[num15];
                                    if (list != null)
                                    {
                                        this.PfProfilerBeginSample("Blueprints");
                                        int num18 = 0;
                                        for (int j = 0; j < list.Count; j++)
                                        {
                                            num18 = Mathf.Max(num18, PathFinder.GetBlueprintCost(list[j], pawn));
                                        }
                                        if (num18 == 2147483647)
                                        {
                                            this.PfProfilerEndSample();
                                            goto IL_E3A;
                                        }
                                        num17 += num18;
                                        this.PfProfilerEndSample();
                                    }
                                    int    num19  = num17 + this.calcGrid[num].knownCost;
                                    ushort status = this.calcGrid[num15].status;
                                    if (status == this.statusClosedValue || status == this.statusOpenValue)
                                    {
                                        int num20 = 0;
                                        if (status == this.statusClosedValue)
                                        {
                                            num20 = num9;
                                        }
                                        if (this.calcGrid[num15].knownCost <= num19 + num20)
                                        {
                                            goto IL_E3A;
                                        }
                                    }
                                    if (flag9)
                                    {
                                        this.calcGrid[num15].heuristicCost = Mathf.RoundToInt((float)this.regionCostCalculator.GetPathCostFromDestToRegion(num15) * PathFinder.RegionHeuristicWeightByNodesOpened.Evaluate((float)num4));
                                        if (this.calcGrid[num15].heuristicCost < 0)
                                        {
                                            Log.ErrorOnce(string.Concat(new object[]
                                            {
                                                "Heuristic cost overflow for ",
                                                pawn.ToStringSafe <Pawn>(),
                                                " pathing from ",
                                                start,
                                                " to ",
                                                dest,
                                                "."
                                            }), pawn.GetHashCode() ^ 193840009, false);
                                            this.calcGrid[num15].heuristicCost = 0;
                                        }
                                    }
                                    else if (status != this.statusClosedValue && status != this.statusOpenValue)
                                    {
                                        int dx    = Math.Abs(num13 - x);
                                        int dz    = Math.Abs(num14 - z);
                                        int num21 = GenMath.OctileDistance(dx, dz, num9, num10);
                                        this.calcGrid[num15].heuristicCost = Mathf.RoundToInt((float)num21 * num8);
                                    }
                                    int num22 = num19 + this.calcGrid[num15].heuristicCost;
                                    if (num22 < 0)
                                    {
                                        Log.ErrorOnce(string.Concat(new object[]
                                        {
                                            "Node cost overflow for ",
                                            pawn.ToStringSafe <Pawn>(),
                                            " pathing from ",
                                            start,
                                            " to ",
                                            dest,
                                            "."
                                        }), pawn.GetHashCode() ^ 87865822, false);
                                        num22 = 0;
                                    }
                                    this.calcGrid[num15].parentIndex  = num;
                                    this.calcGrid[num15].knownCost    = num19;
                                    this.calcGrid[num15].status       = this.statusOpenValue;
                                    this.calcGrid[num15].costNodeCost = num22;
                                    num4++;
                                    this.openList.Push(new PathFinder.CostNode(num15, num22));
                                }
                            }
                        }
                        IL_E3A :;
                    }
                    this.PfProfilerEndSample();
                    num3++;
                    this.calcGrid[num].status = this.statusClosedValue;
                    if (num4 >= num5 && flag7 && !flag9)
                    {
                        flag9 = true;
                        this.regionCostCalculator.Init(cellRect, traverseParms, num9, num10, byteGrid, allowedArea, flag10, this.disallowedCornerIndices);
                        this.InitStatusesAndPushStartNode(ref num, start);
                        num4 = 0;
                        num3 = 0;
                    }
                }
            }
            string text  = (pawn == null || pawn.CurJob == null) ? "null" : pawn.CurJob.ToString();
            string text2 = (pawn == null || pawn.Faction == null) ? "null" : pawn.Faction.ToString();

            Log.Warning(string.Concat(new object[]
            {
                pawn,
                " pathing from ",
                start,
                " to ",
                dest,
                " ran out of cells to process.\nJob:",
                text,
                "\nFaction: ",
                text2
            }), false);
            this.DebugDrawRichData();
            this.PfProfilerEndSample();
            return(PawnPath.NotFound);

Block_32:
            this.PfProfilerEndSample();
            PawnPath result = this.FinalizedPath(num, flag9);

            this.PfProfilerEndSample();
            return(result);

Block_34:
            this.PfProfilerEndSample();
            PawnPath result2 = this.FinalizedPath(num, flag9);

            this.PfProfilerEndSample();
            return(result2);

Block_35:
            Log.Warning(string.Concat(new object[]
            {
                pawn,
                " pathing from ",
                start,
                " to ",
                dest,
                " hit search limit of ",
                160000,
                " cells."
            }), false);
            this.DebugDrawRichData();
            this.PfProfilerEndSample();
            return(PawnPath.NotFound);
        }
Exemplo n.º 27
0
        public PawnPath FindPath(IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode = PathEndMode.OnCell)
        {
            if (DebugSettings.pathThroughWalls)
            {
                traverseParms.mode = TraverseMode.PassAllDestroyableThings;
            }
            Pawn pawn = traverseParms.pawn;

            if (pawn != null && pawn.Map != map)
            {
                Log.Error("Tried to FindPath for pawn which is spawned in another map. His map PathFinder should have been used, not this one. pawn=" + pawn + " pawn.Map=" + pawn.Map + " map=" + map);
                return(PawnPath.NotFound);
            }
            if (!start.IsValid)
            {
                Log.Error("Tried to FindPath with invalid start " + start + ", pawn= " + pawn);
                return(PawnPath.NotFound);
            }
            if (!dest.IsValid)
            {
                Log.Error("Tried to FindPath with invalid dest " + dest + ", pawn= " + pawn);
                return(PawnPath.NotFound);
            }
            if (traverseParms.mode == TraverseMode.ByPawn)
            {
                if (!pawn.CanReach(dest, peMode, Danger.Deadly, traverseParms.canBash, traverseParms.mode))
                {
                    return(PawnPath.NotFound);
                }
            }
            else if (!map.reachability.CanReach(start, dest, peMode, traverseParms))
            {
                return(PawnPath.NotFound);
            }
            PfProfilerBeginSample("FindPath for " + pawn + " from " + start + " to " + dest + (dest.HasThing ? (" at " + dest.Cell) : ""));
            cellIndices      = map.cellIndices;
            pathGrid         = map.pathGrid;
            this.edificeGrid = map.edificeGrid.InnerArray;
            blueprintGrid    = map.blueprintGrid.InnerArray;
            int      x        = dest.Cell.x;
            int      z        = dest.Cell.z;
            int      curIndex = cellIndices.CellToIndex(start);
            int      num      = cellIndices.CellToIndex(dest.Cell);
            ByteGrid byteGrid = pawn?.GetAvoidGrid();
            bool     flag     = traverseParms.mode == TraverseMode.PassAllDestroyableThings || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag2    = traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParms.mode != TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag3    = !flag;
            CellRect cellRect = CalculateDestinationRect(dest, peMode);
            bool     flag4    = cellRect.Width == 1 && cellRect.Height == 1;

            int[]        array       = map.pathGrid.pathGrid;
            TerrainDef[] topGrid     = map.terrainGrid.topGrid;
            EdificeGrid  edificeGrid = map.edificeGrid;
            int          num2        = 0;
            int          num3        = 0;
            Area         allowedArea = GetAllowedArea(pawn);
            bool         flag5       = pawn != null && PawnUtility.ShouldCollideWithPawns(pawn);
            bool         flag6       = (!flag && start.GetRegion(map) != null) & flag2;
            bool         flag7       = !flag || !flag3;
            bool         flag8       = false;
            bool         flag9       = pawn?.Drafted ?? false;
            int          num4        = (pawn?.IsColonist ?? false) ? 100000 : 2000;
            int          num5        = 0;
            int          num6        = 0;
            float        num7        = DetermineHeuristicStrength(pawn, start, dest);
            int          num8;
            int          num9;

            if (pawn != null)
            {
                num8 = pawn.TicksPerMoveCardinal;
                num9 = pawn.TicksPerMoveDiagonal;
            }
            else
            {
                num8 = 13;
                num9 = 18;
            }
            CalculateAndAddDisallowedCorners(traverseParms, peMode, cellRect);
            InitStatusesAndPushStartNode(ref curIndex, start);
            while (true)
            {
                PfProfilerBeginSample("Open cell");
                if (openList.Count <= 0)
                {
                    string text  = (pawn != null && pawn.CurJob != null) ? pawn.CurJob.ToString() : "null";
                    string text2 = (pawn != null && pawn.Faction != null) ? pawn.Faction.ToString() : "null";
                    Log.Warning(pawn + " pathing from " + start + " to " + dest + " ran out of cells to process.\nJob:" + text + "\nFaction: " + text2);
                    DebugDrawRichData();
                    PfProfilerEndSample();
                    PfProfilerEndSample();
                    return(PawnPath.NotFound);
                }
                num5 += openList.Count;
                num6++;
                CostNode costNode = openList.Pop();
                curIndex = costNode.index;
                if (costNode.cost != calcGrid[curIndex].costNodeCost)
                {
                    PfProfilerEndSample();
                    continue;
                }
                if (calcGrid[curIndex].status == statusClosedValue)
                {
                    PfProfilerEndSample();
                    continue;
                }
                IntVec3 c  = cellIndices.IndexToCell(curIndex);
                int     x2 = c.x;
                int     z2 = c.z;
                if (flag4)
                {
                    if (curIndex == num)
                    {
                        PfProfilerEndSample();
                        PawnPath result = FinalizedPath(curIndex, flag8);
                        PfProfilerEndSample();
                        return(result);
                    }
                }
                else if (cellRect.Contains(c) && !disallowedCornerIndices.Contains(curIndex))
                {
                    PfProfilerEndSample();
                    PawnPath result2 = FinalizedPath(curIndex, flag8);
                    PfProfilerEndSample();
                    return(result2);
                }
                if (num2 > 160000)
                {
                    break;
                }
                PfProfilerEndSample();
                PfProfilerBeginSample("Neighbor consideration");
                for (int i = 0; i < 8; i++)
                {
                    uint num10 = (uint)(x2 + Directions[i]);
                    uint num11 = (uint)(z2 + Directions[i + 8]);
                    if (num10 >= mapSizeX || num11 >= mapSizeZ)
                    {
                        continue;
                    }
                    int num12 = (int)num10;
                    int num13 = (int)num11;
                    int num14 = cellIndices.CellToIndex(num12, num13);
                    if (calcGrid[num14].status == statusClosedValue && !flag8)
                    {
                        continue;
                    }
                    int  num15  = 0;
                    bool flag10 = false;
                    if (!flag2 && new IntVec3(num12, 0, num13).GetTerrain(map).HasTag("Water"))
                    {
                        continue;
                    }
                    if (!pathGrid.WalkableFast(num14))
                    {
                        if (!flag)
                        {
                            continue;
                        }
                        flag10 = true;
                        num15 += 70;
                        Building building = edificeGrid[num14];
                        if (building == null || !IsDestroyable(building))
                        {
                            continue;
                        }
                        num15 += (int)((float)building.HitPoints * 0.2f);
                    }
                    switch (i)
                    {
                    case 4:
                        if (BlocksDiagonalMovement(curIndex - mapSizeX))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        if (BlocksDiagonalMovement(curIndex + 1))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        break;

                    case 5:
                        if (BlocksDiagonalMovement(curIndex + mapSizeX))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        if (BlocksDiagonalMovement(curIndex + 1))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        break;

                    case 6:
                        if (BlocksDiagonalMovement(curIndex + mapSizeX))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        if (BlocksDiagonalMovement(curIndex - 1))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        break;

                    case 7:
                        if (BlocksDiagonalMovement(curIndex - mapSizeX))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        if (BlocksDiagonalMovement(curIndex - 1))
                        {
                            if (flag7)
                            {
                                continue;
                            }
                            num15 += 70;
                        }
                        break;
                    }
                    int num16 = (i > 3) ? num9 : num8;
                    num16 += num15;
                    if (!flag10)
                    {
                        num16 += array[num14];
                        num16  = ((!flag9) ? (num16 + topGrid[num14].extraNonDraftedPerceivedPathCost) : (num16 + topGrid[num14].extraDraftedPerceivedPathCost));
                    }
                    if (byteGrid != null)
                    {
                        num16 += byteGrid[num14] * 8;
                    }
                    if (allowedArea != null && !allowedArea[num14])
                    {
                        num16 += 600;
                    }
                    if (flag5 && PawnUtility.AnyPawnBlockingPathAt(new IntVec3(num12, 0, num13), pawn, actAsIfHadCollideWithPawnsJob: false, collideOnlyWithStandingPawns: false, forPathFinder: true))
                    {
                        num16 += 175;
                    }
                    Building building2 = this.edificeGrid[num14];
                    if (building2 != null)
                    {
                        PfProfilerBeginSample("Edifices");
                        int buildingCost = GetBuildingCost(building2, traverseParms, pawn);
                        if (buildingCost == int.MaxValue)
                        {
                            PfProfilerEndSample();
                            continue;
                        }
                        num16 += buildingCost;
                        PfProfilerEndSample();
                    }
                    List <Blueprint> list = blueprintGrid[num14];
                    if (list != null)
                    {
                        PfProfilerBeginSample("Blueprints");
                        int num17 = 0;
                        for (int j = 0; j < list.Count; j++)
                        {
                            num17 = Mathf.Max(num17, GetBlueprintCost(list[j], pawn));
                        }
                        if (num17 == int.MaxValue)
                        {
                            PfProfilerEndSample();
                            continue;
                        }
                        num16 += num17;
                        PfProfilerEndSample();
                    }
                    int    num18  = num16 + calcGrid[curIndex].knownCost;
                    ushort status = calcGrid[num14].status;
                    if (status == statusClosedValue || status == statusOpenValue)
                    {
                        int num19 = 0;
                        if (status == statusClosedValue)
                        {
                            num19 = num8;
                        }
                        if (calcGrid[num14].knownCost <= num18 + num19)
                        {
                            continue;
                        }
                    }
                    if (flag8)
                    {
                        calcGrid[num14].heuristicCost = Mathf.RoundToInt((float)regionCostCalculator.GetPathCostFromDestToRegion(num14) * RegionHeuristicWeightByNodesOpened.Evaluate(num3));
                        if (calcGrid[num14].heuristicCost < 0)
                        {
                            Log.ErrorOnce("Heuristic cost overflow for " + pawn.ToStringSafe() + " pathing from " + start + " to " + dest + ".", pawn.GetHashCode() ^ 0xB8DC389);
                            calcGrid[num14].heuristicCost = 0;
                        }
                    }
                    else if (status != statusClosedValue && status != statusOpenValue)
                    {
                        int dx    = Math.Abs(num12 - x);
                        int dz    = Math.Abs(num13 - z);
                        int num20 = GenMath.OctileDistance(dx, dz, num8, num9);
                        calcGrid[num14].heuristicCost = Mathf.RoundToInt((float)num20 * num7);
                    }
                    int num21 = num18 + calcGrid[num14].heuristicCost;
                    if (num21 < 0)
                    {
                        Log.ErrorOnce("Node cost overflow for " + pawn.ToStringSafe() + " pathing from " + start + " to " + dest + ".", pawn.GetHashCode() ^ 0x53CB9DE);
                        num21 = 0;
                    }
                    calcGrid[num14].parentIndex  = curIndex;
                    calcGrid[num14].knownCost    = num18;
                    calcGrid[num14].status       = statusOpenValue;
                    calcGrid[num14].costNodeCost = num21;
                    num3++;
                    openList.Push(new CostNode(num14, num21));
                }
                PfProfilerEndSample();
                num2++;
                calcGrid[curIndex].status = statusClosedValue;
                if (num3 >= num4 && flag6 && !flag8)
                {
                    flag8 = true;
                    regionCostCalculator.Init(cellRect, traverseParms, num8, num9, byteGrid, allowedArea, flag9, disallowedCornerIndices);
                    InitStatusesAndPushStartNode(ref curIndex, start);
                    num3 = 0;
                    num2 = 0;
                }
            }
            Log.Warning(pawn + " pathing from " + start + " to " + dest + " hit search limit of " + 160000 + " cells.");
            DebugDrawRichData();
            PfProfilerEndSample();
            PfProfilerEndSample();
            return(PawnPath.NotFound);
        }
Exemplo n.º 28
0
        public PawnPath FindPath(IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode = PathEndMode.OnCell)
        {
            if (DebugSettings.pathThroughWalls)
            {
                traverseParms.mode = TraverseMode.PassAllDestroyableThings;
            }
            Pawn pawn = traverseParms.pawn;

            if (pawn != null && pawn.Map != this.map)
            {
                Log.Error("Tried to FindPath for pawn which is spawned in another map. His map PathFinder should have been used, not this one. pawn=" + pawn + " pawn.Map=" + pawn.Map + " map=" + this.map);
                return(PawnPath.NotFound);
            }
            if (!start.IsValid)
            {
                Log.Error("Tried to FindPath with invalid start " + start + ", pawn= " + pawn);
                return(PawnPath.NotFound);
            }
            if (!dest.IsValid)
            {
                Log.Error("Tried to FindPath with invalid dest " + dest + ", pawn= " + pawn);
                return(PawnPath.NotFound);
            }
            if (traverseParms.mode == TraverseMode.ByPawn)
            {
                if (!pawn.CanReach(dest, peMode, Danger.Deadly, traverseParms.canBash, traverseParms.mode))
                {
                    return(PawnPath.NotFound);
                }
            }
            else if (!this.map.reachability.CanReach(start, dest, peMode, traverseParms))
            {
                return(PawnPath.NotFound);
            }
            this.PfProfilerBeginSample("FindPath for " + pawn + " from " + start + " to " + dest + ((!dest.HasThing) ? string.Empty : (" at " + dest.Cell)));
            this.cellIndices = this.map.cellIndices;
            this.pathGrid    = this.map.pathGrid;
            this.edificeGrid = this.map.edificeGrid.InnerArray;
            IntVec3  cell     = dest.Cell;
            int      x        = cell.x;
            IntVec3  cell2    = dest.Cell;
            int      z        = cell2.z;
            int      num      = this.cellIndices.CellToIndex(start);
            int      num2     = this.cellIndices.CellToIndex(dest.Cell);
            ByteGrid byteGrid = (pawn == null) ? null : pawn.GetAvoidGrid();
            bool     flag     = traverseParms.mode == TraverseMode.PassAllDestroyableThings;
            bool     flag2    = traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParms.mode != TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag3    = !flag;
            CellRect cellRect = this.CalculateDestinationRect(dest, peMode);
            bool     flag4    = cellRect.Width == 1 && cellRect.Height == 1;

            int[]       array       = this.map.pathGrid.pathGrid;
            EdificeGrid edificeGrid = this.map.edificeGrid;
            int         num3        = 0;
            int         num4        = 0;
            Area        allowedArea = this.GetAllowedArea(pawn);
            bool        flag5       = pawn != null && PawnUtility.ShouldCollideWithPawns(pawn);
            bool        flag6       = true && DebugViewSettings.drawPaths;
            bool        flag7       = !flag && start.GetRegion(this.map, RegionType.Set_Passable) != null;
            bool        flag8       = !flag || !flag3;
            bool        flag9       = false;
            int         num5        = 0;
            int         num6        = 0;
            float       num7        = this.DetermineHeuristicStrength(pawn, start, dest);
            int         num8;
            int         num9;

            if (pawn != null)
            {
                num8 = pawn.TicksPerMoveCardinal;
                num9 = pawn.TicksPerMoveDiagonal;
            }
            else
            {
                num8 = 13;
                num9 = 18;
            }
            this.CalculateAndAddDisallowedCorners(traverseParms, peMode, cellRect);
            this.InitStatusesAndPushStartNode(ref num, start);
            while (true)
            {
                this.PfProfilerBeginSample("Open cell");
                if (this.openList.Count <= 0)
                {
                    string text  = (pawn == null || pawn.CurJob == null) ? "null" : pawn.CurJob.ToString();
                    string text2 = (pawn == null || pawn.Faction == null) ? "null" : pawn.Faction.ToString();
                    Log.Warning(pawn + " pathing from " + start + " to " + dest + " ran out of cells to process.\nJob:" + text + "\nFaction: " + text2);
                    this.DebugDrawRichData();
                    this.PfProfilerEndSample();
                    return(PawnPath.NotFound);
                }
                num5 += this.openList.Count;
                num6++;
                CostNode costNode = this.openList.Pop();
                num = costNode.index;
                if (costNode.cost != this.calcGrid[num].costNodeCost)
                {
                    this.PfProfilerEndSample();
                    continue;
                }
                if (this.calcGrid[num].status == this.statusClosedValue)
                {
                    this.PfProfilerEndSample();
                    continue;
                }
                IntVec3 c  = this.cellIndices.IndexToCell(num);
                int     x2 = c.x;
                int     z2 = c.z;
                if (flag6)
                {
                    this.DebugFlash(c, (float)((float)this.calcGrid[num].knownCost / 1500.0), this.calcGrid[num].knownCost.ToString());
                }
                if (flag4)
                {
                    if (num == num2)
                    {
                        this.PfProfilerEndSample();
                        PawnPath result = this.FinalizedPath(num);
                        this.PfProfilerEndSample();
                        return(result);
                    }
                }
                else if (cellRect.Contains(c) && !this.disallowedCornerIndices.Contains(num))
                {
                    this.PfProfilerEndSample();
                    PawnPath result2 = this.FinalizedPath(num);
                    this.PfProfilerEndSample();
                    return(result2);
                }
                if (num3 <= 160000)
                {
                    this.PfProfilerEndSample();
                    this.PfProfilerBeginSample("Neighbor consideration");
                    for (int i = 0; i < 8; i++)
                    {
                        uint num10 = (uint)(x2 + PathFinder.Directions[i]);
                        uint num11 = (uint)(z2 + PathFinder.Directions[i + 8]);
                        int  num12;
                        int  num13;
                        int  num14;
                        bool flag10;
                        int  num15;
                        if (num10 < this.mapSizeX && num11 < this.mapSizeZ)
                        {
                            num12 = (int)num10;
                            num13 = (int)num11;
                            num14 = this.cellIndices.CellToIndex(num12, num13);
                            if (this.calcGrid[num14].status == this.statusClosedValue && !flag9)
                            {
                                continue;
                            }
                            num15  = 0;
                            flag10 = false;
                            if (!flag2 && new IntVec3(num12, 0, num13).GetTerrain(this.map).HasTag("Water"))
                            {
                                continue;
                            }
                            if (!this.pathGrid.WalkableFast(num14))
                            {
                                if (!flag)
                                {
                                    if (flag6)
                                    {
                                        this.DebugFlash(new IntVec3(num12, 0, num13), 0.22f, "walk");
                                    }
                                }
                                else
                                {
                                    flag10 = true;
                                    num15 += 70;
                                    Building building = edificeGrid[num14];
                                    if (building != null && PathFinder.IsDestroyable(building))
                                    {
                                        num15 += (int)((float)building.HitPoints * 0.10999999940395355);
                                        goto IL_0749;
                                    }
                                }
                                continue;
                            }
                            goto IL_0749;
                        }
                        continue;
IL_092b:
                        if (this.BlocksDiagonalMovement(num - this.mapSizeX))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2, 0, z2 - 1), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        if (this.BlocksDiagonalMovement(num - 1))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2 - 1, 0, z2), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        goto IL_09bf;
IL_0b0e:
                        ushort status;
                        if (status != this.statusClosedValue && status != this.statusOpenValue)
                        {
                            if (flag9)
                            {
                                this.calcGrid[num14].heuristicCost = Mathf.RoundToInt((float)this.regionCostCalculator.GetPathCostFromDestToRegion(num14) * PathFinder.RegionHeuristicWeightByNodesOpened.Evaluate((float)num4));
                            }
                            else
                            {
                                int dx    = Math.Abs(num12 - x);
                                int dz    = Math.Abs(num13 - z);
                                int num16 = GenMath.OctileDistance(dx, dz, num8, num9);
                                this.calcGrid[num14].heuristicCost = Mathf.RoundToInt((float)num16 * num7);
                            }
                        }
                        int num17;
                        int num18 = num17 + this.calcGrid[num14].heuristicCost;
                        this.calcGrid[num14].parentIndex  = num;
                        this.calcGrid[num14].knownCost    = num17;
                        this.calcGrid[num14].status       = this.statusOpenValue;
                        this.calcGrid[num14].costNodeCost = num18;
                        num4++;
                        this.openList.Push(new CostNode(num14, num18));
                        continue;
IL_0803:
                        if (this.BlocksDiagonalMovement(num + this.mapSizeX))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2, 0, z2 + 1), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        if (this.BlocksDiagonalMovement(num + 1))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2 + 1, 0, z2), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        goto IL_09bf;
IL_09bf:
                        int num19 = (i <= 3) ? num8 : num9;
                        num19    += num15;
                        if (!flag10)
                        {
                            num19 += array[num14];
                        }
                        if (byteGrid != null)
                        {
                            num19 += byteGrid[num14] * 8;
                        }
                        if (allowedArea != null && !allowedArea[num14])
                        {
                            num19 += 600;
                        }
                        if (flag5 && PawnUtility.AnyPawnBlockingPathAt(new IntVec3(num12, 0, num13), pawn, false, false))
                        {
                            num19 += 175;
                        }
                        Building building2 = this.edificeGrid[num14];
                        if (building2 != null)
                        {
                            this.PfProfilerBeginSample("Edifices");
                            int buildingCost = PathFinder.GetBuildingCost(building2, traverseParms, pawn);
                            if (buildingCost == 2147483647)
                            {
                                this.PfProfilerEndSample();
                                continue;
                            }
                            num19 += buildingCost;
                            this.PfProfilerEndSample();
                        }
                        num17  = num19 + this.calcGrid[num].knownCost;
                        status = this.calcGrid[num14].status;
                        if (status != this.statusClosedValue && status != this.statusOpenValue)
                        {
                            goto IL_0b0e;
                        }
                        int num20 = 0;
                        if (status == this.statusClosedValue)
                        {
                            num20 = num8;
                        }
                        if (this.calcGrid[num14].knownCost > num17 + num20)
                        {
                            goto IL_0b0e;
                        }
                        continue;
IL_0897:
                        if (this.BlocksDiagonalMovement(num + this.mapSizeX))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2, 0, z2 + 1), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        if (this.BlocksDiagonalMovement(num - 1))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2 - 1, 0, z2), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        goto IL_09bf;
IL_0749:
                        switch (i)
                        {
                        case 4:
                            break;

                        case 5:
                            goto IL_0803;

                        case 6:
                            goto IL_0897;

                        case 7:
                            goto IL_092b;

                        default:
                            goto IL_09bf;
                        }
                        if (this.BlocksDiagonalMovement(num - this.mapSizeX))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2, 0, z2 - 1), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        if (this.BlocksDiagonalMovement(num + 1))
                        {
                            if (flag8)
                            {
                                if (flag6)
                                {
                                    this.DebugFlash(new IntVec3(x2 + 1, 0, z2), 0.9f, "corn");
                                }
                                continue;
                            }
                            num15 += 70;
                        }
                        goto IL_09bf;
                    }
                    this.PfProfilerEndSample();
                    num3++;
                    this.calcGrid[num].status = this.statusClosedValue;
                    if (num4 >= 2000 && flag7 && !flag9)
                    {
                        flag9 = true;
                        this.regionCostCalculator.Init(cellRect, traverseParms, num8, num9, byteGrid, allowedArea, this.disallowedCornerIndices);
                        this.InitStatusesAndPushStartNode(ref num, start);
                        num4 = 0;
                        num3 = 0;
                    }
                    continue;
                }
                break;
            }
            Log.Warning(pawn + " pathing from " + start + " to " + dest + " hit search limit of " + 160000 + " cells.");
            this.DebugDrawRichData();
            this.PfProfilerEndSample();
            return(PawnPath.NotFound);
        }
Exemplo n.º 29
0
 static PawnPathPool()
 {
     NotFoundPathInt = PawnPath.NewNotFound();
 }
Exemplo n.º 30
0
        // Token: 0x06003EB7 RID: 16055 RVA: 0x001D76A8 File Offset: 0x001D5AA8
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool flag = false;

            if (this.forceCanDig || (pawn.mindState.duty != null && pawn.mindState.duty.canDig) || (this.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge()) || (this.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null && GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction)))
            {
                flag = true;
            }
            IntVec3 c;

            if (pawn.xenomorph().HiveLoc == null)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} no hiveloc", pawn));
                }
                return(null);
            }
            if (!pawn.xenomorph().HiveLoc.IsValid)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} no hiveloc", pawn));
                }
                return(null);
            }
            if (pawn.xenomorph().HiveLoc == IntVec3.Zero)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} hiveloc zero", pawn));
                }
                return(null);
            }
            c = pawn.xenomorph().HiveLoc;

            if (!c.IsValid)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} no c", pawn));
                }
                return(null);
            }
            if (c == IntVec3.Zero)
            {
                if (pawn.jobs.debugLog)
                {
                    pawn.jobs.DebugLogEvent(string.Format("{0} c zero", pawn));
                }
                return(null);
            }

            if (flag)
            {
                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                {
                    IntVec3 cellBeforeBlocker;
                    Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                    if (thing != null)
                    {
                        if (!thing.def.defName.Contains("Xenomorph_Hive"))
                        {
                            Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true);
                            if (job != null)
                            {
                                return(job);
                            }
                        }
                    }
                }
            }

            /*
             * //    Log.Message("TryGiveJob 6");
             * //    Log.Message(string.Format("TryGiveJob 6 {0}, {1}", pawn.Map, c));
             * if (c.GetFirstBuilding(pawn.Map)!=null)
             * {
             * //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == {2}", pawn.Map, c, c.GetFirstBuilding(pawn.Map)));
             *  if (c.GetFirstBuilding(pawn.Map).def == XenomorphDefOf.RRY_Xenomorph_Hive)
             *  {
             *  //    Log.Message("TryGiveJob 6 1");
             *      return null;
             *  }
             * }
             * else
             * {
             * //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == Null", pawn.Map, c));
             *  if (c.GetFirstThing(pawn.Map, XenomorphDefOf.RRY_Xenomorph_Hive) != null)
             *  {
             *  //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == {2}", pawn.Map, c, c.GetFirstThing(pawn.Map, XenomorphDefOf.RRY_Xenomorph_Hive)));
             *      if (c.GetFirstBuilding(pawn.Map).def == )
             *      {
             *      //    Log.Message("TryGiveJob 6 1");
             *          return null;
             *      }
             *  }
             *  else
             *  {
             *  //    Log.Message(string.Format("TryGiveJob 6 {0}, {1} Building == Null", pawn.Map, c));
             *  }
             * }
             * //    Log.Message("TryGiveJob 7");
             */
            return(new Job(JobDefOf.Goto, c)
            {
                exitMapOnArrival = false,
                failIfCantJoinOrCreateCaravan = this.failIfCantJoinOrCreateCaravan,
                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, this.defaultLocomotion, LocomotionUrgency.Jog),
                expiryInterval = this.jobMaxDuration,
                canBash = this.canBash
            });
        }