mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-12 03:02:54 +00:00
Refactored random map generator system and added several terrain generators.
Created a global list to track base turfs for explosions/shuttle moves. Remaps the asteroid to be a moonlet. Tidies up some references to 'asteroid', removes moonbase from the accessible z level list.
This commit is contained in:
65
code/modules/random_map/mazes/maze.dm
Normal file
65
code/modules/random_map/mazes/maze.dm
Normal file
@@ -0,0 +1,65 @@
|
||||
/datum/random_map/maze
|
||||
descriptor = "maze"
|
||||
initial_wall_cell = 100
|
||||
var/list/checked_coord_cache = list()
|
||||
var/list/openlist = list()
|
||||
var/list/closedlist = list()
|
||||
|
||||
/datum/random_map/maze/set_map_size()
|
||||
// Map has to be odd so that there are walls on all sides.
|
||||
if(limit_x%2==0) limit_x++
|
||||
if(limit_y%2==0) limit_y++
|
||||
..()
|
||||
|
||||
/datum/random_map/maze/generate_map()
|
||||
|
||||
// Grab a random point on the map to begin the maze cutting at.
|
||||
var/start_x = rand(1,limit_x-2)
|
||||
var/start_y = rand(1,limit_y-2)
|
||||
if(start_x%2!=0) start_x++
|
||||
if(start_y%2!=0) start_y++
|
||||
|
||||
// Create the origin cell to start us off.
|
||||
openlist += new /datum/maze_cell(start_x,start_y)
|
||||
|
||||
while(openlist.len)
|
||||
// Grab a maze point to use and remove it from the open list.
|
||||
var/datum/maze_cell/next = pick(openlist)
|
||||
openlist -= next
|
||||
if(!isnull(closedlist[next.name]))
|
||||
continue
|
||||
|
||||
// Preliminary marking-off...
|
||||
closedlist[next.name] = next
|
||||
map[get_map_cell(next.x,next.y)] = FLOOR_CHAR
|
||||
|
||||
// Apply the values required and fill gap between this cell and origin point.
|
||||
if(next.ox && next.oy)
|
||||
if(next.ox < next.x)
|
||||
map[get_map_cell(next.x-1,next.y)] = FLOOR_CHAR
|
||||
else if(next.ox == next.x)
|
||||
if(next.oy < next.y)
|
||||
map[get_map_cell(next.x,next.y-1)] = FLOOR_CHAR
|
||||
else
|
||||
map[get_map_cell(next.x,next.y+1)] = FLOOR_CHAR
|
||||
else
|
||||
map[get_map_cell(next.x+1,next.y)] = FLOOR_CHAR
|
||||
|
||||
// Grab valid neighbors for use in the open list!
|
||||
add_to_openlist(next.x,next.y+2,next.x,next.y)
|
||||
add_to_openlist(next.x-2,next.y,next.x,next.y)
|
||||
add_to_openlist(next.x+2,next.y,next.x,next.y)
|
||||
add_to_openlist(next.x,next.y-2,next.x,next.y)
|
||||
|
||||
// Cleanup. Map stays in memory for display proc.
|
||||
checked_coord_cache.Cut()
|
||||
openlist.Cut()
|
||||
closedlist.Cut()
|
||||
|
||||
/datum/random_map/maze/proc/add_to_openlist(var/tx, var/ty, var/nx, var/ny)
|
||||
if(tx < 1 || ty < 1 || tx > limit_x || ty > limit_y || !isnull(checked_coord_cache["[tx]-[ty]"]))
|
||||
return 0
|
||||
checked_coord_cache["[tx]-[ty]"] = 1
|
||||
map[get_map_cell(tx,ty)] = DOOR_CHAR
|
||||
var/datum/maze_cell/new_cell = new(tx,ty,nx,ny)
|
||||
openlist |= new_cell
|
||||
18
code/modules/random_map/mazes/maze_cell.dm
Normal file
18
code/modules/random_map/mazes/maze_cell.dm
Normal file
@@ -0,0 +1,18 @@
|
||||
var/maze_cell_count = 0
|
||||
|
||||
/datum/maze_cell
|
||||
var/name
|
||||
var/uid
|
||||
var/x
|
||||
var/y
|
||||
var/ox
|
||||
var/oy
|
||||
|
||||
/datum/maze_cell/New(var/nx,var/ny,var/nox,var/noy)
|
||||
maze_cell_count++
|
||||
uid = maze_cell_count
|
||||
name = "cell #[uid]"
|
||||
x = nx
|
||||
y = ny
|
||||
ox = nox
|
||||
oy = noy
|
||||
Reference in New Issue
Block a user