mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2025-12-16 05:02:18 +00:00
Debugging the mining distribution map.
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
#define MIN_SURFACE_COUNT 1000
|
#define MIN_SURFACE_COUNT 500
|
||||||
#define MAX_SURFACE_COUNT 5000
|
#define MIN_RARE_COUNT 500
|
||||||
#define MIN_RARE_COUNT 1000
|
|
||||||
#define MAX_RARE_COUNT 5000
|
|
||||||
#define MIN_DEEP_COUNT 100
|
#define MIN_DEEP_COUNT 100
|
||||||
#define MAX_DEEP_COUNT 300
|
|
||||||
|
|
||||||
#define RESOURCE_HIGH_MAX 4
|
#define RESOURCE_HIGH_MAX 4
|
||||||
#define RESOURCE_HIGH_MIN 2
|
#define RESOURCE_HIGH_MIN 2
|
||||||
#define RESOURCE_MID_MAX 3
|
#define RESOURCE_MID_MAX 3
|
||||||
@@ -30,19 +26,25 @@ Deep minerals:
|
|||||||
/datum/random_map/ore
|
/datum/random_map/ore
|
||||||
|
|
||||||
descriptor = "resource distribution map"
|
descriptor = "resource distribution map"
|
||||||
real_size = 65 // Must be (power of 2)+1 for diamond-square.
|
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.
|
cell_range = 255 // These values are used to seed ore values rather than to determine a turf type.
|
||||||
iterations = 0 // We'll handle that on our end.
|
var/cell_base // Set in New()
|
||||||
|
var/initial_cell_range // Set in New()
|
||||||
|
|
||||||
|
iterations = 0 // We'll handle iterating on our end (recursive, with args).
|
||||||
|
|
||||||
var/chunk_size = 4 // Size each cell represents on map
|
var/chunk_size = 4 // Size each cell represents on map
|
||||||
var/random_variance_chance = 25 // % chance of applying random_element.
|
var/random_variance_chance = 25 // % chance of applying random_element.
|
||||||
var/random_element = 0.5 // Determines the variance when smoothing out cell values.
|
var/random_element = 0.5 // Determines the variance when smoothing out cell values.
|
||||||
var/deep_val = 50
|
var/deep_val = 0.8 // Threshold for deep metals, set in new as percentage of cell_range.
|
||||||
var/rare_val = 100
|
var/rare_val = 0.7 // Threshold for rare metal, set in new as percentage of cell_range.
|
||||||
|
|
||||||
/datum/random_map/ore/New()
|
/datum/random_map/ore/New()
|
||||||
deep_val = cell_range*0.60
|
rare_val = cell_range * rare_val
|
||||||
rare_val = cell_range*0.40
|
deep_val = cell_range * deep_val
|
||||||
|
|
||||||
|
initial_cell_range = cell_range/5
|
||||||
|
cell_base = cell_range/2
|
||||||
..()
|
..()
|
||||||
|
|
||||||
/datum/random_map/ore/check_map_sanity()
|
/datum/random_map/ore/check_map_sanity()
|
||||||
@@ -51,26 +53,22 @@ Deep minerals:
|
|||||||
var/surface_count = 0
|
var/surface_count = 0
|
||||||
var/deep_count = 0
|
var/deep_count = 0
|
||||||
|
|
||||||
for(var/x = 1, x <= real_size, x++)
|
// Increment map sanity counters.
|
||||||
for(var/y = 1, y <= real_size, y++)
|
for(var/value in map)
|
||||||
var/current_cell = get_map_cell(x,y)
|
if(value < rare_val)
|
||||||
if(!within_bounds(current_cell))
|
surface_count++
|
||||||
continue
|
else if(value < deep_val)
|
||||||
switch(map[current_cell])
|
rare_count++
|
||||||
if(0 to rare_val)
|
else
|
||||||
surface_count++
|
deep_count++
|
||||||
if(rare_val to deep_val)
|
// Sanity check.
|
||||||
rare_count++
|
if(surface_count < MIN_SURFACE_COUNT)
|
||||||
if(deep_val to INFINITY)
|
|
||||||
deep_count++
|
|
||||||
|
|
||||||
if((surface_count < MIN_SURFACE_COUNT) || (surface_count > MAX_SURFACE_COUNT))
|
|
||||||
world << "<span class='danger'>Insufficient surface minerals. Rerolling...</span>"
|
world << "<span class='danger'>Insufficient surface minerals. Rerolling...</span>"
|
||||||
return 0
|
return 0
|
||||||
else if((rare_count < MIN_RARE_COUNT) || (rare_count > MAX_RARE_COUNT))
|
else if(rare_count < MIN_RARE_COUNT)
|
||||||
world << "<span class='danger'>Insufficient rare minerals. Rerolling...</span>"
|
world << "<span class='danger'>Insufficient rare minerals. Rerolling...</span>"
|
||||||
return 0
|
return 0
|
||||||
else if((deep_count < MIN_DEEP_COUNT) || (deep_count > MAX_DEEP_COUNT))
|
else if(deep_count < MIN_DEEP_COUNT)
|
||||||
world << "<span class='danger'>Insufficient deep minerals. Rerolling...</span>"
|
world << "<span class='danger'>Insufficient deep minerals. Rerolling...</span>"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@@ -79,18 +77,20 @@ Deep minerals:
|
|||||||
//Halfassed diamond-square algorithm with some fuckery since it's a single dimension array.
|
//Halfassed diamond-square algorithm with some fuckery since it's a single dimension array.
|
||||||
/datum/random_map/ore/seed_map()
|
/datum/random_map/ore/seed_map()
|
||||||
|
|
||||||
|
// Reset size.
|
||||||
|
size = real_size-1
|
||||||
|
|
||||||
// Instantiate the grid.
|
// Instantiate the grid.
|
||||||
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[get_map_cell(x,y)] = -1
|
map[get_map_cell(x,y)] = 0
|
||||||
|
|
||||||
// Now dump in the actual random data.
|
// Now dump in the actual random data.
|
||||||
size = real_size-1
|
map[get_map_cell(1,1)] = cell_base+rand(initial_cell_range)
|
||||||
map[get_map_cell(1,1)] = (cell_range/3)+rand(cell_range/5)
|
map[get_map_cell(1,real_size)] = cell_base+rand(initial_cell_range)
|
||||||
map[get_map_cell(1,real_size)] = (cell_range/3)+rand(cell_range/5)
|
map[get_map_cell(real_size,real_size)] = cell_base+rand(initial_cell_range)
|
||||||
map[get_map_cell(real_size,real_size)] = (cell_range/3)+rand(cell_range/5)
|
map[get_map_cell(real_size,1)] = cell_base+rand(initial_cell_range)
|
||||||
map[get_map_cell(real_size,1)] = (cell_range/3)+rand(cell_range/5)
|
iterate(1,1,1,size) // Start the recursion here.
|
||||||
iterate(1,1,1,size) // Handle iteration here since we use different args to parent.
|
|
||||||
|
|
||||||
/datum/random_map/ore/display_map(atom/user)
|
/datum/random_map/ore/display_map(atom/user)
|
||||||
|
|
||||||
@@ -102,15 +102,12 @@ Deep minerals:
|
|||||||
for(var/y = 1, y <= real_size, y++)
|
for(var/y = 1, y <= real_size, y++)
|
||||||
var/current_cell = get_map_cell(x,y)
|
var/current_cell = get_map_cell(x,y)
|
||||||
if(within_bounds(current_cell) && map[current_cell])
|
if(within_bounds(current_cell) && map[current_cell])
|
||||||
switch(map[current_cell])
|
if(map[current_cell] < rare_val)
|
||||||
if(0 to rare_val)
|
line += "S"
|
||||||
line += "S"
|
else if(map[current_cell] < deep_val)
|
||||||
if(rare_val to deep_val)
|
line += "R"
|
||||||
line += "R"
|
else
|
||||||
if(deep_val to INFINITY)
|
line += "D"
|
||||||
line += "D"
|
|
||||||
else
|
|
||||||
line += "?"
|
|
||||||
else
|
else
|
||||||
line += "X"
|
line += "X"
|
||||||
user << line
|
user << line
|
||||||
@@ -122,36 +119,52 @@ Deep minerals:
|
|||||||
world << "<span class='danger'>Iteration count exceeded, aborting.</span>"
|
world << "<span class='danger'>Iteration count exceeded, aborting.</span>"
|
||||||
return
|
return
|
||||||
|
|
||||||
// Make sure we're using the right size for our subdivisions.
|
var/isize = input_size
|
||||||
size = input_size
|
var/hsize = round(input_size/2)
|
||||||
var/hsize = round(size/2)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
(x,y+size)-----(x+hsize,y+size)-----(x+size,y+size)
|
(x,y+isize)----(x+hsize,y+isize)----(x+size,y+isize)
|
||||||
| | |
|
| | |
|
||||||
| | |
|
| | |
|
||||||
| | |
|
| | |
|
||||||
(x,y+hsize)----(x+hsize,y+hsize)----(x+size,y)
|
(x,y+hsize)----(x+hsize,y+hsize)----(x+isize,y)
|
||||||
| | |
|
| | |
|
||||||
| | |
|
| | |
|
||||||
| | |
|
| | |
|
||||||
(x,y)----------(x+hsize,y)----------(x+size,y)
|
(x,y)----------(x+hsize,y)----------(x+isize,y)
|
||||||
*/
|
*/
|
||||||
// Central edge values become average of corners.
|
// Central edge values become average of corners.
|
||||||
map[get_map_cell(x+hsize,y+size)] = round((map[get_map_cell(x,y+size)] + map[get_map_cell(x+size,y+size)])/2)
|
map[get_map_cell(x+hsize,y+isize)] = round((\
|
||||||
map[get_map_cell(x+hsize,y)] = round((map[get_map_cell(x,y)]+map[get_map_cell(x+size,y)])/2)
|
map[get_map_cell(x,y+isize)] + \
|
||||||
map[get_map_cell(x,y+hsize)] = round((map[get_map_cell(x,y+size)]+map[get_map_cell(x,y)])/2)
|
map[get_map_cell(x+isize,y+isize)] \
|
||||||
map[get_map_cell(x+size,y)] = round((map[get_map_cell(x+size,y+size)]+map[get_map_cell(x+size,y)])/2)
|
)/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.
|
// Centre value becomes the average of all other values + possible random variance.
|
||||||
var/current_cell = get_map_cell(x+hsize,y+hsize)
|
var/current_cell = get_map_cell(x+hsize,y+hsize)
|
||||||
map[current_cell] = round((map[get_map_cell(x+hsize,y+size)]+map[get_map_cell(x+hsize,y)]+map[get_map_cell(x,y+hsize)]+map[get_map_cell(x+size,y)])/4)
|
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))
|
if(prob(random_variance_chance))
|
||||||
map[current_cell] *= (rand(1) ? (1.0-random_element) : (1.0+random_element))
|
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]))
|
map[current_cell] = max(0,min(cell_range,map[current_cell]))
|
||||||
|
|
||||||
// Recurse until size is too small to subdivide.
|
// Recurse until size is too small to subdivide.
|
||||||
if(size>3)
|
if(isize>3)
|
||||||
|
sleep(-1)
|
||||||
iteration++
|
iteration++
|
||||||
iterate(iteration, x, y, hsize)
|
iterate(iteration, x, y, hsize)
|
||||||
iterate(iteration, x+hsize, y, hsize)
|
iterate(iteration, x+hsize, y, hsize)
|
||||||
@@ -174,39 +187,54 @@ Deep minerals:
|
|||||||
if(!T || !T.has_resources)
|
if(!T || !T.has_resources)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
T.color = "#FF0000"
|
||||||
|
|
||||||
|
sleep(-1)
|
||||||
|
|
||||||
T.resources = list()
|
T.resources = list()
|
||||||
T.resources["silicates"] = rand(3,5)
|
T.resources["silicates"] = rand(3,5)
|
||||||
T.resources["carbonaceous rock"] = rand(3,5)
|
T.resources["carbonaceous rock"] = rand(3,5)
|
||||||
|
|
||||||
switch(map[get_map_cell(x,y)])
|
var/current_cell = map[get_map_cell(x,y)]
|
||||||
if(0 to 100)
|
if(current_cell < rare_val) // Surface metals.
|
||||||
T.resources["iron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
T.resources["iron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||||
T.resources["gold"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
T.resources["gold"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||||
T.resources["silver"] = 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["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||||
T.resources["diamond"] = 0
|
T.resources["diamond"] = 0
|
||||||
T.resources["phoron"] = 0
|
T.resources["phoron"] = 0
|
||||||
T.resources["osmium"] = 0
|
T.resources["osmium"] = 0
|
||||||
T.resources["hydrogen"] = 0
|
T.resources["hydrogen"] = 0
|
||||||
if(100 to 124)
|
else if(current_cell < deep_val) // Rare metals.
|
||||||
T.resources["gold"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
T.resources["gold"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||||
T.resources["silver"] = 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["uranium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||||
T.resources["phoron"] = 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["osmium"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||||
T.resources["hydrogen"] = 0
|
T.resources["hydrogen"] = 0
|
||||||
T.resources["diamond"] = 0
|
T.resources["diamond"] = 0
|
||||||
T.resources["iron"] = 0
|
T.resources["iron"] = 0
|
||||||
if(125 to 255)
|
else // Deep metals.
|
||||||
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
T.resources["uranium"] = rand(RESOURCE_LOW_MIN, RESOURCE_LOW_MAX)
|
||||||
T.resources["diamond"] = 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["phoron"] = rand(RESOURCE_HIGH_MIN, RESOURCE_HIGH_MAX)
|
||||||
T.resources["osmium"] = 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["hydrogen"] = rand(RESOURCE_MID_MIN, RESOURCE_MID_MAX)
|
||||||
T.resources["iron"] = 0
|
T.resources["iron"] = 0
|
||||||
T.resources["gold"] = 0
|
T.resources["gold"] = 0
|
||||||
T.resources["silver"] = 0
|
T.resources["silver"] = 0
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
/datum/random_map/ore/cleanup()
|
/datum/random_map/ore/cleanup()
|
||||||
return 1
|
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
|
||||||
@@ -12,9 +12,9 @@ var/global/list/random_maps = list()
|
|||||||
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()
|
///obj/item/test_randmap/maze/New()
|
||||||
new /datum/random_map/maze(input("Seed?") as text|null)
|
// new /datum/random_map/maze(input("Seed?") as text|null)
|
||||||
del(src)
|
// del(src)
|
||||||
|
|
||||||
/datum/random_map
|
/datum/random_map
|
||||||
var/descriptor = "debris field" // Display name.
|
var/descriptor = "debris field" // Display name.
|
||||||
@@ -139,6 +139,7 @@ var/global/list/random_maps = list()
|
|||||||
if((origin_x + x) > limit_x) continue
|
if((origin_x + x) > limit_x) continue
|
||||||
for(var/y = 0, y < real_size, y++)
|
for(var/y = 0, y < real_size, y++)
|
||||||
if((origin_y + y) > limit_y) continue
|
if((origin_y + y) > limit_y) continue
|
||||||
|
sleep(-1)
|
||||||
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)
|
||||||
@@ -155,4 +156,5 @@ var/global/list/random_maps = list()
|
|||||||
T.ChangeTurf(/turf/simulated/mineral)
|
T.ChangeTurf(/turf/simulated/mineral)
|
||||||
|
|
||||||
/datum/random_map/proc/cleanup()
|
/datum/random_map/proc/cleanup()
|
||||||
|
sleep(-1)
|
||||||
return 1
|
return 1
|
||||||
Reference in New Issue
Block a user