mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
[MIRROR] Backports Bay/Neb random map optimizations.
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
#define CELL_ALIVE(VAL) (VAL == cell_live_value)
|
||||
#define KILL_CELL(CELL, NEXT_MAP) NEXT_MAP[CELL] = cell_dead_value;
|
||||
#define REVIVE_CELL(CELL, NEXT_MAP) NEXT_MAP[CELL] = cell_live_value;
|
||||
|
||||
/datum/random_map/automata
|
||||
descriptor = "generic caves"
|
||||
initial_wall_cell = 55
|
||||
@@ -8,58 +12,60 @@
|
||||
|
||||
// Automata-specific procs and processing.
|
||||
/datum/random_map/automata/generate_map()
|
||||
for(var/i=1;i<=iterations;i++)
|
||||
iterate(i)
|
||||
for(var/iter = 1 to iterations)
|
||||
var/list/next_map[limit_x*limit_y]
|
||||
var/count
|
||||
var/is_not_border_left
|
||||
var/is_not_border_right
|
||||
var/ilim_u
|
||||
var/ilim_d
|
||||
var/bottom_lim = ((limit_y - 1) * limit_x)
|
||||
|
||||
/datum/random_map/automata/get_additional_spawns(var/value, var/turf/T)
|
||||
return
|
||||
if (!islist(map))
|
||||
set_map_size()
|
||||
|
||||
/datum/random_map/automata/proc/iterate(var/iteration)
|
||||
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/count = 0
|
||||
for (var/i in 1 to (limit_x * limit_y))
|
||||
count = 0
|
||||
|
||||
// Every attempt to place this in a proc or a list has resulted in
|
||||
// the generator being totally bricked and useless. Fuck it. We're
|
||||
// hardcoding this shit. Feel free to rewrite and PR a fix. ~ Z
|
||||
var/tmp_cell = get_map_cell(x,y)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x+1,y+1)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x-1,y-1)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x+1,y-1)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x-1,y+1)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x-1,y)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x,y-1)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x+1,y)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
tmp_cell = get_map_cell(x,y+1)
|
||||
if(tmp_cell && cell_is_alive(map[tmp_cell])) count++
|
||||
is_not_border_left = i != 1 && ((i - 1) % limit_x)
|
||||
is_not_border_right = i % limit_x
|
||||
|
||||
if (CELL_ALIVE(map[i])) // Center row.
|
||||
++count
|
||||
if (is_not_border_left && CELL_ALIVE(map[i - 1]))
|
||||
++count
|
||||
if (is_not_border_right && CELL_ALIVE(map[i + 1]))
|
||||
++count
|
||||
|
||||
if (i > limit_x) // top row
|
||||
ilim_u = i - limit_x
|
||||
if (CELL_ALIVE(map[ilim_u]))
|
||||
++count
|
||||
if (is_not_border_left && CELL_ALIVE(map[ilim_u - 1]))
|
||||
++count
|
||||
if (is_not_border_right && CELL_ALIVE(map[ilim_u + 1]))
|
||||
++count
|
||||
|
||||
if (i <= bottom_lim) // bottom row
|
||||
ilim_d = i + limit_x
|
||||
if (CELL_ALIVE(map[ilim_d]))
|
||||
++count
|
||||
if (is_not_border_left && CELL_ALIVE(map[ilim_d - 1]))
|
||||
++count
|
||||
if (is_not_border_right && CELL_ALIVE(map[ilim_d + 1]))
|
||||
++count
|
||||
|
||||
if(count >= cell_threshold)
|
||||
revive_cell(current_cell, next_map, (iteration == iterations))
|
||||
else
|
||||
kill_cell(current_cell, next_map, (iteration == iterations))
|
||||
map = next_map
|
||||
REVIVE_CELL(i, next_map)
|
||||
else // Nope. Can't be alive. Kill it.
|
||||
KILL_CELL(i, next_map)
|
||||
|
||||
// Check if a given tile counts as alive for the automata generations.
|
||||
/datum/random_map/automata/proc/cell_is_alive(var/value)
|
||||
return (value == cell_live_value) && (value != cell_dead_value)
|
||||
CHECK_TICK
|
||||
|
||||
/datum/random_map/automata/proc/revive_cell(var/target_cell, var/list/use_next_map, var/final_iter)
|
||||
if(!use_next_map)
|
||||
use_next_map = map
|
||||
use_next_map[target_cell] = cell_live_value
|
||||
map = next_map
|
||||
|
||||
/datum/random_map/automata/proc/kill_cell(var/target_cell, var/list/use_next_map, var/final_iter)
|
||||
if(!use_next_map)
|
||||
use_next_map = map
|
||||
use_next_map[target_cell] = cell_dead_value
|
||||
/datum/random_map/automata/get_additional_spawns(value, turf/T)
|
||||
return
|
||||
|
||||
#undef KILL_CELL
|
||||
#undef REVIVE_CELL
|
||||
@@ -18,28 +18,36 @@
|
||||
return "X"
|
||||
return ..(value)
|
||||
|
||||
/datum/random_map/automata/cave_system/revive_cell(var/target_cell, var/list/use_next_map, var/final_iter)
|
||||
..()
|
||||
if(final_iter)
|
||||
ore_turfs |= target_cell
|
||||
|
||||
/datum/random_map/automata/cave_system/kill_cell(var/target_cell, var/list/use_next_map, var/final_iter)
|
||||
..()
|
||||
if(final_iter)
|
||||
ore_turfs -= target_cell
|
||||
|
||||
// Create ore turfs.
|
||||
/datum/random_map/automata/cave_system/cleanup()
|
||||
var/tmp_cell
|
||||
for (var/x = 1 to limit_x)
|
||||
for (var/y = 1 to limit_y)
|
||||
tmp_cell = TRANSLATE_COORD(x, y)
|
||||
if (CELL_ALIVE(map[tmp_cell]))
|
||||
ore_turfs += tmp_cell
|
||||
|
||||
testing("ASGEN: Found [ore_turfs.len] ore turfs.")
|
||||
var/ore_count = round(map.len/20)
|
||||
var/door_count = 0
|
||||
var/empty_count = 0
|
||||
while((ore_count>0) && (ore_turfs.len>0))
|
||||
if(!priority_process) sleep(-1)
|
||||
|
||||
if(!priority_process)
|
||||
CHECK_TICK
|
||||
|
||||
var/check_cell = pick(ore_turfs)
|
||||
ore_turfs -= check_cell
|
||||
if(prob(75))
|
||||
map[check_cell] = DOOR_CHAR // Mineral block
|
||||
door_count += 1
|
||||
else
|
||||
map[check_cell] = EMPTY_CHAR // Rare mineral block.
|
||||
empty_count += 1
|
||||
ore_count--
|
||||
|
||||
testing("ASGEN: Set [door_count] turfs to random minerals.")
|
||||
testing("ASGEN: Set [empty_count] turfs to high-chance random minerals.")
|
||||
return 1
|
||||
|
||||
/datum/random_map/automata/cave_system/apply_to_turf(var/x,var/y)
|
||||
|
||||
Reference in New Issue
Block a user