From 711abc4ecf67063706ed28bf1384559351b239bf Mon Sep 17 00:00:00 2001 From: AnturK Date: Tue, 15 Dec 2015 19:58:35 +0100 Subject: [PATCH] Adds two CA mapGenerators --- .../mapGenerators/cellular.dm | 98 +++++++++++++++++++ tgstation.dme | 1 + 2 files changed, 99 insertions(+) create mode 100644 code/modules/procedural mapping/mapGenerators/cellular.dm diff --git a/code/modules/procedural mapping/mapGenerators/cellular.dm b/code/modules/procedural mapping/mapGenerators/cellular.dm new file mode 100644 index 00000000000..5e23272a703 --- /dev/null +++ b/code/modules/procedural mapping/mapGenerators/cellular.dm @@ -0,0 +1,98 @@ +// Very Simple Cellular Automata generators +// Mostly for better caves +// Should probably move these up and refactor modules so these can be mixed with other ones + +/datum/mapGenerator/ca + var/list/b_rule = list() // 0 -> 1, 1 -> 1 + var/list/s_rule = list() // 0 -> 0, 1 -> 1 + var/iterations = 1 + var/loop_edges = 0 + var/edge_value = 1 //if loop_edges = 0 + var/list/old_state + var/list/current_state + var/width = 10 + var/height = 10 + var/list/type_map = list(/turf/simulated/floor/plating,/turf/simulated/wall) + var/turf/start = null + +/datum/mapGenerator/ca/defineRegion(turf/Start, turf/End, replace = 0) + . = ..() + + var/min_x = min(Start.x,End.x) + var/max_x = max(Start.x,End.x) + var/min_y = min(Start.y,End.y) + var/max_y = max(Start.y,End.y) + width = max_x - min_x + height = max_y - min_y + + //We assume 2D everywhere anyway + start = locate(min_x,min_y,Start.z) + +/datum/mapGenerator/ca/proc/initialize() + old_state = new/list(width) + for(var/i = 1,i<=width,i++) + old_state[i] = new/list(height) + for(var/j = 1,j<=height,j++) + old_state[i][j] = rand(0,1) + + current_state = old_state.Copy() + +/datum/mapGenerator/ca/generate() + set background = 1 + + //Abandon all hope for efficency all who enter here + //Maybe some less basic implemetation later, but this is just simple admin tool + initialize() + + for(var/generation = 0,generation width || n_y <1 || n_y > height) + if(loop_edges) + if(n_x < 1) + n_x = width + else if(n_x > width) + n_x = 1 + if(n_y < 1) + n_y = height + else if(n_y > height) + n_y = 1 + else + value += edge_value + continue + value += old_state[n_x][n_y] + value -= old_state[i][j] + + if(value in b_rule) + return 1 + if(value in s_rule) + return old_state[i][j] + return 0 + +/datum/mapGenerator/ca/caves + b_rule = list(5,6,7,8) + s_rule = list(4) + type_map = list(/turf/simulated/floor/plating/asteroid/basalt,/turf/simulated/mineral/volcanic) + iterations = 5 + +/datum/mapGenerator/ca/maze + b_rule = list(3) + s_rule = list(1,2,3,4,5) + iterations = 20 + edge_value = 0 \ No newline at end of file diff --git a/tgstation.dme b/tgstation.dme index 208ea0314d9..9d294c219d6 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -1447,6 +1447,7 @@ #include "code\modules\procedural mapping\mapGeneratorModules\helpers.dm" #include "code\modules\procedural mapping\mapGeneratorModules\nature.dm" #include "code\modules\procedural mapping\mapGenerators\asteroid.dm" +#include "code\modules\procedural mapping\mapGenerators\cellular.dm" #include "code\modules\procedural mapping\mapGenerators\nature.dm" #include "code\modules\procedural mapping\mapGenerators\shuttle.dm" #include "code\modules\procedural mapping\mapGenerators\syndicate.dm"