Exemplo n.º 1
0
        public void NotifyNeighboursChanged(ILevel level, TileCoordinates coordinates)
        {
            if (IsExtension())
            {
                var below = coordinates.Below();
                level.Tiles[below].NotifyNeighboursChanged(level, below);
            }
            else
            {
                for (int y = 0; y < Height; ++y)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        var dir             = (Direction)i;
                        var neighbourCoords = new TileCoordinates(coordinates.X + dir.GetX(), coordinates.Y + y, coordinates.Z + dir.GetZ());
                        level.Tiles[neighbourCoords].OnNeighbourChanged(level, neighbourCoords);
                    }
                }

                var belowCoords = coordinates.Below();
                level.Tiles[belowCoords].OnNeighbourChanged(level, belowCoords);

                var aboveCoords = coordinates.Move(Direction.Up, Height);
                level.Tiles[aboveCoords].OnNeighbourChanged(level, aboveCoords);
            }
        }
Exemplo n.º 2
0
        public bool CanEnterOnSide(Robot.Robot robot, TileCoordinates coordinates, FlatDirection side, bool ignoreMovingObjects)
        {
            if (GetIncline(robot.Level, coordinates, side.Opposite()) <= 0 && IsSolidOnSide(robot.Level, coordinates, side.ToDirection()))
            {
                return(false);
            }
            if (IsOccupiedByNonVacatingRobot(robot.Level, coordinates, side, robot, ignoreMovingObjects))
            {
                return(false);
            }
            var belowCoords = coordinates.Below();
            var belowTile   = robot.Level.Tiles[belowCoords];

            if (belowTile.IsConveyor(robot.Level, belowCoords))
            {
                var conveyor          = (Conveyor)belowTile.GetEntity(robot.Level, belowCoords);
                var conveyorDirection = belowTile.GetDirection(robot.Level, belowCoords);
                if (conveyor.CurrentMode == ConveyorMode.Forwards)
                {
                    return(side != conveyorDirection);
                }
                else if (conveyor.CurrentMode == ConveyorMode.Reverse)
                {
                    return(side != conveyorDirection.Opposite());
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 private bool IsOccupiedByNonVacatingRobot(ILevel level, TileCoordinates coordinates, FlatDirection side, Robot.Robot exception, bool ignoreMovingRobots)
 {
     if (IsOccupied(level, coordinates))
     {
         var occupant = GetOccupant(level, coordinates);
         if (occupant is Robot.Robot)
         {
             var robot = (Robot.Robot)occupant;
             if (robot == exception)
             {
                 // Ignore ourselves
                 return(false);
             }
             if (ignoreMovingRobots && robot.IsMoving)
             {
                 // Ignore moving robots
                 return(false);
             }
             if (robot.Location != coordinates && robot.IsTurning)
             {
                 // Ignore robot reserving the space ahead of them when turning
                 return(false);
             }
             if ((robot.Location == coordinates || robot.Location == coordinates.Below()) &&
                 robot.Direction != side &&
                 robot.IsVacating)
             {
                 // Ignore robot about to leave
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        protected bool IsFaceHidden(ILevel level, TileCoordinates coordinates, Direction direction)
        {
            var tiles = level.Tiles;

            if (direction.IsFlat())
            {
                var adjoiningPos  = coordinates.Move(direction);
                var adjoiningSide = direction.Opposite();
                for (int i = 0; i < Tile.Height; ++i)
                {
                    var tile = tiles[adjoiningPos];
                    if (tile.IsHidden(level, adjoiningPos) || !tiles[adjoiningPos].IsOpaqueOnSide(level, adjoiningPos, adjoiningSide))
                    {
                        return(false);
                    }
                    adjoiningPos = adjoiningPos.Above();
                }
                return(true);
            }
            else if (direction == Direction.Up)
            {
                var adjoiningPos = coordinates.Move(Direction.Up, Tile.Height);
                var tile         = tiles[adjoiningPos];
                return(!tile.IsHidden(level, adjoiningPos) && tile.IsOpaqueOnSide(level, adjoiningPos, Direction.Down));
            }
            else //if(direction == Direction.Down)
            {
                var adjoiningPos = coordinates.Below();
                var tile         = tiles[adjoiningPos];
                return(!tile.IsHidden(level, adjoiningPos) && tile.IsOpaqueOnSide(level, adjoiningPos, Direction.Up));
            }
        }
Exemplo n.º 5
0
 public bool IsPowered(ILevel level, TileCoordinates coordinates)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         return(level.Tiles[below].IsPowered(level, below));
     }
     else
     {
         for (int i = 0; i < 4; ++i)
         {
             var dir = (Direction)i;
             if (m_behaviour.AcceptsPower(level, coordinates, dir))
             {
                 for (int y = 0; y < Height; ++y)
                 {
                     var neighbourCoords = new TileCoordinates(coordinates.X + dir.GetX(), coordinates.Y + y, coordinates.Z + dir.GetZ());
                     if (level.Tiles[neighbourCoords].GetPowerOutput(level, neighbourCoords, dir.Opposite()))
                     {
                         return(true);
                     }
                 }
             }
         }
         if (m_behaviour.AcceptsPower(level, coordinates, Direction.Down))
         {
             var belowCoords = coordinates.Below();
             if (level.Tiles[belowCoords].GetPowerOutput(level, belowCoords, Direction.Up))
             {
                 return(true);
             }
         }
         if (m_behaviour.AcceptsPower(level, coordinates, Direction.Up))
         {
             var aboveCoords = coordinates.Move(Direction.Up, Height);
             if (level.Tiles[aboveCoords].GetPowerOutput(level, aboveCoords, Direction.Down))
             {
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 6
0
 public bool GetPowerOutput(ILevel level, TileCoordinates coordinates, Direction direction)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         return(level.Tiles[below].GetPowerOutput(level, below, direction));
     }
     else
     {
         return(m_behaviour.GetPowerOutput(level, coordinates, direction));
     }
 }
Exemplo n.º 7
0
 public void OnSteppedOff(ILevel level, TileCoordinates coordinates, Robot.Robot robot, FlatDirection direction)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         level.Tiles[below].OnSteppedOff(level, below, robot, direction);
     }
     else
     {
         m_behaviour.OnSteppedOff(level, coordinates, robot, direction);
     }
 }
Exemplo n.º 8
0
 public void OnNeighbourChanged(ILevel level, TileCoordinates coordinates)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         level.Tiles[below].OnNeighbourChanged(level, below);
     }
     else
     {
         m_behaviour.OnNeighbourChanged(level, coordinates);
     }
 }
Exemplo n.º 9
0
 public FlatDirection GetDirection(ILevel level, TileCoordinates coordinates)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         return(level.Tiles[below].GetDirection(level, below));
     }
     else
     {
         return(level.Tiles.GetState(coordinates).Direction);
     }
 }
Exemplo n.º 10
0
 public bool IsReplaceable(ILevel level, TileCoordinates coordinates)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         return(level.Tiles[below].IsReplaceable(level, below));
     }
     else
     {
         return(m_replaceable);
     }
 }
