| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | src/battle/btl_shim.erl | 2 | ||||
| -rw-r--r-- | src/battle/game-logic/btl_movement.erl | 6 | ||||
| -rw-r--r-- | src/battle/query/btl_load.erl | 2 | ||||
| -rw-r--r-- | src/battle/reply/btl_add_tile.erl | 8 | ||||
| -rw-r--r-- | src/battle/reply/btl_set_map.erl | 2 | ||||
| -rw-r--r-- | src/battle/struct/btl_battle.erl | 6 | ||||
| -rw-r--r-- | src/battle/struct/btl_map.erl | 8 | ||||
| -rw-r--r-- | src/battle/struct/btl_tile.erl.m4 | 117 | ||||
| -rw-r--r-- | src/map/reply/map_add_tile.erl | 8 | ||||
| -rw-r--r-- | src/map/reply/map_set_map.erl | 2 | ||||
| -rw-r--r-- | src/map/struct/map_map.erl | 10 | ||||
| -rw-r--r-- | src/map/struct/map_tile.erl.m4 | 120 | ||||
| -rw-r--r-- | src/shared/struct/shr_armor.erl.m4 | 96 | ||||
| -rw-r--r-- | src/shared/struct/shr_omnimods.erl | 149 | ||||
| -rw-r--r-- | src/shared/struct/shr_weapon.erl.m4 | 122 | 
15 files changed, 188 insertions, 470 deletions
| diff --git a/src/battle/btl_shim.erl b/src/battle/btl_shim.erl index 8819f33..f5fa735 100644 --- a/src/battle/btl_shim.erl +++ b/src/battle/btl_shim.erl @@ -289,7 +289,7 @@ generate_random_battle () ->           fun (_IX, TileInstance, CurrentTileIDs) ->              sets:add_element              ( -               btl_tile:extract_main_class_id(TileInstance), +               shr_tile:extract_main_class_id(TileInstance),                 CurrentTileIDs              )           end, diff --git a/src/battle/game-logic/btl_movement.erl b/src/battle/game-logic/btl_movement.erl index ec903e8..dd7eff9 100644 --- a/src/battle/game-logic/btl_movement.erl +++ b/src/battle/game-logic/btl_movement.erl @@ -31,9 +31,9 @@ cross (_Map, _ForbiddenLocations, [], Cost, Location) ->  cross (Map, ForbiddenLocations, [Step|NextSteps], Cost, Location) ->     NextLocation = btl_location:apply_direction(Step, Location),     NextTileInstance = btl_map:get_tile_instance(NextLocation, Map), -   NextTileClassID = btl_tile:extract_main_class_id(NextTileInstance), -   NextTile = btl_tile:from_class_id(NextTileClassID), -   NextCost = (Cost + btl_tile:get_cost(NextTile)), +   NextTileClassID = shr_tile:extract_main_class_id(NextTileInstance), +   NextTile = shr_tile:from_class_id(NextTileClassID), +   NextCost = (Cost + shr_tile:get_cost(NextTile)),     IsForbidden =        lists:foldl        ( diff --git a/src/battle/query/btl_load.erl b/src/battle/query/btl_load.erl index a93120e..35ad6f9 100644 --- a/src/battle/query/btl_load.erl +++ b/src/battle/query/btl_load.erl @@ -131,7 +131,7 @@ generate_reply (QueryState, Input) ->        lists:map        (           fun (TileClassID) -> -            btl_add_tile:generate(btl_tile:from_class_id(TileClassID)) +            btl_add_tile:generate(shr_tile:from_class_id(TileClassID))           end,           btl_battle:get_used_tile_ids(Battle)        ), diff --git a/src/battle/reply/btl_add_tile.erl b/src/battle/reply/btl_add_tile.erl index a7e8f31..c9cd18e 100644 --- a/src/battle/reply/btl_add_tile.erl +++ b/src/battle/reply/btl_add_tile.erl @@ -16,13 +16,13 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (btl_tile:type()) -> {list(any())}. +-spec generate (shr_tile:type()) -> {list(any())}.  generate (Tile) ->     {        [           {<<"msg">>, <<"add_tile">>}, -         {<<"id">>, btl_tile:get_class_id(Tile)}, -         {<<"nam">>, btl_tile:get_name(Tile)}, -         {<<"ct">>, btl_tile:get_cost(Tile)} +         {<<"id">>, shr_tile:get_class_id(Tile)}, +         {<<"nam">>, shr_tile:get_name(Tile)}, +         {<<"ct">>, shr_tile:get_cost(Tile)}        ]     }. diff --git a/src/battle/reply/btl_set_map.erl b/src/battle/reply/btl_set_map.erl index c0dd2ca..25e0541 100644 --- a/src/battle/reply/btl_set_map.erl +++ b/src/battle/reply/btl_set_map.erl @@ -27,7 +27,7 @@ generate (Map) ->              <<"t">>,              lists:map              ( -               fun btl_tile:instance_to_int_list/1, +               fun shr_tile:instance_to_int_list/1,                 array:sparse_to_list(btl_map:get_tile_instances(Map))              )           } diff --git a/src/battle/struct/btl_battle.erl b/src/battle/struct/btl_battle.erl index b7f158a..dec7fd7 100644 --- a/src/battle/struct/btl_battle.erl +++ b/src/battle/struct/btl_battle.erl @@ -12,7 +12,7 @@        id :: id(),        used_armor_ids :: list(shr_armor:id()),        used_weapon_ids :: list(shr_weapon:id()), -      used_tile_ids :: list(btl_tile:class_id()), +      used_tile_ids :: list(shr_tile:class_id()),        map :: btl_map:type(),        characters :: array:array(btl_character:type()),        players :: array:array(btl_player:type()), @@ -92,7 +92,7 @@ get_used_weapon_ids (Battle) -> Battle#battle.used_weapon_ids.  -spec get_used_armor_ids (type()) -> list(shr_armor:id()).  get_used_armor_ids (Battle) -> Battle#battle.used_armor_ids. --spec get_used_tile_ids (type()) -> list(btl_tile:class_id()). +-spec get_used_tile_ids (type()) -> list(shr_tile:class_id()).  get_used_tile_ids (Battle) -> Battle#battle.used_tile_ids.  -spec get_map (type()) -> btl_map:type(). @@ -189,7 +189,7 @@ set_current_player_turn (PlayerTurn, Battle) ->        list(btl_character:type()),        list(shr_weapon:id()),        list(shr_armor:id()), -      list(btl_tile:class_id()) +      list(shr_tile:class_id())     )     -> type().  new (ID, PlayersAsList, Map, CharactersAsList, UWIDs, UAIDs, UTIDs) -> diff --git a/src/battle/struct/btl_map.erl b/src/battle/struct/btl_map.erl index ddf2bb1..c784bca 100644 --- a/src/battle/struct/btl_map.erl +++ b/src/battle/struct/btl_map.erl @@ -12,7 +12,7 @@        id :: id(),        width :: integer(),        height :: integer(), -      tile_ids :: array:array(btl_tile:instance()) +      tile_ids :: array:array(shr_tile:instance())     }  ). @@ -72,10 +72,10 @@ get_width (Map) -> Map#map.width.  -spec get_height (type()) -> integer().  get_height (Map) -> Map#map.height. --spec get_tile_instances (type()) -> array:array(btl_tile:instance()). +-spec get_tile_instances (type()) -> array:array(shr_tile:instance()).  get_tile_instances (Map) -> Map#map.tile_ids. --spec get_tile_instance (btl_location:type(), type()) -> btl_tile:instance(). +-spec get_tile_instance (btl_location:type(), type()) -> shr_tile:instance().  get_tile_instance (Location, Map) ->     TileIX = location_to_array_index(Map#map.width, Location),     array:get(TileIX, Map#map.tile_ids). @@ -89,7 +89,7 @@ get_tile_instance (Location, Map) ->     )     -> type().  from_list (ID, Width, Height, List) -> -   TileInstances = lists:map(fun btl_tile:instance_from_ints/1, List), +   TileInstances = lists:map(fun shr_tile:instance_from_ints/1, List),     #map     { diff --git a/src/battle/struct/btl_tile.erl.m4 b/src/battle/struct/btl_tile.erl.m4 deleted file mode 100644 index 12653b7..0000000 --- a/src/battle/struct/btl_tile.erl.m4 +++ /dev/null @@ -1,117 +0,0 @@ --module(btl_tile). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( -   tile, -   { -      id :: class_id(), -      name :: binary(), -      cost :: non_neg_integer() -   } -). - --opaque class_id() :: non_neg_integer(). --opaque instance() :: list(non_neg_integer()). --opaque border() :: list(non_neg_integer()). - --opaque type() :: #tile{}. - --export_type([type/0, class_id/0, instance/0, border/0]). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( -   [ -      get_class_id/1, -      get_name/1, -      get_cost/1, -      from_class_id/1, -      cost_when_oob/0 -   ] -). - --export -( -   [ -      instance_to_int_list/1, -      instance_from_ints/1 -   ] -). - --export -( -   [ -      extract_main_class_id/1, -      extract_variant_ix/1, -      extract_borders/1 -   ] -). - --export -( -   [ -      extract_border_main_class_id/1, -      extract_border_variant_ix/1 -   ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec extract_main_class_id (instance()) -> class_id(). -extract_main_class_id (I) -> lists:nth(1, I). - --spec extract_borders (instance()) -> list(border()). -extract_borders (I) -> -   [_|[_|Result]] = I, -   Result. - --spec extract_variant_ix (instance()) -> non_neg_integer(). -extract_variant_ix (I) -> lists:nth(2, I). - --spec extract_border_main_class_id (border()) -> class_id(). -extract_border_main_class_id (B) -> lists:nth(1, B). - --spec extract_border_variant_ix (border()) -> non_neg_integer(). -extract_border_variant_ix (B) -> lists:nth(2, B). - --spec from_class_id (class_id()) -> type(). -m4_include(__MAKEFILE_DATA_DIR/tile/global.m4.conf)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/error.m4d)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/grassland.m4d)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/mud.m4d)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/water.m4d)m4_dnl -from_class_id(_) -> -   from_class_id(0). - --spec cost_when_oob () -> non_neg_integer(). -cost_when_oob () -> __TILE_COST_WHEN_OOB. - --spec get_class_id (type()) -> non_neg_integer(). -get_class_id (Tile) -> Tile#tile.id. - --spec get_cost (type()) -> non_neg_integer(). -get_cost (Tile) -> Tile#tile.cost. - --spec get_name (type()) -> binary(). -get_name (Tile) -> Tile#tile.name. - --spec instance_from_ints (list(non_neg_integer())) -> instance(). -instance_from_ints (L) -> -   LLength = length(L), - -   case (((LLength rem 2) == 0) and (LLength /= 0)) of -      true -> L; -      _ -> [0, 0] -   end. - --spec instance_to_int_list (instance()) -> list(non_neg_integer()). -instance_to_int_list (I) -> I. diff --git a/src/map/reply/map_add_tile.erl b/src/map/reply/map_add_tile.erl index 1047231..d5f029a 100644 --- a/src/map/reply/map_add_tile.erl +++ b/src/map/reply/map_add_tile.erl @@ -16,13 +16,13 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (map_tile:type()) -> {list(any())}. +-spec generate (shr_tile:type()) -> {list(any())}.  generate (Tile) ->     {        [           {<<"msg">>, <<"add_tile">>}, -         {<<"id">>, map_tile:get_class_id(Tile)}, -         {<<"nam">>, map_tile:get_name(Tile)}, -         {<<"ct">>, map_tile:get_cost(Tile)} +         {<<"id">>, shr_tile:get_class_id(Tile)}, +         {<<"nam">>, shr_tile:get_name(Tile)}, +         {<<"ct">>, shr_tile:get_cost(Tile)}        ]     }. diff --git a/src/map/reply/map_set_map.erl b/src/map/reply/map_set_map.erl index a4fc01a..be99103 100644 --- a/src/map/reply/map_set_map.erl +++ b/src/map/reply/map_set_map.erl @@ -27,7 +27,7 @@ generate (Map) ->              <<"t">>,              lists:map              ( -               fun map_tile:instance_to_int_list/1, +               fun shr_tile:instance_to_int_list/1,                 array:sparse_to_list(map_map:get_tile_instances(Map))              )           } diff --git a/src/map/struct/map_map.erl b/src/map/struct/map_map.erl index 46e501f..55c1a41 100644 --- a/src/map/struct/map_map.erl +++ b/src/map/struct/map_map.erl @@ -13,7 +13,7 @@        owner :: binary(),        width :: integer(),        height :: integer(), -      tile_instances :: array:array(map_tile:instance()) +      tile_instances :: array:array(shr_tile:instance())     }  ). @@ -87,10 +87,10 @@ get_width (Map) -> Map#map.width.  -spec get_height (type()) -> integer().  get_height (Map) -> Map#map.height. --spec get_tile_instances (type()) -> array:array(map_tile:instance()). +-spec get_tile_instances (type()) -> array:array(shr_tile:instance()).  get_tile_instances (Map) -> Map#map.tile_instances. --spec get_tile_instance (map_location:type(), type()) -> map_tile:instance(). +-spec get_tile_instance (map_location:type(), type()) -> shr_tile:instance().  get_tile_instance (Location, Map) ->     TileIX = location_to_array_index(Map#map.width, Location),     array:get(TileIX, Map#map.tile_instances). @@ -114,7 +114,7 @@ get_tile_instances_field () -> #map.tile_instances.     )     -> type().  from_list (ID, Owner, Width, Height, List) -> -   TileInstances = lists:map(fun map_tile:instance_from_ints/1, List), +   TileInstances = lists:map(fun shr_tile:instance_from_ints/1, List),     #map     { @@ -134,7 +134,7 @@ from_list (ID, Owner, Width, Height, List) ->     )     -> type().  update_from_list (Map, Width, Height, List) -> -   TileInstances = lists:map(fun map_tile:instance_from_ints/1, List), +   TileInstances = lists:map(fun shr_tile:instance_from_ints/1, List),     Map#map     { diff --git a/src/map/struct/map_tile.erl.m4 b/src/map/struct/map_tile.erl.m4 deleted file mode 100644 index 278e556..0000000 --- a/src/map/struct/map_tile.erl.m4 +++ /dev/null @@ -1,120 +0,0 @@ --module(map_tile). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( -   tile, -   { -      id :: class_id(), -      name :: binary(), -      cost :: non_neg_integer(), -      family :: non_neg_integer(), -      depth :: non_neg_integer() -   } -). - --opaque class_id() :: non_neg_integer(). --opaque instance() :: list(non_neg_integer()). --opaque border() :: list(non_neg_integer()). - --opaque type() :: #tile{}. - --export_type([type/0, class_id/0, instance/0, border/0]). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( -   [ -      get_class_id/1, -      get_name/1, -      get_cost/1, -      from_class_id/1, -      cost_when_oob/0 -   ] -). - --export -( -   [ -      instance_to_int_list/1, -      instance_from_ints/1 -   ] -). - --export -( -   [ -      extract_main_class_id/1, -      extract_variant_ix/1, -      extract_borders/1 -   ] -). - --export -( -   [ -      extract_border_main_class_id/1, -      extract_border_variant_ix/1 -   ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - --spec extract_main_class_id (instance()) -> class_id(). -extract_main_class_id (I) -> lists:nth(1, I). - --spec extract_borders (instance()) -> list(border()). -extract_borders (I) -> -   [_|[_|Result]] = I, -   Result. - --spec extract_variant_ix (instance()) -> non_neg_integer(). -extract_variant_ix (I) -> lists:nth(2, I). - --spec extract_border_main_class_id (border()) -> class_id(). -extract_border_main_class_id (B) -> lists:nth(1, B). - --spec extract_border_variant_ix (border()) -> non_neg_integer(). -extract_border_variant_ix (B) -> lists:nth(2, B). - --spec from_class_id (class_id()) -> type(). -m4_include(__MAKEFILE_DATA_DIR/tile/global.m4.conf)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/error.m4d)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/grassland.m4d)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/mud.m4d)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/tile/water.m4d)m4_dnl -from_class_id(_) -> -   from_class_id(0). - --spec cost_when_oob () -> non_neg_integer(). -cost_when_oob () -> __TILE_COST_WHEN_OOB. - --spec get_class_id (type()) -> non_neg_integer(). -get_class_id (Tile) -> Tile#tile.id. - --spec get_cost (type()) -> non_neg_integer(). -get_cost (Tile) -> Tile#tile.cost. - --spec get_name (type()) -> binary(). -get_name (Tile) -> Tile#tile.name. - --spec instance_from_ints (list(non_neg_integer())) -> instance(). -instance_from_ints (L) -> -   LLength = length(L), - -   case (((LLength rem 2) == 0) and (LLength /= 0)) of -      true -> L; -      _ -> [0, 0] -   end. - --spec instance_to_int_list (instance()) -> list(non_neg_integer()). -instance_to_int_list (I) -> I. diff --git a/src/shared/struct/shr_armor.erl.m4 b/src/shared/struct/shr_armor.erl.m4 index 5db4b36..01d810a 100644 --- a/src/shared/struct/shr_armor.erl.m4 +++ b/src/shared/struct/shr_armor.erl.m4 @@ -5,23 +5,19 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -type id() :: non_neg_integer(). --type category() :: 'kinetic' | 'leather' | 'chain' | 'plate'. -  -record  (     armor,     {        id :: id(),        name :: binary(), -      category :: category(), -      coef :: float() +      omnimods :: shr_omnimods:type()     }  ).  -opaque type() :: #armor{}.  -export_type([type/0, id/0]). --export_type ([category/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -32,8 +28,7 @@     [        get_id/1,        get_name/1, -      get_coefficient/1, -      get_category/1 +      get_omnimods/1     ]  ). @@ -41,9 +36,7 @@  (     [        random_id/0, -      from_id/1, -      apply_to_attributes/2, -      get_resistance_to/2 +      from_id/1     ]  ). @@ -62,11 +55,8 @@ get_id (Ar) -> Ar#armor.id.  -spec get_name (type()) -> binary().  get_name (Ar) -> Ar#armor.name. --spec get_coefficient (type()) -> float(). -get_coefficient (Ar) -> Ar#armor.coef. - --spec get_category (type()) -> category(). -get_category (Ar) -> Ar#armor.category. +-spec get_omnimods (type()) -> shr_omnimods:type(). +get_omnimods (Ar) -> Ar#armor.omnimods.  -spec from_id (id()) -> type().  m4_include(__MAKEFILE_DATA_DIR/armor/global.m4.conf)m4_dnl @@ -76,79 +66,3 @@ from_id(_) ->  -spec random_id () -> id().  random_id () -> shr_roll:between(0, 4). - --spec apply_to_attributes -   ( -      type(), -      shr_attributes:type() -   ) -   -> shr_attributes:type(). -apply_to_attributes (Ar, Att) -> -   Constitution = shr_attributes:get_constitution(Att), -   Dexterity = shr_attributes:get_dexterity(Att), -   Speed = shr_attributes:get_speed(Att), -   Strength = shr_attributes:get_strength(Att), -   Mind = shr_attributes:get_mind(Att), -   Impact = shr_math_util:ceil(20.0 * Ar#armor.coef), -   HalfImpact = shr_math_util:ceil(10.0 * Ar#armor.coef), -   Category = Ar#armor.category, - -   case Category of -      kinetic -> shr_attributes:set_unsafe_mind((Mind - Impact), Att); -      leather -> -         shr_attributes:set_unsafe_constitution -         ( -            (Constitution - HalfImpact), -            shr_attributes:set_unsafe_dexterity((Dexterity - HalfImpact), Att) -         ); - -      chain -> -         shr_attributes:set_unsafe_constitution -         ( -            (Constitution - HalfImpact), -            shr_attributes:set_unsafe_dexterity -            ( -               (Dexterity - HalfImpact), -               shr_attributes:set_unsafe_speed((Speed - Impact), Att) -            ) -         ); - -      plate -> -         shr_attributes:set_unsafe_constitution -         ( -            (Constitution - HalfImpact), -            shr_attributes:set_unsafe_dexterity -            ( -               (Dexterity - HalfImpact), -               shr_attributes:set_unsafe_speed -               ( -                  (Speed - Impact), -                  shr_attributes:set_unsafe_strength((Strength - Impact), Att) -               ) -            ) -         ) -   end. - --spec get_resistance_to (shr_weapon:damage_type(), type()) -> non_neg_integer(). -get_resistance_to (DamageType, Armor) -> -   ArmorCategory = Armor#armor.category, -   BaseResistance = -      case {DamageType, ArmorCategory} of -         {slash, kinetic} -> 0.0; -         {slash, leather} -> 20.0; -         {slash, chain} -> 30.0; -         {slash, plate} -> 30.0; -         {blunt, kinetic} -> 20.0; -         {blunt, leather} -> 20.0; -         {blunt, chain} -> 20.0; -         {blunt, plate} -> 20.0; -         {pierce, kinetic} -> 20.0; -         {pierce, leather} -> 20.0; -         {pierce, chain} -> 20.0; -         {pierce, plate} -> 30.0 -      end, - -   ArmorCoefficient = Armor#armor.coef, -   ActualResistance = (ArmorCoefficient * BaseResistance), - -   shr_math_util:ceil(ActualResistance). diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl index b87f2cd..2d06493 100644 --- a/src/shared/struct/shr_omnimods.erl +++ b/src/shared/struct/shr_omnimods.erl @@ -4,15 +4,16 @@  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -type entry() :: {atom(), integer()}. +-type mods() :: dict:dict(atom(), integer()).  -record  (     omnimods,     { -      attmods = list(entry()), -      stamods = list(entry()), -      atkmods = list(entry()), -      defmods = list(entry()) +      attmods :: mods(), +      stamods :: mods(), +      atkmods :: mods(), +      defmods :: mods()     }  ). @@ -26,7 +27,8 @@  -export  (     [ -      new/4 +      new/4, +      new_dirty/4     ]  ). @@ -34,14 +36,149 @@  -export  (     [ +      merge/2, +      apply_coefficient/2 +   ] +). + +-export +( +   [ +      apply_to_attributes/3, +      apply_to_statistics/3, +      get_attack_damage/3     ]  ).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec cleanup_entry_list (list(entry())) -> list(entry()). +cleanup_entry_list (ModList) -> +   [First|Rem] = ModList, +   case First of +      {none, _} -> Rem; +      _ -> ModList +   end. + +-spec apply_coefficient_to_mods (float(), mods()) -> mods(). +apply_coefficient_to_mods (Coef, Mods) -> +   dict:map(fun ({_Name, Val}) -> shr_util:ceil(Coef * Val) end, Mods). + +-spec merge_mods (mods(), mods()) -> mods(). +merge_mods (ModsA, ModsB) -> +   dict:merge(fun (_Name, ValA, ValB) -> (ValA + ValB) end, ModsA, ModsB).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% +%%% Creation +-spec new +( +      list(entry()), +      list(entry()), +      list(entry()), +      list(entry()) +   ) +   -> type(). +new (AttributeMods, StatisticMods, AttackMods, DefenseMods) -> +   #omnimods +   { +      attmods = dict:from_list(AttributeMods), +      stamods = dict:from_list(StatisticMods), +      atkmods = dict:from_list(AttackMods), +      defmods = dict:from_list(DefenseMods) +   }. + +-spec new_dirty +( +      list(entry()), +      list(entry()), +      list(entry()), +      list(entry()) +   ) +   -> type(). +new_dirty(AttributeMods, StatisticMods, AttackMods, DefenseMods) -> +   new +   ( +      cleanup_entry_list(AttributeMods), +      cleanup_entry_list(StatisticMods), +      cleanup_entry_list(AttackMods), +      cleanup_entry_list(DefenseMods) +   ). + +%%% Modification +-spec merge (type(), type()) -> type(). +merge (OmniA, OmniB) -> +   OmniA#omnimods +   { +      attmods = merge_mods(OmniA#omnimods.attmods, OmniB#omnimods.attmods), +      stamods = merge_mods(OmniA#omnimods.stamods, OmniB#omnimods.stamods), +      atkmods = merge_mods(OmniA#omnimods.atkmods, OmniB#omnimods.atkmods), +      defmods = merge_mods(OmniA#omnimods.defmods, OmniB#omnimods.defmods) +   }. + +-spec apply_coefficient (float(), type()) -> type(). +apply_coefficient (Coef, Omnimods) -> +   Omnimods#omnimods +   { +      attmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.attmods), +      stamods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.stamods), +      atkmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.atkmods), +      defmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.defmods) +   }. + +%%% Application +-spec apply_to_attributes +   ( +      fun((atom(), integer(), shr_attributes:type()) -> shr_attributes:type()), +      type(), +      shr_attributes:type() +   ) +   -> shr_attributes:type(). +apply_to_attributes (UpdateFun, Omnimods, Attributes) -> +   dict:fold +   ( +      UpdateFun, +      Attributes, +      Omnimods#omnimods.attmods +   ). + +-spec apply_to_statistics +   ( +      fun((atom(), integer(), shr_statistics:type()) -> shr_statistics:type()), +      type(), +      shr_statistics:type() +   ) +   -> shr_statistics:type(). +apply_to_statistics (UpdateFun, Omnimods, Statistics) -> +   dict:fold +   ( +      UpdateFun, +      Statistics, +      Omnimods#omnimods.attmods +   ). + +-spec get_attack_damage (float(), type(), type()) -> non_neg_integer(). +get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) -> +   AttackerOmnimodsAttmods = AttackerOmnimods#omnimods.atkmods, +   DefenderOmnimodsDefmods = DefenderOmnimods#omnimods.defmods, + +   S0Calc = +      apply_coefficient_to_mods(-1*AttackModifier, AttackerOmnimodsAttmods), +   S1Calc = merge_mods(DefenderOmnimodsDefmods, S0Calc), + +   Result = +      dict:fold +      ( +         fun (_Name, Val, CurrResult) -> +            case (Val > 0) of +               true -> (CurrResult + Val); +               _ -> CurrResult +            end +         end, +         0, +         S1Calc +      ), + +   Result. diff --git a/src/shared/struct/shr_weapon.erl.m4 b/src/shared/struct/shr_weapon.erl.m4 index 862edb6..55c2815 100644 --- a/src/shared/struct/shr_weapon.erl.m4 +++ b/src/shared/struct/shr_weapon.erl.m4 @@ -5,37 +5,21 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -type id() :: non_neg_integer(). --type range_type() :: 'ranged' | 'melee'. --type range_modifier() :: 'long' | 'short'. --type damage_type() :: 'slash' | 'pierce' | 'blunt'. --type damage_modifier() :: 'heavy' | 'light'. -  -record  (     weapon,     {        id :: id(),        name :: binary(), -      range_type :: range_type(), -      range_mod :: range_modifier(), -      damage_type :: damage_type(), -      damage_mod :: damage_modifier(), -      coef :: float() +      range_min:: non_neg_integer(), +      range_max :: non_neg_integer(), +      omnimods :: shr_omnimods:type()     }  ).  -opaque type() :: #weapon{}.  -export_type([type/0, id/0]). --export_type -( -   [ -      range_type/0, -      range_modifier/0, -      damage_type/0, -      damage_modifier/0 -   ] -).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -46,13 +30,9 @@     [        get_id/1,        get_name/1, -      get_range_type/1, -      get_range_modifier/1, -      get_damage_type/1, -      get_damage_modifier/1, -      get_coefficient/1, -      get_ranges/1, -      get_damages/1 +      get_minimum_range/1, +      get_maximum_range/1, +      get_omnimods/1     ]  ). @@ -60,36 +40,13 @@  (     [        random_id/0, -      from_id/1, -      can_parry/1, -      apply_to_attributes/2 +      from_id/1     ]  ).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec ranges_of_type -   ( -      range_type(), -      range_modifier() -   ) -   -> {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_modifier() -   ) -   -> {non_neg_integer(), non_neg_integer()}. -damages_of_type (ranged, heavy) -> {15, 30}; -damages_of_type (ranged, light) -> {10, 25}; -damages_of_type (melee, heavy) -> {20, 35}; -damages_of_type (melee, light) -> {15, 30}.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -101,33 +58,14 @@ get_id (Wp) -> Wp#weapon.id.  -spec get_name (type()) -> binary().  get_name (Wp) -> Wp#weapon.name. --spec get_range_type (type()) -> range_type(). -get_range_type (Wp) -> Wp#weapon.range_type. - --spec get_range_modifier (type()) -> range_modifier(). -get_range_modifier (Wp) -> Wp#weapon.range_mod. - --spec get_damage_type (type()) -> damage_type(). -get_damage_type (Wp) -> Wp#weapon.damage_type. - --spec get_damage_modifier (type()) -> damage_modifier(). -get_damage_modifier (Wp) -> Wp#weapon.damage_mod. +-spec get_minimum_range (type()) -> non_neg_integer(). +get_minimum_range (Wp) -> Wp#weapon.range_min. --spec get_coefficient (type()) -> float(). -get_coefficient (Wp) -> Wp#weapon.coef. +-spec get_maximum_range (type()) -> non_neg_integer(). +get_maximum_range (Wp) -> Wp#weapon.range_max. --spec get_ranges (type()) -> {non_neg_integer(), non_neg_integer()}. -get_ranges (Wp) -> -   ranges_of_type(Wp#weapon.range_type, Wp#weapon.range_mod). - --spec get_damages (type()) -> {non_neg_integer(), non_neg_integer()}. -get_damages (Wp) -> -   Coef = Wp#weapon.coef, -   {Min, Max} = damages_of_type(Wp#weapon.range_type, Wp#weapon.damage_mod), -   {shr_math_util:ceil(Min * Coef), shr_math_util:ceil(Max * Coef)}. - --spec can_parry (type()) -> boolean(). -can_parry (Wp) -> (Wp#weapon.range_type == melee). +-spec get_omnimods (type()) -> shr_omnimods:type(). +get_omnimods (Wp) -> Wp#weapon.omnimods.  -spec from_id (id()) -> type().  m4_include(__MAKEFILE_DATA_DIR/weapon/global.m4.conf)m4_dnl @@ -135,39 +73,5 @@ m4_include(__MAKEFILE_DATA_DIR/weapon/basic.m4d)m4_dnl  from_id (_) ->     from_id(0). -  -spec random_id () -> id().  random_id () -> shr_roll:between(0, 24). - --spec apply_to_attributes -   ( -      type(), -      shr_attributes:type() -   ) -   -> shr_attributes:type(). -apply_to_attributes (Weapon, Attributes) -> -   Dexterity = shr_attributes:get_dexterity(Attributes), -   Speed = shr_attributes:get_speed(Attributes), -   RangeModifier = Weapon#weapon.range_mod, -   DamageModifier = Weapon#weapon.damage_mod, - -   Impact = (20.0 * Weapon#weapon.coef), -   FullImpact = shr_math_util:ceil(Impact), -   QuarterImpact = shr_math_util:ceil(Impact / 4.0), - -   ResultingDexterity = -      case RangeModifier of -         long -> (Dexterity - FullImpact); -         short -> (Dexterity - QuarterImpact) -      end, -   ResultingSpeed = -      case DamageModifier of -         heavy -> (Speed - FullImpact); -         light -> (Speed - QuarterImpact) -      end, - -   S0Attributes = shr_attributes:set_unsafe_speed(ResultingSpeed, Attributes), -   S1Attributes = -      shr_attributes:set_unsafe_dexterity(ResultingDexterity, S0Attributes), - -   S1Attributes. | 


