wyvern.kernel.dungeon
Class DungeonGenerator

java.lang.Object
  extended bywyvern.kernel.dungeon.AbstractLevelGenerator
      extended bywyvern.kernel.dungeon.DungeonGenerator
All Implemented Interfaces:
DungeonConstants

public class DungeonGenerator
extends AbstractLevelGenerator
implements DungeonConstants

Engine for creating a Nethack-style dungeon level. This class is NOT thread-safe; you should make sure you only call it from one thread. You can call generate() multiple times, however, to make new levels.

Version:
1.0, Oct 07, 1999
Author:
Kiz, stevey

Nested Class Summary
 
Nested classes inherited from class wyvern.kernel.dungeon.DungeonConstants
DungeonConstants.Blockage, DungeonConstants.RoomType, DungeonConstants.TrapCount
 
Field Summary
protected  int blockage_
           
protected  int density_
           
protected  java.lang.String door_
           
protected  int doorHP_
           
protected  int[][] doorType_
           
protected  int eastmost_
           
protected  java.lang.String exits_
           
protected  int height_
           
protected  int[][] itemLocs_
           
protected  int[][] maze_
           
protected  int[][] monsterLocs_
           
protected  int northmost_
           
protected  int numGroups_
           
protected  int numRooms_
           
protected  int numSpecialRooms_
           
protected  Room[][] roomCache_
           
protected  int roomMin_
           
protected  int roomRand_
           
protected  java.util.ArrayList rooms_
           
protected  int southmost_
           
protected  int special_
           
protected  int specialX_
           
protected  int specialY_
           
protected  java.lang.String stair_
           
protected  int[][] submaze_
           
protected  int traps_
           
protected  java.lang.String wall_
           
protected  int westmost_
           
protected  int width_
           
 
Fields inherited from class wyvern.kernel.dungeon.AbstractLevelGenerator
DEFAULT_HEIGHT, DEFAULT_WIDTH, floor_, oobTerrain_, stairsDown_, stairsUp_, terrain_
 
Fields inherited from interface wyvern.kernel.dungeon.DungeonConstants
CORNER, DEFAULT_DEFAULT_TERRAIN, DEFAULT_DENSITY, DEFAULT_DOOR, DEFAULT_DOOR_HP, DEFAULT_DUNGEON_HEIGHT, DEFAULT_DUNGEON_WIDTH, DEFAULT_EXIT_TYPE, DEFAULT_FLOOR, DEFAULT_ROOM_MIN, DEFAULT_ROOM_RAND, DEFAULT_STAIR, DEFAULT_WALL, DOOR, DOWNSTAIR, EAST, EDGEDOOR, FLOOR, FRIENDLY, GENERIC, LOCKEDDOOR, MAX_DUNGEON_HEIGHT, MAX_DUNGEON_WIDTH, MINROOMS, NEVERLOCKED, NEVERTRAPPED, NODOOR, NORMAL, NORMALDOOR, NORTH, ONEDOORWALL, POWERFUL, SECRETDOOR, SOUTH, TRAPPEDDOOR, TRAPPEDSPACE, TREASURE, TUNNEL, UPSTAIR, VERYPOWERFUL, WALL, WEAK, WEST
 
Constructor Summary
DungeonGenerator()
          Constructs a new generator.
DungeonGenerator(int w, int h)
          Constructs a new DungeonGenerator
 
Method Summary
 void addDownstair(GameMap map, int x, int y)
          Adds the staircase down.
protected  void addLever(GameObject gate, GameMap map, int type)
          Adds levers for the "door", if the door-type is a Gate.
 void addStairs()
          Places up & down staircases if applicable.
 void addTraps()
          Puts down random traps throughout the dungeon.
 void addUpstair(GameMap map, int x, int y)
          Adds the staircase up.
 void connectRooms()
          Digs tunnels between existing rooms.
 void createSpecialRoom(int type)
          Creates a shop, lair, vault, snare, etc.
 Room digFrom(int startX, int startY, int xz, int yz, int endX, int endY)
           
 Room digTunnel(Room r1, Room r2)
           
 void eraseMap()
           
 GameMap generate(java.lang.Class mapclass)
          Generates a new dungeon subclassed from the specified map class.
 void generateLair()
          A lair is a room full of a bunch of related monsters.
 GameMap generateMap(java.lang.Class mapclass)
          Produces a wyvern GameMap from the internal data structures.
 void generateRooms()
          Generates the "normal" rooms for the dungeon.
 void generateShop()
          Generates a shop on the level.
 void generateSnare()
          A snare is a square room with lots of traps and some treasure in the center.
 Room generateValidRoom(int bx, int rx)
          Tries to create a room somewhere in the dungeon.
 void generateVault()
          A vault is a small, square room filled with treasure.
 int getBlockage()
           
 java.lang.String getDoorArchetype()
           
 int getDoorHP()
           
 java.lang.String getExitType()
           
 int getMinimumRoomSize()
           
 Room getRoom(int x, int y)
          Returns the Room that contains (x,y).
 int getRoomDensity()
           
 int getRoomRandomSize()
           
 int getSpecialRoom()
           
 java.lang.String getStairArchetype()
           
 int getTraps()
           
 java.lang.String getWallArchetype()
           
 void makeDoor(int x1, int y1, int x2, int y2)
          Places a door in the dungeon.
 void mergeGroups(int g1, int g2)
          Each time a new room is added, the global group count is incremented.
 void setBlockage(int blockage)
          Sets hall/door junction blockage.
 void setDoorArchetype(java.lang.String name)
          Sets the archetype to use for the dungeon doors.
 void setDoorHP(int hp)
          Sets the number of HP to use for doors in the dungeon.
 void setExitType(java.lang.String type)
          Sets whether up/down stairs are desired.
 void setMinimumRoomSize(int size)
          Sets the minimum number of squares across a room in any dimension.
 void setRoomDensity(int density)
          Sets the density of rooms per map area.
 void setRoomRandomSize(int size)
          Sets the maximum random amount added to the room width & height.
 void setSpecialRoom(int type)
          Sets the special room to generate, if any.
 void setStairArchetype(java.lang.String name)
          Sets the archetype base-name to use for the dungeon/room stairs.
 void setTraps(int traps)
          Sets level of traps to generate.
 void setWallArchetype(java.lang.String name)
          Sets the archetype to use for the dungeon/room walls.
protected  boolean useExistingLevers(GameObject gate, GameMap map, int type)
          Tries to use the existing levers for a gate next to another gate.
 boolean validDoor(int x1, int y1, int x2, int y2)
           
 boolean validRoom(int x1, int y1, int x2, int y2)
          This function compares the coordinates of the proposed room to every existing room.
 
Methods inherited from class wyvern.kernel.dungeon.AbstractLevelGenerator
getDefaultTerrain, getDownstairArchetype, getFloorArchetype, getHeight, getOOBTerrain, getUpstairArchetype, getWidth, instantiateFloor, instantiateObject, rand, setDefaultTerrain, setDownstairArchetype, setFloorArchetype, setHeight, setOOBTerrain, setUpstairArchetype, setWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width_

protected int width_

height_

protected int height_

roomMin_

protected int roomMin_

roomRand_

protected int roomRand_

density_

protected int density_

blockage_

protected int blockage_

traps_

protected int traps_

special_

protected int special_

exits_

protected java.lang.String exits_

door_

protected java.lang.String door_

wall_

protected java.lang.String wall_

stair_

protected java.lang.String stair_

maze_

protected int[][] maze_

submaze_

protected int[][] submaze_

doorType_

protected int[][] doorType_

monsterLocs_

protected int[][] monsterLocs_

itemLocs_

protected int[][] itemLocs_

roomCache_

protected Room[][] roomCache_

rooms_

protected java.util.ArrayList rooms_

numRooms_

protected int numRooms_

numSpecialRooms_

protected int numSpecialRooms_

numGroups_

protected int numGroups_

specialX_

protected int specialX_

specialY_

protected int specialY_

northmost_

protected int northmost_

southmost_

protected int southmost_

eastmost_

protected int eastmost_

westmost_

protected int westmost_

doorHP_

protected int doorHP_
Constructor Detail

DungeonGenerator

public DungeonGenerator()
Constructs a new generator.


DungeonGenerator

public DungeonGenerator(int w,
                        int h)
Constructs a new DungeonGenerator

Method Detail

generate

public GameMap generate(java.lang.Class mapclass)
Generates a new dungeon subclassed from the specified map class.

Specified by:
generate in class AbstractLevelGenerator
Parameters:
mapclass - the class (e.g. DenseMap.class) to generate
Returns:
a GameMap containing the dungeon. There are two properties set on the map: "room-list" and "door-list". Both have ArrayList values. The room-list is a list of Room objects, one per room in the dungeon, and the door-list is a list of Door objects that were placed in the dungeon.


generateRooms

public void generateRooms()
Generates the "normal" rooms for the dungeon. Any special room(s) must have been added before calling this.


addStairs

public void addStairs()
Places up & down staircases if applicable.


validRoom

public boolean validRoom(int x1,
                         int y1,
                         int x2,
                         int y2)
This function compares the coordinates of the proposed room to every existing room. We perform four checks to see if it overlaps- the first is to see if the leftmost side of the new room is to the right of the rightmost side of the existing room. If so, they cannot overlap. We perform this check for each side of the room. Actually, this sets it so that rooms must always be at least 2 squares apart. That lets a tunnel go between them, if necessary.


addTraps

public void addTraps()
Puts down random traps throughout the dungeon.


connectRooms

public void connectRooms()
Digs tunnels between existing rooms.


digTunnel

public Room digTunnel(Room r1,
                      Room r2)

digFrom

public Room digFrom(int startX,
                    int startY,
                    int xz,
                    int yz,
                    int endX,
                    int endY)

makeDoor

public void makeDoor(int x1,
                     int y1,
                     int x2,
                     int y2)
Places a door in the dungeon.


validDoor

public boolean validDoor(int x1,
                         int y1,
                         int x2,
                         int y2)

