summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-26 13:52:29 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-26 13:52:29 +0100
commitfd4d031ab5b31763d376c663cc049f62ee389243 (patch)
treecd09a29bb888acf772fa1aee59fe95e8bd75fe4e /src/struct/battlemap.erl
parent66ec11ce5d2e227846d6e6b2899cda851a70fc04 (diff)
Got it to run, at last.
Diffstat (limited to 'src/struct/battlemap.erl')
-rw-r--r--src/struct/battlemap.erl31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl
index b0eb5fb..b999436 100644
--- a/src/struct/battlemap.erl
+++ b/src/struct/battlemap.erl
@@ -27,9 +27,28 @@
get_tile_ids/1
]
).
+
+-export
+(
+ [
+ random/3
+ ]
+).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+generate_random_tile_ids (_PreviousTileID, Result, _X, 0, _Width) ->
+ Result;
+generate_random_tile_ids (PreviousTileID, Result, 0, Y, Width) ->
+ generate_random_tile_ids(PreviousTileID, Result, Width, (Y - 1), Width);
+generate_random_tile_ids (PreviousTileID, Result, X, Y, Width) ->
+ NewTile =
+ case roll:percentage() of
+ N when (N >= 10) -> PreviousTileID;
+ _ -> tile:random_id()
+ end,
+ generate_random_tile_ids(NewTile, [NewTile|Result], (X - 1), Y, Width).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -39,3 +58,15 @@ get_id (Battlemap) -> Battlemap#battlemap.id.
get_width (Battlemap) -> Battlemap#battlemap.width.
get_height (Battlemap) -> Battlemap#battlemap.height.
get_tile_ids (Battlemap) -> Battlemap#battlemap.tile_ids.
+
+random (ID, Width, Height) ->
+ InitialTile = tile:random_id(),
+ TileIDs = generate_random_tile_ids(InitialTile, [], Width, Height, Width),
+
+ #battlemap
+ {
+ id = ID,
+ width = Width,
+ height = Height,
+ tile_ids = TileIDs
+ }.