mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2025-12-25 17:42:26 +00:00
Merge branch 'randmap' of https://github.com/Zuhayr/Baystation12 into randmap
This commit is contained in:
@@ -149,8 +149,8 @@ var/list/admin_verbs_debug = list(
|
||||
/client/proc/reload_admins,
|
||||
/client/proc/reload_mentors,
|
||||
/client/proc/restart_controller,
|
||||
/client/proc/remake_distribution_map,
|
||||
/client/proc/show_distribution_map,
|
||||
/client/proc/print_random_map,
|
||||
/client/proc/create_random_map,
|
||||
/client/proc/show_plant_genes,
|
||||
/client/proc/enable_debug_verbs,
|
||||
/client/proc/callproc,
|
||||
|
||||
@@ -1,233 +0,0 @@
|
||||
//If anyone can think of a less shitty way to work out x,y points on a linear string of integers please tell me.
|
||||
#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 MIN_SURFACE_COUNT 1000
|
||||
#define MAX_SURFACE_COUNT 5000
|
||||
#define MIN_RARE_COUNT 1000
|
||||
#define MAX_RARE_COUNT 5000
|
||||
#define MIN_DEEP_COUNT 100
|
||||
#define MAX_DEEP_COUNT 300
|
||||
#define ITERATE_BEFORE_FAIL 200
|
||||
|
||||
#define RESOURCE_HIGH_MAX 4
|
||||
#define RESOURCE_HIGH_MIN 2
|
||||
#define RESOURCE_MID_MAX 3
|
||||
#define RESOURCE_MID_MIN 1
|
||||
#define RESOURCE_LOW_MAX 1
|
||||
#define RESOURCE_LOW_MIN 0
|
||||
|
||||
/*
|
||||
Surface minerals:
|
||||
silicates
|
||||
iron
|
||||
gold
|
||||
silver
|
||||
|
||||
Rare minerals:
|
||||
uranium
|
||||
diamond
|
||||
|
||||
Deep minerals:
|
||||
phoron
|
||||
osmium (platinum)
|
||||
tritium (hydrogen)
|
||||
*/
|
||||
|
||||
/datum/ore_distribution
|
||||
|
||||
var/real_size = 65 //Overall map size ((must be power of 2)+1)
|
||||
var/chunk_size = 4 //Size each cell represents on map (like hell we're generating up to 100 256^2 grids at roundstart)
|
||||
var/list/map[4225] //The actual map. real_size squared.
|
||||
var/range = 255 //Max random range of cells in map.
|
||||
|
||||
var/random_variance_chance = 25
|
||||
var/random_element = 0.5
|
||||
|
||||
/datum/ore_distribution/proc/map_is_sane()
|
||||
if(!map) return 0
|
||||
|
||||
var/rare_count = 0
|
||||
var/surface_count = 0
|
||||
var/deep_count = 0
|
||||
|
||||
for(var/cell in map)
|
||||
if(cell>(range*0.60))
|
||||
deep_count++
|
||||
else if(cell>(range*0.40))
|
||||
rare_count++
|
||||
else
|
||||
surface_count++
|
||||
|
||||
if(surface_count < MIN_SURFACE_COUNT || surface_count > MAX_SURFACE_COUNT) return 0
|
||||
if(rare_count < MIN_RARE_COUNT || rare_count > MAX_RARE_COUNT) return 0
|
||||
if(deep_count < MIN_DEEP_COUNT || deep_count > MAX_DEEP_COUNT) return 0
|
||||
return 1
|
||||
|
||||
//Halfassed diamond-square algorithm with some fuckery since it's a single dimension array.
|
||||
/datum/ore_distribution/proc/populate_distribution_map()
|
||||
|
||||
//Seed beginning values.
|
||||
var/x = 1
|
||||
var/y = 1
|
||||
var/size = real_size-1
|
||||
map[MAP_TOP_LEFT] = (range/3)+rand(range/5)
|
||||
map[MAP_TOP_RIGHT] = (range/3)+rand(range/5)
|
||||
map[MAP_BOTTOM_LEFT] = (range/3)+rand(range/5)
|
||||
map[MAP_BOTTOM_RIGHT] = (range/3)+rand(range/5)
|
||||
|
||||
//Fill in and smooth it out.
|
||||
var/attempts = 0
|
||||
do
|
||||
attempts++
|
||||
generate_distribution_map(1,1,size)
|
||||
while(attempts < ITERATE_BEFORE_FAIL && !map_is_sane())
|
||||
|
||||
if(attempts >= ITERATE_BEFORE_FAIL)
|
||||
world << "<b><font color='red'>Could not generate a sane distribution map. Aborting.</font></b>"
|
||||
map = null
|
||||
return
|
||||
else
|
||||
apply_to_asteroid()
|
||||
|
||||
/datum/ore_distribution/proc/clear_distribution_map()
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
for(var/y = 1, y <= real_size, y++)
|
||||
map[MAP_CELL] = 0
|
||||
|
||||
/datum/ore_distribution/proc/print_distribution_map(var/mob/usr)
|
||||
var/line = ""
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
for(var/y = 1, y <= real_size, y++)
|
||||
line += num2text(round(map[MAP_CELL]/25.5))
|
||||
if(usr)
|
||||
usr << line
|
||||
else
|
||||
world << line
|
||||
line = ""
|
||||
|
||||
/datum/ore_distribution/proc/generate_distribution_map(var/x,var/y,var/input_size)
|
||||
|
||||
var/size = input_size
|
||||
|
||||
map[MAP_MID_TOP] = (map[MAP_TOP_LEFT] + map[MAP_TOP_RIGHT])/2
|
||||
map[MAP_MID_RIGHT] = (map[MAP_BOTTOM_RIGHT] + map[MAP_TOP_RIGHT])/2
|
||||
map[MAP_MID_BOTTOM] = (map[MAP_BOTTOM_LEFT] + map[MAP_BOTTOM_RIGHT])/2
|
||||
map[MAP_MID_LEFT] = (map[MAP_TOP_LEFT] + map[MAP_BOTTOM_RIGHT])/2
|
||||
map[MAP_CENTRE] = (map[MAP_MID_LEFT]+map[MAP_MID_RIGHT]+map[MAP_MID_BOTTOM]+map[MAP_MID_TOP])/4
|
||||
|
||||
if(prob(random_variance_chance))
|
||||
map[MAP_CENTRE] *= (rand(1) ? (1.0-random_element) : (1.0+random_element))
|
||||
map[MAP_CENTRE] = max(0,min(range,map[MAP_CENTRE]))
|
||||
|
||||
if(size>3)
|
||||
generate_distribution_map(x,y,input_size/2)
|
||||
generate_distribution_map(x+(input_size/2),y,input_size/2)
|
||||
generate_distribution_map(x,y+(input_size/2),input_size/2)
|
||||
generate_distribution_map(x+(input_size/2),y+(input_size/2),input_size/2)
|
||||
|
||||
/datum/ore_distribution/proc/apply_to_asteroid()
|
||||
|
||||
// THESE VALUES DETERMINE THE AREA THAT THE DISTRIBUTION MAP IS APPLIED TO.
|
||||
// IF YOU DO NOT RUN OFFICIAL BAYCODE ASTEROID MAP YOU NEED TO CHANGE THEM.
|
||||
// ORIGIN IS THE BOTTOM LEFT CORNER OF THE SQUARE CONTAINING ALL ASTEROID
|
||||
// TILES YOU WISH TO APPLY THE DISTRIBUTION MAP TO.
|
||||
|
||||
var/origin_x = 13 //We start here...
|
||||
var/origin_y = 32 //...and here...
|
||||
var/limit_x = 217 //...and iterate until here...
|
||||
var/limit_y = 223 //...and here...
|
||||
var/asteroid_z = 5 //...on this Z-level.
|
||||
|
||||
var/tx = origin_x
|
||||
var/ty = origin_y
|
||||
|
||||
for(var/y = 1, y <= real_size, y++)
|
||||
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
|
||||
var/turf/target_turf
|
||||
|
||||
for(var/i=0,i<chunk_size,i++)
|
||||
|
||||
for(var/j=0,j<chunk_size,j++)
|
||||
|
||||
if(tx+j > limit_x || ty+i > limit_y)
|
||||
continue
|
||||
|
||||
target_turf = locate(tx+j, ty+i, asteroid_z)
|
||||
|
||||
if(target_turf && target_turf.has_resources)
|
||||
target_turf.resources = list()
|
||||
target_turf.resources["silicates"] = rand(3,5)
|
||||
target_turf.resources["carbonaceous rock"] = rand(3,5)
|
||||
|
||||
switch(map[MAP_CELL])
|
||||
if(0 to 100)
|
||||
target_turf.resources["iron"] = rand(RESOURCE_HIGH_MIN,RESOURCE_HIGH_MAX)
|
||||
target_turf.resources["gold"] = rand(RESOURCE_LOW_MIN,RESOURCE_LOW_MAX)
|
||||
target_turf.resources["silver"] = rand(RESOURCE_LOW_MIN,RESOURCE_LOW_MAX)
|
||||
target_turf.resources["uranium"] = rand(RESOURCE_LOW_MIN,RESOURCE_LOW_MAX)
|
||||
target_turf.resources["diamond"] = 0
|
||||
target_turf.resources["phoron"] = 0
|
||||
target_turf.resources["osmium"] = 0
|
||||
target_turf.resources["hydrogen"] = 0
|
||||
if(100 to 124)
|
||||
target_turf.resources["iron"] = 0
|
||||
target_turf.resources["gold"] = rand(RESOURCE_MID_MIN,RESOURCE_MID_MAX)
|
||||
target_turf.resources["silver"] = rand(RESOURCE_MID_MIN,RESOURCE_MID_MAX)
|
||||
target_turf.resources["uranium"] = rand(RESOURCE_MID_MIN,RESOURCE_MID_MAX)
|
||||
target_turf.resources["diamond"] = 0
|
||||
target_turf.resources["phoron"] = rand(RESOURCE_MID_MIN,RESOURCE_MID_MAX)
|
||||
target_turf.resources["osmium"] = rand(RESOURCE_MID_MIN,RESOURCE_MID_MAX)
|
||||
target_turf.resources["hydrogen"] = 0
|
||||
if(125 to 255)
|
||||
target_turf.resources["iron"] = 0
|
||||
target_turf.resources["gold"] = 0
|
||||
target_turf.resources["silver"] = 0
|
||||
target_turf.resources["uranium"] = rand(RESOURCE_LOW_MIN,RESOURCE_LOW_MAX)
|
||||
target_turf.resources["diamond"] = rand(RESOURCE_LOW_MIN,RESOURCE_LOW_MAX)
|
||||
target_turf.resources["phoron"] = rand(RESOURCE_HIGH_MIN,RESOURCE_HIGH_MAX)
|
||||
target_turf.resources["osmium"] = rand(RESOURCE_HIGH_MIN,RESOURCE_HIGH_MAX)
|
||||
target_turf.resources["hydrogen"] = rand(RESOURCE_MID_MIN,RESOURCE_MID_MAX)
|
||||
|
||||
tx += chunk_size
|
||||
tx = origin_x
|
||||
ty += chunk_size
|
||||
|
||||
world << "<b><font color='red'>Resource map generation complete.</font></b>"
|
||||
return
|
||||
|
||||
#undef MAP_CELL
|
||||
#undef MAP_CENTRE
|
||||
#undef MAP_TOP_LEFT
|
||||
#undef MAP_TOP_RIGHT
|
||||
#undef MAP_BOTTOM_LEFT
|
||||
#undef MAP_BOTTOM_RIGHT
|
||||
#undef MAP_MID_TOP
|
||||
#undef MAP_MID_BOTTOM
|
||||
#undef MAP_MID_LEFT
|
||||
#undef MAP_MID_RIGHT
|
||||
|
||||
#undef MIN_SURFACE_COUNT
|
||||
#undef MAX_SURFACE_COUNT
|
||||
#undef MIN_RARE_COUNT
|
||||
#undef MAX_RARE_COUNT
|
||||
#undef MIN_DEEP_COUNT
|
||||
#undef MAX_DEEP_COUNT
|
||||
#undef ITERATE_BEFORE_FAIL
|
||||
|
||||
#undef RESOURCE_HIGH_MAX
|
||||
#undef RESOURCE_HIGH_MIN
|
||||
#undef RESOURCE_MID_MAX
|
||||
#undef RESOURCE_MID_MIN
|
||||
#undef RESOURCE_LOW_MAX
|
||||
#undef RESOURCE_LOW_MIN
|
||||
@@ -29,7 +29,8 @@
|
||||
|
||||
/turf/simulated/mineral/New()
|
||||
|
||||
MineralSpread()
|
||||
spawn(0)
|
||||
MineralSpread()
|
||||
|
||||
spawn(2)
|
||||
var/list/step_overlays = list("s" = NORTH, "n" = SOUTH, "w" = EAST, "e" = WEST)
|
||||
@@ -86,7 +87,7 @@
|
||||
if(mineral && mineral.spread)
|
||||
for(var/trydir in cardinal)
|
||||
if(prob(mineral.spread_chance))
|
||||
var/turf/simulated/mineral/random/target_turf = get_step(src, trydir)
|
||||
var/turf/simulated/mineral/target_turf = get_step(src, trydir)
|
||||
if(istype(target_turf) && !target_turf.mineral)
|
||||
target_turf.mineral = mineral
|
||||
target_turf.UpdateMineral()
|
||||
@@ -363,7 +364,7 @@
|
||||
/turf/simulated/mineral/random
|
||||
name = "Mineral deposit"
|
||||
var/mineralSpawnChanceList = list("Uranium" = 5, "Platinum" = 5, "Iron" = 35, "Coal" = 35, "Diamond" = 1, "Gold" = 5, "Silver" = 5, "Phoron" = 10)
|
||||
var/mineralChance = 10 //means 10% chance of this plot changing to a mineral deposit
|
||||
var/mineralChance = 100 //10 //means 10% chance of this plot changing to a mineral deposit
|
||||
|
||||
/turf/simulated/mineral/random/New()
|
||||
if (prob(mineralChance) && !mineral)
|
||||
@@ -379,7 +380,7 @@
|
||||
. = ..()
|
||||
|
||||
/turf/simulated/mineral/random/high_chance
|
||||
mineralChance = 25
|
||||
mineralChance = 100 //25
|
||||
mineralSpawnChanceList = list("Uranium" = 10, "Platinum" = 10, "Iron" = 20, "Coal" = 20, "Diamond" = 2, "Gold" = 10, "Silver" = 10, "Phoron" = 20)
|
||||
|
||||
|
||||
|
||||
242
code/modules/random_map/mining_distribution.dm
Normal file
242
code/modules/random_map/mining_distribution.dm
Normal file
@@ -0,0 +1,242 @@
|
||||
#define MIN_SURFACE_COUNT 500
|
||||
#define MIN_RARE_COUNT 200
|
||||
#define MIN_DEEP_COUNT 100
|
||||
#define RESOURCE_HIGH_MAX 4
|
||||
#define RESOURCE_HIGH_MIN 2
|
||||
#define RESOURCE_MID_MAX 3
|
||||
#define RESOURCE_MID_MIN 1
|
||||
#define RESOURCE_LOW_MAX 1
|
||||
#define RESOURCE_LOW_MIN 0
|
||||
|
||||
/*
|
||||
Surface minerals:
|
||||
silicates
|
||||
iron
|
||||
gold
|
||||
silver
|
||||
Rare minerals:
|
||||
uranium
|
||||
diamond
|
||||
Deep minerals:
|
||||
phoron
|
||||
osmium (platinum)
|
||||
tritium (hydrogen)
|
||||
*/
|
||||
|
||||
/datum/random_map/ore
|
||||
|
||||
descriptor = "resource distribution map"
|
||||
real_size = 65 // Must be (power of 2)+1 for diamond-square.
|
||||
cell_range = 255 // These values are used to seed ore values rather than to determine a turf type.
|
||||
iterations = 0 // We'll handle iterating on our end (recursive, with args).
|
||||
|
||||
var/chunk_size = 4 // Size each cell represents on map
|
||||
var/random_variance_chance = 25 // % chance of applying random_element.
|
||||
var/random_element = 0.5 // Determines the variance when smoothing out cell values.
|
||||
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/cell_base // Set in New()
|
||||
var/initial_cell_range // Set in New()
|
||||
|
||||
/datum/random_map/ore/New()
|
||||
rare_val = cell_range * rare_val
|
||||
deep_val = cell_range * deep_val
|
||||
|
||||
initial_cell_range = cell_range/5
|
||||
cell_base = cell_range/2
|
||||
..()
|
||||
|
||||
/datum/random_map/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)
|
||||
world << "<span class='danger'>Insufficient surface minerals. Rerolling...</span>"
|
||||
return 0
|
||||
else if(rare_count < MIN_RARE_COUNT)
|
||||
world << "<span class='danger'>Insufficient rare minerals. Rerolling...</span>"
|
||||
return 0
|
||||
else if(deep_count < MIN_DEEP_COUNT)
|
||||
world << "<span class='danger'>Insufficient deep minerals. Rerolling...</span>"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
||||
//Halfassed diamond-square algorithm with some fuckery since it's a single dimension array.
|
||||
/datum/random_map/ore/seed_map()
|
||||
|
||||
// Instantiate the grid.
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
for(var/y = 1, y <= real_size, 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,real_size)] = cell_base+rand(initial_cell_range)
|
||||
map[get_map_cell(real_size,real_size)] = cell_base+rand(initial_cell_range)
|
||||
map[get_map_cell(real_size,1)] = cell_base+rand(initial_cell_range)
|
||||
iterate(1,1,1,(real_size-1)) // Start the recursion here.
|
||||
|
||||
/datum/random_map/ore/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) && map[current_cell])
|
||||
if(map[current_cell] < rare_val)
|
||||
line += "S"
|
||||
else if(map[current_cell] < deep_val)
|
||||
line += "R"
|
||||
else
|
||||
line += "D"
|
||||
else
|
||||
line += "X"
|
||||
user << line
|
||||
|
||||
/datum/random_map/ore/iterate(var/iteration,var/x,var/y,var/input_size)
|
||||
|
||||
// Infinite loop check!
|
||||
if(iteration>=iterate_before_fail)
|
||||
world << "<span class='danger'>Iteration count exceeded, aborting.</span>"
|
||||
return
|
||||
|
||||
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)
|
||||
sleep(-1)
|
||||
iteration++
|
||||
iterate(iteration, x, y, hsize)
|
||||
iterate(iteration, x+hsize, y, hsize)
|
||||
iterate(iteration, x, y+hsize, hsize)
|
||||
iterate(iteration, x+hsize, y+hsize, hsize)
|
||||
|
||||
/datum/random_map/ore/apply_to_map()
|
||||
for(var/x = 0, x < real_size, x++)
|
||||
if((origin_x + x) > limit_x) continue
|
||||
for(var/y = 0, y < real_size, y++)
|
||||
if((origin_y + y) > limit_y) continue
|
||||
sleep(-1)
|
||||
apply_to_turf(x,y)
|
||||
|
||||
/datum/random_map/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++)
|
||||
if(ty+i>limit_y)
|
||||
continue
|
||||
for(var/j=0,j<chunk_size,j++)
|
||||
if(tx+j>limit_x)
|
||||
continue
|
||||
|
||||
var/turf/T = locate(tx+j, ty+i, origin_z)
|
||||
if(!T || !T.has_resources)
|
||||
continue
|
||||
|
||||
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/ore/cleanup()
|
||||
return 1
|
||||
|
||||
#undef MIN_SURFACE_COUNT
|
||||
#undef MIN_RARE_COUNT
|
||||
#undef MIN_DEEP_COUNT
|
||||
#undef RESOURCE_HIGH_MAX
|
||||
#undef RESOURCE_HIGH_MIN
|
||||
#undef RESOURCE_MID_MAX
|
||||
#undef RESOURCE_MID_MIN
|
||||
#undef RESOURCE_LOW_MAX
|
||||
#undef RESOURCE_LOW_MIN
|
||||
173
code/modules/random_map/random_map.dm
Normal file
173
code/modules/random_map/random_map.dm
Normal file
@@ -0,0 +1,173 @@
|
||||
#define ORE_COUNT 1000
|
||||
/*
|
||||
This module is used to generate the debris fields/distribution maps/procedural stations.
|
||||
*/
|
||||
|
||||
var/global/list/random_maps = list()
|
||||
|
||||
/datum/random_map
|
||||
var/descriptor = "asteroid" // Display name.
|
||||
var/real_size = 246 // Size of each edge (must be square :().
|
||||
var/cell_range = 2 // Random range for initial cells.
|
||||
var/iterations = 5 // Number of times to apply the automata rule.
|
||||
var/max_attempts = 5 // Fail if a sane map isn't generated by this point.
|
||||
var/raw_map_size // Used for creating new maps each iteration. Value must be real_size^2
|
||||
var/list/map = list() // Actual map.
|
||||
var/origin_x = 1 // Origin point, left.
|
||||
var/origin_y = 1 // Origin point, bottom.
|
||||
var/origin_z = 1 // Target Z-level.
|
||||
var/limit_x = 256 // Maximum x 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)
|
||||
|
||||
// Store this for debugging.
|
||||
random_maps |= src
|
||||
|
||||
// Initialize map.
|
||||
set_map_size()
|
||||
|
||||
// Get origins for applying the map later.
|
||||
if(tx) origin_x = tx
|
||||
if(ty) origin_y = ty
|
||||
if(tz) origin_z = tz
|
||||
if(tlx) limit_x = tlx
|
||||
if(tly) limit_y = tly
|
||||
|
||||
// testing needed to see how reliable this is (asynchronous calls, called during worldgen), DM ref is not optimistic
|
||||
if(seed) rand_seed(seed)
|
||||
|
||||
var/start_time = world.timeofday
|
||||
world << "<span class='danger'>Generating [descriptor].</span>"
|
||||
for(var/i = 0;i<max_attempts;i++)
|
||||
if(generate())
|
||||
world << "<span class='danger'>[capitalize(descriptor)] generation completed in [round(0.1*(world.timeofday-start_time),0.1)] seconds.</span>"
|
||||
return
|
||||
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>"
|
||||
|
||||
/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)
|
||||
if(!raw_size)
|
||||
raw_size = real_size * real_size
|
||||
raw_map_size = raw_size
|
||||
map.len = raw_map_size
|
||||
|
||||
/datum/random_map/proc/seed_map()
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
for(var/y = 1, y <= real_size, y++)
|
||||
var/current_cell = get_map_cell(x,y)
|
||||
if(prob(55))
|
||||
map[current_cell] = 2
|
||||
else
|
||||
map[current_cell] = 1
|
||||
|
||||
/datum/random_map/proc/clear_map()
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
for(var/y = 1, y <= real_size, y++)
|
||||
map[get_map_cell(x,y)] = 0
|
||||
|
||||
/datum/random_map/proc/generate()
|
||||
seed_map()
|
||||
for(var/i=1;i<=iterations;i++)
|
||||
iterate(i)
|
||||
if(check_map_sanity())
|
||||
cleanup()
|
||||
apply_to_map()
|
||||
return 1
|
||||
return 0
|
||||
|
||||
/datum/random_map/proc/iterate(var/iteration)
|
||||
var/list/next_map[raw_map_size]
|
||||
for(var/x = 1, x <= real_size, x++)
|
||||
for(var/y = 1, y <= real_size, y++)
|
||||
var/current_cell = get_map_cell(x,y)
|
||||
// Sanity check.
|
||||
if(!within_bounds(current_cell))
|
||||
continue
|
||||
// Copy over original value.
|
||||
next_map[current_cell] = map[current_cell]
|
||||
// Check all neighbors.
|
||||
var/count = 0
|
||||
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(within_bounds(cell) && map[cell] == 2)
|
||||
count++
|
||||
if(count>=5)
|
||||
next_map[current_cell] = 2 // becomes a wall
|
||||
else
|
||||
next_map[current_cell] = 1 // becomes a floor
|
||||
map = next_map
|
||||
|
||||
/datum/random_map/proc/check_map_sanity()
|
||||
return 1
|
||||
|
||||
/datum/random_map/proc/apply_to_map()
|
||||
for(var/x = 0, x < real_size, x++)
|
||||
if((origin_x + x) > limit_x) continue
|
||||
for(var/y = 0, y < real_size, y++)
|
||||
if((origin_y + y) > limit_y) continue
|
||||
sleep(-1)
|
||||
apply_to_turf(origin_x+x,origin_y+y)
|
||||
|
||||
/datum/random_map/proc/apply_to_turf(var/x,var/y)
|
||||
var/current_cell = get_map_cell(x,y)
|
||||
if(!within_bounds(current_cell))
|
||||
return
|
||||
var/turf/T = locate(x,y,origin_z)
|
||||
if(!T || !istype(T,/turf/unsimulated/mask))
|
||||
return
|
||||
switch(map[current_cell])
|
||||
if(1)
|
||||
T.ChangeTurf(/turf/simulated/floor/plating/airless/asteroid)
|
||||
if(2)
|
||||
T.ChangeTurf(/turf/simulated/mineral)
|
||||
if(3)
|
||||
T.ChangeTurf(/turf/simulated/mineral/random)
|
||||
if(4)
|
||||
T.ChangeTurf(/turf/simulated/mineral/random/high_chance)
|
||||
|
||||
/datum/random_map/proc/cleanup()
|
||||
|
||||
sleep(-1)
|
||||
// Create ore.
|
||||
var/ore_count = ORE_COUNT
|
||||
while(ore_count)
|
||||
var/check_cell = get_map_cell(rand(1,real_size),rand(1,real_size))
|
||||
if(!(within_bounds(check_cell)) || map[check_cell] != 2)
|
||||
continue
|
||||
if(prob(25))
|
||||
map[check_cell] = 4
|
||||
else
|
||||
map[check_cell] = 3
|
||||
ore_count--
|
||||
|
||||
sleep(-1)
|
||||
|
||||
// Place random asteroid rooms.
|
||||
var/rooms_placed = 0
|
||||
for(var/i = 0, i < max_secret_rooms, i++)
|
||||
if(make_mining_asteroid_secret())
|
||||
rooms_placed++
|
||||
world << "<span class='danger'>Placed [rooms_placed] secrets.</span>"
|
||||
return 1
|
||||
125
code/modules/random_map/setpiece.dm
Normal file
125
code/modules/random_map/setpiece.dm
Normal file
@@ -0,0 +1,125 @@
|
||||
/datum/setpiece
|
||||
var/descriptor
|
||||
var/base_x
|
||||
var/base_y
|
||||
var/origin_x
|
||||
var/origin_y
|
||||
var/origin_z
|
||||
var/x_bound
|
||||
var/y_bound
|
||||
var/list/map
|
||||
var/min_x = 32
|
||||
var/min_y = 32
|
||||
|
||||
/datum/setpiece/New(var/x, var/y, var/x_size, var/y_size)
|
||||
|
||||
// Get operating paramaters.
|
||||
if(x_size)
|
||||
x_bound = x_size
|
||||
else
|
||||
x_bound = base_x
|
||||
if(y_size)
|
||||
y_bound = y_size
|
||||
else
|
||||
y_bound = base_y
|
||||
|
||||
origin_x = x
|
||||
origin_y = y
|
||||
|
||||
// Initialize map.
|
||||
map = list()
|
||||
map.len = x_bound * y_bound
|
||||
|
||||
// Build.
|
||||
if(is_buildable())
|
||||
generate()
|
||||
apply_to_map()
|
||||
return 1
|
||||
return 0
|
||||
|
||||
/datum/setpiece/proc/is_buildable()
|
||||
return 1
|
||||
|
||||
/datum/setpiece/proc/apply_to_map()
|
||||
return 1
|
||||
|
||||
/datum/setpiece/proc/generate()
|
||||
return 1
|
||||
|
||||
/datum/setpiece/asteroid_secret
|
||||
descriptor = "secret room"
|
||||
base_x = 5
|
||||
base_y = 5
|
||||
min_x = 5
|
||||
min_y = 5
|
||||
|
||||
/datum/setpiece/asteroid_secret/is_buildable()
|
||||
|
||||
var/valid = 0
|
||||
var/turf/T = null
|
||||
var/sanity = 0
|
||||
var/list/room = null
|
||||
var/list/turfs = null
|
||||
|
||||
turfs = get_area_turfs(/area/mine/unexplored)
|
||||
|
||||
if(!turfs.len)
|
||||
return 0
|
||||
|
||||
while(!valid)
|
||||
valid = 1
|
||||
sanity++
|
||||
if(sanity > 100)
|
||||
return 0
|
||||
|
||||
T=pick(turfs)
|
||||
if(!T)
|
||||
return 0
|
||||
|
||||
var/list/surroundings = list()
|
||||
|
||||
surroundings += range(7, locate(T.x,T.y,T.z))
|
||||
surroundings += range(7, locate(T.x+size,T.y,T.z))
|
||||
surroundings += range(7, locate(T.x,T.y+size,T.z))
|
||||
surroundings += range(7, locate(T.x+size,T.y+size,T.z))
|
||||
|
||||
if(locate(/area/mine/explored) in surroundings) // +5s are for view range
|
||||
valid = 0
|
||||
continue
|
||||
|
||||
if(locate(/turf/space) in surroundings)
|
||||
valid = 0
|
||||
continue
|
||||
|
||||
if(locate(/area/asteroid/artifactroom) in surroundings)
|
||||
valid = 0
|
||||
continue
|
||||
|
||||
if(locate(/turf/simulated/floor/plating/airless/asteroid) in surroundings)
|
||||
valid = 0
|
||||
continue
|
||||
|
||||
if(!T)
|
||||
return 0
|
||||
|
||||
room = spawn_room(T,size,size,,,1)
|
||||
|
||||
if(room)
|
||||
T = pick(room["floors"])
|
||||
if(T)
|
||||
var/surprise = null
|
||||
valid = 0
|
||||
while(!valid)
|
||||
surprise = pickweight(space_surprises)
|
||||
if(surprise in spawned_surprises)
|
||||
if(prob(20))
|
||||
valid++
|
||||
else
|
||||
continue
|
||||
else
|
||||
valid++
|
||||
|
||||
spawned_surprises.Add(surprise)
|
||||
new surprise(T)
|
||||
|
||||
return 1
|
||||
Reference in New Issue
Block a user