mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 02:34:00 +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:
65
code/modules/random_map/automata/automata.dm
Normal file
65
code/modules/random_map/automata/automata.dm
Normal file
@@ -0,0 +1,65 @@
|
||||
/datum/random_map/automata
|
||||
descriptor = "generic caves"
|
||||
initial_wall_cell = 55
|
||||
var/iterations = 0 // Number of times to apply the automata rule.
|
||||
var/cell_live_value = WALL_CHAR // Cell is alive if it has this value.
|
||||
var/cell_dead_value = FLOOR_CHAR // As above for death.
|
||||
var/cell_threshold = 5 // Cell becomes alive with this many live neighbors.
|
||||
|
||||
// Automata-specific procs and processing.
|
||||
/datum/random_map/automata/generate_map()
|
||||
for(var/i=1;i<=iterations;i++)
|
||||
iterate(i)
|
||||
|
||||
/datum/random_map/automata/get_additional_spawns(var/value, var/turf/T)
|
||||
return
|
||||
|
||||
/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
|
||||
|
||||
// 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++
|
||||
|
||||
if(count >= cell_threshold)
|
||||
revive_cell(current_cell, next_map, (iteration == iterations))
|
||||
else
|
||||
kill_cell(current_cell, next_map, (iteration == iterations))
|
||||
map = 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)
|
||||
|
||||
/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
|
||||
|
||||
/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
|
||||
52
code/modules/random_map/automata/caves.dm
Normal file
52
code/modules/random_map/automata/caves.dm
Normal file
@@ -0,0 +1,52 @@
|
||||
/datum/random_map/automata/cave_system
|
||||
iterations = 5
|
||||
descriptor = "moon caves"
|
||||
wall_type = /turf/simulated/mineral
|
||||
floor_type = /turf/simulated/floor/plating/airless/asteroid
|
||||
target_turf_type = /turf/unsimulated/mask
|
||||
var/mineral_sparse = /turf/simulated/mineral/random
|
||||
var/mineral_rich = /turf/simulated/mineral/random/high_chance
|
||||
var/list/ore_turfs = list()
|
||||
|
||||
/datum/random_map/automata/cave_system/get_appropriate_path(var/value)
|
||||
switch(value)
|
||||
if(DOOR_CHAR)
|
||||
return mineral_sparse
|
||||
if(EMPTY_CHAR)
|
||||
return mineral_rich
|
||||
if(FLOOR_CHAR)
|
||||
return floor_type
|
||||
if(WALL_CHAR)
|
||||
return wall_type
|
||||
|
||||
/datum/random_map/automata/cave_system/get_map_char(var/value)
|
||||
switch(value)
|
||||
if(DOOR_CHAR)
|
||||
return "x"
|
||||
if(EMPTY_CHAR)
|
||||
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/ore_count = round(map.len/20)
|
||||
while((ore_count>0) && (ore_turfs.len>0))
|
||||
if(!priority_process) sleep(-1)
|
||||
var/check_cell = pick(ore_turfs)
|
||||
ore_turfs -= check_cell
|
||||
if(prob(75))
|
||||
map[check_cell] = DOOR_CHAR // Mineral block
|
||||
else
|
||||
map[check_cell] = EMPTY_CHAR // Rare mineral block.
|
||||
ore_count--
|
||||
return 1
|
||||
Reference in New Issue
Block a user