summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-04-10 13:01:12 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-04-10 13:01:12 +0200 |
commit | 1001c3f6cfefd880c1721f2b80c1795197d05365 (patch) | |
tree | 8696137b5684547b80129d308bc854a7e74fa0b0 /src/struct/battlemap.erl | |
parent | d7032b408c5f66a3cb62c44cf0953abe48c39ef9 (diff) |
Changing how the server services are organized...
Diffstat (limited to 'src/struct/battlemap.erl')
-rw-r--r-- | src/struct/battlemap.erl | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl deleted file mode 100644 index 59e0639..0000000 --- a/src/struct/battlemap.erl +++ /dev/null @@ -1,121 +0,0 @@ --module(battlemap). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type id() :: binary(). - --record -( - battlemap, - { - id :: id(), - width :: integer(), - height :: integer(), - tile_ids :: array:array(tile:id()) - } -). - --opaque struct() :: #battlemap{}. - --export_type([struct/0, id/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_id/1, - get_width/1, - get_height/1, - get_tile_ids/1, - get_tile_id/2 - ] -). - --export -( - [ - random/3 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate_random_tile_ids - ( - tile:id(), - list(tile:id()), - non_neg_integer(), - non_neg_integer(), - non_neg_integer() - ) - -> list(tile:id()). -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). - --spec location_to_array_index - ( - non_neg_integer(), - location:type() - ) - -> ('error' | non_neg_integer()). -location_to_array_index (ArrayWidth, {X, Y}) -> - if - (X < 0) -> error; - (Y < 0) -> error; - (X >= ArrayWidth) -> error; - true -> ((Y * ArrayWidth) + X) - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_id (struct()) -> id(). -get_id (Battlemap) -> Battlemap#battlemap.id. - --spec get_width (struct()) -> integer(). -get_width (Battlemap) -> Battlemap#battlemap.width. - --spec get_height (struct()) -> integer(). -get_height (Battlemap) -> Battlemap#battlemap.height. - --spec get_tile_ids (struct()) -> array:array(tile:id()). -get_tile_ids (Battlemap) -> Battlemap#battlemap.tile_ids. - --spec get_tile_id (location:type(), struct()) -> tile:id(). -get_tile_id (Location, Battlemap) -> - TileIX = location_to_array_index(Battlemap#battlemap.width, Location), - array:get(TileIX, Battlemap#battlemap.tile_ids). - --spec random - ( - non_neg_integer(), - non_neg_integer(), - non_neg_integer() - ) - -> struct(). -random (ID, Width, Height) -> - InitialTile = tile:random_id(), - TileIDs = generate_random_tile_ids(InitialTile, [], Width, Height, Width), - - #battlemap - { - id = list_to_binary(integer_to_list(ID)), - width = Width, - height = Height, - tile_ids = array:from_list(TileIDs) - }. |