| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/battlemap/movement.erl | 43 | ||||
| -rw-r--r-- | src/battlemap/roll.erl | 2 | ||||
| -rw-r--r-- | src/struct/character.erl | 8 | ||||
| -rw-r--r-- | src/struct/character_instance.erl | 49 | ||||
| -rw-r--r-- | src/struct/glyph.erl | 45 | ||||
| -rw-r--r-- | src/struct/player_turn.erl | 11 | ||||
| -rw-r--r-- | src/struct/statistics.erl | 66 | ||||
| -rw-r--r-- | src/struct/tile.erl | 6 | ||||
| -rw-r--r-- | src/struct/weapon.erl | 110 | 
9 files changed, 233 insertions, 107 deletions
| diff --git a/src/battlemap/movement.erl b/src/battlemap/movement.erl index 513d032..9eb45db 100644 --- a/src/battlemap/movement.erl +++ b/src/battlemap/movement.erl @@ -7,7 +7,6 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -  -export  (     [ @@ -19,6 +18,13 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec location_after_step +   ( +      binary(), +      integer(), +      integer() +   ) +   -> {integer(), integer()}.  location_after_step (Step, X, Y) ->     case Step of        <<"L">> -> {(X - 1), Y}; @@ -27,10 +33,17 @@ location_after_step (Step, X, Y) ->        <<"D">> -> {X, (Y + 1)}     end. +-spec location_to_array_index +   ( +      non_neg_integer(), +      integer(), +      integer() +   ) +   -> ('error' | non_neg_integer()).  location_to_array_index (ArrayWidth, X, Y) ->     if -      (X < 0) -> -1; -      (Y < 0) -> -1; +      (X < 0) -> error; +      (Y < 0) -> error;        (X >= ArrayWidth) -> error;        true -> ((Y * ArrayWidth) + X)     end. @@ -38,6 +51,16 @@ location_to_array_index (ArrayWidth, X, Y) ->  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec cross +   ( +      battlemap:struct(), +      array:array(non_neg_integer(), non_neg_integer()), +      list(binary()), +      non_neg_integer(), +      non_neg_integer(), +      non_neg_integer() +   ) +   -> {{non_neg_integer(), non_neg_integer()}, non_neg_integer()}.  cross (_Battlemap, _ForbiddenLocations, [], Cost, X, Y) ->     {{X, Y}, Cost};  cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, X, Y) -> @@ -63,8 +86,22 @@ cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, X, Y) ->     cross(Battlemap, ForbiddenLocations, NextSteps, NextCost, NextX, NextY). +-spec cross +   ( +      battlemap:struct(), +      array:array(non_neg_integer(), non_neg_integer()), +      list(binary()), +      {non_neg_integer(), non_neg_integer()} +   ) +   -> {{non_neg_integer(), non_neg_integer()}, non_neg_integer()}.  cross (Battlemap, ForbiddenLocations, Path, {X, Y}) ->     cross(Battlemap, ForbiddenLocations, Path, 0, X, Y). +-spec steps_between +   ( +      {non_neg_integer(), non_neg_integer()}, +      {non_neg_integer(), non_neg_integer()} +   ) +   -> non_neg_integer().  steps_between ({OX, OY}, {DX, DY}) ->     (abs(DY - OY) + abs(DX - OX)). diff --git a/src/battlemap/roll.erl b/src/battlemap/roll.erl index 803a6de..074054b 100644 --- a/src/battlemap/roll.erl +++ b/src/battlemap/roll.erl @@ -22,9 +22,11 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec between (non_neg_integer(), non_neg_integer()) -> non_neg_integer().  between (Min, Max) ->     Diff = (Max - Min),     (Min + (rand:uniform(Diff + 1) - 1)). +-spec percentage () -> 0..100.  percentage () ->     between(0, 100). diff --git a/src/struct/character.erl b/src/struct/character.erl index 3ee9a31..bf6e046 100644 --- a/src/struct/character.erl +++ b/src/struct/character.erl @@ -3,7 +3,7 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --opaque id() :: integer(). +-opaque id() :: non_neg_integer().  -record  ( @@ -16,7 +16,6 @@        portrait :: binary(),        attributes :: attributes:struct(),        statistics :: statistics:struct(), -      glyphs :: list(glyph:id()),        weapon_ids :: {weapon:id(), weapon:id()}     }  ). @@ -39,7 +38,6 @@        get_attributes/1,        get_statistics/1,        get_weapon_ids/1, -      get_glyphs/1,        set_weapon_ids/2,        set_statistics/2 @@ -82,9 +80,6 @@ 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. @@ -134,6 +129,5 @@ random (ID, OwnerID) ->        portrait = IDAsBinaryString,        attributes = Attributes,        weapon_ids = WeaponIDs, -      glyphs = [],        statistics = Statistics     }. 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     ( diff --git a/src/struct/glyph.erl b/src/struct/glyph.erl deleted file mode 100644 index 18d8455..0000000 --- a/src/struct/glyph.erl +++ /dev/null @@ -1,45 +0,0 @@ --module(glyph). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( -   glyph, -   { -      id, -      name, -      icon, -      pos_attrib_mods, -      neg_attrib_mods -   } -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( -   [ -      get_id/1, -      get_name/1, -      get_icon/1, -      get_pos_attrib_mods/1, -      get_neg_attrib_mods/1 -   ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors -get_id (Gh) -> Gh#glyph.id. -get_name (Gh) -> Gh#glyph.name. -get_icon (Gh) -> Gh#glyph.icon. -get_pos_attrib_mods (Gh) -> Gh#glyph.pos_attrib_mods. -get_neg_attrib_mods (Gh) -> Gh#glyph.neg_attrib_mods. diff --git a/src/struct/player_turn.erl b/src/struct/player_turn.erl index e49156e..7795f35 100644 --- a/src/struct/player_turn.erl +++ b/src/struct/player_turn.erl @@ -7,11 +7,15 @@  (     player_turn,     { -      number, -      player_ix +      number :: non_neg_integer(), +      player_ix :: non_neg_integer()     }  ). +-opaque struct() :: #player_turn{}. + +-export_type([struct/0]). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -39,6 +43,7 @@  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%% Accessors +-spec new (non_neg_integer(), non_neg_integer()) -> struct().  new (Number, PlayerIX) ->     #player_turn     { @@ -46,6 +51,8 @@ new (Number, PlayerIX) ->        player_ix = PlayerIX     }. +-spec get_number (struct()) -> non_neg_integer().  get_number (PlayerTurn) -> PlayerTurn#player_turn.number. +-spec get_player_ix (struct()) -> non_neg_integer().  get_player_ix (PlayerTurn) -> PlayerTurn#player_turn.player_ix. diff --git a/src/struct/statistics.erl b/src/struct/statistics.erl index f8797bb..f3d78a8 100644 --- a/src/struct/statistics.erl +++ b/src/struct/statistics.erl @@ -7,18 +7,22 @@  (     statistics,     { -      movement_points, -      health, -      dodges, -      parries, -      damage_min, -      damage_max, -      accuracy, -      double_hits, -      critical_hits +      movement_points :: non_neg_integer(), +      health :: non_neg_integer(), +      dodges :: non_neg_integer(), +      parries :: non_neg_integer(), +      damage_min :: non_neg_integer(), +      damage_max :: non_neg_integer(), +      accuracy :: non_neg_integer(), +      double_hits :: non_neg_integer(), +      critical_hits :: non_neg_integer()     }  ). +-opaque struct() :: #statistics{}. + +-export_type([struct/0]). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -50,6 +54,7 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec ceil (float()) -> integer().  ceil (F) ->     I = trunc(F),     case (F > I) of @@ -57,32 +62,47 @@ ceil (F) ->        _ -> I     end. -float_to_int (F) -> trunc(ceil(F)). +-spec float_to_int (float()) -> integer(). +float_to_int (F) -> ceil(F). + +-spec min_max (number(), number(), number()) -> number().  min_max (Min, Max, V) -> min(Max, max(Min, V)). +-spec average (list(number())) -> number().  average ([]) -> 0;  average (L) -> lists:sum(L) / length(L).  % V | 010 | 030 | 050 | 070 | 100 |  % F | 004 | 023 | 058 | 104 | 200 | +-spec gentle_squared_growth (number()) -> non_neg_integer().  gentle_squared_growth (V) -> float_to_int(math:pow(V, 1.8) / 20).  % V | 010 | 030 | 050 | 070 | 100 |  % F | 001 | 005 | 018 | 041 | 100 | +-spec sudden_squared_growth (number()) -> non_neg_integer().  sudden_squared_growth (V) -> float_to_int(math:pow(V, 2.5) / 1000).  % V | 010 | 030 | 050 | 070 | 100 |  % F | 002 | 006 | 016 | 049 | 256 | +-spec sudden_exp_growth (number()) -> non_neg_integer().  sudden_exp_growth (V) -> float_to_int(math:pow(4, V / 25)).  % V | 010 | 030 | 050 | 070 | 100 |  % F | 040 | 066 | 079 | 088 | 099 |  % Seems too generous, values for attributes below 50 should dip faster and  % lower. -already_high_slow_growth (V) -> float_to_int(30 * math:log((V + 5)/4)). +%-spec already_high_slow_growth (non_neg_integer()) -> non_neg_integer(). +%already_high_slow_growth (V) -> float_to_int(30 * math:log((V + 5)/4)). +-spec damage_base_modifier (non_neg_integer()) -> float().  damage_base_modifier (Strength) -> ((math:pow(Strength, 1.8) / 2000.0) - 0.75). +-spec apply_damage_base_modifier +   ( +      float(), +      non_neg_integer() +   ) +   -> non_neg_integer().  apply_damage_base_modifier (Modifier, BaseValue) ->     max(0, float_to_int(BaseValue + (BaseValue * Modifier))). @@ -90,22 +110,46 @@ apply_damage_base_modifier (Modifier, BaseValue) ->  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%% Accessors +-spec get_movement_points (struct()) -> non_neg_integer().  get_movement_points (Stats) -> Stats#statistics.movement_points. + +-spec get_health (struct()) -> non_neg_integer().  get_health (Stats) -> Stats#statistics.health. + +-spec get_dodges (struct()) -> non_neg_integer().  get_dodges (Stats) -> Stats#statistics.dodges. + +-spec get_parries (struct()) -> non_neg_integer().  get_parries (Stats) -> Stats#statistics.parries. + +-spec get_damage_min (struct()) -> non_neg_integer().  get_damage_min (Stats) -> Stats#statistics.damage_min. + +-spec get_damage_max (struct()) -> non_neg_integer().  get_damage_max (Stats) -> Stats#statistics.damage_max. + +-spec get_accuracy (struct()) -> non_neg_integer().  get_accuracy (Stats) -> Stats#statistics.accuracy. + +-spec get_double_hits (struct()) -> non_neg_integer().  get_double_hits (Stats) -> Stats#statistics.double_hits. + +-spec get_critical_hits (struct()) -> non_neg_integer().  get_critical_hits (Stats) -> Stats#statistics.critical_hits. +-spec get_damages (struct()) -> {non_neg_integer(), non_neg_integer()}.  get_damages (Stats) ->     {        Stats#statistics.damage_min,        Stats#statistics.damage_max     }. +-spec new +   ( +      attributes:struct(), +      {weapon:id(), weapon:id()} +   ) +   -> struct().  new (BaseAttributes, WeaponIDs) ->     {ActiveWeaponID, _} = WeaponIDs,     ActiveWeapon = weapon:from_id(ActiveWeaponID), diff --git a/src/struct/tile.erl b/src/struct/tile.erl index 299481b..e86da56 100644 --- a/src/struct/tile.erl +++ b/src/struct/tile.erl @@ -3,8 +3,8 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --opaque id() :: integer(). --opaque struct() :: integer(). +-opaque id() :: non_neg_integer(). +-opaque struct() :: id().  -export_type([struct/0, id/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -32,8 +32,10 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec cost_when_oob () -> non_neg_integer().  cost_when_oob () -> 255. +-spec get_cost (id()) -> non_neg_integer().  get_cost (N) ->     if        (N =< 200) -> (N + 8); diff --git a/src/struct/weapon.erl b/src/struct/weapon.erl index 41f99f8..d96886c 100644 --- a/src/struct/weapon.erl +++ b/src/struct/weapon.erl @@ -3,19 +3,39 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-opaque id() :: non_neg_integer(). + +-type range_type() :: 'ranged' | 'melee'. +-type range_mod() :: 'long' | 'short'. +-type damage_type() :: 'slash' | 'pierce' | 'blunt'. +-type damage_mod() :: 'heavy' | 'light'. +  -record  (     weapon,     { -      id, -      name, -      range_type, -      range_mod, -      damage_type, -      damage_mod +      id :: id(), +      name :: binary(), +      range_type :: range_type(), +      range_mod :: range_mod(), +      damage_type :: damage_type(), +      damage_mod :: damage_mod()     }  ). +-opaque struct() :: #weapon{}. + +-export_type([struct/0, id/0]). +-export_type +( +   [ +      range_type/0, +      range_mod/0, +      damage_type/0, +      damage_mod/0 +   ] +). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -42,11 +62,23 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec ranges_of_type +   ( +      range_type(), +      range_mod() +   ) +   -> {non_neg_integer(), non_neg_integer()}.  ranges_of_type (ranged, long) -> {2, 6};  ranges_of_type (ranged, short) -> {1, 4};  ranges_of_type (melee, long) -> {0, 2};  ranges_of_type (melee, short) -> {0, 1}. +-spec damages_of_type +   ( +      range_type(), +      damage_mod() +   ) +   -> {non_neg_integer(), non_neg_integer()}.  damages_of_type (ranged, heavy) -> {10, 25};  damages_of_type (ranged, light) -> {5, 20};  damages_of_type (melee, heavy) -> {20, 35}; @@ -56,19 +88,25 @@ damages_of_type (melee, light) -> {15, 30}.  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%% Accessors +-spec get_id (struct()) -> id().  get_id (Wp) -> Wp#weapon.id. +-spec get_range_type (struct()) -> range_type().  get_range_type (Wp) -> Wp#weapon.range_type. +-spec get_ranges (struct()) -> {non_neg_integer(), non_neg_integer()}.  get_ranges (Wp) ->     ranges_of_type(Wp#weapon.range_type, Wp#weapon.range_mod). + +-spec get_damages (struct()) -> {non_neg_integer(), non_neg_integer()}.  get_damages (Wp) ->     damages_of_type(Wp#weapon.range_type, Wp#weapon.damage_mod). +-spec from_id (id()) -> struct().  from_id (0) ->     #weapon{        id = 0, -      name = "None", +      name = <<"None">>,        range_type = melee,        range_mod = short,        damage_type = blunt, @@ -77,7 +115,7 @@ from_id (0) ->  from_id (1) ->     #weapon{        id = 1, -      name = "Dagger", +      name = <<"Dagger">>,        range_type = melee,        range_mod = short,        damage_type = slash, @@ -86,7 +124,7 @@ from_id (1) ->  from_id (2) ->     #weapon{        id = 2, -      name = "Sword", +      name = <<"Sword">>,        range_type = melee,        range_mod = short,        damage_type = slash, @@ -95,7 +133,7 @@ from_id (2) ->  from_id (3) ->     #weapon{        id = 3, -      name = "Claymore", +      name = <<"Claymore">>,        range_type = melee,        range_mod = long,        damage_type = slash, @@ -104,7 +142,7 @@ from_id (3) ->  from_id (4) ->     #weapon{        id = 4, -      name = "Bardiche", +      name = <<"Bardiche">>,        range_type = melee,        range_mod = long,        damage_type = slash, @@ -113,7 +151,7 @@ from_id (4) ->  from_id (5) ->     #weapon{        id = 5, -      name = "Stiletto", +      name = <<"Stiletto">>,        range_type = melee,        range_mod = short,        damage_type = pierce, @@ -122,7 +160,7 @@ from_id (5) ->  from_id (6) ->     #weapon{        id = 6, -      name = "Pickaxe", +      name = <<"Pickaxe">>,        range_type = melee,        range_mod = short,        damage_type = pierce, @@ -131,7 +169,7 @@ from_id (6) ->  from_id (7) ->     #weapon{        id = 7, -      name = "Rapier", +      name = <<"Rapier">>,        range_type = melee,        range_mod = long,        damage_type = pierce, @@ -140,7 +178,7 @@ from_id (7) ->  from_id (8) ->     #weapon{        id = 8, -      name = "Pike", +      name = <<"Pike">>,        range_type = melee,        range_mod = long,        damage_type = pierce, @@ -149,7 +187,7 @@ from_id (8) ->  from_id (9) ->     #weapon{        id = 9, -      name = "Club", +      name = <<"Club">>,        range_type = melee,        range_mod = short,        damage_type = blunt, @@ -158,7 +196,7 @@ from_id (9) ->  from_id (10) ->     #weapon{        id = 10, -      name = "Mace", +      name = <<"Mace">>,        range_type = melee,        range_mod = short,        damage_type = blunt, @@ -167,7 +205,7 @@ from_id (10) ->  from_id (11) ->     #weapon{        id = 11, -      name = "Staff", +      name = <<"Staff">>,        range_type = melee,        range_mod = long,        damage_type = blunt, @@ -176,7 +214,7 @@ from_id (11) ->  from_id (12) ->     #weapon{        id = 12, -      name = "War Hammer", +      name = <<"War Hammer">>,        range_type = melee,        range_mod = long,        damage_type = blunt, @@ -185,7 +223,7 @@ from_id (12) ->  from_id (13) ->     #weapon{        id = 13, -      name = "Short Bow (Broadhead)", +      name = <<"Short Bow (Broadhead)">>,        range_type = ranged,        range_mod = short,        damage_type = slash, @@ -194,7 +232,7 @@ from_id (13) ->  from_id (14) ->     #weapon{        id = 14, -      name = "Short Bow (Blunt)", +      name = <<"Short Bow (Blunt)">>,        range_type = ranged,        range_mod = short,        damage_type = blunt, @@ -203,7 +241,7 @@ from_id (14) ->  from_id (15) ->     #weapon{        id = 15, -      name = "Short Bow (Bodkin Point)", +      name = <<"Short Bow (Bodkin Point)">>,        range_type = ranged,        range_mod = short,        damage_type = pierce, @@ -212,7 +250,7 @@ from_id (15) ->  from_id (16) ->     #weapon{        id = 16, -      name = "Long Bow (Broadhead)", +      name = <<"Long Bow (Broadhead)">>,        range_type = ranged,        range_mod = long,        damage_type = slash, @@ -221,7 +259,7 @@ from_id (16) ->  from_id (17) ->     #weapon{        id = 17, -      name = "Long Bow (Blunt)", +      name = <<"Long Bow (Blunt)">>,        range_type = ranged,        range_mod = long,        damage_type = blunt, @@ -230,7 +268,7 @@ from_id (17) ->  from_id (18) ->     #weapon{        id = 18, -      name = "Long Bow (Bodkin Point)", +      name = <<"Long Bow (Bodkin Point)">>,        range_type = ranged,        range_mod = long,        damage_type = pierce, @@ -239,7 +277,7 @@ from_id (18) ->  from_id (19) ->     #weapon{        id = 19, -      name = "Crossbow (Broadhead)", +      name = <<"Crossbow (Broadhead)">>,        range_type = ranged,        range_mod = short,        damage_type = slash, @@ -248,7 +286,7 @@ from_id (19) ->  from_id (20) ->     #weapon{        id = 20, -      name = "Crossbow (Blunt)", +      name = <<"Crossbow (Blunt)">>,        range_type = ranged,        range_mod = short,        damage_type = blunt, @@ -257,7 +295,7 @@ from_id (20) ->  from_id (21) ->     #weapon{        id = 21, -      name = "Crossbow (Bodkin Point)", +      name = <<"Crossbow (Bodkin Point)">>,        range_type = ranged,        range_mod = short,        damage_type = pierce, @@ -266,7 +304,7 @@ from_id (21) ->  from_id (22) ->     #weapon{        id = 22, -      name = "Arbalest (Broadhead)", +      name = <<"Arbalest (Broadhead)">>,        range_type = ranged,        range_mod = long,        damage_type = slash, @@ -275,7 +313,7 @@ from_id (22) ->  from_id (23) ->     #weapon{        id = 23, -      name = "Arbalest (Blunt)", +      name = <<"Arbalest (Blunt)">>,        range_type = ranged,        range_mod = long,        damage_type = blunt, @@ -284,16 +322,22 @@ from_id (23) ->  from_id (24) ->     #weapon{        id = 24, -      name = "Arbalest (Bodkin Point)", +      name = <<"Arbalest (Bodkin Point)">>,        range_type = ranged,        range_mod = long,        damage_type = pierce,        damage_mod = heavy     }. -random_id () -> -   roll:between(0, 24). +-spec random_id () -> id(). +random_id () -> roll:between(0, 24). +-spec apply_to_attributes +   ( +      attributes:struct(), +      weapon:struct() +   ) +   -> attributes:struct().  apply_to_attributes (Attributes, Weapon) ->     Dexterity = attributes:get_dexterity(Attributes),     Speed = attributes:get_speed(Attributes), | 


