mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-07-13 17:07:53 +01:00
Overmap exoplanet generation, ported from Bay. (#12362)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
var/cell_base // Set in New()
|
||||
var/initial_cell_range // Set in New()
|
||||
var/smoothing_iterations = 0
|
||||
var/smooth_single_tiles // Single turfs of different value are not allowed
|
||||
|
||||
/datum/random_map/noise/New()
|
||||
initial_cell_range = cell_range/5
|
||||
@@ -28,13 +29,15 @@
|
||||
limit_y = limit_x
|
||||
else if(limit_y > limit_x)
|
||||
limit_x = limit_y
|
||||
log_debug("Generating Noise map with limits: [limit_x], [limit_y]")
|
||||
..()
|
||||
|
||||
// Diamond-square algorithm.
|
||||
/datum/random_map/noise/seed_map()
|
||||
// Instantiate the grid.
|
||||
for (var/i = 1 to (limit_x * limit_y))
|
||||
map[i] = 0
|
||||
for(var/x = 1, x <= limit_x, x++)
|
||||
for(var/y = 1, y <= limit_y, y++)
|
||||
map[TRANSLATE_COORD(x,y)] = 0
|
||||
|
||||
// Now dump in the actual random data.
|
||||
map[TRANSLATE_COORD(1,1)] = cell_base+rand(initial_cell_range)
|
||||
@@ -51,6 +54,9 @@
|
||||
if(isnull(val)) val = 0
|
||||
return "[val]"
|
||||
|
||||
/datum/random_map/noise/proc/noise2value(var/value)
|
||||
return min(9,max(0,round((value/cell_range)*10)))
|
||||
|
||||
/datum/random_map/noise/proc/subdivide(var/iteration,var/x,var/y,var/input_size)
|
||||
|
||||
var/isize = input_size
|
||||
@@ -78,7 +84,7 @@
|
||||
map[TRANSLATE_COORD(x+isize,y)] \
|
||||
)/2)
|
||||
|
||||
map[TRANSLATE_COORD(x,y+hsize)] = round(( \
|
||||
map[get_map_cell(x,y+hsize)] = round(( \
|
||||
map[TRANSLATE_COORD(x,y+isize)] + \
|
||||
map[TRANSLATE_COORD(x,y)] \
|
||||
)/2)
|
||||
@@ -103,7 +109,7 @@
|
||||
|
||||
// Recurse until size is too small to subdivide.
|
||||
if(isize>3)
|
||||
if(!priority_process)
|
||||
if(!priority_process)
|
||||
CHECK_TICK
|
||||
iteration++
|
||||
subdivide(iteration, x, y, hsize)
|
||||
@@ -164,3 +170,32 @@
|
||||
map[current_cell]-=cell_smooth_amt
|
||||
map[current_cell] = max(0,min(cell_range,map[current_cell]))
|
||||
map = next_map
|
||||
|
||||
if(smooth_single_tiles)
|
||||
var/list/buddies = list()
|
||||
for(var/x in 1 to limit_x - 1)
|
||||
for(var/y in 1 to limit_y - 1)
|
||||
var/mapcell = get_map_cell(x,y)
|
||||
var/list/neighbors = get_neighbors(x, y)
|
||||
buddies.Cut()
|
||||
for(var/cell in neighbors)
|
||||
if(noise2value(map[cell]) == noise2value(map[mapcell]))
|
||||
buddies |= cell
|
||||
if(!length(buddies))
|
||||
map[mapcell] = map[pick(neighbors)]
|
||||
|
||||
/datum/random_map/noise/proc/get_neighbors(x, y, include_diagonals)
|
||||
. = list()
|
||||
if(!include_diagonals)
|
||||
var/static/list/ortho_offsets = list(list(-1, 0), list(1, 0), list(0, 1), list(0,-1))
|
||||
for(var/list/offset in ortho_offsets)
|
||||
var/tmp_cell = get_map_cell(x+offset[1],y+offset[2])
|
||||
if(tmp_cell)
|
||||
. += tmp_cell
|
||||
else
|
||||
for(var/dx in -1 to 1)
|
||||
for(var/dy in -1 to 1)
|
||||
var/tmp_cell = get_map_cell(x+dx,y+dy)
|
||||
if(tmp_cell)
|
||||
. += tmp_cell
|
||||
. -= get_map_cell(x,y)
|
||||
|
||||
@@ -96,3 +96,8 @@
|
||||
return "R"
|
||||
else
|
||||
return "D"
|
||||
|
||||
/datum/random_map/noise/ore/rich
|
||||
deep_val = 0.7
|
||||
rare_val = 0.5
|
||||
|
||||
@@ -25,6 +25,8 @@ var/global/list/map_count = list()
|
||||
var/target_turf_type
|
||||
var/spawn_roof = FALSE //Set to TRUE if a roof should be spawned based.
|
||||
|
||||
var/area/use_area // If set, turfs will be put in this area. If set to type, new instance will be spawned for the map
|
||||
|
||||
// Storage for the final iteration of the map.
|
||||
var/list/map = list() // Actual map.
|
||||
var/tmp/map_len = 0
|
||||
@@ -33,7 +35,7 @@ var/global/list/map_count = list()
|
||||
// Test to see if rand_seed() can be used reliably.
|
||||
var/priority_process
|
||||
|
||||
/datum/random_map/New(var/seed, var/tx, var/ty, var/tz, var/tlx, var/tly, var/do_not_apply, var/do_not_announce)
|
||||
/datum/random_map/New(var/seed, var/tx, var/ty, var/tz, var/tlx, var/tly, var/do_not_apply, var/do_not_announce, var/never_be_priority = 0, var/used_area)
|
||||
|
||||
// Store this for debugging.
|
||||
if(!map_count[descriptor])
|
||||
@@ -48,6 +50,12 @@ var/global/list/map_count = list()
|
||||
if(tlx) limit_x = tlx
|
||||
if(tly) limit_y = tly
|
||||
|
||||
if(used_area)
|
||||
if(ispath(used_area))
|
||||
use_area = new(used_area)
|
||||
else
|
||||
use_area = used_area
|
||||
|
||||
if(do_not_apply)
|
||||
auto_apply = null
|
||||
|
||||
@@ -61,7 +69,7 @@ var/global/list/map_count = list()
|
||||
// Testing needed to see how reliable this is (asynchronous calls, called during worldgen), DM ref is not optimistic
|
||||
if(seed)
|
||||
rand_seed(seed)
|
||||
priority_process = 1
|
||||
priority_process = !never_be_priority
|
||||
|
||||
for(var/i = 0;i<max_attempts;i++)
|
||||
if(generate())
|
||||
@@ -183,6 +191,8 @@ var/global/list/map_count = list()
|
||||
if(spawn_roof)
|
||||
T.spawn_roof()
|
||||
get_additional_spawns(map[tmp_cell],T,get_spawn_dir(x, y))
|
||||
if(use_area)
|
||||
ChangeArea(T, use_area)
|
||||
return T
|
||||
|
||||
/datum/random_map/proc/get_spawn_dir()
|
||||
|
||||
Reference in New Issue
Block a user