From fd4d031ab5b31763d376c663cc049f62ee389243 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 26 Feb 2018 13:52:29 +0100 Subject: Got it to run, at last. --- src/struct/battlemap.erl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/struct/battlemap.erl') 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 + }. -- cgit v1.2.3-70-g09d2