mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-21 23:52:12 +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:
40
code/modules/random_map/noise/desert.dm
Normal file
40
code/modules/random_map/noise/desert.dm
Normal file
@@ -0,0 +1,40 @@
|
||||
/datum/random_map/noise/desert
|
||||
descriptor = "desert"
|
||||
smoothing_iterations = 3
|
||||
|
||||
/datum/random_map/noise/desert/replace_space
|
||||
descriptor = "desert (replacement)"
|
||||
target_turf_type = /turf/space
|
||||
|
||||
/datum/random_map/noise/desert/get_map_char(var/value)
|
||||
return "<font color='#[value][value][value][value][value][value]'>[pick(list(",",".","'","`"))]</font>"
|
||||
|
||||
/datum/random_map/noise/desert/get_appropriate_path(var/value)
|
||||
var/val = min(9,max(0,round((value/cell_range)*10)))
|
||||
if(isnull(val)) val = 0
|
||||
switch(val)
|
||||
if(0 to 1)
|
||||
return /turf/simulated/floor/beach/water
|
||||
else
|
||||
return /turf/simulated/floor/beach/sand/desert
|
||||
|
||||
/datum/random_map/noise/desert/get_additional_spawns(var/value, var/turf/T)
|
||||
var/val = min(9,max(0,round((value/cell_range)*10)))
|
||||
if(isnull(val)) val = 0
|
||||
switch(val)
|
||||
if(2 to 3)
|
||||
if(prob(60))
|
||||
var/grass_path = pick(typesof(/obj/structure/flora/grass)-/obj/structure/flora/grass)
|
||||
new grass_path(T)
|
||||
if(prob(5))
|
||||
var/mob_type = pick(list(/mob/living/simple_animal/lizard, /mob/living/simple_animal/mouse))
|
||||
new mob_type(T)
|
||||
if(5 to 6)
|
||||
if(prob(20))
|
||||
var/grass_path = pick(typesof(/obj/structure/flora/grass)-/obj/structure/flora/grass)
|
||||
new grass_path(T)
|
||||
if(7 to 9)
|
||||
if(prob(60))
|
||||
new /obj/structure/flora/bush(T)
|
||||
else if(prob(20))
|
||||
new /obj/structure/flora/tree/dead(T)
|
||||
44
code/modules/random_map/noise/magma.dm
Normal file
44
code/modules/random_map/noise/magma.dm
Normal file
@@ -0,0 +1,44 @@
|
||||
// This is basically filler at this point. Subsidence and all kinds of fun
|
||||
// hazards will be included when it is done.
|
||||
/datum/random_map/noise/volcanism
|
||||
descriptor = "volcanism"
|
||||
smoothing_iterations = 6
|
||||
target_turf_type = /turf/simulated
|
||||
|
||||
// Get rid of those dumb little single-tile volcanic areas.
|
||||
/datum/random_map/noise/volcanism/cleanup()
|
||||
for(var/x = 1, x <= limit_x, x++)
|
||||
for(var/y = 1, y <= limit_y, y++)
|
||||
var/current_cell = get_map_cell(x,y)
|
||||
if(map[current_cell] < 178)
|
||||
continue
|
||||
var/count
|
||||
var/tmp_cell = get_map_cell(x+1,y+1)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x-1,y-1)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x+1,y-1)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x-1,y+1)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x-1,y)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x,y-1)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x+1,y)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
tmp_cell = get_map_cell(x,y+1)
|
||||
if(tmp_cell && map[tmp_cell] >= 178) count++
|
||||
if(!count)
|
||||
map[current_cell] = 177
|
||||
|
||||
/datum/random_map/noise/volcanism/get_appropriate_path(var/value)
|
||||
return
|
||||
|
||||
/datum/random_map/noise/volcanism/get_additional_spawns(var/value, var/turf/T)
|
||||
if(value>=178)
|
||||
if(istype(T,/turf/simulated/floor/plating/airless/asteroid))
|
||||
T.ChangeTurf(/turf/simulated/floor/airless/lava)
|
||||
else if(istype(T,/turf/simulated/mineral))
|
||||
var/turf/simulated/mineral/M = T
|
||||
M.mined_turf = /turf/simulated/floor/airless/lava
|
||||
168
code/modules/random_map/noise/noise.dm
Normal file
168
code/modules/random_map/noise/noise.dm
Normal file
@@ -0,0 +1,168 @@
|
||||
// NOTE: Maps generated with this datum as the base are not DIRECTLY compatible with maps generated from
|
||||
// the automata, building or maze datums, as the noise generator uses 0-255 instead of WALL_CHAR/FLOOR_CHAR.
|
||||
// TODO: Consider writing a conversion proc for noise-to-regular maps.
|
||||
/datum/random_map/noise
|
||||
descriptor = "distribution map"
|
||||
var/cell_range = 255 // These values are used to seed ore values rather than to determine a turf type.
|
||||
var/cell_smooth_amt = 5
|
||||
var/random_variance_chance = 25 // % chance of applying random_element.
|
||||
var/random_element = 0.5 // Determines the variance when smoothing out cell values.
|
||||
var/cell_base // Set in New()
|
||||
var/initial_cell_range // Set in New()
|
||||
var/smoothing_iterations = 0
|
||||
|
||||
/datum/random_map/noise/New()
|
||||
initial_cell_range = cell_range/5
|
||||
cell_base = cell_range/2
|
||||
..()
|
||||
|
||||
/datum/random_map/noise/set_map_size()
|
||||
// Make sure the grid is a square with limits that are
|
||||
// (n^2)+1, otherwise diamond-square won't work.
|
||||
if(!IsPowerOfTwo((limit_x-1)))
|
||||
limit_x = RoundUpToPowerOfTwo(limit_x) + 1
|
||||
if(!IsPowerOfTwo((limit_y-1)))
|
||||
limit_y = RoundUpToPowerOfTwo(limit_y) + 1
|
||||
// Sides must be identical lengths.
|
||||
if(limit_x > limit_y)
|
||||
limit_y = limit_x
|
||||
else if(limit_y > limit_x)
|
||||
limit_x = limit_y
|
||||
..()
|
||||
|
||||
// Diamond-square algorithm.
|
||||
/datum/random_map/noise/seed_map()
|
||||
// Instantiate the grid.
|
||||
for(var/x = 1, x <= limit_x, x++)
|
||||
for(var/y = 1, y <= limit_y, y++)
|
||||
map[get_map_cell(x,y)] = 0
|
||||
|
||||
// Now dump in the actual random data.
|
||||
map[get_map_cell(1,1)] = cell_base+rand(initial_cell_range)
|
||||
map[get_map_cell(1,limit_y)] = cell_base+rand(initial_cell_range)
|
||||
map[get_map_cell(limit_x,limit_y)] = cell_base+rand(initial_cell_range)
|
||||
map[get_map_cell(limit_x,1)] = cell_base+rand(initial_cell_range)
|
||||
|
||||
/datum/random_map/noise/generate_map()
|
||||
// Begin recursion.
|
||||
subdivide(1,1,1,(limit_y-1))
|
||||
|
||||
/datum/random_map/noise/get_map_char(var/value)
|
||||
var/val = min(9,max(0,round((value/cell_range)*10)))
|
||||
if(isnull(val)) val = 0
|
||||
return "[val]"
|
||||
|
||||
/datum/random_map/noise/proc/subdivide(var/iteration,var/x,var/y,var/input_size)
|
||||
|
||||
var/isize = input_size
|
||||
var/hsize = round(input_size/2)
|
||||
|
||||
/*
|
||||
(x,y+isize)----(x+hsize,y+isize)----(x+size,y+isize)
|
||||
| | |
|
||||
| | |
|
||||
| | |
|
||||
(x,y+hsize)----(x+hsize,y+hsize)----(x+isize,y)
|
||||
| | |
|
||||
| | |
|
||||
| | |
|
||||
(x,y)----------(x+hsize,y)----------(x+isize,y)
|
||||
*/
|
||||
// Central edge values become average of corners.
|
||||
map[get_map_cell(x+hsize,y+isize)] = round((\
|
||||
map[get_map_cell(x,y+isize)] + \
|
||||
map[get_map_cell(x+isize,y+isize)] \
|
||||
)/2)
|
||||
|
||||
map[get_map_cell(x+hsize,y)] = round(( \
|
||||
map[get_map_cell(x,y)] + \
|
||||
map[get_map_cell(x+isize,y)] \
|
||||
)/2)
|
||||
|
||||
map[get_map_cell(x,y+hsize)] = round(( \
|
||||
map[get_map_cell(x,y+isize)] + \
|
||||
map[get_map_cell(x,y)] \
|
||||
)/2)
|
||||
|
||||
map[get_map_cell(x+isize,y+hsize)] = round(( \
|
||||
map[get_map_cell(x+isize,y+isize)] + \
|
||||
map[get_map_cell(x+isize,y)] \
|
||||
)/2)
|
||||
|
||||
// Centre value becomes the average of all other values + possible random variance.
|
||||
var/current_cell = get_map_cell(x+hsize,y+hsize)
|
||||
map[current_cell] = round(( \
|
||||
map[get_map_cell(x+hsize,y+isize)] + \
|
||||
map[get_map_cell(x+hsize,y)] + \
|
||||
map[get_map_cell(x,y+hsize)] + \
|
||||
map[get_map_cell(x+isize,y)] \
|
||||
)/4)
|
||||
|
||||
if(prob(random_variance_chance))
|
||||
map[current_cell] *= (rand(1,2)==1 ? (1.0-random_element) : (1.0+random_element))
|
||||
map[current_cell] = max(0,min(cell_range,map[current_cell]))
|
||||
|
||||
// Recurse until size is too small to subdivide.
|
||||
if(isize>3)
|
||||
if(!priority_process) sleep(-1)
|
||||
iteration++
|
||||
subdivide(iteration, x, y, hsize)
|
||||
subdivide(iteration, x+hsize, y, hsize)
|
||||
subdivide(iteration, x, y+hsize, hsize)
|
||||
subdivide(iteration, x+hsize, y+hsize, hsize)
|
||||
|
||||
/datum/random_map/noise/cleanup()
|
||||
|
||||
for(var/i = 1;i<=smoothing_iterations;i++)
|
||||
var/list/next_map[limit_x*limit_y]
|
||||
for(var/x = 1, x <= limit_x, x++)
|
||||
for(var/y = 1, y <= limit_y, y++)
|
||||
|
||||
var/current_cell = get_map_cell(x,y)
|
||||
next_map[current_cell] = map[current_cell]
|
||||
var/val_count = 0
|
||||
var/total = 0
|
||||
|
||||
// Get the average neighboring value.
|
||||
var/tmp_cell = get_map_cell(x+1,y+1)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x-1,y-1)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x+1,y-1)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x-1,y+1)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x-1,y)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x,y-1)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x+1,y)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
tmp_cell = get_map_cell(x,y+1)
|
||||
if(tmp_cell)
|
||||
total += map[tmp_cell]
|
||||
val_count++
|
||||
total = round(total/val_count)
|
||||
|
||||
if(abs(map[current_cell]-total) <= cell_smooth_amt)
|
||||
map[current_cell] = total
|
||||
else if(map[current_cell] < total)
|
||||
map[current_cell]+=cell_smooth_amt
|
||||
else if(map[current_cell] < total)
|
||||
map[current_cell]-=cell_smooth_amt
|
||||
map[current_cell] = max(0,min(cell_range,map[current_cell]))
|
||||
map = next_map
|
||||
90
code/modules/random_map/noise/ore.dm
Normal file
90
code/modules/random_map/noise/ore.dm
Normal file
@@ -0,0 +1,90 @@
|
||||
/datum/random_map/noise/ore
|
||||
descriptor = "ore distribution map"
|
||||
var/deep_val = 0.8 // Threshold for deep metals, set in new as percentage of cell_range.
|
||||
var/rare_val = 0.7 // Threshold for rare metal, set in new as percentage of cell_range.
|
||||
var/chunk_size = 4 // Size each cell represents on map
|
||||
|
||||
/datum/random_map/noise/ore/New()
|
||||
rare_val = cell_range * rare_val
|
||||
deep_val = cell_range * deep_val
|
||||
..()
|
||||
|
||||
/datum/random_map/noise/ore/check_map_sanity()
|
||||
|
||||
var/rare_count = 0
|
||||
var/surface_count = 0
|
||||
var/deep_count = 0
|
||||
|
||||
// Increment map sanity counters.
|
||||
for(var/value in map)
|
||||
if(value < rare_val)
|
||||
surface_count++
|
||||
else if(value < deep_val)
|
||||
rare_count++
|
||||
else
|
||||
deep_count++
|
||||
// Sanity check.
|
||||
if(surface_count < MIN_SURFACE_COUNT)
|
||||
admin_notice("<span class='danger'>Insufficient surface minerals. Rerolling...</span>", R_DEBUG)
|
||||
return 0
|
||||
else if(rare_count < MIN_RARE_COUNT)
|
||||
admin_notice("<span class='danger'>Insufficient rare minerals. Rerolling...</span>", R_DEBUG)
|
||||
return 0
|
||||
else if(deep_count < MIN_DEEP_COUNT)
|
||||
admin_notice("<span class='danger'>Insufficient deep minerals. Rerolling...</span>", R_DEBUG)
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
||||
/datum/random_map/noise/ore/apply_to_turf(var/x,var/y)
|
||||
|
||||
var/tx = (origin_x+(x-1))*chunk_size
|
||||
var/ty = (origin_y+(y-1))*chunk_size
|
||||
|
||||
for(var/i=0,i<chunk_size,i++)
|
||||
for(var/j=0,j<chunk_size,j++)
|
||||
var/turf/simulated/T = locate(tx+j, ty+i, origin_z)
|
||||
if(!istype(T) || !T.has_resources)
|
||||
continue
|
||||
if(!priority_process) sleep(-1)
|
||||
T.resources = list()
|
||||
T.resources["silicates"] = rand(3,5)
|
||||
T.resources["carbonaceous rock"] = rand(3,5)
|
||||
|
||||
var/current_cell = map[get_map_cell(x,y)]
|
||||
if(current_cell < rare_val) // Surface metals.
|
||||
T.resources["iron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["gold"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["silver"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["diamond"] = 0
|
||||
T.resources["phoron"] = 0
|
||||
T.resources["osmium"] = 0
|
||||
T.resources["hydrogen"] = 0
|
||||
else if(current_cell < deep_val) // Rare metals.
|
||||
T.resources["gold"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["silver"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["uranium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["phoron"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["osmium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["hydrogen"] = 0
|
||||
T.resources["diamond"] = 0
|
||||
T.resources["iron"] = 0
|
||||
else // Deep metals.
|
||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["diamond"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||
T.resources["phoron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["osmium"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||
T.resources["hydrogen"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||
T.resources["iron"] = 0
|
||||
T.resources["gold"] = 0
|
||||
T.resources["silver"] = 0
|
||||
return
|
||||
|
||||
/datum/random_map/noise/ore/get_map_char(var/value)
|
||||
if(value < rare_val)
|
||||
return "S"
|
||||
else if(value < deep_val)
|
||||
return "R"
|
||||
else
|
||||
return "D"
|
||||
72
code/modules/random_map/noise/tundra.dm
Normal file
72
code/modules/random_map/noise/tundra.dm
Normal file
@@ -0,0 +1,72 @@
|
||||
/datum/random_map/noise/tundra
|
||||
descriptor = "tundra"
|
||||
smoothing_iterations = 1
|
||||
|
||||
/datum/random_map/noise/tundra/replace_space
|
||||
descriptor = "tundra (replacement)"
|
||||
target_turf_type = /turf/space
|
||||
|
||||
/datum/random_map/noise/tundra/get_map_char(var/value)
|
||||
var/val = min(9,max(0,round((value/cell_range)*10)))
|
||||
if(isnull(val)) val = 0
|
||||
switch(val)
|
||||
if(0)
|
||||
return "<font color='#000099'>~</font>"
|
||||
if(1)
|
||||
return "<font color='#0000BB'>~</font>"
|
||||
if(2)
|
||||
return "<font color='#0000DD'>~</font>"
|
||||
if(3)
|
||||
return "<font color='#66AA00'>[pick(list(".",","))]</font>"
|
||||
if(4)
|
||||
return "<font color='#77CC00'>[pick(list(".",","))]</font>"
|
||||
if(5)
|
||||
return "<font color='#88DD00'>[pick(list(".",","))]</font>"
|
||||
if(6)
|
||||
return "<font color='#99EE00'>[pick(list(".",","))]</font>"
|
||||
if(7)
|
||||
return "<font color='#00BB00'>[pick(list("T","t"))]</font>"
|
||||
if(8)
|
||||
return "<font color='#00DD00'>[pick(list("T","t"))]</font>"
|
||||
if(9)
|
||||
return "<font color='#00FF00'>[pick(list("T","t"))]</font>"
|
||||
|
||||
/datum/random_map/noise/tundra/get_appropriate_path(var/value)
|
||||
var/val = min(9,max(0,round((value/cell_range)*10)))
|
||||
if(isnull(val)) val = 0
|
||||
switch(val)
|
||||
if(0 to 4)
|
||||
return /turf/simulated/floor/beach/water/ocean
|
||||
else
|
||||
return /turf/simulated/floor/snow
|
||||
|
||||
/datum/random_map/noise/tundra/get_additional_spawns(var/value, var/turf/T)
|
||||
var/val = min(9,max(0,round((value/cell_range)*10)))
|
||||
if(isnull(val)) val = 0
|
||||
switch(val)
|
||||
if(2)
|
||||
if(prob(5))
|
||||
new /mob/living/simple_animal/crab(T)
|
||||
if(6)
|
||||
if(prob(60))
|
||||
var/grass_path = pick(typesof(/obj/structure/flora/grass)-/obj/structure/flora/grass)
|
||||
new grass_path(T)
|
||||
if(prob(5))
|
||||
var/mob_type = pick(list(/mob/living/simple_animal/lizard, /mob/living/simple_animal/mouse))
|
||||
new mob_type(T)
|
||||
if(7)
|
||||
if(prob(60))
|
||||
new /obj/structure/flora/bush(T)
|
||||
else if(prob(30))
|
||||
new /obj/structure/flora/tree/pine(T)
|
||||
else if(prob(20))
|
||||
new /obj/structure/flora/tree/dead(T)
|
||||
if(8)
|
||||
if(prob(70))
|
||||
new /obj/structure/flora/tree/pine(T)
|
||||
else if(prob(30))
|
||||
new /obj/structure/flora/tree/dead(T)
|
||||
else
|
||||
new /obj/structure/flora/bush(T)
|
||||
if(9)
|
||||
new /obj/structure/flora/tree/pine(T)
|
||||
Reference in New Issue
Block a user