Exemplo n.º 11
0
        protected override void OnUpdate(float dt)
        {
            if (CurrentState.State != FallState.Landed)
            {
                // Work out where we are
                float newDistance = CurrentState.Distance;
                if (CurrentState.State == FallState.Falling)
                {
                    float duration = Level.TimeMachine.Time - CurrentState.Time;
                    newDistance += SPEED * duration;
                }

                // Work out if we need to land
                var newCoords = new TileCoordinates(Location.X, Location.Y - (int)(newDistance / 0.5f), Location.Z);
                if (!Level.Tiles[newCoords.Below()].CanEnterOnTop(Level, newCoords.Below()))
                {
                    // Stop
                    newDistance = (Location.Y - newCoords.Y) * 0.5f;

                    if (Level.Tiles[newCoords.Below()].IsSolidOnSide(Level, newCoords.Below(), Direction.Up))
                    {
                        // Land permanently
                        Level.Tiles[newCoords].Clear(Level, newCoords);
                        Level.Tiles.SetTile(newCoords, Tile, m_direction);
                        PushState(new FallingTileState(FallState.Landed, newDistance, Level.TimeMachine.Time));
                    }
                    else if (CurrentState.State != FallState.Blocked)
                    {
                        // Land temporarily
                        PushState(new FallingTileState(FallState.Blocked, newDistance, Level.TimeMachine.Time));
                    }
                }
                else if (CurrentState.State != FallState.Falling)
                {
                    // Resume falling
                    PushState(new FallingTileState(FallState.Falling, CurrentState.Distance, Level.TimeMachine.Time));
                }
            }
        }
Exemplo n.º 12
0
 public void Clear(ILevel level, TileCoordinates coordinates, bool notifyNeighbours = true)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         level.Tiles[below].Clear(level, below, notifyNeighbours);
     }
     else
     {
         for (int i = 0; i < m_height; ++i)
         {
             level.Tiles.SetTile(coordinates.Move(Direction.Up, i), Tiles.Air, FlatDirection.North, notifyNeighbours);
         }
     }
 }
Exemplo n.º 13
0
 public TileCoordinates GetBase(ILevel level, TileCoordinates coordinates)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         while (level.Tiles[below].IsExtension())
         {
             below = below.Below();
         }
         return(below);
     }
     else
     {
         return(coordinates);
     }
 }
Exemplo n.º 14
0
 public void SetHidden(ILevel level, TileCoordinates coordinates, bool hidden)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         level.Tiles[below].SetHidden(level, below, hidden);
     }
     else
     {
         var state = level.Tiles.GetState(coordinates);
         if (state.Hidden != hidden)
         {
             state.Hidden = hidden;
             level.Tiles.RequestRebuild(coordinates);
         }
     }
 }
Exemplo n.º 15
0
        private bool IsSupported(ILevel level, TileCoordinates coordinates)
        {
            var belowCoords = coordinates.Below();

            return(level.Tiles[belowCoords].IsSolidOnSide(level, belowCoords, Direction.Up));
        }