Esempio n. 1
0
        protected internal override void Decorate()
        {
            var start = RoomExit.Top * Width + RoomExit.Left + 1;
            var end   = start + RoomExit.Width() - 1;

            for (var i = start; i < end; i++)
            {
                if (i != exit)
                {
                    map[i]         = Terrain.WALL_DECO;
                    map[i + Width] = Terrain.WATER;
                }
                else
                {
                    map[i + Width] = Terrain.EMPTY;
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }
        }
Esempio n. 2
0
        protected internal override void CreateItems()
        {
            var keyPos = _anteroom.Random();

            while (!passable[keyPos])
            {
                keyPos = _anteroom.Random();
            }

            Drop(new IronKey(), keyPos).HeapType = Heap.Type.Chest;

            var item = Bones.Get();

            if (item == null)
            {
                return;
            }
            int pos;

            do
            {
                pos = RoomEntrance.Random();
            }while (pos == entrance || map[pos] == Terrain.SIGN);

            Drop(item, pos).HeapType = Heap.Type.Skeleton;
        }
Esempio n. 3
0
    void CreateHallway(Vector3 center, RoomEndButton server, Vector3 doorOffset)
    {
        //create floor tiles for the hallway
        for (int i = -3; i < 3; i++)
        {
            floorGrid.SetTile(new Vector3Int((int)center.x + i, (int)center.y - 1, (int)center.z), floorTile);
            floorGrid.SetTile(new Vector3Int((int)center.x + i, (int)center.y, (int)center.z), floorTile);

            floorGrid.SetTile(new Vector3Int((int)center.x - 1, (int)center.y + i, (int)center.z), floorTile);
            floorGrid.SetTile(new Vector3Int((int)center.x, (int)center.y + i, (int)center.z), floorTile);
        }

        RoomPreviewTile previewTile = Instantiate(previewTilePrefab, center + (doorOffset / 4) + (3f / 4f) * new Vector3(doorOffset.y, doorOffset.x), Quaternion.identity).GetComponent <RoomPreviewTile>();

        previewTile.room  = server;
        previewTile.speed = .02f;

        Door door = Instantiate(doorPrefab, center + doorOffset, Quaternion.identity).GetComponent <Door>();

        door.room = server;
        server.doors.Add(door);

        RoomEntrance entrance = Instantiate(entrancePrefab, center + doorOffset * 2, Quaternion.identity).GetComponent <RoomEntrance>();

        entrance.centralComputer = server;
        server.entrances.Add(entrance);
    }
Esempio n. 4
0
        protected internal override void Decorate()
        {
            for (var i = 0; i < Length; i++)
            {
                if (map[i] == Terrain.EMPTY && pdsharp.utils.Random.Int(10) == 0)
                {
                    map[i] = Terrain.EMPTY_DECO;
                }
                else
                if (map[i] == Terrain.WALL && pdsharp.utils.Random.Int(8) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }
        }
    private Point GetNextPoint(RoomEntrance ent)
    {
        Dictionary <string, int[]> directions = new Dictionary <string, int[]>();

        directions.Add("N", new int[] { 0, -1 });
        directions.Add("S", new int[] { 0, +1 });
        directions.Add("E", new int[] { +1, 0 });
        directions.Add("W", new int[] { -1, 0 });
        Point result = new Point();

        result.x = ent.point.x + directions[ent.direction][0];
        result.y = ent.point.y + directions[ent.direction][1];
        return(result);
    }
Esempio n. 6
0
        protected internal override void CreateItems()
        {
            var item = Bones.Get();

            if (item == null)
            {
                return;
            }

            int pos;

            do
            {
                pos = RoomEntrance.Random();
            }while (pos == entrance || map[pos] == Terrain.SIGN);

            Drop(item, pos).HeapType = Heap.Type.Skeleton;
        }
Esempio n. 7
0
        protected internal override void Decorate()
        {
            for (var i = 0; i < Width; i++)
            {
                if (map[i] == Terrain.WALL && map[i + Width] == Terrain.WATER && Random.Int(4) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            for (var i = Width; i < Length - Width; i++)
            {
                if (map[i] == Terrain.WALL && map[i - Width] == Terrain.WALL && map[i + Width] == Terrain.WATER && Random.Int(2) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            for (var i = Width + 1; i < Length - Width - 1; i++)
            {
                if (map[i] == Terrain.EMPTY)
                {
                    var count = (map[i + 1] == Terrain.WALL ? 1 : 0) + (map[i - 1] == Terrain.WALL ? 1 : 0) + (map[i + Width] == Terrain.WALL ? 1 : 0) + (map[i - Width] == Terrain.WALL ? 1 : 0);

                    if (Random.Int(16) < count * count)
                    {
                        map[i] = Terrain.EMPTY_DECO;
                    }
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }
        }
Esempio n. 8
0
        protected internal override void Decorate()
        {
            for (var i = Width + 1; i < Length - Width - 1; i++)
            {
                switch (map[i])
                {
                case Terrain.EMPTY:
                {
                    var count = NEIGHBOURS8.Count(neighbour => (Terrain.Flags[map[i + neighbour]] & Terrain.PASSABLE) > 0);

                    if (pdsharp.utils.Random.Int(80) < count)
                    {
                        map[i] = Terrain.EMPTY_DECO;
                    }
                }
                break;

                case Terrain.WALL:
                {
                    var count = NEIGHBOURS4.Count(neighbour => map[i + neighbour] == Terrain.WATER);

                    if (pdsharp.utils.Random.Int(4) < count)
                    {
                        map[i] = Terrain.WALL_DECO;
                    }
                }
                break;
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }
        }
    private RoomEntrance GetDoorPoint(Room room, string direction, bool opposite = false)
    {
        Dictionary <string, string> oppositions = new Dictionary <string, string>();

        oppositions.Add("N", "S");
        oppositions.Add("S", "N");
        oppositions.Add("E", "W");
        oppositions.Add("W", "E");
        RoomEntrance result = new RoomEntrance();

        result.direction = direction[Random.Range(0, direction.Length)].ToString();
        if (opposite)
        {
            result.direction = oppositions[result.direction];
        }
        switch (result.direction)
        {
        case "N":
            result.point.x = Random.Range(room.x, room.x + room.wd);
            result.point.y = room.y - 1;
            break;

        case "S":
            result.point.x = Random.Range(room.x, room.x + room.wd);
            result.point.y = room.y + room.hd;
            break;

        case "E":
            result.point.x = room.x + room.wd;
            result.point.y = Random.Range(room.y, room.y + room.hd);
            break;

        case "W":
            result.point.x = room.x - 1;
            result.point.y = Random.Range(room.y, room.y + room.hd);
            break;
        }
        return(result);
    }
Esempio n. 10
0
        protected internal override void Decorate()
        {
            foreach (var room in Rooms)
            {
                if (room.type != RoomType.STANDARD)
                {
                    continue;
                }

                if (room.Width() <= 3 || room.Height() <= 3)
                {
                    continue;
                }

                var s = room.Square();

                if (Random.Int(s) > 8)
                {
                    var corner = (room.Left + 1) + (room.Top + 1) * Width;
                    if (map[corner - 1] == Terrain.WALL && map[corner - Width] == Terrain.WALL)
                    {
                        map[corner] = Terrain.WALL;
                    }
                }

                if (Random.Int(s) > 8)
                {
                    var corner = (room.Right - 1) + (room.Top + 1) * Width;
                    if (map[corner + 1] == Terrain.WALL && map[corner - Width] == Terrain.WALL)
                    {
                        map[corner] = Terrain.WALL;
                    }
                }

                if (Random.Int(s) > 8)
                {
                    var corner = (room.Left + 1) + (room.Bottom - 1) * Width;
                    if (map[corner - 1] == Terrain.WALL && map[corner + Width] == Terrain.WALL)
                    {
                        map[corner] = Terrain.WALL;
                    }
                }

                if (Random.Int(s) > 8)
                {
                    var corner = (room.Right - 1) + (room.Bottom - 1) * Width;
                    if (map[corner + 1] == Terrain.WALL && map[corner + Width] == Terrain.WALL)
                    {
                        map[corner] = Terrain.WALL;
                    }
                }

                foreach (var n in room.Connected.Keys)
                {
                    if ((n.type == RoomType.STANDARD || n.type == RoomType.TUNNEL) && Random.Int(3) == 0)
                    {
                        Painter.Set(this, room.Connected[n], Terrain.EMPTY_DECO);
                    }
                }
            }

            for (var i = Width + 1; i < Length - Width; i++)
            {
                if (map[i] != Terrain.EMPTY)
                {
                    continue;
                }

                var n = 0;
                if (map[i + 1] == Terrain.WALL)
                {
                    n++;
                }

                if (map[i - 1] == Terrain.WALL)
                {
                    n++;
                }

                if (map[i + Width] == Terrain.WALL)
                {
                    n++;
                }

                if (map[i - Width] == Terrain.WALL)
                {
                    n++;
                }

                if (Random.Int(6) <= n)
                {
                    map[i] = Terrain.EMPTY_DECO;
                }
            }

            for (var i = 0; i < Length; i++)
            {
                if (map[i] == Terrain.WALL && Random.Int(12) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }

            if (Dungeon.BossLevel(Dungeon.Depth + 1))
            {
                return;
            }

            foreach (var r in Rooms)
            {
                if (r.type != RoomType.STANDARD)
                {
                    continue;
                }

                foreach (var n in r.Neigbours)
                {
                    if (n.type != RoomType.STANDARD || r.Connected.ContainsKey(n))
                    {
                        continue;
                    }

                    var w = r.Intersect(n);
                    if (w.Left == w.Right && w.Bottom - w.Top >= 5)
                    {
                        w.Top    += 2;
                        w.Bottom -= 1;

                        w.Right++;

                        Painter.Fill(this, w.Left, w.Top, 1, w.Height(), Terrain.CHASM);
                    }
                    else
                    if (w.Top == w.Bottom && w.Right - w.Left >= 5)
                    {
                        w.Left  += 2;
                        w.Right -= 1;

                        w.Bottom++;

                        Painter.Fill(this, w.Left, w.Top, w.Width(), 1, Terrain.CHASM);
                    }
                }
            }
        }
Esempio n. 11
0
        protected internal override void Decorate()
        {
            for (var i = Width + 1; i < Length - Width - 1; i++)
            {
                if (map[i] != Terrain.EMPTY)
                {
                    continue;
                }

                var c = 0.05f;
                if (map[i + 1] == Terrain.WALL && map[i + Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }
                if (map[i - 1] == Terrain.WALL && map[i + Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }
                if (map[i + 1] == Terrain.WALL && map[i - Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }
                if (map[i - 1] == Terrain.WALL && map[i - Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }

                if (pdsharp.utils.Random.Float() < c)
                {
                    map[i] = Terrain.EMPTY_DECO;
                }
            }

            for (var i = 0; i < Width; i++)
            {
                if (map[i] == Terrain.WALL && (map[i + Width] == Terrain.EMPTY || map[i + Width] == Terrain.EMPTY_SP) && pdsharp.utils.Random.Int(6) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            for (var i = Width; i < Length - Width; i++)
            {
                if (map[i] == Terrain.WALL && map[i - Width] == Terrain.WALL && (map[i + Width] == Terrain.EMPTY || map[i + Width] == Terrain.EMPTY_SP) && pdsharp.utils.Random.Int(3) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }
        }
Esempio n. 12
0
        protected override bool Build()
        {
            InitRooms();

            int distance;
            var retry = 0;

            do
            {
                if (retry++ > 10)
                {
                    return(false);
                }

                var innerRetry = 0;
                do
                {
                    if (innerRetry++ > 10)
                    {
                        return(false);
                    }

                    RoomEntrance = Random.Element(Rooms);
                } while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4);

                innerRetry = 0;
                do
                {
                    if (innerRetry++ > 10)
                    {
                        return(false);
                    }

                    RoomExit = Random.Element(Rooms);
                }while (RoomExit == RoomEntrance || RoomExit.Width() < 7 || RoomExit.Height() < 7 || RoomExit.Top == 0);

                Graph.BuildDistanceMap(Rooms, RoomExit);
                distance = Graph.BuildPath(Rooms, RoomEntrance, RoomExit).Count;
            } while (distance < 3);

            RoomEntrance.type = RoomType.ENTRANCE;
            RoomExit.type     = RoomType.BOSS_EXIT;

            var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit);

            Graph.SetPrice(path, RoomEntrance.distance);

            Graph.BuildDistanceMap(Rooms, RoomExit);
            path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit);

            _anteroom      = path[path.Count - 2];
            _anteroom.type = RoomType.STANDARD;

            var room = RoomEntrance;

            foreach (var next in path)
            {
                room.Connect(next);
                room = next;
            }

            foreach (var room1 in Rooms.Where(room1 => room1.type == RoomType.NULL && room1.Connected.Count > 0))
            {
                room1.type = RoomType.PASSAGE;
            }

            Paint();

            var r = RoomExit.Connected.Keys.ToArray()[0];

            if (RoomExit.Connected[r].Y == RoomExit.Top)
            {
                return(false);
            }

            PaintWater();
            PaintGrass();

            PlaceTraps();

            return(true);
        }
Esempio n. 13
0
        protected internal override void Decorate()
        {
            for (var i = Width + 1; i < Length - Width - 1; i++)
            {
                if (map[i] != Terrain.EMPTY)
                {
                    continue;
                }

                var c = 0.15f;
                if (map[i + 1] == Terrain.WALL && map[i + Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }
                if (map[i - 1] == Terrain.WALL && map[i + Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }
                if (map[i + 1] == Terrain.WALL && map[i - Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }
                if (map[i - 1] == Terrain.WALL && map[i - Width] == Terrain.WALL)
                {
                    c += 0.2f;
                }

                if (Random.Float() < c)
                {
                    map[i] = Terrain.EMPTY_DECO;
                }
            }

            for (var i = 0; i < Width; i++)
            {
                if (map[i] == Terrain.WALL && (map[i + Width] == Terrain.EMPTY || map[i + Width] == Terrain.EMPTY_SP) && Random.Int(4) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            for (var i = Width; i < Length - Width; i++)
            {
                if (map[i] == Terrain.WALL && map[i - Width] == Terrain.WALL && (map[i + Width] == Terrain.EMPTY || map[i + Width] == Terrain.EMPTY_SP) && Random.Int(2) == 0)
                {
                    map[i] = Terrain.WALL_DECO;
                }
            }

            while (true)
            {
                var pos = RoomEntrance.Random();

                if (pos == entrance)
                {
                    continue;
                }

                map[pos] = Terrain.SIGN;
                break;
            }

            var door = RoomExit.Entrance();

            _arenaDoor = door.X + door.Y * Width;
            Painter.Set(this, _arenaDoor, Terrain.LOCKED_DOOR);

            Painter.Fill(this, RoomExit.Left + 2, RoomExit.Top + 2, RoomExit.Width() - 3, RoomExit.Height() - 3, Terrain.INACTIVE_TRAP);
        }
Esempio n. 14
0
        protected override bool Build()
        {
            InitRooms();

            int distance;
            var retry       = 0;
            var minDistance = (int)Math.Sqrt(Rooms.Count);

            do
            {
                var innerRetry = 0;
                do
                {
                    if (innerRetry++ > 10)
                    {
                        return(false);
                    }

                    RoomEntrance = pdsharp.utils.Random.Element(Rooms);
                }while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4);

                innerRetry = 0;
                do
                {
                    if (innerRetry++ > 10)
                    {
                        return(false);
                    }

                    RoomExit = pdsharp.utils.Random.Element(Rooms);
                }while (RoomExit == RoomEntrance || RoomExit.Width() < 6 || RoomExit.Height() < 6 || RoomExit.Top == 0);

                Graph.BuildDistanceMap(Rooms, RoomExit);
                distance = RoomEntrance.Distance();

                if (retry++ > 10)
                {
                    return(false);
                }
            }while (distance < minDistance);

            RoomEntrance.type = RoomType.ENTRANCE;
            RoomExit.type     = RoomType.BOSS_EXIT;

            Graph.BuildDistanceMap(Rooms, RoomExit);
            var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit);

            Graph.SetPrice(path, RoomEntrance.distance);

            Graph.BuildDistanceMap(Rooms, RoomExit);
            path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit);

            var room = RoomEntrance;

            foreach (var next in path)
            {
                room.Connect(next);
                room = next;
            }

            room = RoomExit.Connected.Keys.First();
            if (RoomExit.Top == room.Bottom)
            {
                return(false);
            }

            foreach (var r in Rooms.Where(r => r.type == RoomType.NULL && r.Connected.Count > 0))
            {
                r.type = RoomType.TUNNEL;
            }

            var candidates = new List <Room>();

            foreach (var r in RoomExit.Neigbours)
            {
                if (!RoomExit.Connected.ContainsKey(r) && (RoomExit.Left == r.Right || RoomExit.Right == r.Left || RoomExit.Bottom == r.Top))
                {
                    candidates.Add(r);
                }
            }

            if (candidates.Count > 0)
            {
                var kingsRoom = pdsharp.utils.Random.Element(candidates);
                kingsRoom.Connect(RoomExit);
                kingsRoom.type = RoomType.RAT_KING;
            }

            Paint();

            PaintWater();
            PaintGrass();

            PlaceTraps();

            return(true);
        }
Esempio n. 15
0
        protected override bool Build()
        {
            InitRooms();

            int distance;
            var retry       = 0;
            var minDistance = (int)Math.Sqrt(Rooms.Count);

            do
            {
                var innerRetry = 0;
                do
                {
                    if (innerRetry++ > 10)
                    {
                        return(false);
                    }

                    RoomEntrance = pdsharp.utils.Random.Element(Rooms);
                }while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4);

                innerRetry = 0;
                do
                {
                    if (innerRetry++ > 10)
                    {
                        return(false);
                    }

                    RoomExit = pdsharp.utils.Random.Element(Rooms);
                }while (RoomExit == RoomEntrance || RoomExit.Width() < 6 || RoomExit.Height() < 6 || RoomExit.Top == 0);

                Graph.BuildDistanceMap(Rooms, RoomExit);
                distance = Graph.BuildPath(Rooms, RoomEntrance, RoomExit).Count;

                if (retry++ > 10)
                {
                    return(false);
                }
            }while (distance < minDistance);

            RoomEntrance.type = RoomType.ENTRANCE;
            RoomExit.type     = RoomType.EXIT;

            Graph.BuildDistanceMap(Rooms, RoomExit);
            var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit);

            Graph.SetPrice(path, RoomEntrance.distance);

            Graph.BuildDistanceMap(Rooms, RoomExit);
            path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit);

            var room = RoomEntrance;

            foreach (var next in path)
            {
                room.Connect(next);
                room = next;
            }

            Room roomShop   = null;
            var  shopSquare = 0;

            foreach (var r in Rooms)
            {
                if (r.type != RoomType.NULL || r.Connected.Count <= 0)
                {
                    continue;
                }

                r.type = RoomType.PASSAGE;

                if (r.Square() <= shopSquare)
                {
                    continue;
                }

                roomShop   = r;
                shopSquare = r.Square();
            }

            if (roomShop == null || shopSquare < 30)
            {
                return(false);
            }

            roomShop.type = Imp.Quest.IsCompleted ? RoomType.SHOP : RoomType.STANDARD;

            Paint();

            PaintWater();
            PaintGrass();

            return(true);
        }