Ejemplo n.º 1
0
        public MapGENArea(string line)
        {
            string[] args = line.Split(new char[] { ',' });
            // x1, y1, x2, y2, floorTile

            int x1 = int.Parse(args[0]);
            int y1 = int.Parse(args[1]);
            int x2 = int.Parse(args[2]);
            int y2 = int.Parse(args[3]);

            Rect = new Rectangle(x1, y1, x2 - x1, y2 - y1);

            Left   = Rect.Left;
            Top    = Rect.Top;
            Right  = Rect.Right;
            Bottom = Rect.Bottom;

            Width  = Rect.Width;
            Height = Rect.Height;

            Floor = int.Parse(args[4]);

            WallHorizontal = int.Parse(args[5]);
            WallVertical   = int.Parse(args[6]);
            WallNE         = int.Parse(args[7]);
            WallSolid      = int.Parse(args[8]);

            DoorHorz = Doors[int.Parse(args[9])].Copy();
            DoorVert = Doors[int.Parse(args[10])].Copy();

            RuinsHorz = int.Parse(args[11]);
            RuinsVert = int.Parse(args[12]);

            Floor2 = int.Parse(args[13]);
        }
Ejemplo n.º 2
0
        public void Merge(MapGENTile tile)
        {
            for (int i = 0; i < 4; i++)
            {
                if (Tiles[i] == -1)
                {
                    continue;
                }

                tile.Tiles[i] = Tiles[i];
            }
        }
Ejemplo n.º 3
0
        static MapGENArea()
        {
            Doors = new MapGENTile[14];

            Doors[0] = new MapGENTile(new int[] { 0, 0, 507, 0 }, false, true, false);                  // Dungeon Door, Horz
            Doors[1] = new MapGENTile(new int[] { 0, 0, 609, 0 }, false, true, false);                  // Dungeon Door, Vert
            Doors[2] = new MapGENTile(new int[] { 0, 0, 513, 0 }, false, true, false);                  // Town Door, Horz
            Doors[3] = new MapGENTile(new int[] { 0, 0, 631, 0 }, false, true, false);                  // Town Door, Vert

            Doors[4] = new MapGENTile(new int[] { 0, 650, 368, 0 }, false, true, false);                // Dungeon Door, Horz
            Doors[5] = new MapGENTile(new int[] { 0, 649, 367, 0 }, false, true, false);                // Dungeon Door, Vert

            Doors[6] = new MapGENTile(new int[] { 0, 115, 518, 501 }, false, true, false);              // Fancy Door, Horz
            Doors[7] = new MapGENTile(new int[] { 0, 217, 628, 621 }, false, true, false);              // Fancy Door, Vert

            Doors[8] = new MapGENTile(new int[] { 0, 374, 372, 0 }, false, true, false);                // Torii Door, Horz
            Doors[9] = new MapGENTile(new int[] { 0, 373, 375, 0 }, false, true, false);                // Torii Door, Vert

            Doors[10] = new MapGENTile(new int[] { 0, 194, 192, 0 }, false, true, false);               // Torii Door, Horz
            Doors[11] = new MapGENTile(new int[] { 0, 193, 191, 0 }, false, true, false);               // Torii Door, Vert
        }
