Exemplo n.º 1
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.º 2
0
        private static bool ExploreNetwork(ILevel level, TileCoordinates coordinates, HashSet <TileCoordinates> o_coordinates)
        {
            if (!o_coordinates.Contains(coordinates))
            {
                o_coordinates.Add(coordinates);

                var  tile      = level.Tiles[coordinates];
                var  behaviour = (WireTileBehaviour)tile.GetBehaviour(level, coordinates);
                bool powered   = tile.IsPowered(level, coordinates);
                for (int i = 0; i < 6; ++i)
                {
                    var dir = (Direction)i;
                    if (behaviour.IsConnected(level, coordinates, dir))
                    {
                        var neighbourCoords = coordinates.Move(dir, (dir == Direction.Up) ? tile.Height : 1);
                        var neighbourTile   = level.Tiles[neighbourCoords];
                        if (neighbourTile.IsWire(level, neighbourCoords))
                        {
                            var neighbourBehaviour  = (WireTileBehaviour)neighbourTile.GetBehaviour(level, neighbourCoords);
                            var neighbourBaseCoords = neighbourTile.GetBase(level, neighbourCoords);
                            if (neighbourBehaviour.IsConnected(level, neighbourBaseCoords, dir.Opposite()))
                            {
                                powered = powered || ExploreNetwork(level, neighbourBaseCoords, o_coordinates);
                            }
                        }
                    }
                }
                return(powered);
            }
            return(false);
        }
Exemplo n.º 3
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.º 4
0
 public void Shutdown(ILevel level, TileCoordinates coordinates)
 {
     OnShutdown(level, coordinates);
     for (int i = 1; i < m_height; ++i)
     {
         level.Tiles.SetTile(coordinates.Move(Direction.Up, i), Tiles.Air, FlatDirection.North, false);
     }
 }
Exemplo n.º 5
0
 public void Init(ILevel level, TileCoordinates coordinates, FlatDirection direction)
 {
     level.Tiles.GetState(coordinates).Direction = direction;
     for (int i = 1; i < m_height; ++i)
     {
         level.Tiles.SetTile(coordinates.Move(Direction.Up, i), Tiles.Extension, direction, false);
     }
     OnInit(level, coordinates);
 }
Exemplo n.º 6
0
        private int Render(ILevel level, TileCoordinates coordinates, Geometry output, TextureAtlas textures, bool allFaces)
        {
            // Draw adjoining faces only
            int facesDrawn   = 0;
            var diffuseArea  = textures.GetTextureArea("models/tiles/xray.png").Value;
            var specularArea = textures.GetTextureArea("black.png").Value;
            var emissiveArea = textures.GetTextureArea("black.png").Value;
            var normalArea   = textures.GetTextureArea("flat.png").Value;
            var center       = new Vector3(coordinates.X + 0.5f, coordinates.Y * 0.5f + 0.5f, coordinates.Z + 0.5f);

            for (int i = 0; i < 6; ++i)
            {
                var dir           = (Direction)i;
                var neighbour     = (dir == Direction.Up) ? coordinates.Move(dir, Tile.Height) : coordinates.Move(dir);
                var neighbourTile = level.Tiles[neighbour];
                if (allFaces ||
                    (!(neighbourTile.GetBehaviour(level, neighbour) is XRayTileBehaviour) &&
                     neighbourTile.IsOpaqueOnSide(level, neighbour, dir.Opposite())))
                {
                    Vector3 fwd = 0.45f * dir.ToVector();
                    if (allFaces)
                    {
                        fwd = -fwd;
                    }

                    Vector3 up, right;
                    if (dir.IsFlat())
                    {
                        up    = 0.45f * Vector3.UnitY;
                        right = 0.45f * dir.RotateRight().ToVector();
                    }
                    else if (dir == Direction.Up)
                    {
                        up    = 0.45f * Vector3.UnitZ;
                        right = 0.45f * Vector3.UnitX;
                    }
                    else// if( dir == Direction.Down )
                    {
                        up    = -0.45f * Vector3.UnitZ;
                        right = 0.45f * Vector3.UnitX;
                    }
                    output.AddQuad(
                        center + fwd + up - right,
                        center + fwd + up + right,
                        center + fwd - up - right,
                        center + fwd - up + right,
                        diffuseArea,
                        specularArea,
                        normalArea,
                        emissiveArea,
                        Vector4.One
                        );
                    ++facesDrawn;
                }
            }
            return(facesDrawn);
        }
Exemplo n.º 7
0
 public virtual bool CanPlaceOnSide(ILevel level, TileCoordinates coordinates, Direction direction)
 {
     if (Tile.AllowPlacement || direction != Direction.Up)
     {
         if (Tile.IsSolidOnSide(level, coordinates, direction) &&
             Tile.IsOpaqueOnSide(level, coordinates, direction))
         {
             var neighbour = coordinates.Move(direction);
             if (direction == Direction.Up && Tile.Height > 1)
             {
                 neighbour = coordinates.Move(Direction.Up, Tile.Height);
             }
             if (level.Tiles[neighbour].IsReplaceable(level, neighbour) &&
                 !level.Tiles[neighbour].IsXRay(level, neighbour))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 8
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.º 9
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);
     }
 }