| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/struct/character_instance.erl')
| -rw-r--r-- | src/struct/character_instance.erl | 49 | 
1 files changed, 45 insertions, 4 deletions
| diff --git a/src/struct/character_instance.erl b/src/struct/character_instance.erl index e736a4c..9b64f9a 100644 --- a/src/struct/character_instance.erl +++ b/src/struct/character_instance.erl @@ -7,13 +7,17 @@  (     character_instance,     { -      character, -      location, -      current_health, -      active +      character :: character:struct(), +      location :: {non_neg_integer(), non_neg_integer()}, +      current_health :: non_neg_integer(), +      active :: boolean()     }  ). +-opaque struct() :: #character_instance{}. + +-export_type([struct/0]). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -44,6 +48,13 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec find_random_location +   ( +      non_neg_integer(), +      non_neg_integer(), +      list({non_neg_integer(), non_neg_integer()}) +   ) +   -> {non_neg_integer(), non_neg_integer()}.  find_random_location (BattlemapWidth, BattlemapHeight, ForbiddenLocations) ->     X = roll:between(0, (BattlemapWidth - 1)),     Y = roll:between(0, (BattlemapHeight - 1)), @@ -66,9 +77,16 @@ find_random_location (BattlemapWidth, BattlemapHeight, ForbiddenLocations) ->  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%% Accessors +-spec get_character (struct()) -> character:struct().  get_character (CharInst) -> CharInst#character_instance.character. + +-spec get_location (struct()) -> {non_neg_integer(), non_neg_integer()}.  get_location (CharInst) -> CharInst#character_instance.location. + +-spec get_current_health (struct()) -> non_neg_integer().  get_current_health (CharInst) -> CharInst#character_instance.current_health. + +-spec get_is_active (struct()) -> boolean().  get_is_active (CharInst) ->     (        CharInst#character_instance.active @@ -76,24 +94,33 @@ get_is_active (CharInst) ->        (CharInst#character_instance.current_health > 0)     ). +-spec set_character (character:struct(), struct()) -> struct().  set_character (Char, CharInst) ->     CharInst#character_instance     {        character = Char     }. +-spec set_location +   ( +      {non_neg_integer(), non_neg_integer()}, +      struct() +   ) +   -> struct().  set_location (Location, CharInst) ->     CharInst#character_instance     {        location = Location     }. +-spec set_current_health (non_neg_integer(), struct()) -> struct().  set_current_health (Health, CharInst) ->     CharInst#character_instance     {        current_health = Health     }. +-spec set_is_active (boolean(), struct()) -> struct().  set_is_active (Active, CharInst) ->     CharInst#character_instance     { @@ -101,6 +128,12 @@ set_is_active (Active, CharInst) ->     }.  %%%% Utils +-spec new +   ( +      character:struct(), +      {non_neg_integer(), non_neg_integer()} +   ) +   -> struct().  new (Character, Location) ->     CharacterStatistics = character:get_statistics(Character),     #character_instance @@ -111,6 +144,14 @@ new (Character, Location) ->        active = false     }. +-spec random +   ( +      character:struct(), +      non_neg_integer(), +      non_neg_integer(), +      list({non_neg_integer(), non_neg_integer()}) +   ) +   -> struct().  random (Character, BattlemapWidth, BattlemapHeight, ForbiddenLocations) ->     new     ( | 


