summaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/battle/struct/btl_battle.erl | 18 | ||||
-rw-r--r-- | src/battle/struct/btl_pending_battle.erl | 84 | ||||
-rw-r--r-- | src/shared/reply/shr_set_inventory.erl | 4 | ||||
-rw-r--r-- | src/shared/struct/shr_inventory.erl | 32 | ||||
-rw-r--r-- | src/special/spe_battle.erl | 97 |
5 files changed, 159 insertions, 76 deletions
diff --git a/src/battle/struct/btl_battle.erl b/src/battle/struct/btl_battle.erl index dec7fd7..5cc7bc3 100644 --- a/src/battle/struct/btl_battle.erl +++ b/src/battle/struct/btl_battle.erl @@ -10,9 +10,9 @@ battle, { id :: id(), - used_armor_ids :: list(shr_armor:id()), - used_weapon_ids :: list(shr_weapon:id()), - used_tile_ids :: list(shr_tile:class_id()), + used_armor_ids :: ordsets:ordset(shr_armor:id()), + used_weapon_ids :: ordsets:ordset(shr_weapon:id()), + used_tile_ids :: ordsets:ordset(shr_tile:class_id()), map :: btl_map:type(), characters :: array:array(btl_character:type()), players :: array:array(btl_player:type()), @@ -86,13 +86,13 @@ get_all_timelines (Result, CurrentIndex, EndPoint, ArraySize, Players) -> -spec get_id (type()) -> id(). get_id (Battle) -> Battle#battle.id. --spec get_used_weapon_ids (type()) -> list(shr_weapon:id()). +-spec get_used_weapon_ids (type()) -> ordsets:ordset(shr_weapon:id()). get_used_weapon_ids (Battle) -> Battle#battle.used_weapon_ids. --spec get_used_armor_ids (type()) -> list(shr_armor:id()). +-spec get_used_armor_ids (type()) -> ordsets:ordset(shr_armor:id()). get_used_armor_ids (Battle) -> Battle#battle.used_armor_ids. --spec get_used_tile_ids (type()) -> list(shr_tile:class_id()). +-spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:class_id()). get_used_tile_ids (Battle) -> Battle#battle.used_tile_ids. -spec get_map (type()) -> btl_map:type(). @@ -187,9 +187,9 @@ set_current_player_turn (PlayerTurn, Battle) -> list(btl_player:type()), btl_map:type(), list(btl_character:type()), - list(shr_weapon:id()), - list(shr_armor:id()), - list(shr_tile:class_id()) + ordsets:ordset(shr_weapon:id()), + ordsets:ordset(shr_armor:id()), + ordsets:ordset(shr_tile:class_id()) ) -> type(). new (ID, PlayersAsList, Map, CharactersAsList, UWIDs, UAIDs, UTIDs) -> diff --git a/src/battle/struct/btl_pending_battle.erl b/src/battle/struct/btl_pending_battle.erl new file mode 100644 index 0000000..6e21f79 --- /dev/null +++ b/src/battle/struct/btl_pending_battle.erl @@ -0,0 +1,84 @@ +-module(btl_pending_battle). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-type id() :: binary(). + +-record +( + pending_battle, + { + id :: id(), + free_slots :: non_neg_integer(), + battle :: btl_battle:type() + } +). + +-opaque type() :: #pending_battle{}. + +-export_type([type/0, id/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_id/1, + get_battle/1, + get_free_slots/1, + + set_battle/2, + set_free_slots/2, + + get_battle_field/0, + get_free_slots_field/0 + ] +). + +-export +( + [ + new/3 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec new (id(), non_neg_integer(), btl_battle:type()) -> type(). +new (ID, FreeSlots, Battle) -> + #pending_battle + { + id = ID, + free_slots = FreeSlots, + battle = Battle + }. + +%%%% Accessors +-spec get_id (type()) -> id(). +get_id (PBattle) -> PBattle#pending_battle.id. + +-spec get_battle (type()) -> btl_battle:type(). +get_battle (PBattle) -> PBattle#pending_battle.battle. + +-spec get_free_slots (type()) -> non_neg_integer(). +get_free_slots (PBattle) -> PBattle#pending_battle.free_slots. + +-spec set_battle (btl_battle:type(), type()) -> type(). +set_battle (Battle, PBattle) -> PBattle#pending_battle{ battle = Battle }. + +-spec set_free_slots (non_neg_integer(), type()) -> type(). +set_free_slots (Val, PBattle) -> PBattle#pending_battle{ free_slots = Val }. + +-spec get_battle_field () -> non_neg_integer(). +get_battle_field () -> #pending_battle.battle. + +-spec get_free_slots_field () -> non_neg_integer(). +get_free_slots_field () -> #pending_battle.free_slots. diff --git a/src/shared/reply/shr_set_inventory.erl b/src/shared/reply/shr_set_inventory.erl index 8c04606..61ba336 100644 --- a/src/shared/reply/shr_set_inventory.erl +++ b/src/shared/reply/shr_set_inventory.erl @@ -12,8 +12,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec encode_set (sets:set(binary())) -> list(binary()). -encode_set (Set) -> sets:to_list(Set). +-spec encode_set (ordsets:ordset(binary())) -> list(binary()). +encode_set (Set) -> ordsets:to_list(Set). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/shared/struct/shr_inventory.erl b/src/shared/struct/shr_inventory.erl index 5d70720..0225fcb 100644 --- a/src/shared/struct/shr_inventory.erl +++ b/src/shared/struct/shr_inventory.erl @@ -8,11 +8,11 @@ inventory, { owner_id :: shr_player:id(), - portrait_ids :: sets:set(binary()), - glyph_ids :: sets:set(binary()), - glyph_board_ids :: sets:set(binary()), - weapon_ids :: sets:set(binary()), - armor_ids :: sets:set(binary()) + portrait_ids :: ordsets:ordset(binary()), + glyph_ids :: ordsets:ordset(binary()), + glyph_board_ids :: ordsets:ordset(binary()), + weapon_ids :: ordsets:ordset(binary()), + armor_ids :: ordsets:ordset(binary()) } ). @@ -72,50 +72,50 @@ -spec get_owner_id (type()) -> shr_player:id(). get_owner_id (Inv) -> Inv#inventory.owner_id. --spec get_portrait_ids (type()) -> sets:set(binary()). +-spec get_portrait_ids (type()) -> ordsets:ordset(binary()). get_portrait_ids (Inv) -> Inv#inventory.portrait_ids. --spec get_glyph_ids (type()) -> sets:set(binary()). +-spec get_glyph_ids (type()) -> ordsets:ordset(binary()). get_glyph_ids (Inv) -> Inv#inventory.glyph_ids. --spec get_glyph_board_ids (type()) -> sets:set(binary()). +-spec get_glyph_board_ids (type()) -> ordsets:ordset(binary()). get_glyph_board_ids (Inv) -> Inv#inventory.glyph_board_ids. --spec get_weapon_ids (type()) -> sets:set(binary()). +-spec get_weapon_ids (type()) -> ordsets:ordset(binary()). get_weapon_ids (Inv) -> Inv#inventory.weapon_ids. --spec get_armor_ids (type()) -> sets:set(binary()). +-spec get_armor_ids (type()) -> ordsets:ordset(binary()). get_armor_ids (Inv) -> Inv#inventory.armor_ids. --spec set_portrait_ids (sets:set(binary()), type()) -> type(). +-spec set_portrait_ids (ordsets:ordset(binary()), type()) -> type(). set_portrait_ids (Value, Inv) -> Inv#inventory { portrait_ids = Value }. --spec set_glyph_ids (sets:set(binary()), type()) -> type(). +-spec set_glyph_ids (ordsets:ordset(binary()), type()) -> type(). set_glyph_ids (Value, Inv) -> Inv#inventory { glyph_ids = Value }. --spec set_glyph_board_ids (sets:set(binary()), type()) -> type(). +-spec set_glyph_board_ids (ordsets:ordset(binary()), type()) -> type(). set_glyph_board_ids (Value, Inv) -> Inv#inventory { glyph_board_ids = Value }. --spec set_weapon_ids (sets:set(binary()), type()) -> type(). +-spec set_weapon_ids (ordsets:ordset(binary()), type()) -> type(). set_weapon_ids (Value, Inv) -> Inv#inventory { weapon_ids = Value }. --spec set_armor_ids (sets:set(binary()), type()) -> type(). +-spec set_armor_ids (ordsets:ordset(binary()), type()) -> type(). set_armor_ids (Value, Inv) -> Inv#inventory { @@ -139,7 +139,7 @@ get_armor_ids_field () -> #inventory.armor_ids. -spec new (shr_player:id()) -> type(). new (OwnerID) -> - EmptySet = sets:new(), + EmptySet = ordsets:new(), #inventory { diff --git a/src/special/spe_battle.erl b/src/special/spe_battle.erl index fe18da1..edc18df 100644 --- a/src/special/spe_battle.erl +++ b/src/special/spe_battle.erl @@ -7,7 +7,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/2]). +-export([generate/2, add_to/2]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -29,7 +29,7 @@ commit (_Battle) -> ( list(btl_character:type()) ) - -> {sets:set(binary()), sets:set(binary())}. + -> {ordsets:ordset(binary()), ordsets:ordset(binary())}. get_equipment_ids (Characters) -> {UsedWeaponIDs, UsedArmorIDs} = lists:foldl @@ -38,29 +38,33 @@ get_equipment_ids (Characters) -> {MWpID, SWpID} = btl_character:get_weapon_ids(Character), AID = btl_character:get_armor_id(Character), { - sets:add_element(MWpID, sets:add_element(SWpID, UWIDs)), - sets:add_element(AID, UAIDs) + ordsets:add_element(MWpID, ordsets:add_element(SWpID, UWIDs)), + ordsets:add_element(AID, UAIDs) } end, - {sets:new(), sets:new()}, + {ordsets:new(), ordsets:new()}, Characters ), {UsedWeaponIDs, UsedArmorIDs}. --spec get_tile_ids (array:array(shr_tile:instance())) -> sets:set(binary()). +-spec get_tile_ids + ( + array:array(shr_tile:instance()) + ) + -> ordsets:ordset(binary()). get_tile_ids (TileInstances) -> UsedTileIDs = array:sparse_foldl ( fun (_IX, TileInstance, CurrentTileIDs) -> - sets:add_element + ordsets:add_element ( shr_tile:extract_main_class_id(TileInstance), CurrentTileIDs ) end, - sets:new(), + ordsets:new(), TileInstances ), @@ -70,7 +74,7 @@ get_tile_ids (TileInstances) -> -spec find_random_location ( btl_map:type(), - list({non_neg_integer(), non_neg_integer()}) + ordsets:ordset({non_neg_integer(), non_neg_integer()}) ) -> {{non_neg_integer(), non_neg_integer()}, shr_tile:type()}. find_random_location (Map, ForbiddenLocations) -> @@ -83,7 +87,7 @@ find_random_location (Map, ForbiddenLocations) -> shr_roll:between(0, (MapHeight - 1)) }, - IsForbidden = lists:member(Candidate, ForbiddenLocations), + IsForbidden = ordsets:is_element(Candidate, ForbiddenLocations), case IsForbidden of true -> find_random_location(Map, ForbiddenLocations); @@ -121,7 +125,7 @@ get_glyphs_omnimods (RosterChar) -> non_neg_integer(), rst_character:type(), btl_map:type(), - list(btl_location:type()) + ordsets:ordset(btl_location:type()) ) -> btl_character:type(). create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) -> @@ -151,11 +155,11 @@ create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) -> non_neg_integer(), list(btl_character:type()), btl_map:type(), - list(btl_location:type()) + ordsets:ordset(btl_location:type()) ) - -> {list(btl_character:type()), list(btl_location:type())}. -handle_characters ([], _PlayerIX, Characters, _Map, UsedLocations) -> - {Characters, UsedLocations}; + -> list(btl_character:type()). +handle_characters ([], _PlayerIX, Characters, _Map, _UsedLocations) -> + Characters; handle_characters ( [RosterCharacter|NextRosterCharacters], @@ -176,47 +180,33 @@ handle_characters [btl_character:get_location(NewCharacter)|UsedLocations] ). --spec handle_rosters +-spec handle_roster ( - list(rst_roster:type()), - list(btl_character:type()), - list(btl_player:type()), + rst_roster:type(), non_neg_integer(), btl_map:type(), - list(btl_location:type()) + ordsets:ordset(btl_location:type()) ) - -> {list(btl_character:type()), list(btl_player:type())}. -handle_rosters ([], Characters, Players, _PlayersCount, _Map, _UsedLocations) -> - {Characters, lists:reverse(Players)}; -handle_rosters + -> {list(btl_character:type()), btl_player:type()}. +handle_roster ( - [Roster|NextRosters], - Characters, - Players, + Roster, PlayersCount, Map, UsedLocations ) -> NewPlayer = btl_player:new(PlayersCount, 0, rst_roster:get_owner(Roster)), - {NextCharacters, NextUsedLocations} = + NewCharacters = handle_characters ( array:to_list(rst_roster:get_characters(Roster)), PlayersCount, - Characters, + [], Map, UsedLocations ), - handle_rosters - ( - NextRosters, - NextCharacters, - [NewPlayer|Players], - (PlayersCount + 1), - Map, - NextUsedLocations - ). + {NewCharacters, NewPlayer}. %%%% BATTLE CREATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -224,10 +214,10 @@ handle_rosters ( binary(), map_map:type(), - list(rst_roster:type()) + rst_roster:type() ) -> btl_battle:type(). -generate_battle (ID, Map, Rosters) -> +generate_battle (ID, Map, Roster) -> TileInstances = map_map:get_tile_instances(Map), BattleMap = btl_map:from_array @@ -236,8 +226,8 @@ generate_battle (ID, Map, Rosters) -> map_map:get_height(Map), TileInstances ), - {Characters, PlayersAsList} = - handle_rosters(Rosters, [], [], 0, BattleMap, []), + {Characters, FirstPlayer} = + handle_roster(Roster, 0, BattleMap, ordsets:new()), {UsedWeaponIDs, UsedArmorIDs} = get_equipment_ids(Characters), UsedTileIDs = get_tile_ids(TileInstances), @@ -246,12 +236,12 @@ generate_battle (ID, Map, Rosters) -> btl_battle:new ( ID, - PlayersAsList, + [FirstPlayer], BattleMap, Characters, - sets:to_list(UsedWeaponIDs), - sets:to_list(UsedArmorIDs), - sets:to_list(UsedTileIDs) + UsedWeaponIDs, + UsedArmorIDs, + UsedTileIDs ), Battle. @@ -262,11 +252,20 @@ generate_battle (ID, Map, Rosters) -> -spec generate ( map_map:type(), - list(rst_roster:type()) + rst_roster:type() ) -> btl_battle:type(). -generate (Map, Rosters) -> +generate (Map, Roster) -> ID = reserve_id(), - Battle = generate_battle(ID, Map, Rosters), + Battle = generate_battle(ID, Map, Roster), ok = commit(Battle), Battle. + +-spec add_to + ( + rst_roster:type(), + btl_battle:type() + ) + -> btl_battle:type(). +add_to (_Roster, Battle) -> + Battle. |