summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-27 14:16:16 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-27 14:16:16 +0100
commit292022649270d36c8ab0c813e4d7e07f3e067231 (patch)
tree8e25f8c3e5db7f6bae7001d405f24e29115750f3 /src/struct
parentbe9a65dd6d24ca8e7006c0b8825a3fa46419e201 (diff)
Starting to specify types everywhere...
Diffstat (limited to 'src/struct')
-rw-r--r--src/struct/attributes.erl57
-rw-r--r--src/struct/battlemap.erl31
-rw-r--r--src/struct/battlemap_instance.erl58
-rw-r--r--src/struct/character.erl57
-rw-r--r--src/struct/tile.erl4
5 files changed, 170 insertions, 37 deletions
diff --git a/src/struct/attributes.erl b/src/struct/attributes.erl
index bb68032..6728831 100644
--- a/src/struct/attributes.erl
+++ b/src/struct/attributes.erl
@@ -7,15 +7,19 @@
(
attributes,
{
- constitution,
- dexterity,
- intelligence,
- mind,
- speed,
- strength
+ constitution :: integer(),
+ dexterity :: integer(),
+ intelligence :: integer(),
+ mind :: integer(),
+ speed :: integer(),
+ strength :: integer()
}
).
+-opaque struct() :: #attributes{}.
+
+-export_type([struct/0]).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -55,26 +59,43 @@
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
+-spec get_constitution (struct()) -> integer().
get_constitution (Att) -> Att#attributes.constitution.
+
+-spec get_dexterity (struct()) -> integer().
get_dexterity (Att) -> Att#attributes.dexterity.
+
+-spec get_intelligence (struct()) -> integer().
get_intelligence (Att) -> Att#attributes.intelligence.
+
+-spec get_mind (struct()) -> integer().
get_mind (Att) -> Att#attributes.mind.
+
+-spec get_speed (struct()) -> integer().
get_speed (Att) -> Att#attributes.speed.
+
+-spec get_strength (struct()) -> integer().
get_strength (Att) -> Att#attributes.strength.
-set_constitution (Val, Att) ->
- Att#attributes{ constitution = Val }.
-set_dexterity (Val, Att) ->
- Att#attributes{ dexterity = Val }.
-set_intelligence (Val, Att) ->
- Att#attributes{ intelligence = Val }.
-set_mind (Val, Att) ->
- Att#attributes{ mind = Val }.
-set_speed (Val, Att) ->
- Att#attributes{ speed = Val }.
-set_strength (Val, Att) ->
- Att#attributes{ strength = Val }.
+-spec set_constitution (integer(), struct()) -> struct().
+set_constitution (Val, Att) -> Att#attributes{ constitution = Val }.
+
+-spec set_dexterity (integer(), struct()) -> struct().
+set_dexterity (Val, Att) -> Att#attributes{ dexterity = Val }.
+
+-spec set_intelligence (integer(), struct()) -> struct().
+set_intelligence (Val, Att) -> Att#attributes{ intelligence = Val }.
+
+-spec set_mind (integer(), struct()) -> struct().
+set_mind (Val, Att) -> Att#attributes{ mind = Val }.
+
+-spec set_speed (integer(), struct()) -> struct().
+set_speed (Val, Att) -> Att#attributes{ speed = Val }.
+
+-spec set_strength (integer(), struct()) -> struct().
+set_strength (Val, Att) -> Att#attributes{ strength = Val }.
+-spec random () -> struct().
random () ->
#attributes
{
diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl
index 733f76c..76f8fd4 100644
--- a/src/struct/battlemap.erl
+++ b/src/struct/battlemap.erl
@@ -3,17 +3,23 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-opaque id() :: binary().
+
-record
(
battlemap,
{
- id,
- width,
- height,
- tile_ids
+ id :: id(),
+ width :: integer(),
+ height :: integer(),
+ tile_ids :: array:array(tile:id())
}
).
+-opaque struct() :: #battlemap{}.
+
+-export_type([struct/0, id/0]).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -38,6 +44,15 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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) ->
@@ -54,11 +69,19 @@ generate_random_tile_ids (PreviousTileID, Result, X, Y, Width) ->
%% 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 random (id(), non_neg_integer(), non_neg_integer()) -> struct().
random (ID, Width, Height) ->
InitialTile = tile:random_id(),
TileIDs = generate_random_tile_ids(InitialTile, [], Width, Height, Width),
diff --git a/src/struct/battlemap_instance.erl b/src/struct/battlemap_instance.erl
index bae7a4a..c3b411b 100644
--- a/src/struct/battlemap_instance.erl
+++ b/src/struct/battlemap_instance.erl
@@ -3,19 +3,25 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-opaque id() :: binary().
+
-record
(
battlemap_instance,
{
- id,
- battlemap,
- character_instances,
- player_ids,
- current_player_turn,
- last_turns_effects
+ id :: id(),
+ battlemap :: battlemap:struct(),
+ character_instances :: array:array(character_instance:struct()),
+ player_ids :: array:array(player:id()),
+ current_player_turn :: player_turn:struct(),
+ last_turns_effects :: list(any())
}
).
+-opaque struct() :: #battlemap_instance{}.
+
+-export_type([struct/0, id/0]).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -53,53 +59,93 @@
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
+-spec get_id (struct()) -> id().
get_id (BattlemapInstance) -> BattlemapInstance#battlemap_instance.id.
+-spec get_battlemap (struct()) -> battlemap:struct().
get_battlemap (BattlemapInstance) ->
BattlemapInstance#battlemap_instance.battlemap.
+-spec get_character_instances (struct()) ->
+ array:array(character_instance:struct()).
get_character_instances (BattlemapInstance) ->
BattlemapInstance#battlemap_instance.character_instances.
+-spec get_player_ids (struct()) -> array:array(player:id()).
get_player_ids (BattlemapInstance) ->
BattlemapInstance#battlemap_instance.player_ids.
+-spec get_current_player_turn (struct()) -> player_turn:struct().
get_current_player_turn (BattlemapInstance) ->
BattlemapInstance#battlemap_instance.current_player_turn.
+-spec get_last_turns_effects (struct()) -> list(any()).
get_last_turns_effects (BattlemapInstance) ->
BattlemapInstance#battlemap_instance.last_turns_effects.
+-spec set_battlemap (battlemap:struct(), struct()) -> struct().
set_battlemap (Battlemap, BattlemapInstance) ->
BattlemapInstance#battlemap_instance
{
battlemap = Battlemap
}.
+-spec set_character_instances
+ (
+ array:array(character_instance:struct()),
+ struct()
+ )
+ -> struct().
set_character_instances (CharacterInstances, BattlemapInstance) ->
BattlemapInstance#battlemap_instance
{
character_instances = CharacterInstances
}.
+-spec set_player_ids
+ (
+ array:array(player:id()),
+ struct()
+ )
+ -> struct().
set_player_ids (Players, BattlemapInstance) ->
BattlemapInstance#battlemap_instance
{
player_ids = Players
}.
+-spec set_current_player_turn
+ (
+ player_turn:struct(),
+ struct()
+ )
+ -> struct().
set_current_player_turn (PlayerTurn, BattlemapInstance) ->
BattlemapInstance#battlemap_instance
{
current_player_turn = PlayerTurn
}.
+-spec set_last_turns_effects
+ (
+ list(any()),
+ struct()
+ )
+ -> struct().
set_last_turns_effects (Effects, BattlemapInstance) ->
BattlemapInstance#battlemap_instance
{
last_turns_effects = Effects
}.
+-spec random
+ (
+ id(),
+ list(player:id()),
+ battlemap:struct(),
+ list(character:struct())
+ )
+ -> struct().
random (ID, PlayersAsList, Battlemap, Characters) ->
BattlemapWidth = battlemap:get_width(Battlemap),
BattlemapHeight = battlemap:get_height(Battlemap),
diff --git a/src/struct/character.erl b/src/struct/character.erl
index 90e449c..3ee9a31 100644
--- a/src/struct/character.erl
+++ b/src/struct/character.erl
@@ -3,22 +3,27 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-opaque id() :: integer().
+
-record
(
character,
{
- id,
- owner_id,
- name,
- icon,
- portrait,
- attributes,
- statistics,
- glyphs,
- weapon_ids
+ id :: id(),
+ owner_id :: player:id(),
+ name :: binary(),
+ icon :: binary(),
+ portrait :: binary(),
+ attributes :: attributes:struct(),
+ statistics :: statistics:struct(),
+ glyphs :: list(glyph:id()),
+ weapon_ids :: {weapon:id(), weapon:id()}
}
).
+-opaque struct() :: #character{}.
+
+-export_type([struct/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -56,29 +61,63 @@
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
+-spec get_id (struct()) -> id().
get_id (Char) -> Char#character.id.
+
+-spec get_owner_id (struct()) -> player:id().
get_owner_id (Char) -> Char#character.owner_id.
+
+-spec get_name (struct()) -> binary().
get_name (Char) -> Char#character.name.
+
+-spec get_icon (struct()) -> binary().
get_icon (Char) -> Char#character.icon.
+
+-spec get_portrait (struct()) -> binary().
get_portrait (Char) -> Char#character.portrait.
+
+-spec get_attributes (struct()) -> attributes:struct().
get_attributes (Char) -> Char#character.attributes.
+
+-spec get_weapon_ids (struct()) -> {weapon:id(), weapon:id()}.
get_weapon_ids (Char) -> Char#character.weapon_ids.
+
+-spec get_glyphs (struct()) -> list(glyph:id()).
get_glyphs (Char) -> Char#character.glyphs.
+-spec get_statistics (struct()) -> statistics:struct().
get_statistics (Char) -> Char#character.statistics.
+-spec set_weapon_ids
+ (
+ {weapon:id(), weapon:id()},
+ struct()
+ )
+ -> struct().
set_weapon_ids (WeaponIDs, Char) ->
Char#character
{
weapon_ids = WeaponIDs
}.
+-spec set_statistics
+ (
+ statistics:struct(),
+ struct()
+ )
+ -> struct().
set_statistics (Stats, Char) ->
Char#character
{
statistics = Stats
}.
+-spec random
+ (
+ id(),
+ player:id()
+ )
+ -> struct().
random (ID, OwnerID) ->
WeaponIDs = {weapon:random_id(), weapon:random_id()},
Attributes = attributes:random(),
diff --git a/src/struct/tile.erl b/src/struct/tile.erl
index 05da3ec..299481b 100644
--- a/src/struct/tile.erl
+++ b/src/struct/tile.erl
@@ -3,7 +3,10 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-opaque id() :: integer().
+-opaque struct() :: integer().
+-export_type([struct/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -37,5 +40,6 @@ get_cost (N) ->
true -> cost_when_oob()
end.
+-spec random_id () -> id().
random_id () ->
roll:between(0, 15).