| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-03-01 13:24:11 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-03-01 13:24:11 +0100 | 
| commit | 55c32019f5b82fd488c4ceed8c80e1b7a0fa114f (patch) | |
| tree | b28565216098599b53b8cbe3619e51104c325e88 /src/struct/battlemap.erl | |
| parent | 9b413bc5936994b66f3a1c693fbbfad0995c0b93 (diff) | |
Cleaning up the handling of character turns.
Diffstat (limited to 'src/struct/battlemap.erl')
| -rw-r--r-- | src/struct/battlemap.erl | 22 | 
1 files changed, 21 insertions, 1 deletions
| diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl index 8f85bbb..9204084 100644 --- a/src/struct/battlemap.erl +++ b/src/struct/battlemap.erl @@ -30,7 +30,8 @@        get_id/1,        get_width/1,        get_height/1, -      get_tile_ids/1 +      get_tile_ids/1, +      get_tile_id/2     ]  ). @@ -65,6 +66,20 @@ generate_random_tile_ids (PreviousTileID, Result, X, Y, Width) ->        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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -81,6 +96,11 @@ 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(), | 


