Added random cave system generator, very basic.

This commit is contained in:
Zuhayr
2015-01-13 19:24:10 +10:30
parent 3fb41affa8
commit a0fab91b35
3 changed files with 50 additions and 26 deletions

View File

@@ -951,7 +951,6 @@
#include "code\modules\mining\ore.dm" #include "code\modules\mining\ore.dm"
#include "code\modules\mining\ore_datum.dm" #include "code\modules\mining\ore_datum.dm"
#include "code\modules\mining\satchel_ore_boxdm.dm" #include "code\modules\mining\satchel_ore_boxdm.dm"
#include "code\modules\mining\drilling\distribution.dm"
#include "code\modules\mining\drilling\drill.dm" #include "code\modules\mining\drilling\drill.dm"
#include "code\modules\mining\drilling\scanner.dm" #include "code\modules\mining\drilling\scanner.dm"
#include "code\modules\mob\death.dm" #include "code\modules\mob\death.dm"
@@ -1264,6 +1263,8 @@
#include "code\modules\projectiles\projectile\energy.dm" #include "code\modules\projectiles\projectile\energy.dm"
#include "code\modules\projectiles\projectile\force.dm" #include "code\modules\projectiles\projectile\force.dm"
#include "code\modules\projectiles\projectile\special.dm" #include "code\modules\projectiles\projectile\special.dm"
#include "code\modules\random_map\maze.dm"
#include "code\modules\random_map\mining_distribution.dm"
#include "code\modules\random_map\random_map.dm" #include "code\modules\random_map\random_map.dm"
#include "code\modules\reagents\Chemistry-Colours.dm" #include "code\modules\reagents\Chemistry-Colours.dm"
#include "code\modules\reagents\Chemistry-Holder.dm" #include "code\modules\reagents\Chemistry-Holder.dm"

View File

@@ -1,11 +0,0 @@
#define MAP_CELL ((y-1)*real_size)+x
#define MAP_CENTRE (((y-1)+size/2)*real_size)+(x+size/2)
#define MAP_TOP_LEFT ((y-1)*real_size)+x
#define MAP_TOP_RIGHT ((y-1)*real_size)+(x+size)
#define MAP_BOTTOM_LEFT (((y+size)-1)*real_size)+x
#define MAP_BOTTOM_RIGHT ((((y+size)-1)*real_size)+(x+size))
#define MAP_MID_TOP MAP_TOP_LEFT + (size/2)
#define MAP_MID_BOTTOM MAP_BOTTOM_LEFT + (size/2)
#define MAP_MID_LEFT (((y-1)+size/2)*real_size)+x
#define MAP_MID_RIGHT (((y-1)+size/2)*real_size)+(x+size)
#define ITERATE_BEFORE_FAIL 200

View File