createSpecialRoom

public void createSpecialRoom(int type)
Creates a shop, lair, vault, snare, etc.

Parameters:
type - "shop", "lair", "vault", etc.

generateLair

public void generateLair()
A lair is a room full of a bunch of related monsters. The inner floor never has traps, because, well, they live there.

What we actually do is generate one critter off of a special list of lairing creatures- it will automatically surround itself with appropriate critters.


generateSnare

public void generateSnare()
A snare is a square room with lots of traps and some treasure in the center. It never has monsters in it. There is never a trap in the exact center.


generateVault

public void generateVault()
A vault is a small, square room filled with treasure. Its entrance is always locked and trapped. It often has a Vault Guardian of some sort inside.


generateShop

public void generateShop()
Generates a shop on the level.


generateValidRoom

public Room generateValidRoom(int bx,
                              int rx)
Tries to create a room somewhere in the dungeon.

Parameters:
bx - base width/height
rx - random range to add to width and height
Returns:
a Room object, or null if we couldn't make one

getRoom

public Room getRoom(int x,
                    int y)
Returns the Room that contains (x,y).

Parameters:
x - map x
y - map y
Returns:
the room with (x,y) in it, or null if (x,y) is not in any room.

eraseMap

public void eraseMap()

mergeGroups

public void mergeGroups(int g1,
                        int g2)
Each time a new room is added, the global group count is incremented. When the room is connected, the group count is decremented. When the group count hits zero we know all the rooms are reachable.


generateMap

public GameMap generateMap(java.lang.Class mapclass)
Produces a wyvern GameMap from the internal data structures. Does NOT call doneLoading() on the map - you are required to do this before players enter the map, or things won't update properly.

Parameters:
mapclass - the GameMap implementation class to use
Returns:
a GameMap produced by generating a random dungeon

addUpstair

public void addUpstair(GameMap map,
                       int x,
                       int y)
Adds the staircase up.


addDownstair

public void addDownstair(GameMap map,
                         int x,
                         int y)
Adds the staircase down.


addLever

protected void addLever(GameObject gate,
                        GameMap map,
                        int type)
Adds levers for the "door", if the door-type is a Gate.

Parameters:
gate - the gate
map - the map
type - NORTH, SOUTH, EAST or WEST

useExistingLevers

protected boolean useExistingLevers(GameObject gate,
                                    GameMap map,
                                    int type)
Tries to use the existing levers for a gate next to another gate.


setMinimumRoomSize

public void setMinimumRoomSize(int size)
Sets the minimum number of squares across a room in any dimension. Actual room size will be one smaller than this, so for 4x4 rooms, set size to 5. Default: 5.


getMinimumRoomSize

public int getMinimumRoomSize()

setRoomRandomSize

public void setRoomRandomSize(int size)
Sets the maximum random amount added to the room width & height. The max room size will be the min room size plus the random size. Typical values: 5, 10, 20. Default: 10.


getRoomRandomSize

public int getRoomRandomSize()

setRoomDensity

public void setRoomDensity(int density)
Sets the density of rooms per map area. Minimum 50, max 1000. Default: 100.


getRoomDensity

public int getRoomDensity()

setBlockage

public void setBlockage(int blockage)
Sets hall/door junction blockage. Allowable values are constants from the DungeonConstants.Blockage interface. Default: mostly doors.


getBlockage

public int getBlockage()

setTraps

public void setTraps(int traps)
Sets level of traps to generate. Allowable values are constants from the DungeonConstants.TrapCount interface. Default: lots.


getTraps

public int getTraps()

setSpecialRoom

public void setSpecialRoom(int type)
Sets the special room to generate, if any. Valid values are constants from the DungeonConstants.RoomType interface.


getSpecialRoom

public int getSpecialRoom()

setExitType

public void setExitType(java.lang.String type)
Sets whether up/down stairs are desired. Allowable values: "none", "upstair", "downstair", "up & downstair". Default: "none".


getExitType

public java.lang.String getExitType()

setDoorArchetype

public void setDoorArchetype(java.lang.String name)
Sets the archetype to use for the dungeon doors.

Parameters:
name - the archetype to use, e.g. "walls/dungeon_door"

getDoorArchetype

public java.lang.String getDoorArchetype()

setWallArchetype

public void setWallArchetype(java.lang.String name)
Sets the archetype to use for the dungeon/room walls.

Parameters:
name - the archetype to use, e.g. "walls/dungeon_wall"

getWallArchetype

public java.lang.String getWallArchetype()

setStairArchetype

public void setStairArchetype(java.lang.String name)
Sets the archetype base-name to use for the dungeon/room stairs. The dungeon generator will append "_downE", "_upN", or whatever, as appropriate for the stair that's generated.

Parameters:
name - the archetype base to use, e.g. "indoor/stairs"

getStairArchetype

public java.lang.String getStairArchetype()

setDoorHP

public void setDoorHP(int hp)
Sets the number of HP to use for doors in the dungeon.

Parameters:
hp - the HP to use for doors

getDoorHP

public int getDoorHP()