Ejemplo n.º 1
0
        private bool TryRecoverFromUnwalkablePosition(int originalDest, CaravanArrivalAction originalArrivalAction)
        {
            int num;

            if (GenWorldClosest.TryFindClosestTile(this.caravan.Tile, (int t) => this.IsPassable(t), out num, 2147483647, true))
            {
                Log.Warning(string.Concat(new object[]
                {
                    this.caravan,
                    " on unwalkable tile ",
                    this.caravan.Tile,
                    ". Teleporting to ",
                    num
                }));
                this.caravan.Tile = num;
                this.moving       = false;
                this.nextTile     = this.caravan.Tile;
                this.StartPath(originalDest, originalArrivalAction, false);
                return(true);
            }
            Find.WorldObjects.Remove(this.caravan);
            Log.Error(string.Concat(new object[]
            {
                this.caravan,
                " on unwalkable tile ",
                this.caravan.Tile,
                ". Could not find walkable position nearby. Removed."
            }));
            return(false);
        }
 public void StartPath(int destTile, CaravanArrivalAction arrivalAction, bool repathImmediately = false, bool resetPauseStatus = true)
 {
     this.caravan.autoJoinable = false;
     if (resetPauseStatus)
     {
         this.paused = false;
     }
     if (arrivalAction == null || arrivalAction.StillValid(this.caravan, destTile))
     {
         if (!this.IsPassable(this.caravan.Tile))
         {
             if (!this.TryRecoverFromUnwalkablePosition())
             {
                 return;
             }
         }
         if (this.moving && this.curPath != null && this.destTile == destTile)
         {
             this.arrivalAction = arrivalAction;
         }
         else if (!this.caravan.CanReach(destTile))
         {
             this.PatherFailed();
         }
         else
         {
             this.destTile      = destTile;
             this.arrivalAction = arrivalAction;
             this.caravan.Notify_DestinationOrPauseStatusChanged();
             if (this.nextTile < 0 || !this.IsNextTilePassable())
             {
                 this.nextTile         = this.caravan.Tile;
                 this.nextTileCostLeft = 0f;
                 this.previousTileForDrawingIfInDoubt = -1;
             }
             if (this.AtDestinationPosition())
             {
                 this.PatherArrived();
             }
             else
             {
                 if (this.curPath != null)
                 {
                     this.curPath.ReleaseToPool();
                 }
                 this.curPath = null;
                 this.moving  = true;
                 if (repathImmediately)
                 {
                     bool flag = this.TrySetNewPath();
                     if (flag && this.nextTileCostLeft <= 0f && this.moving)
                     {
                         this.TryEnterNextPathTile();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void StopDead()
 {
     if (this.curPath != null)
     {
         this.curPath.ReleaseToPool();
     }
     this.curPath          = null;
     this.moving           = false;
     this.nextTile         = this.caravan.Tile;
     this.arrivalAction    = null;
     this.nextTileCostLeft = 0f;
 }
Ejemplo n.º 4
0
 public bool StartPath(int destTile, CaravanArrivalAction arrivalAction, bool repathImmediately = false, bool resetPauseStatus = true)
 {
     caravan.autoJoinable = false;
     if (resetPauseStatus)
     {
         paused = false;
     }
     if (arrivalAction != null && !arrivalAction.StillValid(caravan, destTile))
     {
         return(false);
     }
     if (!IsPassable(caravan.Tile) && !TryRecoverFromUnwalkablePosition())
     {
         return(false);
     }
     if (moving && curPath != null && this.destTile == destTile)
     {
         this.arrivalAction = arrivalAction;
         return(true);
     }
     if (!caravan.CanReach(destTile))
     {
         PatherFailed();
         return(false);
     }
     this.destTile      = destTile;
     this.arrivalAction = arrivalAction;
     caravan.Notify_DestinationOrPauseStatusChanged();
     if (nextTile < 0 || !IsNextTilePassable())
     {
         nextTile         = caravan.Tile;
         nextTileCostLeft = 0f;
         previousTileForDrawingIfInDoubt = -1;
     }
     if (AtDestinationPosition())
     {
         PatherArrived();
         return(true);
     }
     if (curPath != null)
     {
         curPath.ReleaseToPool();
     }
     curPath = null;
     moving  = true;
     if (repathImmediately && TrySetNewPath() && nextTileCostLeft <= 0f && moving)
     {
         TryEnterNextPathTile();
     }
     return(true);
 }
Ejemplo n.º 5
0
        private void PatherArrived()
        {
            CaravanArrivalAction caravanArrivalAction = arrivalAction;

            StopDead();
            if (caravanArrivalAction != null && (bool)caravanArrivalAction.StillValid(caravan, caravan.Tile))
            {
                caravanArrivalAction.Arrived(caravan);
            }
            else if (caravan.IsPlayerControlled && !caravan.VisibleToCameraNow())
            {
                Messages.Message("MessageCaravanArrivedAtDestination".Translate(caravan.Label), caravan, MessageTypeDefOf.TaskCompletion);
            }
        }
Ejemplo n.º 6
0
        private void PatherArrived()
        {
            CaravanArrivalAction caravanArrivalAction = this.arrivalAction;

            this.StopDead();
            if (caravanArrivalAction != null && caravanArrivalAction.StillValid(this.caravan, this.caravan.Tile))
            {
                caravanArrivalAction.Arrived(this.caravan);
            }
            else if (this.caravan.IsPlayerControlled && !this.caravan.VisibleToCameraNow())
            {
                Messages.Message("MessageCaravanArrivedAtDestination".Translate(this.caravan.Label).CapitalizeFirst(), this.caravan, MessageTypeDefOf.TaskCompletion, true);
            }
        }
 public void StopDead()
 {
     if (this.curPath != null)
     {
         this.curPath.ReleaseToPool();
     }
     this.curPath  = null;
     this.moving   = false;
     this.paused   = false;
     this.nextTile = this.caravan.Tile;
     this.previousTileForDrawingIfInDoubt = -1;
     this.arrivalAction    = null;
     this.nextTileCostLeft = 0f;
     this.caravan.Notify_DestinationOrPauseStatusChanged();
 }
Ejemplo n.º 8
0
 public void StopDead()
 {
     if (curPath != null)
     {
         curPath.ReleaseToPool();
     }
     curPath  = null;
     moving   = false;
     paused   = false;
     nextTile = caravan.Tile;
     previousTileForDrawingIfInDoubt = -1;
     arrivalAction    = null;
     nextTileCostLeft = 0f;
     caravan.Notify_DestinationOrPauseStatusChanged();
 }
        private bool TryRecoverFromUnwalkablePosition(int originalDest, CaravanArrivalAction originalArrivalAction)
        {
            int num = default(int);

            if (GenWorldClosest.TryFindClosestTile(this.caravan.Tile, (Predicate <int>)((int t) => this.IsPassable(t)), out num, 2147483647, true))
            {
                Log.Warning(this.caravan + " on unwalkable tile " + this.caravan.Tile + ". Teleporting to " + num);
                this.caravan.Tile = num;
                this.moving       = false;
                this.nextTile     = this.caravan.Tile;
                this.StartPath(originalDest, originalArrivalAction, false);
                return(true);
            }
            Find.WorldObjects.Remove(this.caravan);
            Log.Error(this.caravan + " on unwalkable tile " + this.caravan.Tile + ". Could not find walkable position nearby. Removed.");
            return(false);
        }
Ejemplo n.º 10
0
 public void StartPath(int destTile, CaravanArrivalAction arrivalAction, bool repathImmediately = false)
 {
     this.caravan.autoJoinable = false;
     if (!this.IsPassable(this.caravan.Tile) && !this.TryRecoverFromUnwalkablePosition(destTile, arrivalAction))
     {
         return;
     }
     if (this.moving && this.curPath != null && this.destTile == destTile)
     {
         return;
     }
     if (!this.caravan.CanReach(destTile))
     {
         this.PatherFailed();
         return;
     }
     this.destTile      = destTile;
     this.arrivalAction = arrivalAction;
     if (this.nextTile < 0 || !this.IsNextTilePassable())
     {
         this.nextTile = this.caravan.Tile;
     }
     if (this.AtDestinationPosition())
     {
         this.PatherArrived();
         return;
     }
     if (this.curPath != null)
     {
         this.curPath.ReleaseToPool();
     }
     this.curPath = null;
     this.moving  = true;
     if (repathImmediately)
     {
         bool flag = this.TrySetNewPath();
         if (flag && this.nextTileCostLeft <= 0f && this.moving)
         {
             this.TryEnterNextPathTile();
         }
     }
 }