Ejemplo n.º 4
0
        public void Import(string path)
        {
            var definitionFile = new FileInfo(path);

            var directory   = definitionFile.Directory.FullName;
            var segmentName = _name = definitionFile.Name.Replace(".def", String.Empty);

            var overridesFile = new FileInfo($@"{directory}\{segmentName}.ovr");
            var terrainFile   = new FileInfo($@"{directory}\{segmentName}.txt");

            var line = String.Empty;

            var id = 1;

            /**/
            using (var defStream = new FileStream(definitionFile.FullName,
                                                  FileMode.Open, FileAccess.Read, FileShare.None))
                using (var defReader = new StreamReader(defStream))
                {
                    while ((line = defReader.ReadLine()) != null)
                    {
                        if (line.StartsWith(";"))
                        {
                            continue;
                        }

                        Regions.Add(new MapGENRegion(line)
                        {
                            Id     = id++,
                            Import = true,
                        });
                    }
                }

            var mapTiles = _tiles = new MapGENTile[255, 255];

            int yCoord = 0;
            int yMax = 0, xMax = 0;

            /**/
            using (var stream = new FileStream(terrainFile.FullName,
                                               FileMode.Open, FileAccess.Read, FileShare.None))
                using (var reader = new StreamReader(stream))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        for (int xCoord = 0; xCoord < line.Length; xCoord++)
                        {
                            mapTiles[xCoord, yCoord] = TranslateTile(xCoord, yCoord, line[xCoord]);

                            if (xCoord > xMax)
                            {
                                xMax = xCoord;
                            }
                        }

                        yCoord++;

                        if (yCoord > yMax)
                        {
                            yMax = yCoord;
                        }
                    }
                }

            xMax++;

            int xMin = 0;
            int yMin = 0;

            /**/
            using (var ovrStream = new FileStream(overridesFile.FullName,
                                                  FileMode.Open, FileAccess.Read, FileShare.None))
                using (var ovrReader = new StreamReader(ovrStream))
                {
                    _overrides = new List <MapGENOverride>();

                    while ((line = ovrReader.ReadLine()) != null)
                    {
                        if (line.StartsWith(";"))
                        {
                            continue;
                        }

                        if (line.StartsWith("#W"))
                        {
                            string[] wArg = line.Replace("#W", "").Split(new char[] { ',' });

                            int xW = int.Parse(wArg[0]);
                            int yW = int.Parse(wArg[1]);

                            var tile = mapTiles[xW, yW];

                            tile.WallConnect = true;
                            continue;
                        }

                        var ovr = new MapGENOverride(line);

                        if (ovr.X < xMin)
                        {
                            xMin = ovr.X;
                        }

                        if (ovr.Y < yMin)
                        {
                            yMin = ovr.Y;
                        }

                        _overrides.Add(ovr);
                    }
                }

            /**/
            for (int i = 0; i < yMax; i++)
            {
                for (int j = 0; j < xMax; j++)
                {
                    var tile = mapTiles[j, i];
                    var area = Regions.FirstOrDefault(a => a.Contains(j, i)) ?? DefaultArea;

                    MapGENTile tileW = null, tileE = null, tileN = null, tileNW = null, tileS = null, tileNE = null, tileSE = null;

                    if (j > 0)
                    {
                        tileW = mapTiles[j - 1, i];
                    }
                    if (j < xMax)
                    {
                        tileE = mapTiles[j + 1, i];
                    }
                    if (i > 0)
                    {
                        tileN = mapTiles[j, i - 1];
                    }
                    if (i > 0 && j > 0)
                    {
                        tileNW = mapTiles[j - 1, i - 1];
                    }
                    if (i > 0 && i < yMax && j < xMax)
                    {
                        tileNE = mapTiles[j + 1, i - 1];
                    }
                    if (i < yMax)
                    {
                        tileS = mapTiles[j, i + 1];
                    }
                    if (j > 0 && j < xMax && i >= 0 && i < (yMax - 1))
                    {
                        tileSE = mapTiles[j - 1, i + 1];
                    }

                    bool needW = (tileW != null && (tileW.Wall || tileW.WallConnect));
                    bool needE = (tileE != null && (tileE.Wall || tileE.WallConnect));
                    bool needN = (tileN != null && (tileN.Wall || tileN.WallConnect));
                    bool needS = (tileS != null && (tileS.Wall || tileS.WallConnect));

                    if (tile != null && tile.Wall)
                    {
                        if (tile.Tiles[1] == 0 && tile.Tiles[1] != area.WallSolid)
                        {
                            tile.Tiles[1] = area.WallVertical;
                        }

                        if (tile.Tiles[0] == 0)
                        {
                            tile.Tiles[0] = area.Floor;
                        }

                        if (needW || needE)
                        {
                            tile.Tiles[1] = area.WallHorizontal;
                        }

                        if (needN)
                        {
                            tile.Tiles[1] = area.WallVertical;
                        }

                        if (needN && needW)
                        {
                            tile.Tiles[1] = area.WallVertical;
                            tile.Tiles[2] = area.WallHorizontal;
                        }

                        if (needE && needS && !needN && !needW)
                        {
                            tile.Tiles[1] = area.WallNE;
                        }

                        if (tileW != null && !needW && !tileW.IsEmpty && tileS != null && !needS && !tileS.IsEmpty)
                        {
                            tile.Tiles[0] = area.Floor;
                        }

                        if (tileN != null && !needN && !tileN.IsEmpty && tileE != null && !needE && !tileE.IsEmpty)
                        {
                            tile.Tiles[0] = area.Floor;
                        }

                        if (tileW != null && !needW && tileW.IsEmpty && tileS != null && !needS && tileS.IsEmpty)
                        {
                            tile.Tiles[0] = 0;
                        }

                        if (tileN != null && !needN && tileN.IsEmpty && tileE != null && !needE && tileE.IsEmpty)
                        {
                            tile.Tiles[0] = 0;
                        }

                        if (tileNE != null && tileN != null && tileE != null && tileNE.IsEmpty && tileN.IsEmpty && tileE.IsEmpty)
                        {
                            tile.Tiles[0] = 0;
                        }

                        if (tileS != null && tileS.Wall && tileN != null && !tileN.Wall && !tileN.WallConnect)
                        {
                            tile.Tiles[0] = tileN.Tiles[0];
                        }

                        if (needW && tileN != null && tileE != null && !tileE.Wall && !tileE.WallConnect)
                        {
                            tile.Tiles[0] = tileN.Tiles[0];
                        }

                        if (_name == "Rift Glacier")
                        {
                            if (tileS != null && needN && !needS && !needW)
                            {
                                tile.Tiles[0] = tileS.Tiles[0];
                            }

                            if (tileSE == null)
                            {
                                tile.Tiles[0] = 0;
                            }

                            if (tileNE == null && needS)
                            {
                                tile.Tiles[0] = 0;
                            }
                        }
                    }
                    else if (tile != null && tile.Ruins)
                    {
                        if (needN)
                        {
                            tile.Tiles[2] = area.RuinsVert;
                        }

                        if (needW)
                        {
                            tile.Tiles[2] = area.RuinsHorz;
                        }
                    }
                }
            }

            for (int i = yMin; i < yMax; i++)
            {
                for (int j = xMin; j < xMax; j++)
                {
                    var tile = default(MapGENTile);

                    if (i >= 0 && j >= 0)
                    {
                        tile = mapTiles[j, i];
                    }
                    else
                    {
                        tile = new MapGENTile(new int[] { 0, 0, 0, 0 });
                    }

                    var ovr = GetTileOverride(j, i);

                    if (ovr != null)
                    {
                        ovr.Merge(tile);
                    }
                }
            }