예제 #1
0
    // Advances our pathfinding progress by one tile.
    void AdvancePathing()
    {
        if (remainingMovement <= 0)
        {
            return;
        }

        if (currentPath == null || currentPath.Count <= 1)
        {
            return;
        }

        map.audioSource.PlayOneShot(sndSlide);

        // Teleport us to our correct "current" position, in case we
        // haven't finished the animation yet.
        transform.position = map.TileCoordToWorldCoord(pos, Y_POS);

        //Debug.Log(remainingMovement + " on tile " + currentPath[0].pos + ". Moving to " + currentPath[1].pos);

        // Move us to the next tile in the sequence
        pos.x = currentPath[1].pos.x;
        pos.y = currentPath[1].pos.y;

        // Add our remaining movement to current tile
        ClickableTile currentTile = map.tiles[pos.x, pos.y];

        currentTile.AddToValue(moveSpeed - remainingMovement + 1);
        currentTile.DrawHighlight(false, .01f);
        if (currentTile.CheckForCapture(faction))
        {
            // This is the last tile, so set out movespeed to one
            if (currentTile.pos == currentPath[currentPath.Count - 1].pos)
            {
                SetMoveSpeed(1);
            }
        }

        // Subtract cost from current tile to next tile
        remainingMovement -= 1;

        // Remove the old "current" tile from the pathfinding list
        currentPath.RemoveAt(0);

        if (currentPath.Count == 1)
        {
            // We only have one tile left in the path, and that tile MUST be our ultimate
            // destination -- and we are standing on it!

            // Unit arrived at destination. Sending out event message!
            if (pathCompleteEvent != null)
            {
                pathCompleteEvent();
            }

            // We are at our destinationa and we are out of moves, so end our turn
            if (remainingMovement <= 0)
            {
                //Debug.Log("Unit out of path and moves! Ending turn.");
                FinishTurn();
            }
        }
    }