Exemplo n.º 1
0
        public Actor addDoor(int x, int y, bool open)
        {
            TCODRandom rng = TCODRandom.getInstance();

            if (rng.getInt(0, 100) < 50)
            {
                Actor door = ActorLoader.getActor("Wooden Door");
                if (door != null)
                {
                    Components.Blocks.Door d = (Components.Blocks.Door)door.getComponent(typeof(Components.Blocks.Door));
                    if (d != null)
                    {
                        d.open = open;
                    }
                    if (door != null)
                    {
                        door.x = x;
                        door.y = y;
                        level.actorHandler.addActor(door);
                        level.actorHandler.sendToBack(door);
                        return(door);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 public override void render()
 {
     base.render();
     for (int x = (Program.engine.map.renderWidth / 2) - 10; x < (Program.engine.map.renderWidth / 2) + 14; x++)
     {
         for (int y = (Program.engine.map.renderHeight / 2) - 3; y < (Program.engine.map.renderHeight / 2) + 3; y++)
         {
             TCODConsole.root.setChar(x, y, '+');
             TCODConsole.root.setCharBackground(x, y, TCODColor.black);
         }
     }
     for (int x = (Program.engine.map.renderWidth / 2) - 9; x < (Program.engine.map.renderWidth / 2) + 13; x++)
     {
         for (int y = (Program.engine.map.renderHeight / 2) - 2; y < (Program.engine.map.renderHeight / 2) + 2; y++)
         {
             TCODConsole.root.setChar(x, y, 0);
             TCODConsole.root.setCharBackground(x, y, TCODColor.black);
         }
     }
     if (!flag)
     {
         i    = TCODRandom.getInstance().getInt(0, texts.Count - 1);
         flag = true;
     }
     TCODConsole.root.print((Program.engine.map.renderWidth / 2) - 8, (Program.engine.map.renderHeight / 2) - 1, texts[i]);
 }
Exemplo n.º 3
0
 public void TestConstructors()
 {
     TCODRandom a = new TCODRandom();
     TCODRandom c = new TCODRandom(42);
     a.Dispose();
     c.Dispose();
 }
Exemplo n.º 4
0
        // permament features
        public override void InitializeConsole()
        {
            base.InitializeConsole();
            TCODRandom rng = TCODRandom.getInstance();

            // draw a bunch of random characters in the background for random visual interest
            for (int x = 0; x < console.getWidth(); x++)
            {
                for (int y = 0; y < console.getHeight(); y++)
                {
                    char randChar = (char)rng.getInt(0, 255);
                    DrawText(x, y, "" + randChar, subtleColor);
                }
            }

            const string menuTile = " [Rogue Game] ";

            // inner box in which the buttons and stuff are drawn
            int innerWidth  = 40;
            int innerHeight = 50;
            int innerX      = console.getWidth() / 2 - innerWidth / 2;
            int innerY      = console.getHeight() / 2 - innerHeight / 2;

            // draw inner box, then main title
            DrawBox(innerX, innerY, innerWidth, innerHeight, backgroundColor, true);
            DrawText(console.getWidth() / 2 - menuTile.Length / 2, innerY, menuTile, foregroundColor);
        }
Exemplo n.º 5
0
        void update()
        {
            TCODRandom rng = TCODRandom.getInstance();
            int        dx  = rng.getInt(-1, 1);
            int        dy  = rng.getInt(-1, 1);

            if (dx != 0 || dy != 0)
            {
                int destx = owner.x + dx;
                int desty = owner.y + dy;
                if (Program.engine.map.canWalk(destx, desty))
                {
                    owner.x = destx;
                    owner.y = desty;
                }
                else
                {
                    Actor actor = Program.engine.actorHandler.getActor(destx, desty);
                    if (actor != null)
                    {
                        Attacker a = (Attacker)owner.getComponent(typeof(Attacker));
                        a.attack(owner, actor);
                    }
                }
            }
            base.update();
        }
Exemplo n.º 6
0
        // Randomly selects an open tile as the spawn location
        public Vector2 ChooseRandomLocation()
        {
            TCODRandom rng       = TCODRandom.getInstance();
            Vector2    randomLoc = new Vector2(rng.getInt(0, width - 1), rng.getInt(0, height - 1));

            return(GetNearestValidMove(randomLoc));
        }
Exemplo n.º 7
0
        public DungeonGenerator(Level level)
            : base(level)
        {
            TCODRandom rng = TCODRandom.getInstance();

            roomTries            = rng.getInt(minRoomTries, maxRoomTries);
            windingPercent       = rng.getInt(5, 100);
            roomExtraSize        = rng.getInt(0, 5);
            extraConnectorChance = rng.getInt(10, 100);
            regions = new int[map.width, map.height];

            if (debugDraw)
            {
                map.showAllTiles = true;

                Program.engine.update();
                TCODConsole.root.clear();
                TCODConsole.flush();
            }


            addRooms();
            Program.engine.loadingGui.loading++;
            Program.engine.render();
            roomNumber = currentRegion + 1;
            startRegion();

            for (var y = 1; y < map.height; y += 2)
            {
                for (var x = 1; x < map.width; x += 2)
                {
                    if (map.isWall(x, y))
                    {
                        continue;
                    }

                    growMaze(x, y);
                }
            }
            connectRegions();
            addRandomJuctions();
            Program.engine.loadingGui.loading++;
            Program.engine.render();
            removeDeadEnds();
            Program.engine.loadingGui.loading++;
            Program.engine.render();
            smooth();
            Program.engine.loadingGui.loading = 10;
            Program.engine.render();

            if (debugDraw)
            {
                map.showAllTiles = false;
                Program.engine.update();
            }
        }
Exemplo n.º 8
0
        // The special constructor is used to deserialize values.
        public World(SerializationInfo info, StreamingContext context)
        {
            // TODO: move this to more generic place
            currentMapInfo = XMLObjectLoader.LoadXMLObject <MapInfo>("data\\xml\\DefaultMapInfo.xml", MapInfo.PostLoadInitialization);

            engine = Engine.instance;
            rng    = TCODRandom.getInstance();
            player = null;

            mapCache = (List <AreaMap>)info.GetValue("mapCache", typeof(List <AreaMap>));
            mapIdx   = (int)info.GetValue("mapIdx", typeof(int));
        }
Exemplo n.º 9
0
        public void createRoom(RoomType type, int x1, int y1, int x2, int y2)
        {
            if (type == RoomType.entrance)
            {
                map.startx  = x1 + ((x2 - x1) / 2);
                map.starty  = y1 + ((y2 - y1) / 2);
                map.offsetX = 0;
                while (map.offsetX + map.renderWidth < map.startx + 10)
                {
                    map.offsetX += 10;
                }
                map.offsetY = 0;
                while (map.offsetY + map.renderHeight < map.starty + 10)
                {
                    map.offsetY += 10;
                }

                addPortal(map.startx, map.starty, 1);
                addActor(x1, y1 + ((y2 - y1) / 3), "Wall Torch");
            }
            else if (type == RoomType.exit)
            {
                addPortal(x1 + ((x2 - x1) / 2), y1 - 1 + ((y2 - y1) / 2), -1);
            }
            else
            {
                TCODRandom rng        = TCODRandom.getInstance();
                int        nbMonsters = rng.getInt(0, DungeonGenerator.ROOM_MAX_MONSTERS);
                while (nbMonsters > 0)
                {
                    int x = rng.getInt(x1, x2);
                    int y = rng.getInt(y1, y2);
                    if (map.canWalk(x, y))
                    {
                        addRandomActorOfType(x, y, "creatures*");
                    }
                    nbMonsters--;
                }
                int nbItems = rng.getInt(0, DungeonGenerator.ROOM_MAX_ITEMS);
                while (nbItems > 0)
                {
                    int x = rng.getInt(x1, x2);
                    int y = rng.getInt(y1, y2);
                    if (map.canWalk(x, y))
                    {
                        addRandomActorOfType(x, y, "items*");
                    }
                    nbItems--;
                }
                addActor(x1, y1 + ((y2 - y1) / 3), "Wall Torch");
            }
        }
Exemplo n.º 10
0
 public void ConstructorTest()
 {
     using (TCODRandom rand = new TCODRandom())
     {
         using (TCODNoise a = new TCODNoise(1, rand))
         {
             using (TCODNoise b = new TCODNoise(2, .5, 2.0))
             {
                 using (TCODNoise c = new TCODNoise(3, .2, .3, rand))
                 {
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
 public void addRandomJuctions()
 {
     for (int y = 1; y < map.height - 1; y++)
     {
         for (int x = 1; x < map.width - 1; x++)
         {
             if ((map.isWall(x - 1, y) && map.isWall(x + 1, y)) || map.isWall(x, y - 1) && map.isWall(x, y + 1))
             {
                 int rand = TCODRandom.getInstance().getInt(0, 1000);
                 if (rand > 1000 - (1000 / extraConnectorChance))
                 {
                     addJunction(x, y);
                 }
             }
         }
     }
 }
Exemplo n.º 12
0
        public Point GetRandomTerrain(TerrainType terrainType, TCODRandom random)
        {
            int  x     = 0;
            int  y     = 0;
            bool Found = false;

            do
            {
                x = random.getInt(1, 299);
                y = random.getInt(1, 199);
                if (this.Cells[x, y].Terrain == terrainType)
                {
                    Found = true;
                }
            }while (!Found);

            return(new Point(x, y));
        }
Exemplo n.º 13
0
        public void addJunction(int x, int y)
        {
            junctions.Add(new Point(x, y));
            TCODRandom rng = TCODRandom.getInstance();

            map.dig(x, y, x, y);
            if (rng.getInt(1, 4) == 1)
            {
                if (rng.getInt(1, 3) == 1)
                {
                    addDoor(x, y, true);
                }
            }
            else
            {
                addDoor(x, y, false);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets a name from the input spawn frequency table
        /// </summary>
        public static string GetRandomFrom(SpawnFrequency[] table, TCODRandom rng)
        {
            float randVal = rng.getFloat(0.0f, 1.0f);

            float totalProb = 0.0f;

            for (int i = 0; i < table.Length; i++)
            {
                totalProb += table[i].chance;

                if (randVal < totalProb)
                {
                    return(table[i].name);
                }
            }

            return("");
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new WorldMap object, which provides cell retrieval and terrain generation functions.
        /// </summary>
        /// <param name="seed">The map seed.</param>
        /// <param name="dbconn">The connection to the object database.</param>
        /// <param name="parameters">The parameters for terrain generation.</param>
        public WorldMap(uint seed, SQLiteConnection dbconn, int[] parameters)
        {
            //Initialization
            this.dbconn = dbconn;
            this.seed = seed;
            rand = new TCODRandom(seed, TCODRandomType.ComplementaryMultiplyWithCarry);
            noise = new TCODNoise(2, rand);

            CELL_WIDTH = parameters[0];
            CELL_HEIGHT = parameters[1];
            CELL_DEPTH = parameters[2];

            CELLS_X = parameters[3];
            CELLS_Y = parameters[4];
            CELLS_Z = parameters[5];

            GLOBAL_WIDTH = CELLS_X * CELL_WIDTH;
            GLOBAL_HEIGHT = CELLS_Y * CELL_HEIGHT;
            GLOBAL_DEPTH = CELLS_Z * CELL_DEPTH;

            GROUND_LEVEL = parameters[6];

            //Create Cells
            cells = new Cell[CELLS_X, CELLS_Y, CELLS_Z];
            int id = 0;
            for (int x = 0; x < CELLS_X; x++)
            {
                for (int y = 0; y < CELLS_Y; y++)
                {
                    for (int z = 0; z < CELLS_Z; z++)
                    {
                        cells[x, y, z] = new Cell(x * CELL_WIDTH, y * CELL_HEIGHT, z * CELL_DEPTH, id, this);
                        id++;
                    }
                }
            }

            //Create Tiles
            makeDefaultTileSetup();
            loadTileDict();
            makeTestDiffs();
        }
Exemplo n.º 16
0
        public void addMonster(int x, int y)
        {
            TCODRandom rng = TCODRandom.getInstance();

            if (rng.getInt(0, 100) < 70)
            {
                if (rng.getInt(0, 100) < 60)
                {
                    Actor kobold = ActorLoader.getActor("kobold");


                    if (kobold != null)
                    {
                        kobold.x = x; kobold.y = y;
                        level.actorHandler.addActor(kobold);
                    }
                }
                else if (rng.getInt(0, 100) < 90)
                {
                    Actor orc = ActorLoader.getActor("orc");


                    if (orc != null)
                    {
                        orc.x = x; orc.y = y;
                        level.actorHandler.addActor(orc);
                    }
                }
                else
                {
                    Actor troll = ActorLoader.getActor("troll");

                    if (troll != null)
                    {
                        troll.x = x; troll.y = y;
                        level.actorHandler.addActor(troll);
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void generatecave()
        {
            random = TCODRandom.getInstance();
            map.generator.resetMap(false);

            RandomFillMap();

            for (int i = 0; i < steps; i++)
            {
                MakeCaverns();
            }


            for (int x = 0; x < map.width; x++)
            {
                for (int y = 0; y < map.height; y++)
                {
                    if (InBounds(x, y))
                    {
                        if (GetAdjacentCount(x, y, true) > 6)
                        {
                            map.setWall(x, y);
                        }
                        else
                        {
                            if (GetAdjacentCount(x, y, false) > 5)
                            {
                                // dig out most walls inbetween
                                if (random.getInt(0, 100) > PercentInbetweenWalls)
                                {
                                    dig(x, y);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        public static Actor getRandomActorOfType(string type, float minRarity, float maxRarity)
        {
            SortedList <float, List <Actor> > actors = getActorsOfType(type);

            if (actors != null)
            {
                float randInt = getRandomRarity(minRarity > actors.Keys.Min() ? minRarity : actors.Keys.Min(), maxRarity > actors.Keys.Max() ? maxRarity : actors.Keys.Max());
                float index   = float.MaxValue;

                foreach (float k in actors.Keys)
                {
                    if (Math.Abs(randInt - k) < Math.Abs(randInt - index))
                    {
                        index = k;
                    }
                }
                if (actors.ContainsKey(index))
                {
                    int randIndex = TCODRandom.getInstance().getInt(0, actors[index].Count - 1);
                    return(ActorLoader.getActor(actors[index][randIndex].name));
                }
            }
            return(null);
        }
Exemplo n.º 19
0
 public GenCaveDungeon(TCODRandom rng, Terrain[] terrains, MapInfo mapInfo)
     : base(rng, terrains, mapInfo)
 {
     perlin = new PerlinNoise(rng.getInt(0, 2147483647));
 }
Exemplo n.º 20
0
 public Generator(TCODRandom rng, Terrain[] terrains, MapInfo mapInfo)
 {
     this.terrains = terrains;
     this.rng      = rng;
     this.mapInfo  = mapInfo;
 }
Exemplo n.º 21
0
        public void smooth()
        {
            bool done  = false;
            int  tries = 0;
            int  l     = 0;

            int percent = windingPercent ^ 2;

            while (!done && !TCODConsole.isWindowClosed() && tries < percent)
            {
                // Program.engine.update();
                if (debugDraw)
                {
                    Program.engine.render();
                    TCODConsole.flush();
                }
                done = true;

                percent = (windingPercent ^ 2) + TCODRandom.getInstance().getInt(-50, 50);

                for (var y = 1; y < map.height; y += 1)
                {
                    for (var x = 1; x < map.width; x += 1)
                    {
                        if (!map.isWall(x, y))
                        {
                            List <Point> exits = new List <Point>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (!map.isWall(x + p.X, y + p.Y))
                                    {
                                        exits.Add(p);
                                    }
                                }
                            }
                            if (exits.Count == 2)
                            {
                                Point a = exits[0];
                                Point b = exits[1];
                                if (a.X != 0) //checks if pathway is horisontal or vertical
                                {
                                    if (map.isWall(x + (a.X * 2), y) && map.isWall(x + (b.X * 2), y))
                                    {
                                        if (!map.isWall(x + a.X, y + 1) && !map.isWall(x + b.X, y + 1))
                                        {
                                            if (map.isWall(x + a.X, y - 1) && map.isWall(x + b.X, y - 1))
                                            {
                                                map.setWall(x + a.X, y);
                                                map.setWall(x + b.X, y);
                                                map.setWall(x, y);
                                                map.dig(x, y + 1, x, y + 1);


                                                done = false;
                                            }
                                        }
                                        else
                                        if (!map.isWall(x + a.X, y - 1) && !map.isWall(x + b.X, y - 1))
                                        {
                                            if (map.isWall(x + a.X, y + 1) && map.isWall(x + b.X, y + 1))
                                            {
                                                map.setWall(x + a.X, y);
                                                map.setWall(x + b.X, y);
                                                map.setWall(x, y);
                                                map.dig(x, y - 1, x, y - 1);

                                                done = false;
                                            }
                                        }
                                    }
                                }
                                else if (a.Y != 0)
                                {
                                    if (map.isWall(x, y + (a.Y * 2)) && map.isWall(x, y + (b.Y * 2)))
                                    {
                                        if (!map.isWall(x + 1, y + a.Y) && !map.isWall(x + 1, y + b.Y))
                                        {
                                            if (map.isWall(x - 1, y + a.Y) && map.isWall(x - 1, y + b.Y))
                                            {
                                                map.setWall(x, y + a.Y);
                                                map.setWall(x, y + b.Y);
                                                map.setWall(x, y);
                                                map.dig(x + 1, y, x + 1, y);

                                                done = false;
                                            }
                                        }
                                        else

                                        if (!map.isWall(x - 1, y + a.Y) && !map.isWall(x - 1, y + b.Y))
                                        {
                                            if (map.isWall(x + 1, y + a.Y) && map.isWall(x + 1, y + b.Y))
                                            {
                                                map.setWall(x, y + a.Y);
                                                map.setWall(x, y + b.Y);
                                                map.setWall(x, y);
                                                map.dig(x - 1, y, x - 1, y);

                                                done = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }


                tries++;
                l++;
                if (l < (windingPercent * windingPercent) / 4)
                {
                    Program.engine.loadingGui.loading++;
                    Program.engine.render();
                    l = 0;
                }
            }
            done  = false;
            tries = 0;
            while (!done && !TCODConsole.isWindowClosed() && tries < percent)
            {
                // Program.engine.update();
                //Program.engine.render();

                //TCODConsole.flush();
                if (debugDraw)
                {
                    Program.engine.render();
                    TCODConsole.flush();
                }
                done = true;

                percent = (windingPercent ^ 2) + TCODRandom.getInstance().getInt(-50, 50);

                for (var y = 1; y < map.height; y += 1)
                {
                    for (var x = 1; x < map.width; x += 1)
                    {
                        if (!map.isWall(x, y))
                        {
                            List <Point> exits = new List <Point>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (!map.isWall(x + p.X, y + p.Y))
                                    {
                                        exits.Add(p);
                                    }
                                }
                            }
                            if (exits.Count == 2)
                            {
                                Point a = exits[0];
                                Point b = exits[1];
                                if (a.X != 0) //checks if pathway is horisontal or vertical
                                {
                                    if (map.isWall(x + (a.X * 3), y) && map.isWall(x + (b.X * 3), y))
                                    {
                                        if (!map.isWall(x + (a.X * 2), y) && !map.isWall(x + (b.X * 2), y))
                                        {
                                            if (!map.isWall(x + (a.X * 2), y + 1) && !map.isWall(x + (b.X * 2), y + 1))
                                            {
                                                if (map.isWall(x + (a.X * 2), y - 1) && map.isWall(x + (b.X * 2), y - 1))
                                                {
                                                    map.setWall(x + a.X, y);
                                                    map.setWall(x + b.X, y);
                                                    map.setWall(x + (a.X * 2), y);
                                                    map.setWall(x + (b.X * 2), y);
                                                    map.setWall(x, y);
                                                    map.dig(x, y + 1, x, y + 1);
                                                    map.dig(x + a.X, y + 1, x + a.X, y + 1);
                                                    map.dig(x + b.X, y + 1, x + b.X, y + 1);

                                                    done = false;
                                                }
                                            }
                                            else

                                            if (!map.isWall(x + (a.X * 2), y - 1) && !map.isWall(x + (b.X * 2), y - 1))
                                            {
                                                if (map.isWall(x + (a.X * 2), y + 1) && map.isWall(x + (b.X * 2), y + 1))
                                                {
                                                    map.setWall(x + a.X, y);
                                                    map.setWall(x + b.X, y);
                                                    map.setWall(x + (a.X * 2), y);
                                                    map.setWall(x + (b.X * 2), y);
                                                    map.setWall(x, y);
                                                    map.dig(x, y - 1, x, y - 1);
                                                    map.dig(x + a.X, y - 1, x + a.X, y - 1);
                                                    map.dig(x + b.X, y - 1, x + b.X, y - 1);

                                                    done = false;
                                                }
                                            }
                                        }
                                    }
                                    else if (a.Y != 0)
                                    {
                                        if (map.isWall(x, y + (a.Y * 3)) && map.isWall(x, y + (b.Y * 3)))
                                        {
                                            if (!map.isWall(x, y + (a.Y * 2)) && !map.isWall(x, y + (b.Y * 2)))
                                            {
                                                if (!map.isWall(x + 1, y + (a.Y * 2)) && !map.isWall(x + 1, y + (b.Y * 2)))
                                                {
                                                    if (map.isWall(x - 1, y + (a.Y * 2)) && map.isWall(x - 1, y + (b.Y * 2)))
                                                    {
                                                        map.setWall(x, y + a.Y);
                                                        map.setWall(x, y + b.Y);
                                                        map.setWall(x, y + (a.Y * 2));
                                                        map.setWall(x, y + (b.Y * 2));
                                                        map.setWall(x, y);
                                                        map.dig(x + 1, y + 1, x, y);
                                                        map.dig(x + 1, y + a.Y, x + 1, y + a.Y);
                                                        map.dig(x + 1, y + b.Y, x + 1, y + b.Y);

                                                        done = false;
                                                    }
                                                }
                                                else

                                                if (!map.isWall(x + (a.X * 2), y + 1) && !map.isWall(x + (b.X * 2), y + 1))
                                                {
                                                    if (map.isWall(x + (a.X * 2), y - 1) && map.isWall(x + (b.X * 2), y - 1))

                                                    {
                                                        map.setWall(x, y + a.Y);
                                                        map.setWall(x, y + b.Y);
                                                        map.setWall(x, y + (a.Y * 2));
                                                        map.setWall(x, y + (b.Y * 2));
                                                        map.setWall(x, y);
                                                        map.dig(x - 1, y - 1, x, y);
                                                        map.dig(x - 1, y + a.Y, x - 1, y + a.Y);
                                                        map.dig(x - 1, y + b.Y, x - 1, y + b.Y);

                                                        done = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                tries++;
            }
        }
Exemplo n.º 22
0
        public void removeDeadEnds()
        {
            bool         done    = false;
            int          tries   = 0;
            int          l       = 0;
            List <Point> ignores = new List <Point>();

            while (!done && !TCODConsole.isWindowClosed() && tries < 100)
            {
                // Program.engine.update();
                //Program.engine.render();
                //TCODConsole.flush();
                if (debugDraw)
                {
                    Program.engine.render();
                    TCODConsole.flush();
                }
                done = true;


                for (var y = 1; y < map.height; y += 1)
                {
                    for (var x = 1; x < map.width; x += 1)
                    {
                        if (!map.isWall(x, y))
                        {
                            List <Point> exits = new List <Point>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (!map.isWall(x + p.X, y + p.Y) || ignores.Contains(new Point(x + p.X, y + p.Y)))
                                    {
                                        exits.Add(p);
                                    }
                                }
                            }
                            if (exits.Count == 1)
                            {
                                if (TCODRandom.getInstance().getInt(0, 100) < 100 - deadEndLength)
                                {
                                    done = false;
                                    map.setWall(x, y);
                                }
                                else
                                {
                                    ignores.Add(new Point(x, y));
                                }
                            }
                        }
                    }
                }
                tries++;
                l++;
                if (l > (100 - deadEndLength) / 5)
                {
                    Program.engine.loadingGui.loading++;
                    Program.engine.render();
                    l = 0;
                }
            }
        }
Exemplo n.º 23
0
        public Item(TCODRandom rnd, ItemType desiredItemType, ItemQuality desiredItemQuality, int desiredItemLevel, ItemStatus desiredItemStatus)
        {
            // Set defaults
            type         = desiredItemType;
            status       = desiredItemStatus;
            itemLevel    = desiredItemLevel;
            itemLevel    = 0;
            attackBonus  = 0;
            defenseBonus = 0;
            bodyBonus    = 0;
            mindBonus    = 0;
            finesseBonus = 0;
            charges      = 0;
            quality      = desiredItemQuality;
            potionType   = ItemPotionType.None;
            scrollType   = ItemScrollType.None;
            wandType     = ItemWandType.None;
            itemGraphic  = ' ';
            itemColour   = new TCODColor(0, 0, 0);

            // Generate random numbers in case we need to use it later
            ItemStatistic randomStatistic1 = (ItemStatistic)rnd.getInt(0, 2);
            ItemStatistic randomStatistic2 = (ItemStatistic)rnd.getInt(0, 2);

            StringBuilder nameBuilder = new StringBuilder(string.Empty);

            // Generate items based upon their specified type, quality and level
            switch (desiredItemType)
            {
            case ItemType.Weapon:
            {
                int typeOfWeapon = rnd.getInt(1, 6);
                switch (typeOfWeapon)
                {
                case 1:
                    nameBuilder.Append("Longsword ");
                    break;

                case 2:
                    nameBuilder.Append("Polearm ");
                    break;

                case 3:
                    nameBuilder.Append("Spear ");
                    break;

                case 4:
                    nameBuilder.Append("Mace ");
                    break;

                case 5:
                    nameBuilder.Append("Warhammer ");
                    break;

                case 6:
                    nameBuilder.Append("Halberd ");
                    break;
                }
                itemGraphic = ')';
                switch (desiredItemQuality)
                {
                case ItemQuality.Common:
                    attackBonus = BaseWeaponDamage;
                    nameBuilder.Append("+0");
                    itemColour = TCODColor.lightestGrey;
                    break;

                case ItemQuality.Uncommon:
                    attackBonus = BaseWeaponDamage + desiredItemLevel;
                    nameBuilder.Append("+");
                    nameBuilder.Append(desiredItemLevel.ToString());
                    itemColour = TCODColor.green;
                    break;

                case ItemQuality.Superior:
                    attackBonus = BaseWeaponDamage + desiredItemLevel;
                    nameBuilder.Append("+");
                    nameBuilder.Append(desiredItemLevel.ToString());
                    itemColour = TCODColor.blue;
                    switch (randomStatistic1)
                    {
                    case ItemStatistic.Body:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("B)");
                        bodyBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Mind:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("M)");
                        mindBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Finesse:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("F)");
                        finesseBonus = desiredItemLevel;
                        break;
                    }
                    break;

                case ItemQuality.Epic:
                    attackBonus = BaseWeaponDamage + desiredItemLevel;
                    nameBuilder.Append("+");
                    nameBuilder.Append(desiredItemLevel.ToString());
                    itemColour = TCODColor.purple;
                    switch (randomStatistic1)
                    {
                    case ItemStatistic.Body:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("B)");
                        bodyBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Mind:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("M)");
                        mindBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Finesse:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("F)");
                        finesseBonus = desiredItemLevel;
                        break;
                    }
                    switch (randomStatistic2)
                    {
                    case ItemStatistic.Body:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("B)");
                        bodyBonus += desiredItemLevel;
                        break;

                    case ItemStatistic.Mind:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("M)");
                        mindBonus += desiredItemLevel;
                        break;

                    case ItemStatistic.Finesse:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("F)");
                        finesseBonus += desiredItemLevel;
                        break;
                    }
                    break;
                }
            }
            break;

            case ItemType.Armour:
            {
                int typeOfArmour = rnd.getInt(1, 4);
                switch (typeOfArmour)
                {
                case 1:
                    nameBuilder.Append("Chainmail ");
                    break;

                case 2:
                    nameBuilder.Append("Plate Armour ");
                    break;

                case 3:
                    nameBuilder.Append("Leather Armour ");
                    break;

                case 4:
                    nameBuilder.Append("Scale Armour ");
                    break;
                }
                itemGraphic = '[';
                switch (desiredItemQuality)
                {
                case ItemQuality.Common:
                    defenseBonus = BaseArmourClass;
                    nameBuilder.Append("+0");
                    itemColour = TCODColor.grey;
                    break;

                case ItemQuality.Uncommon:
                    defenseBonus = BaseArmourClass + desiredItemLevel;
                    nameBuilder.Append("+");
                    nameBuilder.Append(desiredItemLevel.ToString());
                    itemColour = TCODColor.green;
                    break;

                case ItemQuality.Superior:
                    defenseBonus = BaseArmourClass + desiredItemLevel;
                    nameBuilder.Append("+");
                    nameBuilder.Append(desiredItemLevel.ToString());
                    itemColour = TCODColor.blue;
                    switch (randomStatistic1)
                    {
                    case ItemStatistic.Body:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("B)");
                        bodyBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Mind:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("M)");
                        mindBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Finesse:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("F)");
                        finesseBonus = desiredItemLevel;
                        break;
                    }
                    break;

                case ItemQuality.Epic:
                    defenseBonus = BaseArmourClass + desiredItemLevel;
                    nameBuilder.Append("+");
                    nameBuilder.Append(desiredItemLevel.ToString());
                    itemColour = TCODColor.purple;
                    switch (randomStatistic1)
                    {
                    case ItemStatistic.Body:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("B)");
                        bodyBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Mind:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("M)");
                        mindBonus = desiredItemLevel;
                        break;

                    case ItemStatistic.Finesse:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("F)");
                        finesseBonus = desiredItemLevel;
                        break;
                    }
                    switch (randomStatistic2)
                    {
                    case ItemStatistic.Body:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("B)");
                        bodyBonus += desiredItemLevel;
                        break;

                    case ItemStatistic.Mind:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("M)");
                        mindBonus += desiredItemLevel;
                        break;

                    case ItemStatistic.Finesse:
                        nameBuilder.Append(" (+");
                        nameBuilder.Append(desiredItemLevel.ToString());
                        nameBuilder.Append("F)");
                        finesseBonus += desiredItemLevel;
                        break;
                    }
                    break;
                }
            }
            break;

            case ItemType.Potion:
                nameBuilder.Append("Potion of ");
                itemGraphic = '!';
                ItemPotionType randomPotionType = (ItemPotionType)rnd.getInt(0, 2);
                potionType = randomPotionType;
                nameBuilder.Append(randomPotionType.ToString());
                itemColour = TCODColor.white;
                break;

            case ItemType.Scroll:
                nameBuilder.Append("Scroll of ");
                itemGraphic = '?';
                ItemScrollType randomScrollType = (ItemScrollType)rnd.getInt(0, 3);
                scrollType = randomScrollType;
                nameBuilder.Append(randomScrollType.ToString());
                itemColour = TCODColor.white;
                break;

            case ItemType.Wand:
                nameBuilder.Append("Wand of ");
                itemGraphic = '/';
                ItemWandType randomWandType = (ItemWandType)rnd.getInt(0, 4);
                wandType = randomWandType;
                nameBuilder.Append(randomWandType.ToString());
                charges    = rnd.getInt(10, 20);
                itemColour = TCODColor.brass;
                break;

            case ItemType.Corpse:
                nameBuilder.Append("frozen corpse");
                itemGraphic = '%';
                itemColour  = TCODColor.grey;
                break;
            }

            name = nameBuilder.ToString().TrimEnd();
        }
Exemplo n.º 24
0
 public RoomGenerator(TCODRandom rng)
 {
     this.rng = rng;
     rooms    = new List <DungeonRoom>();
 }
Exemplo n.º 25
0
 public World()
 {
     engine = Engine.instance;
     rng    = TCODRandom.getInstance();
 }
Exemplo n.º 26
0
 public GenComplexDungeon(TCODRandom rng, Terrain[] terrains, MapInfo mapInfo)
     : base(rng, terrains, mapInfo)
 {
 }
Exemplo n.º 27
0
 public MapGen(uint seed)
 {
     _rand = new TCODRandom(seed);
 }
Exemplo n.º 28
0
 public MapGen()
 {
     _rand = new TCODRandom();
 }
Exemplo n.º 29
0
 public static float getRandomRarity(float min, float max)
 {
     return(getRarity(min, max, (double)TCODRandom.getInstance().getFloat(min, max)));
 }
Exemplo n.º 30
0
        public void connectRegions()
        {
            List <int[]> _regions       = new List <int[]>();
            List <Point> _points        = new List <Point>();
            TCODRandom   rng            = TCODRandom.getInstance();
            List <Point> extraJunctions = new List <Point>();

            for (var y = 1; y < map.height - 1; y++)
            {
                for (var x = 1; x < map.width - 1; x++)
                {
                    if (map.isWall(x, y))
                    {
                        List <int> regs = new List <int>();

                        foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                        {
                            if (dir != Direction.NULL)
                            {
                                Point p = dirToPoint(dir);
                                if (x + p.X < regions.GetLength(0) - 1 && y + p.Y < regions.GetLength(1) - 1 && x + p.X > 0 && y + p.Y > 0)
                                {
                                    int region = regions[x + p.X, y + p.Y];
                                    if (region != 0 && !regs.Contains(region))
                                    {
                                        regs.Add(region);
                                    }
                                }
                            }
                        }
                        if (regs.Count < 2)
                        {
                            if (rng.getInt(0, extraConnectorChance * extraConnectorChance) == 0)
                            {
                                extraJunctions.Add(new Point(x, y));
                            }
                            continue;
                        }
                        _regions.Add(regs.ToArray());
                        _points.Add(new Point(x, y));
                    }
                    else
                    {
                    }
                }
            }



            int openRegions = currentRegion;
            int tries       = 0;

            while (_regions.Count > 1 && !TCODConsole.isWindowClosed())
            {
                int rnum = TCODRandom.getInstance().getInt(0, _regions.Count - 1);
                if (_regions.Count > 0)
                {
                    int[] connectorReg = _regions[rnum];
                    Point connectorPos = _points[rnum];


                    addJunction(connectorPos.X, connectorPos.Y);

                    List <int> sources = new List <int>();
                    int        dest    = connectorReg[0];
                    bool       foo     = true;

                    for (int y = 1; y < map.height - 1; y++)
                    {
                        for (int x = 1; x < map.width - 1; x++)
                        {
                            for (int j = 0; j < connectorReg.Length; j++)
                            {
                                if (regions[x, y] == connectorReg[j] && regions[x, y] != dest)
                                {
                                    regions[x, y] = dest;
                                    if (foo)
                                    {
                                        foo = false;
                                    }
                                }
                            }
                        }
                    }
                    if (!foo)
                    {
                        openRegions--;
                    }



                    _regions.Remove(connectorReg);
                    _points.Remove(connectorPos);


                    for (int i = 0; i < _regions.Count; i++)
                    {
                        if (i < _regions.Count)
                        {
                            if (Math.Sqrt(Math.Pow(connectorPos.X - _points[i].X, 2) + Math.Pow(connectorPos.Y - _points[i].Y, 2)) < 2)
                            {
                                _points.RemoveAt(i);
                                _regions.RemoveAt(i);
                                continue;
                            }
                            List <int> regs = new List <int>();
                            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
                            {
                                if (dir != Direction.NULL)
                                {
                                    Point p = dirToPoint(dir);
                                    if (_points[i].X + p.X < regions.GetLength(0) - 1 && _points[i].Y + p.Y < regions.GetLength(1) - 1 && _points[i].X + p.X > 0 && _points[i].Y + p.Y > 0)
                                    {
                                        int region = regions[_points[i].X + p.X, _points[i].Y + p.Y];
                                        if (region != 0 && !regs.Contains(region))
                                        {
                                            regs.Add(region);
                                        }
                                    }
                                }
                            }
                            _regions[i] = regs.ToArray();
                            if (_regions[i].Length > 1)
                            {
                                continue;
                            }

                            if (rng.getInt(0, extraConnectorChance) == 0)
                            {
                                if (!extraJunctions.Contains(_points[i]))
                                {
                                    extraJunctions.Add(_points[i]);
                                }
                            }

                            _points.RemoveAt(i);
                            _regions.RemoveAt(i);
                        }
                    }
                }
                else
                {
                    break;
                }
                tries++;
            }


            for (int i = 0; i < maxExtraJunctions; i++)
            {
                if (extraJunctions.Count > 0)
                {
                    Point p = extraJunctions[rng.getInt(0, extraJunctions.Count - 1)];
                    addJunction(p.X, p.Y);
                }
            }

            /*
             * int[] merged = null;
             * if (currentRegion > 0)
             *  merged = new int[currentRegion + 1];
             * List<int> openRegions = new List<int>();
             * for (int i = 0; i <= currentRegion; i++)
             * {
             *  openRegions.Add(i);
             *  if (merged != null)
             *      merged[i] = i;
             * }
             * TCODRandom rng = TCODRandom.getInstance();
             *
             * while (openRegions.Count > 1 && !TCODConsole.isWindowClosed())
             * {
             *
             *  ConnectorCell connector = connectorRegions[rng.getInt(0, connectorRegions.Count - 1)];
             *  addJunction(connector.pos.X, connector.pos.Y);
             *
             *  List<int> regs = new List<int>();
             *
             *
             *  regs = merged.ToList();
             *  int dest = regs[0];
             *  int[] sources = regs.Skip(1).ToArray();
             *  for (int i = 0; i <= currentRegion; i++)
             *  {
             *      if (sources.Contains(merged[i]))
             *      {
             *          merged[i] = dest;
             *      }
             *  }
             *  for (int i = 0; i < sources.Length; i++)
             *  {
             *      openRegions.Remove(sources[i]);
             *  }
             *
             *  for (int i = 0; i < connectorRegions.Count; i++)
             *  {
             *      if (i < connectorRegions.Count)
             *      {
             *          ConnectorCell c = connectorRegions[i];
             *          if (connector.pos.X - c.pos.X < 2 || connector.pos.Y - c.pos.Y < 2)
             *          {
             *              connectorRegions.Remove(c);
             *              continue;
             *          }
             *          if (regions.Length > 1) { continue; }
             *
             *          if (rng.getInt(0, extraConnectorChance) > 0)
             *          {
             *              addJunction(c.pos.X, c.pos.Y);
             *              connectorRegions.Remove(c);
             *              continue;
             *          }
             *      }
             *  }
             *
             * }
             */
        }
Exemplo n.º 31
0
 public void Init()
 {
     r = new TCODRandom();
 }
Exemplo n.º 32
0
 public MapGen(uint seed)
 {
     _rand = new TCODRandom(seed);
 }
Exemplo n.º 33
0
        private void setupStaticData()
        {
            random = new TCODRandom();

            render_cols = new TCODColor[4];
            render_cols[0] = new TCODColor(50, 40, 150);
            render_cols[1] = new TCODColor(240, 85, 5);
            render_cols[2] = new TCODColor(50, 35, 240);
            render_cols[3] = new TCODColor(10, 200, 130);

            render_dirr = new int[] { 1, -1, 1, 1 };
            render_dirg = new int[] { 1, -1, -1, 1 };
            render_dirb = new int[] { 1, 1, 1, -1 };

            off_secondary = new TCODConsole(SAMPLE_SCREEN_WIDTH / 2, SAMPLE_SCREEN_HEIGHT / 2);
            off_screenshot = new TCODConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);
            line_bk = new TCODConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);
            noise = new TCODNoise(2, noise_hurst, noise_lacunarity);
        }
Exemplo n.º 34
0
            public override bool visitNode(TCODBsp node)
            {
                TCODRandom rnd = new TCODRandom();

                if (node.isLeaf())
                {
                    // calculate the room size
                    int minx = node.x + 1;
                    int maxx = node.x + node.w - 1;
                    int miny = node.y + 1;
                    int maxy = node.y + node.h - 1;
                    int x, y;
                    if (!roomWalls)
                    {
                        if (minx > 1) minx--;
                        if (miny > 1) miny--;
                    }
                    if (maxx == SAMPLE_SCREEN_WIDTH - 1) maxx--;
                    if (maxy == SAMPLE_SCREEN_HEIGHT - 1) maxy--;
                    if (randomRoom)
                    {
                        minx = rnd.getInt(minx, maxx - minRoomSize + 1);
                        miny = rnd.getInt(miny, maxy - minRoomSize + 1);
                        maxx = rnd.getInt(minx + minRoomSize - 1, maxx);
                        maxy = rnd.getInt(miny + minRoomSize - 1, maxy);
                    }
                    // resize the node to fit the room
                    //	printf("node %dx%d %dx%d => room %dx%d %dx%d\n",node->x,node->y,node->w,node->h,minx,miny,maxx-minx+1,maxy-miny+1);
                    node.x = minx;
                    node.y = miny;
                    node.w = maxx - minx + 1;
                    node.h = maxy - miny + 1;
                    // dig the room
                    for (x = minx; x <= maxx; x++)
                    {
                        for (y = miny; y <= maxy; y++)
                        {
                            bsp_map[x, y] = ' ';
                        }
                    }
                }
                else
                {
                    //	printf("lvl %d %dx%d %dx%d\n",node->level, node->x,node->y,node->w,node->h);
                    // resize the node to fit its sons
                    TCODBsp left = node.getLeft();
                    TCODBsp right = node.getRight();

                    node.x = System.Math.Min(left.x, right.x);
                    node.y = System.Math.Min(left.y, right.y);
                    node.w = System.Math.Max(left.x + left.w, right.x + right.w) - node.x;
                    node.h = System.Math.Max(left.y + left.h, right.y + right.h) - node.y;
                    // create a corridor between the two lower nodes
                    if (node.horizontal)
                    {
                        // vertical corridor
                        if (left.x + left.w - 1 < right.x || right.x + right.w - 1 < left.x)
                        {
                            // no overlapping zone. we need a Z shaped corridor
                            int x1 = rnd.getInt(left.x, left.x + left.w - 1);
                            int x2 = rnd.getInt(right.x, right.x + right.w - 1);
                            int y = rnd.getInt(left.y + left.h, right.y);
                            vline_up(bsp_map, x1, y - 1);
                            hline(bsp_map, x1, y, x2);
                            vline_down(bsp_map, x2, y + 1);
                        }
                        else
                        {
                            // straight vertical corridor
                            int minx = System.Math.Max(left.x, right.x);
                            int maxx = System.Math.Min(left.x + left.w - 1, right.x + right.w - 1);
                            int x = rnd.getInt(minx, maxx);
                            vline_down(bsp_map, x, right.y);
                            vline_up(bsp_map, x, right.y - 1);
                        }
                    }
                    else
                    {
                        // horizontal corridor
                        if (left.y + left.h - 1 < right.y || right.y + right.h - 1 < left.y)
                        {
                            // no overlapping zone. we need a Z shaped corridor
                            int y1 = rnd.getInt(left.y, left.y + left.h - 1);
                            int y2 = rnd.getInt(right.y, right.y + right.h - 1);
                            int x = rnd.getInt(left.x + left.w, right.x);
                            hline_left(bsp_map, x - 1, y1);
                            vline(bsp_map, x, y1, y2);
                            hline_right(bsp_map, x + 1, y2);
                        }
                        else
                        {
                            // straight horizontal corridor
                            int miny = System.Math.Max(left.y, right.y);
                            int maxy = System.Math.Min(left.y + left.h - 1, right.y + right.h - 1);
                            int y = rnd.getInt(miny, maxy);
                            hline_left(bsp_map, right.x - 1, y);
                            hline_right(bsp_map, right.x, y);
                        }
                    }
                }
                return true;
            }
Exemplo n.º 35
0
 public MapGen()
 {
     _rand = new TCODRandom();
 }