summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-04-01 18:02:12 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-04-01 18:02:12 +0200 |
commit | 567ad4994492f4d53325260c63638cf12fe928e4 (patch) | |
tree | 98183a7f0b520764cf84f5c872e5a117005e1a81 | |
parent | ada321442febcee20e0d4e6d29238cf10e6fca6a (diff) |
[Broken] Refactoring...
-rw-r--r-- | src/shared/struct/inventory/shr_armor.erl.m4 | 12 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_equipment.erl | 257 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_glyph.erl.m4 | 16 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_glyph_board.erl.m4 | 12 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_inventory.erl | 175 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_portrait.erl.m4 | 6 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_weapon.erl.m4 | 12 | ||||
-rw-r--r-- | src/shared/struct/shr_character.erl | 175 |
8 files changed, 651 insertions, 14 deletions
diff --git a/src/shared/struct/inventory/shr_armor.erl.m4 b/src/shared/struct/inventory/shr_armor.erl.m4 index 18d203a..0594577 100644 --- a/src/shared/struct/inventory/shr_armor.erl.m4 +++ b/src/shared/struct/inventory/shr_armor.erl.m4 @@ -35,7 +35,8 @@ -export ( [ - none/0, + default/0, + default_id/0, from_id/1 ] ). @@ -62,7 +63,10 @@ get_omnimods (Ar) -> Ar#armor.omnimods. m4_include(__MAKEFILE_DATA_DIR/armor/global.m4.conf)m4_dnl m4_include(__MAKEFILE_DATA_DIR/armor/basic.m4d)m4_dnl from_id(_) -> - none(). + default(). --spec none () -> type(). -none () -> from_id(<<"0">>). +-spec default () -> type(). +default () -> from_id(<<"0">>). + +-spec default_id () -> id(). +default_id () -> <<"0">>. diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl new file mode 100644 index 0000000..f5eba8f --- /dev/null +++ b/src/shared/struct/inventory/shr_equipment.erl @@ -0,0 +1,257 @@ +-module(shr_equipment). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + shr_eq_ref, + { + primary :: shr_weapon:id(), + secondary :: shr_weapon:id(), + armor :: shr_armor:id(), + portrait :: shr_portrait:id(), + glyph_board :: shr_glyph_board:id(), + glyphs :: list(shr_glyph:id()) + } +). + +-record +( + shr_eq, + { + primary :: shr_weapon:type(), + secondary :: shr_weapon:type(), + armor :: shr_armor:type(), + portrait :: shr_portrait:type(), + glyph_board :: shr_glyph_board:type(), + glyphs :: list(shr_glyph:type()) + } +). + +-opaque type() :: #shr_eq{}. +-opaque unresolved() :: #shr_eq_ref{}. +-type either() :: (type() | unresolved()). + +-export_type([type/0, unresolved/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_primary_weapon/1, + get_secondary_weapon/1, + get_armor/1, + get_portrait/1, + get_glyph_board/1, + get_glyphs/1, + + set_primary_weapon/2, + set_secondary_weapon/2, + set_armor/2, + set_portrait/2, + set_glyph_board/2, + set_glyphs/2, + + get_primary_weapon_id/1, + get_secondary_weapon_id/1, + get_armor_id/1, + get_portrait_id/1, + get_glyph_board_id/1, + get_glyph_ids/1, + + set_primary_weapon_id/2, + set_secondary_weapon_id/2, + set_armor_id/2, + set_portrait_id/2, + set_glyph_board_id/2, + set_glyph_ids/2 + ] +). + +%%%% Accessors +-export +( + [ + default/0, + default_unresolved/0 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec get_primary_weapon (either()) -> shr_weapon:type(). +get_primary_weapon (#shr_eq{ primary = R }) -> R; +get_primary_weapon (#shr_eq_ref{ primary = R }) -> shr_weapon:from_id(R). + +-spec get_secondary_weapon (either()) -> shr_weapon:type(). +get_secondary_weapon (#shr_eq{ secondary = R }) -> R; +get_secondary_weapon (#shr_eq_ref{ secondary = R }) -> shr_weapon:from_id(R). + +-spec get_armor (either()) -> shr_armor:type(). +get_armor (#shr_eq{ armor = R }) -> R; +get_armor (#shr_eq_ref{ armor = R }) -> shr_armor:from_id(R). + +-spec get_portrait (either()) -> shr_portrait:type(). +get_portrait (#shr_eq{ portrait = R }) -> R; +get_portrait (#shr_eq_ref{ portrait = R }) -> shr_portrait:from_id(R). + +-spec get_glyph_board (either()) -> shr_glyph_board:type(). +get_glyph_board (#shr_eq{ glyph_board = R }) -> R; +get_glyph_board (#shr_eq_ref{ glyph_board = R }) -> shr_glyph_board:from_id(R). + +-spec get_glyphs (either()) -> list(shr_glyph:type()). +get_glyphs (#shr_eq{ glyphs = R }) -> R; +get_glyphs (#shr_eq_ref{ glyphs = R }) -> lists:map(fun shr_glyph:from_id/1, R). + +-spec get_primary_weapon_id (either()) -> shr_weapon:id(). +get_primary_weapon_id (#shr_eq_ref{ primary = R }) -> R; +get_primary_weapon_id (#shr_eq{ primary = R }) -> shr_weapon:get_id(R). + +-spec get_secondary_weapon_id (either()) -> shr_weapon:id(). +get_secondary_weapon_id (#shr_eq_ref{ secondary = R }) -> R; +get_secondary_weapon_id (#shr_eq{ secondary = R }) -> shr_weapon:get_id(R). + +-spec get_armor_id (either()) -> shr_armor:id(). +get_armor_id (#shr_eq_ref{ armor = R }) -> R; +get_armor_id (#shr_eq{ armor = R }) -> shr_armor:get_id(R). + +-spec get_portrait_id (either()) -> shr_portrait:id(). +get_portrait_id (#shr_eq_ref{ portrait = R }) -> R; +get_portrait_id (#shr_eq{ portrait = R }) -> shr_portrait:get_id(R). + +-spec get_glyph_board_id (either()) -> shr_glyph_board:id(). +get_glyph_board_id (#shr_eq_ref{ glyph_board = R }) -> R; +get_glyph_board_id (#shr_eq{ glyph_board = R }) -> shr_glyph_board:get_id(R). + +-spec get_glyph_ids (type()) -> list(shr_glyph:id()). +get_glyph_ids (#shr_eq_ref{ glyphs = R }) -> R; +get_glyph_ids (#shr_eq{ glyphs = R }) -> lists:map(fun shr_glyph:get_id/1, R). + +-spec set_primary_weapon + (shr_weapon:type(), type()) -> type(); + (shr_weapon:type(), unresolved()) -> unresolved(). +set_primary_weapon (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ primary = V }; +set_primary_weapon (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ primary = shr_weapon:get_id(V) }. + +-spec set_secondary_weapon + (shr_weapon:type(), type()) -> type(); + (shr_weapon:type(), unresolved()) -> unresolved(). +set_secondary_weapon (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ secondary = V }; +set_secondary_weapon (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ secondary = shr_weapon:get_id(V) }. + +-spec set_armor + (shr_armor:type(), type()) -> type(); + (shr_armor:type(), unresolved()) -> unresolved(). +set_armor (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ armor = V }; +set_armor (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ armor = shr_armor:get_id(V) }. + +-spec set_portrait + (shr_portrait:type(), type()) -> type(); + (shr_portrait:type(), unresolved()) -> unresolved(). +set_portrait (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ portrait = V }; +set_portrait (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ portrait = shr_portrait:get_id(V) }. + +-spec set_glyph_board + (shr_glyph_board:type(), type()) -> type(); + (shr_glyph_board:type(), unresolved()) -> unresolved(). +set_glyph_board (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ glyph_board = V }; +set_glyph_board (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ glyph_board = shr_glyph_board:get_id(V) }. + +-spec set_glyphs + (list(shr_glyph:type()), type()) -> type(); + (list(shr_glyph:type()), unresolved()) -> unresolved(). +set_glyphs (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ glyphs = V }; +set_glyphs (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ glyphs = lists:map(fun shr_glyph:get_id/1, V) }. + +-spec set_primary_weapon_id + (shr_weapon:id(), type()) -> type(); + (shr_weapon:id(), unresolved()) -> unresolved(). +set_primary_weapon_id (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ primary = V }; +set_primary_weapon_id (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ primary = shr_weapon:from_id(V) }. + +-spec set_secondary_weapon_id + (shr_weapon:id(), type()) -> type(); + (shr_weapon:id(), unresolved()) -> unresolved(). +set_secondary_weapon_id (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ secondary = V }; +set_secondary_weapon_id (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ secondary = shr_weapon:from_id(V) }. + +-spec set_armor_id + (shr_armor:id(), type()) -> type(); + (shr_armor:id(), unresolved()) -> unresolved(). +set_armor_id (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ armor = V }; +set_armor_id (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ armor = shr_armor:from_id(V) }. + +-spec set_portrait_id + (shr_portrait:id(), type()) -> type(); + (shr_portrait:id(), unresolved()) -> unresolved(). +set_portrait_id (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ portrait = V }; +set_portrait_id (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ portrait = shr_portrait:from_id(V) }. + +-spec set_glyph_board_id + (shr_glyph_board:id(), type()) -> type(); + (shr_glyph_board:id(), unresolved()) -> unresolved(). +set_glyph_board_id (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ glyph_board = V }; +set_glyph_board_id (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ glyph_board = shr_glyph_board:from_id(V) }. + +-spec set_glyph_ids + (list(shr_glyph:id()), type()) -> type(); + (list(shr_glyph:id()), unresolved()) -> unresolved(). +set_glyph_ids (V, Eq) when is_record(Eq, shr_eq_ref) -> + Eq#shr_eq_ref{ glyphs = V }; +set_glyph_ids (V, Eq) when is_record(Eq, shr_eq) -> + Eq#shr_eq{ glyphs = lists:map(fun shr_glyph:from_id/1, V) }. + +-spec default () -> type(). +default () -> + #shr_eq + { + primary = shr_weapon:default(), + secondary = shr_weapon:default(), + armor = shr_armor:default(), + portrait = shr_portrait:default(), + glyph_board = shr_glyph_board:default(), + glyphs = [] + }. + +-spec default_unresolved () -> unresolved(). +default_unresolved () -> + #shr_eq_ref + { + primary = shr_weapon:default_id(), + secondary = shr_weapon:default_id(), + armor = shr_armor:default_id(), + portrait = shr_portrait:default_id(), + glyph_board = shr_glyph_board:default_id(), + glyphs = [] + }. diff --git a/src/shared/struct/inventory/shr_glyph.erl.m4 b/src/shared/struct/inventory/shr_glyph.erl.m4 index cd59a27..0ce4c47 100644 --- a/src/shared/struct/inventory/shr_glyph.erl.m4 +++ b/src/shared/struct/inventory/shr_glyph.erl.m4 @@ -35,7 +35,15 @@ [ get_id/1, get_name/1, - get_omnimods/1 + get_omnimods/1, + ] +). + +-export +( + [ + default/0, + default_id/0 ] ). @@ -60,3 +68,9 @@ m4_include(__MAKEFILE_DATA_DIR/glyph/global.m4.conf)m4_dnl m4_include(__MAKEFILE_DATA_DIR/glyph/basic.m4d)m4_dnl from_id(_) -> from_id(<<"0">>). + +-spec default () -> type(). +default () -> from_id(<<"0">>). + +-spec default_id () -> id(). +default_id () -> <<"0">>. diff --git a/src/shared/struct/inventory/shr_glyph_board.erl.m4 b/src/shared/struct/inventory/shr_glyph_board.erl.m4 index 7fe77b1..c2128a9 100644 --- a/src/shared/struct/inventory/shr_glyph_board.erl.m4 +++ b/src/shared/struct/inventory/shr_glyph_board.erl.m4 @@ -43,7 +43,8 @@ -export ( [ - none/0, + default/0, + default_id/0, get_omnimods_with_glyphs/2 ] ). @@ -91,10 +92,10 @@ get_slots (GlyphBoard) -> GlyphBoard#glyph_board.slots. m4_include(__MAKEFILE_DATA_DIR/glyph_board/global.m4.conf)m4_dnl m4_include(__MAKEFILE_DATA_DIR/glyph_board/basic.m4d)m4_dnl from_id(_) -> - none(). + default(). --spec none () -> type(). -none () -> from_id(<<"0">>). +-spec default () -> type(). +default () -> from_id(<<"0">>). -spec get_omnimods_with_glyphs ( @@ -107,3 +108,6 @@ get_omnimods_with_glyphs (Glyphs, GlyphBoard) -> BoardSlots = GlyphBoard#glyph_board.slots, get_omnimods_with_glyphs_internals(BoardOmnimods, Glyphs, BoardSlots). + +-spec default_id () -> id(). +default_id () -> <<"0">>. diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl new file mode 100644 index 0000000..d6e6dbe --- /dev/null +++ b/src/shared/struct/inventory/shr_inventory.erl @@ -0,0 +1,175 @@ +-module(shr_inventory). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + inventory, + { + weapons :: ordsets:ordset(shr_weapon:id()), + armors :: ordsets:ordset(shr_armor:id()), + portraits :: ordsets:ordset(shr_portrait:id()), + glyph_boards :: ordsets:ordset(shr_glyph_board:id()), + glyphs :: ordsets:ordset(shr_glyph:id()) + } +). + +-opaque type() :: #inventory{}. + +-export_type([type/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_weapons/1, + get_armors/1, + get_portraits/1, + get_glyph_boards/1, + get_glyphs/1, + + set_weapons/2, + set_armors/2, + set_portraits/2, + set_glyph_boards/2, + set_glyphs/2 + ] +). + +%%%% Accessors +-export +( + [ + default/0, + allows_equipment/2, + add_equipment/2 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec get_weapons (type()) -> ordsets:ordset(shr_weapon:id()). +get_weapons (Inv) -> Inv#inventory.weapons. + +-spec get_armors (type()) -> ordsets:ordset(shr_armor:id()). +get_armors (Inv) -> Inv#inventory.armors. + +-spec get_portraits (type()) -> ordsets:ordset(shr_portrait:id()). +get_portraits (Inv) -> Inv#inventory.portraits. + +-spec get_glyph_boards (type()) -> ordsets:ordset(shr_glyph_board:id()). +get_glyph_boards (Inv) -> Inv#inventory.glyph_boards. + +-spec get_glyphs (type()) -> ordsets:ordset(shr_glyph:id()). +get_glyphs (Inv) -> Inv#inventory.glyphs. + +-spec set_weapons (ordsets:ordset(shr_weapon:id()), type()) -> type(). +set_weapons (V, Inv) -> Inv#inventory{ weapons = V }. + +-spec set_armors (ordsets:ordset(shr_armor:id()), type()) -> type(). +set_armors (V, Inv) -> Inv#inventory{ armors = V }. + +-spec set_portraits (ordsets:ordset(shr_portrait:id()), type()) -> type(). +set_portraits (V, Inv) -> Inv#inventory{ portraits = V }. + +-spec set_glyph_boards (ordsets:ordset(shr_glyph_board:id()), type()) -> type(). +set_glyph_boards (V, Inv) -> Inv#inventory{ glyph_boards = V }. + +-spec set_glyphs (ordsets:ordset(shr_glyph:id()), type()) -> type(). +set_glyphs (V, Inv) -> Inv#inventory{ glyphs = V }. + +-spec default () -> type(). +default () -> + EmptySet = ordsets:new(), + #inventory + { + weapons = EmptySet, + armors = EmptySet, + portraits = EmptySet, + glyph_boards = EmptySet, + glyphs = EmptySet + }. + +-spec allows_equipment (shr_equipment:type(), type()) -> boolean(). +allows_equipment (Eq, Inv) -> + Weapons = Inv#inventory.weapons, + Glyphs = Inv#inventory.glyphs, + + ( + ordsets:is_element(shr_equipment:get_primary_weapon_id(Eq), Weapons) + and ordsets:is_element(shr_equipment:get_secondary_weapon_id(Eq), Weapons) + and + ordsets:is_element + ( + shr_equipment:get_armor_id(Eq), + Inv#inventory.armors + ) + and + ordsets:is_element + ( + shr_equipment:get_portrait_id(Eq), + Inv#inventory.portraits + ) + and + ordsets:is_element + ( + shr_equipment:get_glyph_board_id(Eq), + Inv#inventory.glyph_boards + ) + and + lists:all + ( + fun (G) -> ordsets:is_element(G, Glyphs) end, + shr_equipment:get_glyph_ids(Eq) + ) + ). + +-spec add_equipment (shr_equipment:type(), type()) -> type(). +add_equipment (Eq, Inv) -> + Inv#inventory + { + weapons = + ordsets:add_element + ( + shr_equipment:get_primary_weapon_id(Eq), + ordsets:add_element + ( + shr_equipment:get_secondary_weapon_id(Eq), + Inv#inventory.weapons + ) + ), + armors = + ordsets:add_element + ( + shr_equipment:get_armor_id(Eq), + Inv#inventory.armors + ), + portraits = + ordsets:add_element + ( + shr_equipment:get_portrait_id(Eq), + Inv#inventory.portraits + ), + glyph_boards = + ordsets:add_element + ( + shr_equipment:get_glyph_board_id(Eq), + Inv#inventory.glyph_boards + ), + glyphs = + lists:foldl + ( + fun ordsets:add_element/2, + Inv#inventory.glyph_boards, + shr_equipment:get_glyph_ids(Eq) + ) + }. diff --git a/src/shared/struct/inventory/shr_portrait.erl.m4 b/src/shared/struct/inventory/shr_portrait.erl.m4 index fefc434..1e65263 100644 --- a/src/shared/struct/inventory/shr_portrait.erl.m4 +++ b/src/shared/struct/inventory/shr_portrait.erl.m4 @@ -38,7 +38,8 @@ ( [ from_id/1, - default/0 + default/0, + default_id/0 ] ). @@ -71,3 +72,6 @@ from_id(_) -> -spec default () -> type(). default () -> from_id(<<"cat">>). + +-spec default_id () -> id(). +default_id () -> <<"cat">>. diff --git a/src/shared/struct/inventory/shr_weapon.erl.m4 b/src/shared/struct/inventory/shr_weapon.erl.m4 index 1a2dcf5..189afa7 100644 --- a/src/shared/struct/inventory/shr_weapon.erl.m4 +++ b/src/shared/struct/inventory/shr_weapon.erl.m4 @@ -40,7 +40,8 @@ -export ( [ - none/0, + default/0, + default/0, from_id/1 ] ). @@ -73,7 +74,10 @@ m4_include(__MAKEFILE_DATA_DIR/weapon/global.m4.conf)m4_dnl m4_include(__MAKEFILE_DATA_DIR/weapon/basic.m4d)m4_dnl m4_include(__MAKEFILE_DATA_DIR/weapon/secondary.m4d)m4_dnl from_id (_) -> - none(). + default(). --spec none () -> type(). -none () -> from_id(<<"0">>). +-spec default () -> type(). +default () -> from_id(<<"0">>). + +-spec default_id () -> id(). +default_id () -> <<"0">>. diff --git a/src/shared/struct/shr_character.erl b/src/shared/struct/shr_character.erl new file mode 100644 index 0000000..33081bb --- /dev/null +++ b/src/shared/struct/shr_character.erl @@ -0,0 +1,175 @@ +-module(shr_character). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + shr_char_ref, + { + name :: binary(), + equipment :: shr_equipment:unresolved(), + is_using_secondary :: boolean() + } +). + +-record +( + shr_char, + { + name :: binary(), + equipment :: shr_equipment:type(), + is_using_secondary :: boolean(), + statistics :: shr_statistics:type(), + attributes :: shr_attributes:type(), + omnimods :: shr_omnimods:type(), + extra_omnimods :: shr_omnimods:type() + } +). + +-opaque type() :: #shr_char{}. +-opaque unresolved() :: #shr_char_ref{}. +-type either() :: (type() | unresolved()). + +-export_type([type/0, unresolved/0, either/0]). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_name/1, + get_equipment/1, + get_attributes/1, + get_statistics/1, + get_active_weapon/1, + get_inactive_weapon/1, + get_omnimods/1, + + set_name/2, + + set_equipment/2, + dirty_set_equipment/2, + + set_extra_omnimods/2, + dirty_set_extra_omnimods/2, + + switch_weapons/1, + dirty_switch_weapons/1 + ] +). + +-export +( + [ + resolve/1, + to_unresolved/1 + ] +). + +-export +( + [ + validate/2 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec refresh_omnimods (type()) -> type(). +refresh_omnimods (Char) -> Char. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-spec get_name (either()) -> binary(). +get_name (#shr_char{ name = R }) -> R; +get_name (#shr_char_ref{ name = R }) -> R. + +-spec set_name + (binary(), type()) -> type(); + (binary(), unresolved()) -> unresolved(). +set_name (Name, Char) when is_record(Char, shr_char) -> + Char#shr_char { name = Name }; +set_name (Name, Char) when is_record(Char, shr_char_ref) -> + Char#shr_char_ref{ name = Name }. + +-spec get_equipment + (type()) -> shr_equipment:type(); + (unresolved()) -> shr_equipment:unresolved(). +get_equipment (#shr_char{ equipment = R }) -> R; +get_equipment (#shr_char_ref{ equipment = R }) -> R. + +-spec switch_weapons + (type()) -> type(); + (unresolved()) -> unresolved(). +switch_weapons (Char) when is_record(Char, shr_char) -> + refresh_omnimods + ( + Char#shr_char + { + is_using_secondary = (not Char#shr_char.is_using_secondary) + } + ); +switch_weapons (Char) when is_record(Char, shr_char_ref) -> + Char#shr_char_ref + { + is_using_secondary = (not Char#shr_char_ref.is_using_secondary) + }. + +-spec dirty_switch_weapons + (type()) -> type(); + (unresolved()) -> unresolved(). +dirty_switch_weapons (Char) when is_record(Char, shr_char) -> + Char#shr_char + { + is_using_secondary = (not Char#shr_char.is_using_secondary) + }; +dirty_switch_weapons (Char) when is_record(Char, shr_char_ref) -> + Char#shr_char_ref + { + is_using_secondary = (not Char#shr_char_ref.is_using_secondary) + }. + +-spec get_active_weapon (either()) -> shr_weapon:type(). +get_active_weapon (#shr_char{ is_using_secondary = B, equipment = E }) -> + case B of + true -> shr_equipment:get_secondary_weapon(E); + false -> shr_equipment:get_primary_weapon(E) + end; +get_active_weapon (#shr_char_ref{ is_using_secondary = B, equipment = E }) -> + case B of + true -> shr_equipment:get_secondary_weapon(E); + false -> shr_equipment:get_primary_weapon(E) + end. + +-spec get_inactive_weapon (either()) -> shr_weapon:type(). +get_inactive_weapon (#shr_char{ is_using_secondary = B, equipment = E }) -> + case B of + false -> shr_equipment:get_secondary_weapon(E); + true -> shr_equipment:get_primary_weapon(E) + end; +get_inactive_weapon (#shr_char_ref{ is_using_secondary = B, equipment = E }) -> + case B of + false -> shr_equipment:get_secondary_weapon(E); + true -> shr_equipment:get_primary_weapon(E) + end. + +-spec get_attributes (type()) -> shr_attributes:type(). +get_attributes (Char) -> Char#shr_char.attributes. + +-spec get_statistics (type()) -> shr_statistics:type(). +get_statistics (Char) -> Char#shr_char.statistics. + +-spec get_omnimods (type()) -> shr_omnimods:type(). +get_omnimods (Char) -> Char#shr_char.omnimods. + +-spec set_extra_omnimods (shr_omnimods:type(), type()) -> type(). +set_extra_omnimods (O, Char) -> + refresh_omnimods(Char#shr_char{ extra_omnimods = O }). + +-spec dirty_set_extra_omnimods (shr_omnimods:type(), type()) -> type(). +dirty_set_extra_omnimods (O, Char) -> Char#shr_char{ extra_omnimods = O }. |