Random Dungeon Creator
Version: 2.0
Author: Racanhack
Translater: LilTerra
Version History
- <Version 3.0> 06.27.2011 -Fixed A Few Bugs + Posted It On RMRK
- <Version 2.0> 06.25.2011 - Translated Main Part Of script
- <Version 1.0> Forgotten Time - Original Release
Description
Creates A dungeon Which Changes Every Time You Use It
Features
- Creates A Random Dungeon!
- Compatible With Most Battle Scripts
- It Makes More Than One Floor for Its Dungeon
Screenshots
Not Yet
Instructions
The Notes There Should Be Enough (I Call Comments Notes)
Script
#-------------------------------------------------------------------------------
# Map Genarator For A Roguelike Dungeon
# Thanks to Old Rougelike Scripts Creator For The Script (It Was Untranslated)
# Author: Racanhack (http://racanhack.sourceforge.jp/rhdoc/index.html)
# Translator: LilTerra
#----------------------------------------------------------------------------
# Description: Make A Dungeon Which is Never the Same!!!
# How to use: Below Or Use script command $game_map.make_dungeon
#----------------------------------------------------------------------------
module ROGUELIKE_MAP
# The Map Id You want edited (Make Sure The maps Are Empty)
# Example: ROGUELIKE_MAP_ID = [3,5]
#
ROGUELIKE_MAP_ID = []
# The Tile You want For Blank Spaces
SPACE_TILE_ID = ????
# The Tile For The Floor
FLOOR_TILE_ID = ????
# Tile For The Wall
WALL_TILE_ID = ????
# Probability of Large Room May Use Numbers (Below 100) Or Fractions (like 1 / 1)
# Switch For Big Room (nil=Disabled)
BIG_ROOM = ? / ?
BIG_ROOM_SWITCH = nil
# Add a constant related to the passage (96 by default)
ADD_COUPLE = 96
# Minimum Size Of Divided Rooms (Rooms In The Dungeon)
MIN_ROOM_SIZE = 2
# ????????(3?????????????) ( Need Help On Translating this)
MIN_BTWN_RECT_ROOM = 3
# ?????????(??????2 + 3 * 2 = 8) (Need Help Here)
MIN_RECT_SIZE = MIN_ROOM_SIZE + (MIN_BTWN_RECT_ROOM * 2)
#The Main Script Has been Translated
#--------------------------------------------------------------------------
R_VERTICAL = 0
R_HORIZONAL = 1
# ?????????
# min??max??????int??????
def rand_range(min, max)
return((min + rand(max - min)).round)
end
#-------------------------------------------------------------------------------
#R_Couple??? ????????
class R_Couple
attr_accessor :v_or_h
attr_accessor :rect0
attr_accessor :rect1
def initialize(v_or_h, rect0, rect1)
@v_or_h = v_or_h
@rect0 = rect0
@rect1 = rect1
end
end
#R_Room??? ????????
class R_Room
attr_accessor :lx
attr_accessor :ly
attr_accessor :hx
attr_accessor :hy
def initialize(lx, ly, hx, hy)
@lx = lx
@ly = ly
@hx = hx
@hy = hy
end
end
#R_Rect??? ????????
class R_Rect < R_Room
attr_accessor :done_v
attr_accessor :done_h
attr_accessor :room
def initialize(lx, ly, hx, hy, done_v = false, done_h = false, room = nil)
super(lx, ly, hx, hy)
@done_v = done_v
@done_h = done_h
@room = room
end
end
end
#-------------------------------------------------------------------------------
# ? Game_Map
#-------------------------------------------------------------------------------
# ??????????????????????????????????????
# ????????????? $game_map ????????
#-------------------------------------------------------------------------------
class Game_Map
include ROGUELIKE_MAP
#--------------------------------------------------------------------------
# ? ??????
# map_id : ??? ID
#--------------------------------------------------------------------------
alias randmap_setup setup
def setup(map_id)
#????
randmap_setup(map_id)
#???ID?????????ID?????????????????
make_dungeon if(ROGUELIKE_MAP_ID.include?(map_id))
end
#--------------------------------------------------------------------------
# ? ??????????????????
# ???????$game_map.make_dungeon??????setup???????
#--------------------------------------------------------------------------
def make_dungeon
@rect_list = [] # ?????
@room_list = [] # ?????
@couple_list = [] # ??????
# ???????????????????
for i in 0...@map.width
for j in 0...@map.height
@map.data[i,j,0] = SPACE_TILE_ID
end
end
# ?????(split_rect????????????)
split_rect(add_rect(0,0,@map.width - 1, @map.height - 1), true)
# ?????
make_room
# ???????
for n in 0...@room_list.size
for i in @room_list[n].lx..@room_list[n].hx
for j in @room_list[n].ly..@room_list[n].hy
@map.data[i,j,0] = FLOOR_TILE_ID
end
end
end
# ????????????????????
rect_map = Array.new(@map.width)
for i in 0...rect_map.size
rect_map[i] = Array.new(@map.height)
end
for i in 0...@rect_list.size
for j in @rect_list[i].lx..@rect_list[i].hx
for k in @rect_list[i].ly..@rect_list[i].hy
rect_map[j][k] = @rect_list[i]
end
end
end
for i in 0...(@map.width - 1)
for j in 0...(@map.height - 1)
break unless(rect_map[i][j] != nil)
break unless(rect_map[i + 1][j] != nil)
break unless(rect_map[i][j + 1] != nil)
if(rect_map[i][j] != rect_map[i][j + 1])
add_couple(R_VERTICAL, rect_map[i][j], rect_map[i][j + 1]) if (rand(ADD_COUPLE) == 0)
end
if(rect_map[i][j] != rect_map[i + 1][j])
add_couple(R_HORIZONAL, rect_map[i][j], rect_map[i + 1][j]) if (rand(ADD_COUPLE) == 0)
end
end
end
# ????????????????
for i in 0...@couple_list.size
# ???????????
if(@couple_list[i].v_or_h == R_HORIZONAL)
break unless(@couple_list[i].rect0.hx == @couple_list[i].rect1.lx)
c0x = @couple_list[i].rect0.hx
c0y = rand_range(@couple_list[i].rect0.room.ly + 1,
@couple_list[i].rect0.room.hy)
c1x = @couple_list[i].rect1.lx
c1y = rand_range(@couple_list[i].rect1.room.ly + 1,
@couple_list[i].rect1.room.hy)
make_line(c0x, c0y, c1x, c1y)
make_line(@couple_list[i].rect0.room.hx, c0y, c0x, c0y)
make_line(@couple_list[i].rect1.room.lx, c1y, c1x, c1y)
# ???????????
elsif(@couple_list[i].v_or_h == R_VERTICAL)
break unless(@couple_list[i].rect0.hy == @couple_list[i].rect1.ly)
c0x = rand_range(@couple_list[i].rect0.room.lx + 1,
@couple_list[i].rect0.room.hx)
c0y = @couple_list[i].rect0.hy
c1x = rand_range(@couple_list[i].rect1.room.lx + 1,
@couple_list[i].rect1.room.hx)
c1y = @couple_list[i].rect1.ly
make_line(c0x, c0y, c1x, c1y)
make_line(c0x, @couple_list[i].rect0.room.hy, c0x, c0y)
make_line(c1x, @couple_list[i].rect1.room.ly, c1x, c1y)
end
end
# ???(????????????????????????????????)
for i in 0...@map.width
for j in 1...@map.height
if(@map.data[i, j, 0] == FLOOR_TILE_ID &&
@map.data[i, j - 1, 0] == SPACE_TILE_ID)
@map.data[i, j - 1, 0] = WALL_TILE_ID
end
end
end
# ??
end
# ????????????????????
def add_rect(lx, ly, hx, hy)
@rect_list.push(R_Rect.new(lx, ly, hx, hy))
return(@rect_list.last)
end
# ???????????(??)
def split_rect(rect_par, flag = false)
# ?????????????????????????????????
if(rect_par.hx - rect_par.lx <= MIN_RECT_SIZE * 2)
rect_par.done_v = true
end
if(rect_par.hy - rect_par.ly <= MIN_RECT_SIZE * 2)
rect_par.done_h = true
end
# ?????????(?????????????????)
if (rand(BIG_ROOM) == 0 && flag == true)
rect_par.done_v = true
rect_par.done_h = true
end
# ????????????????
if((rect_par.done_v == true) && (rect_par.done_h == true))
return
end
# ?????
rect_child = add_rect(rect_par.lx, rect_par.ly, rect_par.hx, rect_par.hy)
# ?????????????
if(rect_par.done_v == false)
split_coord_y = rand_range(rect_par.ly + MIN_RECT_SIZE,
rect_par.hy - MIN_RECT_SIZE)
rect_par.hy = split_coord_y;
rect_child.ly = split_coord_y;
# ???????
rect_par.done_v = true
rect_child.done_v = true
# ???????
add_couple(R_VERTICAL, rect_par, rect_child);
# ??
split_rect(rect_par)
split_rect(rect_child)
return
end
# ?????????????
if(rect_par.done_h == false)
split_coord_x = rand_range(rect_par.lx + MIN_RECT_SIZE,
rect_par.hx - MIN_RECT_SIZE)
rect_par.hx = split_coord_x;
rect_child.lx = split_coord_x;
# ???????
rect_par.done_h = true
rect_child.done_h = true
# ???????
add_couple(R_HORIZONAL, rect_par, rect_child);
# ??
split_rect(rect_par)
split_rect(rect_child)
return
end
end
# ????????????????????
def add_room(lx, ly, hx, hy)
@room_list.push(R_Room.new(lx, ly, hx, hy))
return(@room_list.last)
end
# ???????????
def make_room()
for i in 0...@rect_list.size
#?????????X
w = rand_range(MIN_ROOM_SIZE,
(@rect_list[i].hx - @rect_list[i].lx - (MIN_BTWN_RECT_ROOM * 2) + 1))
#?????????Y
h = rand_range(MIN_ROOM_SIZE,
(@rect_list[i].hy - @rect_list[i].ly - (MIN_BTWN_RECT_ROOM * 2) + 1))
#?????
x = rand_range(@rect_list[i].lx + MIN_BTWN_RECT_ROOM,
@rect_list[i].hx - MIN_BTWN_RECT_ROOM - w + 1)
#?????
y = rand_range(@rect_list[i].ly + MIN_BTWN_RECT_ROOM,
@rect_list[i].hy - MIN_BTWN_RECT_ROOM - h + 1)
#?????????????
@rect_list[i].room = add_room(x, y, x + w, y + h)
end
end
#--------------------------------------------------------------------------
# ? split_rect?????????????????????????
# ??split_rect???????????????
# v_or_h : ????????
# rect0 : ??1
# rect1 : ??2
#--------------------------------------------------------------------------
def add_couple(v_or_h, rect0, rect1)
@couple_list.push(R_Couple.new(v_or_h, rect0, rect1))
return(@couple_list.last)
end
#--------------------------------------------------------------------------
# ? ??????????????????????
# x0 : ?1?X??
# y0 : ?1?Y??
# x1 : ?2?X??
# y1 : ?2?Y??
#--------------------------------------------------------------------------
def make_line(x0, y0, x1, y1)
min_x = [x0, x1].min
max_x = [x0, x1].max
min_y = [y0, y1].min
max_y = [y0, y1].max
unless((min_x >= 0) && (max_x < @map.width) &&
(min_y >= 0) && (max_y < @map.height))
return
end
if((x0 <= x1) && (y0 >= y1))
for i in min_x..max_x
@map.data[i, max_y, 0] = FLOOR_TILE_ID
end
for j in min_y..max_y
@map.data[max_x, j, 0] = FLOOR_TILE_ID
end
return
end
if((x0 > x1) && (y0 > y1))
for i in min_x..max_x
@map.data[i, min_y, 0] = FLOOR_TILE_ID
end
for j in min_y..max_y
@map.data[max_x, j, 0] = FLOOR_TILE_ID
end
return
end
if((x0 > x1) && (y0 <= y1))
for i in min_x..max_x
@map.data[i, min_y, 0] = FLOOR_TILE_ID
end
for j in min_y..max_y
@map.data[min_x, j, 0] = FLOOR_TILE_ID
end
return
end
if((x0 <= x1) && (y0 < y1))
for i in min_x..max_x
@map.data[i, max_y, 0] = FLOOR_TILE_ID
end
for j in min_y..max_y
@map.data[min_x, j, 0] = FLOOR_TILE_ID
end
return
end
end
end
#-------------------------------------------------------------------------------
# ? Game_Interpreter
#-------------------------------------------------------------------------------
# ????????????????????????????? Game_Map ????
# Game_Troop ????Game_Event ??????????????
#-------------------------------------------------------------------------------
class Game_Interpreter
#--------------------------------------------------------------------------
# ?
# $game_map.make_dungeon
#--------------------------------------------------------------------------
def make_dungeon
$game_map.make_dungeon
end
end
Credit
Thanks To:
- My Younger Sister (She Was Messing About On My PC and found the script in a .txt file)
- Google Translate
Support
On This Topic
Known Compatibility Issues
It Hates ABS
Demo
Coming Soon
Author's Notes
I Did Not Create The Entire Script Just Edited It And Translated Abit (Abit is in my own words Abit is in Google Translate)
Restrictions
Credit Me For Translating . Free For Use In Games . If it Is A Commercial Game Pm Me And I Expect A Free Copy Of The Full Game! (: