From 46d5ee83311ff0b26aa0930fdc39785663179cf2 Mon Sep 17 00:00:00 2001 From: Elronnd Date: Thu, 23 Nov 2017 22:20:49 -0800 Subject: [PATCH] Rennovate mapgen internal api. Now you're more likely to encounter one of smuglerl's signature wide open caves. Also committing because this commit breaks gdc --- src/item.d | 4 +++- src/mapgen.d | 55 +++++++++++++++++++++++++++---------------------------- src/util.d | 4 ++-- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/item.d b/src/item.d index 6e94ef8..5d0df38 100644 --- a/src/item.d +++ b/src/item.d @@ -19,7 +19,9 @@ struct Item { void delegate(ref Item self, Graphics1 graphics) _on_pick_up; void delegate(ref Item self, Graphics1 grahpics) _on_use; - mixin funcwrappers!(_on_pick_up, _on_use); + mixin funcwrapper!_on_pick_up; + mixin funcwrapper!_on_use; +// mixin funcwrappers!(_on_pick_up, _on_use); } Item[] items; diff --git a/src/mapgen.d b/src/mapgen.d index 6f12873..c0c0d0e 100644 --- a/src/mapgen.d +++ b/src/mapgen.d @@ -4,7 +4,9 @@ import std.random: uniform; import util; // 1/a chance of any tile being walkable -private void map_random(Tile[][] map, int[] flags) { +private Tile[][] map_random(int[] flags) { + Tile[][] map = newmap(); + uint a, b; a = 1; b = 2; @@ -26,6 +28,8 @@ private void map_random(Tile[][] map, int[] flags) { map[tmpy][tmpx].blocks_light = !map[tmpy][tmpx].walkable; } } + + return map; } private void mapcaves_postprocess(Tile[][] map) { @@ -39,8 +43,11 @@ private void mapcaves_postprocess(Tile[][] map) { } } -private void real_map_caves(Tile[][] map, int[] flags, int iters = 1000) { +private Tile[][] real_map_caves(Tile[][] init, int[] flags, int iters = 100) { import std.stdio; + + Tile[][] map = init ? init.dup : newmap(); + enum Direction: bool {y = true, x = false} enum Sign: bool {plus = true, minus = false} bool d = Direction.x; @@ -60,20 +67,17 @@ private void real_map_caves(Tile[][] map, int[] flags, int iters = 1000) { foreach (_; 0..uniform(8000, 9000)) { foreach (__; 0..uniform(3, 20)) { - // we hit an edge, reverse direction + // we hit an edge, start over if ((tmpx >= map_x) || (tmpy >= map_y)) { - s = Sign.minus; - continue; + return real_map_caves(init, flags, iters); } else if ((tmpx <= 2) || (tmpy <= 2)) { - s = Sign.plus; - continue; + return real_map_caves(init, flags, iters); } foreach (i; tmpx-uniform(-1, 3)..tmpx+uniform(-1, 3)) { // we hit an edge, try again if ((i > map_x) || (i < 2)) { - map_caves(map, []); - return; + return real_map_caves(init, flags, iters); } map[tmpy][i].walkable = true; map[tmpy][i].blocks_light = false; @@ -81,8 +85,7 @@ private void real_map_caves(Tile[][] map, int[] flags, int iters = 1000) { foreach (i; tmpy-uniform(-1, 3)..tmpy+uniform(-1, 3)) { // ditto if ((i > map_y) || (i < 2)) { - map_caves(map, []); - return; + return real_map_caves(init, flags, iters); } map[i][tmpx].walkable = true; map[i][tmpx].blocks_light = false; @@ -110,19 +113,21 @@ private void real_map_caves(Tile[][] map, int[] flags, int iters = 1000) { } } -/+ if (chances(iters, 1001)) { - map_caves(g, [], iters-1); - }+/ +/* if (chances(iters, 1001)) { + return real_map_caves(map, flags, iters--); + } else {*/ + return map; + /*}*/ } -private void map_caves(Tile[][] map, int[] flags) { - real_map_caves(map, flags); - real_map_caves(map, flags); - real_map_caves(map, flags); +private Tile[][] map_caves(int[] flags) { + Tile[][] map = real_map_caves(null, flags); mapcaves_postprocess(map); mapcaves_postprocess(map); - mapcaves_postprocess(map); + //mapcaves_postprocess(map); + + return map; } @@ -150,16 +155,10 @@ private void veriflags(MapType type, ulong flags) { Tile[][] genmap(MapType type, int[] flags = []) { veriflags(type, flags.length); - Tile[][] ret = newmap(); + switch(type) { - case MapType.random: - map_random(ret, flags); - break; - case MapType.caves: - map_caves(ret, flags); - break; + case MapType.random: return map_random(flags); + case MapType.caves: return map_caves(flags); default: assert(0); } - - return ret; } diff --git a/src/util.d b/src/util.d index 608f7c0..350d330 100644 --- a/src/util.d +++ b/src/util.d @@ -18,11 +18,11 @@ mixin template funcwrapper(alias func) { ~ __traits(identifier, func) ~ "(this, args);" ~ "}"); } -mixin template funcwrappers(funcs...) { +/*mixin template funcwrappers(funcs...) { static foreach (func; funcs) { mixin funcwrapper!func; } -} +}*/ // example: /* -- 2.11.4.GIT