@@ -2,6 +2,8 @@
This module is used to generate the debris fields/distribution maps/procedural stations. This module is used to generate the debris fields/distribution maps/procedural stations.
*/ */
var/global/list/random_maps = list()
/obj/item/test_randmap/New() /obj/item/test_randmap/New()
new /datum/random_map(input("Seed?") as text|null) new /datum/random_map(input("Seed?") as text|null)
del(src) del(src)
@@ -10,6 +12,10 @@
new /datum/random_map/ore(input("Seed?") as text|null) new /datum/random_map/ore(input("Seed?") as text|null)
del(src) del(src)
/obj/item/test_randmap/maze/New()
new /datum/random_map/maze(input("Seed?") as text|null)
del(src)
/datum/random_map /datum/random_map
var/descriptor = "debris field" // Display name. var/descriptor = "debris field" // Display name.
var/real_size = 128 // Size of each edge (must be square :(). var/real_size = 128 // Size of each edge (must be square :().
@@ -24,9 +30,32 @@
var/origin_z = 1 // Target Z-level. var/origin_z = 1 // Target Z-level.
var/limit_x = 256 // Maximum x bound. var/limit_x = 256 // Maximum x bound.
var/limit_y = 256 // Maximum y bound. var/limit_y = 256 // Maximum y bound.
var/iterate_before_fail = 120 // Infinite loop safeguard.
/datum/random_map/proc/get_map_cell(var/x,var/y)
return ((y-1)*real_size)+x
/datum/random_map/proc/display_map(atom/user)
if(!user)
user = world
for(var/x = 1, x <= real_size, x++)
var/line = ""
for(var/y = 1, y <= real_size, y++)
var/current_cell = get_map_cell(x,y)
if(within_bounds(current_cell))
if(map[current_cell] == 2)
line += "#"
else
line += "."
user << line
/datum/random_map/New(var/seed, var/tx, var/ty, var/tz, var/tlx, var/tly) /datum/random_map/New(var/seed, var/tx, var/ty, var/tz, var/tlx, var/tly)
// Store this for debugging.
random_maps |= src
// Initialize map. // Initialize map.
set_map_size() set_map_size()
@@ -46,8 +75,10 @@
if(generate()) if(generate())
world << "<span class='danger'>[capitalize(descriptor)] generation completed in [round(0.1*(world.timeofday-start_time),0.1)] seconds.</span>" world << "<span class='danger'>[capitalize(descriptor)] generation completed in [round(0.1*(world.timeofday-start_time),0.1)] seconds.</span>"
return return
world << "<span class='danger'>[capitalize(descriptor)] generation failed: could not produce sane map.</span>" world << "<span class='danger'>[capitalize(descriptor)] generation failed in [round(0.1*(world.timeofday-start_time),0.1)] seconds: could not produce sane map.</span>"
del(src)
/datum/random_map/proc/within_bounds(var/val)
return (val>0) && (val<=raw_map_size)
/datum/random_map/proc/set_map_size(var/raw_size) /datum/random_map/proc/set_map_size(var/raw_size)
if(!raw_size) if(!raw_size)
@@ -58,19 +89,20 @@
/datum/random_map/proc/seed_map() /datum/random_map/proc/seed_map()
for(var/x = 1, x <= real_size, x++) for(var/x = 1, x <= real_size, x++)
for(var/y = 1, y <= real_size, y++) for(var/y = 1, y <= real_size, y++)
var/current_cell = get_map_cell(x,y)
if(x == 1 || x == real_size || y == 1 || y == real_size) if(x == 1 || x == real_size || y == 1 || y == real_size)
map[MAP_CELL] = rand(1,2) map[current_cell] = rand(1,2)
else else
map[MAP_CELL] = rand(1,cell_range) map[current_cell] = rand(1,cell_range)
/datum/random_map/proc/clear_map() /datum/random_map/proc/clear_map()
for(var/x = 1, x <= real_size, x++) for(var/x = 1, x <= real_size, x++)
for(var/y = 1, y <= real_size, y++) for(var/y = 1, y <= real_size, y++)
map[MAP_CELL] = 0 map[get_map_cell(x,y)] = 0
/datum/random_map/proc/generate() /datum/random_map/proc/generate()
seed_map() seed_map()
for(var/i=0;i<iterations;i++) for(var/i=1;i<=iterations;i++)
iterate(i) iterate(i)
if(check_map_sanity()) if(check_map_sanity())
cleanup() cleanup()
@@ -82,20 +114,21 @@
var/list/next_map[raw_map_size] var/list/next_map[raw_map_size]
for(var/x = 1, x <= real_size, x++) for(var/x = 1, x <= real_size, x++)
for(var/y = 1, y <= real_size, y++) for(var/y = 1, y <= real_size, y++)
var/current_cell = get_map_cell(x,y)
// Sanity check. // Sanity check.
if(MAP_CELL <= 0 || MAP_CELL > raw_map_size) if(!within_bounds(current_cell))
continue continue
// Copy over original value. // Copy over original value.
next_map[MAP_CELL] = map[MAP_CELL] next_map[current_cell] = map[current_cell]
// Check all neighbors. // Check all neighbors.
var/count = 0 var/count = 0
for(var/cell in list(MAP_CELL,MAP_TOP_LEFT,MAP_MID_TOP,MAP_TOP_RIGHT,MAP_MID_RIGHT,MAP_BOTTOM_RIGHT,MAP_MID_BOTTOM,MAP_BOTTOM_LEFT,MAP_MID_LEFT)) for(var/cell in list(current_cell,get_map_cell(x+1,y+1),get_map_cell(x-1,y-1),get_map_cell(x+1,y-1),get_map_cell(x-1,y+1),get_map_cell(x-1,y),get_map_cell(x,y-1),get_map_cell(x+1,y),get_map_cell(x,y+1)))
if((cell > 0) && (cell <= raw_map_size) && (map[cell] == 2)) if(within_bounds(cell) && map[cell] == 2)
count++ count++
if(count>=5) if(count>=5)
next_map[MAP_CELL] = 2 // becomes a wall next_map[current_cell] = 2 // becomes a wall
else else
next_map[MAP_CELL] = 1 // becomes a floor next_map[current_cell] = 1 // becomes a floor
map = next_map map = next_map
/datum/random_map/proc/check_map_sanity() /datum/random_map/proc/check_map_sanity()
@@ -109,12 +142,13 @@
apply_to_turf(origin_x+x,origin_y+y) apply_to_turf(origin_x+x,origin_y+y)
/datum/random_map/proc/apply_to_turf(var/x,var/y) /datum/random_map/proc/apply_to_turf(var/x,var/y)
if((MAP_CELL <= 0) || (MAP_CELL > raw_map_size)) var/current_cell = get_map_cell(x,y)
if(!within_bounds(current_cell))
return return
var/turf/T = locate(x,y,origin_z) var/turf/T = locate(x,y,origin_z)
if(!T) if(!T)
return return
switch(map[MAP_CELL]) switch(map[current_cell])
if(1) if(1)
T.ChangeTurf(/turf/simulated/floor/plating/airless/asteroid) T.ChangeTurf(/turf/simulated/floor/plating/airless/asteroid)
if(2) if(2)