summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
23 files changed, 108 insertions, 429 deletions
diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl index 462e868..b59efb7 100644 --- a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl +++ b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl @@ -123,7 +123,7 @@ handle_attack_sequence -> list(btl_attack:step()). get_attack_sequence (Character, TargetCharacter) -> Range = - btl_location:dist + shr_location:dist ( btl_character:get_location(Character), btl_character:get_location(TargetCharacter) diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_move.erl b/src/battle/mechanic/turn_action/btl_turn_actions_move.erl index bf023d5..814239b 100644 --- a/src/battle/mechanic/turn_action/btl_turn_actions_move.erl +++ b/src/battle/mechanic/turn_action/btl_turn_actions_move.erl @@ -18,18 +18,18 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec cross ( - btl_map:type(), - list(btl_location:type()), - list(btl_direction:enum()), + shr_map:type(), + list(shr_location:type()), + list(shr_direction:enum()), non_neg_integer(), - btl_location:type() + shr_location:type() ) - -> {btl_location:type(), non_neg_integer()}. + -> {shr_location:type(), non_neg_integer()}. cross (_Map, _ForbiddenLocations, [], Cost, Location) -> {Location, Cost}; cross (Map, ForbiddenLocations, [Step|NextSteps], Cost, Location) -> - NextLocation = btl_location:apply_direction(Step, Location), - NextTileInstance = btl_map:get_tile_instance(NextLocation, Map), + NextLocation = shr_location:apply_direction(Step, Location), + NextTileInstance = shr_map:get_tile_instance(NextLocation, Map), NextTileClassID = shr_tile:extract_main_class_id(NextTileInstance), NextTile = shr_tile:from_class_id(NextTileClassID), NextCost = (Cost + shr_tile:get_cost(NextTile)), @@ -49,21 +49,21 @@ cross (Map, ForbiddenLocations, [Step|NextSteps], Cost, Location) -> -spec cross ( - btl_map:type(), - list(btl_location:type()), - list(btl_direction:enum()), - btl_location:type() + shr_map:type(), + list(shr_location:type()), + list(shr_direction:enum()), + shr_location:type() ) - -> {btl_location:type(), non_neg_integer()}. + -> {shr_location:type(), non_neg_integer()}. cross (Map, ForbiddenLocations, Path, Location) -> cross(Map, ForbiddenLocations, Path, 0, Location). -spec get_path_cost_and_destination ( btl_character_turn_data:type(), - list(btl_direction:type()) + list(shr_direction:type()) ) - -> {non_neg_integer(), btl_location:type()}. + -> {non_neg_integer(), shr_location:type()}. get_path_cost_and_destination (Data, Path) -> Character = btl_character_turn_data:get_character(Data), CharacterIX = btl_character_turn_data:get_character_ix(Data), @@ -116,8 +116,8 @@ assert_character_can_move (Data, Cost) -> ( btl_character_current_data:type(), btl_character_turn_update:type(), - list(btl_direction:type()), - btl_location:type() + list(shr_direction:type()), + shr_location:type() ) -> btl_character_turn_update:type(). commit_move (PreviousCurrentData, Update, Path, NewLocation) -> diff --git a/src/battle/query/btl_load.erl b/src/battle/query/btl_load.erl index f41e46c..eec8edb 100644 --- a/src/battle/query/btl_load.erl +++ b/src/battle/query/btl_load.erl @@ -100,7 +100,7 @@ generate_reply (QueryState, Input) -> btl_battle:get_encoded_last_turns_effects(Battle) ), - SetMap = btl_set_map:generate(btl_battle:get_map(Battle)), + SetMap = shr_set_map:generate(btl_battle:get_map(Battle)), AddCharList = lists:map diff --git a/src/battle/reply/btl_add_char.erl b/src/battle/reply/btl_add_char.erl index 6cd2157..9518677 100644 --- a/src/battle/reply/btl_add_char.erl +++ b/src/battle/reply/btl_add_char.erl @@ -46,7 +46,7 @@ generate (IX, Character, PlayerIX) -> <<"hea">>, btl_character:get_current_health(Character) }, - {<<"lc">>, btl_location:encode(Location)}, + {<<"lc">>, shr_location:encode(Location)}, {<<"pla">>, CharacterPlayerIX}, { <<"ena">>, diff --git a/src/battle/struct/btl_battle.erl b/src/battle/struct/btl_battle.erl index 7acdc13..7237072 100644 --- a/src/battle/struct/btl_battle.erl +++ b/src/battle/struct/btl_battle.erl @@ -13,7 +13,7 @@ used_weapon_ids :: ordsets:ordset(shr_weapon:id()), used_portrait_ids :: ordsets:ordset(shr_portrait:id()), used_tile_ids :: ordsets:ordset(shr_tile:class_id()), - map :: btl_map:type(), + map :: shr_map:type(), characters :: orddict:orddict(non_neg_integer(), btl_character:type()), players :: orddict:orddict(non_neg_integer(), btl_player:type()), current_player_turn :: btl_player_turn:type() @@ -102,7 +102,7 @@ get_used_armor_ids (Battle) -> Battle#battle.used_armor_ids. -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(). +-spec get_map (type()) -> shr_map:type(). get_map (Battle) -> Battle#battle.map. -spec get_characters @@ -142,7 +142,7 @@ get_encoded_last_turns_effects (Battle) -> StartingPoint = ((CurrentPlayerIX + 1) rem PlayersCount), get_all_timelines([], StartingPoint, CurrentPlayerIX, PlayersCount, Players). --spec set_map (btl_map:type(), type()) -> type(). +-spec set_map (shr_map:type(), type()) -> type(). set_map (Map, Battle) -> Battle#battle { @@ -230,7 +230,7 @@ set_current_player_turn (PlayerTurn, Battle) -> current_player_turn = PlayerTurn }. --spec new (btl_map:type()) -> type(). +-spec new (shr_map:type()) -> type(). new (Map) -> EmptySet = ordsets:new(), EmptyDict = orddict:new(), @@ -240,7 +240,7 @@ new (Map) -> used_portrait_ids = EmptySet, used_weapon_ids = EmptySet, used_armor_ids = EmptySet, - used_tile_ids = btl_map:get_used_tile_ids(Map), + used_tile_ids = shr_map:get_used_tile_ids(Map), map = Map, characters = EmptyDict, players = EmptyDict, diff --git a/src/battle/struct/btl_battle_action.erl b/src/battle/struct/btl_battle_action.erl index 5d42536..2c7564b 100644 --- a/src/battle/struct/btl_battle_action.erl +++ b/src/battle/struct/btl_battle_action.erl @@ -7,7 +7,7 @@ ( move, { - path :: list(btl_direction:enum()) + path :: list(shr_direction:enum()) } ). @@ -60,10 +60,10 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec maybe_decode_move (list(btl_direction:type())) -> list(type()). +-spec maybe_decode_move (list(shr_direction:type())) -> list(type()). maybe_decode_move ([]) -> []; maybe_decode_move (PathInBinary) -> - Path = lists:map(fun btl_direction:decode/1, PathInBinary), + Path = lists:map(fun shr_direction:decode/1, PathInBinary), [#move { path = Path }]. @@ -83,7 +83,7 @@ can_follow (move, switch_weapon) -> true; can_follow (move, attack) -> true; can_follow (_, _) -> false. --spec get_path (type()) -> list(btl_direction:type()). +-spec get_path (type()) -> list(shr_direction:type()). get_path (Action) when is_record(Action, move) -> Action#move.path; get_path (_) -> diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 53e80aa..08a1080 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -187,7 +187,7 @@ set_weapon_ids (WeaponIDs, Char) -> shr_portrait:id(), {shr_weapon:id(), shr_weapon:id()}, shr_armor:id(), - btl_location:type(), + shr_location:type(), shr_omnimods:type() ) -> type(). diff --git a/src/battle/struct/btl_character_current_data.erl b/src/battle/struct/btl_character_current_data.erl index 60bfdbc..0be920b 100644 --- a/src/battle/struct/btl_character_current_data.erl +++ b/src/battle/struct/btl_character_current_data.erl @@ -43,11 +43,11 @@ -spec location_to_omnimods ( {non_neg_integer(), non_neg_integer()}, - btl_map:type() + shr_map:type() ) -> shr_omnimods:type(). location_to_omnimods (Location, Map) -> - TileInstance = btl_map:get_tile_instance(Location, Map), + TileInstance = shr_map:get_tile_instance(Location, Map), TileClassID = shr_tile:extract_main_class_id(TileInstance), Tile = shr_tile:from_class_id(TileClassID), @@ -73,7 +73,7 @@ get_attributes (Char) -> Char#character_current_data.attributes. get_statistics (Char) -> Char#character_current_data.statistics. %%%% Utils --spec new (btl_character:type(), btl_map:type()) -> type(). +-spec new (btl_character:type(), shr_map:type()) -> type(). new (Character, Map) -> PermanentOmnimods = btl_character:get_permanent_omnimods(Character), diff --git a/src/battle/struct/btl_direction.erl b/src/battle/struct/btl_direction.erl deleted file mode 100644 index 9fb5a01..0000000 --- a/src/battle/struct/btl_direction.erl +++ /dev/null @@ -1,38 +0,0 @@ --module(btl_direction). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type enum() :: ('up' | 'down' | 'left' | 'right'). --type type() :: enum(). - --export_type([enum/0, type/0]). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - decode/1, - encode/1 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec decode (binary()) -> enum(). -decode (<<"U">>) -> up; -decode (<<"D">>) -> down; -decode (<<"L">>) -> left; -decode (<<"R">>) -> right. - --spec encode (enum()) -> binary(). -encode (up) -> <<"U">>; -encode (down) -> <<"D">>; -encode (left) -> <<"L">>; -encode (right) -> <<"R">>. diff --git a/src/battle/struct/btl_map.erl b/src/battle/struct/btl_map.erl deleted file mode 100644 index 17a272b..0000000 --- a/src/battle/struct/btl_map.erl +++ /dev/null @@ -1,126 +0,0 @@ --module(btl_map). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - map, - { - width :: integer(), - height :: integer(), - tile_ids :: shr_tile:instances_tuple() - } -). - --opaque type() :: #map{}. - --export_type([type/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_width/1, - get_height/1, - get_tile_instances/1, - get_tile_instance/2, - get_used_tile_ids/1 - ] -). - --export -( - [ - from_list/3, - from_instances_tuple/3 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec location_to_index - ( - non_neg_integer(), - btl_location:type() - ) - -> ('error' | non_neg_integer()). -location_to_index (ArrayWidth, {X, Y}) -> - if - (X < 0) -> error; - (Y < 0) -> error; - (X >= ArrayWidth) -> error; - true -> ((Y * ArrayWidth) + X) - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_width (type()) -> integer(). -get_width (Map) -> Map#map.width. - --spec get_height (type()) -> integer(). -get_height (Map) -> Map#map.height. - --spec get_tile_instances (type()) -> shr_tile:instances_tuple(). -get_tile_instances (Map) -> Map#map.tile_ids. - --spec get_tile_instance (btl_location:type(), type()) -> shr_tile:instance(). -get_tile_instance (Location, Map) -> - TileIX = location_to_index(Map#map.width, Location), - element((TileIX + 1), Map#map.tile_ids). - --spec from_list - ( - non_neg_integer(), - non_neg_integer(), - list(list(binary())) - ) - -> type(). -from_list (Width, Height, List) -> - TileInstances = lists:map(fun shr_tile:instance_from_binary_list/1, List), - - #map - { - width = Width, - height = Height, - tile_ids = list_to_tuple(TileInstances) - }. - --spec from_instances_tuple - ( - non_neg_integer(), - non_neg_integer(), - shr_tile:instances_tuple() - ) - -> type(). -from_instances_tuple (Width, Height, TileInstances) -> - #map - { - width = Width, - height = Height, - tile_ids = TileInstances - }. - --spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:class_id()). -get_used_tile_ids (Map) -> - UsedTileIDs = - lists:foldl - ( - fun (TileInstance, CurrentTileIDs) -> - ordsets:add_element - ( - shr_tile:extract_main_class_id(TileInstance), - CurrentTileIDs - ) - end, - ordsets:new(), - tuple_to_list(Map#map.tile_ids) - ), - - UsedTileIDs. diff --git a/src/battle/struct/btl_turn_result.erl b/src/battle/struct/btl_turn_result.erl index 7ae9ffe..af1fded 100644 --- a/src/battle/struct/btl_turn_result.erl +++ b/src/battle/struct/btl_turn_result.erl @@ -17,8 +17,8 @@ moved, { character_ix :: non_neg_integer(), - path :: list(btl_direction:enum()), - new_location :: btl_location:type() + path :: list(shr_direction:enum()), + new_location :: shr_location:type() } ). @@ -117,8 +117,8 @@ new_character_switched_weapons (CharacterIX) -> -spec new_character_moved ( non_neg_integer(), - list(btl_direction:enum()), - btl_location:type() + list(shr_direction:enum()), + shr_location:type() ) -> type(). new_character_moved (CharacterIX, Path, NewLocation) -> @@ -170,8 +170,8 @@ encode (TurnResult) when is_record(TurnResult, moved) -> Path = TurnResult#moved.path, NewLocation = TurnResult#moved.new_location, - EncodedPath = lists:map(fun btl_direction:encode/1, Path), - EncodedNewLocation = btl_location:encode(NewLocation), + EncodedPath = lists:map(fun shr_direction:encode/1, Path), + EncodedNewLocation = shr_location:encode(NewLocation), { [ diff --git a/src/bounty/bnt_grant_land.erl b/src/bounty/bnt_grant_land.erl index 3a279a9..25b713b 100644 --- a/src/bounty/bnt_grant_land.erl +++ b/src/bounty/bnt_grant_land.erl @@ -16,9 +16,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec attempt (shr_player:id()) -> map_map:type(). +-spec attempt (shr_player:id()) -> shr_map:type(). attempt (OwnerID) -> - Map = map_map:default(OwnerID), + Map = shr_map:default(OwnerID), {ok, MapID} = ataxia_client:add diff --git a/src/bounty/bnt_join_battle.erl b/src/bounty/bnt_join_battle.erl index 63b57df..b89627b 100644 --- a/src/bounty/bnt_join_battle.erl +++ b/src/bounty/bnt_join_battle.erl @@ -82,7 +82,7 @@ get_equipment_ids (Characters) -> ( btl_battle:type() ) - -> ordsets:ordset(btl_location:type()). + -> ordsets:ordset(shr_location:type()). get_forbidden_locations (Battle) -> orddict:fold ( @@ -95,13 +95,13 @@ get_forbidden_locations (Battle) -> -spec find_random_location ( - btl_map:type(), - ordsets:ordset(btl_location:type()) + shr_map:type(), + ordsets:ordset(shr_location:type()) ) - -> {btl_location:type(), shr_tile:type()}. + -> {shr_location:type(), shr_tile:type()}. find_random_location (Map, ForbiddenLocations) -> - MapWidth = btl_map:get_width(Map), - MapHeight = btl_map:get_height(Map), + MapWidth = shr_map:get_width(Map), + MapHeight = shr_map:get_height(Map), Candidate = { @@ -120,7 +120,7 @@ find_random_location (Map, ForbiddenLocations) -> ( shr_tile:extract_main_class_id ( - btl_map:get_tile_instance(Candidate, Map) + shr_map:get_tile_instance(Candidate, Map) ) ), @@ -146,8 +146,8 @@ get_glyphs_omnimods (RosterChar) -> ( non_neg_integer(), rst_character:type(), - btl_map:type(), - ordsets:ordset(btl_location:type()) + shr_map:type(), + ordsets:ordset(shr_location:type()) ) -> btl_character:type(). create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) -> @@ -175,8 +175,8 @@ create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) -> ( list(rst_character:type()), non_neg_integer(), - btl_map:type(), - ordsets:ordset(btl_location:type()), + shr_map:type(), + ordsets:ordset(shr_location:type()), non_neg_integer(), orddict:orddict(non_neg_integer(), btl_character:type()), list(ataxic:basic()) @@ -482,7 +482,7 @@ add_to_pending_battle shr_player:id(), non_neg_integer(), shr_battle_summary:category(), - map_map:id(), + shr_map:id(), list(non_neg_integer()) ) -> btl_pending_battle:type(). @@ -501,16 +501,8 @@ generate_pending_battle ataxia_security:user_from_id(PlayerID), MapID ), - TileInstances = map_map:get_tile_instances(Map), - BattleMap = - btl_map:from_instances_tuple - ( - map_map:get_width(Map), - map_map:get_height(Map), - TileInstances - ), - Battle = btl_battle:new(BattleMap), + Battle = btl_battle:new(Map), PendingBattle = btl_pending_battle:new @@ -581,7 +573,7 @@ repair_join_battle shr_battle_summary:category(), list(non_neg_integer()), btl_pending_battle:id(), - map_map:id() + shr_map:id() ) -> {ok, btl_pending_battle:type()}. repair_create_battle @@ -854,7 +846,7 @@ repair_battle_final_links (PendingBattleID, BattleID, Battle) -> shr_battle_summary:mode(), shr_battle_summary:category(), non_neg_integer(), - map_map:id(), + shr_map:id(), list(non_neg_integer()) ) -> 'ok'. diff --git a/src/map/query/map_load.erl b/src/map/query/map_load.erl index dde2fab..b8126dd 100644 --- a/src/map/query/map_load.erl +++ b/src/map/query/map_load.erl @@ -17,7 +17,7 @@ ( query_state, { - map :: map_map:type() + map :: shr_map:type() } ). @@ -80,7 +80,7 @@ fetch_data (Input) -> generate_reply (QueryState) -> Map = QueryState#query_state.map, - SetMap = map_set_map:generate(Map), + SetMap = shr_set_map:generate(Map), Output = jiffy:encode([SetMap]), Output. diff --git a/src/map/query/map_update.erl b/src/map/query/map_update.erl index b6e36c2..5cb9e42 100644 --- a/src/map/query/map_update.erl +++ b/src/map/query/map_update.erl @@ -20,7 +20,7 @@ ( query_state, { - map :: map_map:type() + map :: shr_map:type() } ). @@ -104,7 +104,7 @@ update_data (QueryState, Input) -> QueryState#query_state { map = - map_map:update_from_list + shr_map:update_from_list ( QueryState#query_state.map, Input#input.w, @@ -131,18 +131,18 @@ commit_update (QueryState, Input) -> [ ataxic:update_field ( - map_map:get_height_field(), + shr_map:get_height_field(), ataxic:constant(Input#input.h) ), ataxic:update_field ( - map_map:get_width_field(), + shr_map:get_width_field(), ataxic:constant(Input#input.w) ), ataxic:update_field ( - map_map:get_tile_instances_field(), - ataxic:constant(map_map:get_tile_instances(Map)) + shr_map:get_tile_instances_field(), + ataxic:constant(shr_map:get_tile_instances(Map)) ) ] ) diff --git a/src/map/reply/map_add_tile.erl b/src/map/reply/map_add_tile.erl deleted file mode 100644 index d5f029a..0000000 --- a/src/map/reply/map_add_tile.erl +++ /dev/null @@ -1,28 +0,0 @@ --module(map_add_tile). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (shr_tile:type()) -> {list(any())}. -generate (Tile) -> - { - [ - {<<"msg">>, <<"add_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 deleted file mode 100644 index 67675fe..0000000 --- a/src/map/reply/map_set_map.erl +++ /dev/null @@ -1,35 +0,0 @@ --module(map_set_map). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (map_map:type()) -> {list(any())}. -generate (Map) -> - { - [ - {<<"msg">>, <<"set_map">>}, - {<<"w">>, map_map:get_width(Map)}, - {<<"h">>, map_map:get_height(Map)}, - { - <<"t">>, - lists:map - ( - fun shr_tile:instance_to_binary_list/1, - tuple_to_list(map_map:get_tile_instances(Map)) - ) - } - ] - }. diff --git a/src/map/struct/map_location.erl b/src/map/struct/map_location.erl deleted file mode 100644 index edfb85a..0000000 --- a/src/map/struct/map_location.erl +++ /dev/null @@ -1,90 +0,0 @@ --module(map_location). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type type() :: ({non_neg_integer(), non_neg_integer()} | 'nowhere'). - --export_type([type/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - decode/1, - encode/1, - get_nowhere/0 - ] -). - --export -( - [ - apply_direction/2, - dist/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec validate ({integer(), integer()}) -> type(). -validate ({X, Y}) -> - if - (X < 0) -> nowhere; - (Y < 0) -> nowhere; - true -> {X, Y} - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec get_nowhere () -> type(). -get_nowhere () -> nowhere. - --spec apply_direction (map_direction:enum(), type()) -> type(). -apply_direction (left, {X, Y}) -> - validate({(X - 1), Y}); -apply_direction (right, {X, Y}) -> - validate({(X + 1), Y}); -apply_direction (up, {X, Y}) -> - validate({X, (Y - 1)}); -apply_direction (down, {X, Y}) -> - validate({X, (Y + 1)}); -apply_direction (_, nowhere) -> - error("Trying to move from 'nowhere'."), - nowhere. - --spec dist(type(), type()) -> non_neg_integer(). -dist ({OX, OY}, {DX, DY}) -> - (abs(DY - OY) + abs(DX - OX)); -dist (_, _) -> - error("Trying to measure distance to 'nowhere'"), - 999. - --spec encode (type()) -> {list(any())}. -encode ({X, Y}) -> - { - [ - {<<"x">>, X}, - {<<"y">>, Y} - ] - }; -encode (nowhere) -> - { - [ - {<<"x">>, -1}, - {<<"y">>, -1} - ] - }. - --spec decode (map()) -> type(). -decode (Map) -> - X = maps:get(<<"x">>, Map), - Y = maps:get(<<"y">>, Map), - - true = (is_integer(X) and is_integer(Y)), - - validate({X, Y}). diff --git a/src/battle/reply/btl_set_map.erl b/src/shared/reply/shr_set_map.erl index 3be6985..b335302 100644 --- a/src/battle/reply/btl_set_map.erl +++ b/src/shared/reply/shr_set_map.erl @@ -1,4 +1,4 @@ --module(btl_set_map). +-module(shr_set_map). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -16,19 +16,19 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (btl_map:type()) -> {list(any())}. +-spec generate (shr_map:type()) -> {list(any())}. generate (Map) -> { [ {<<"msg">>, <<"set_map">>}, - {<<"w">>, btl_map:get_width(Map)}, - {<<"h">>, btl_map:get_height(Map)}, + {<<"w">>, shr_map:get_width(Map)}, + {<<"h">>, shr_map:get_height(Map)}, { <<"t">>, lists:map ( fun shr_tile:instance_to_binary_list/1, - tuple_to_list(btl_map:get_tile_instances(Map)) + tuple_to_list(shr_map:get_tile_instances(Map)) ) } ] diff --git a/src/map/struct/map_direction.erl b/src/shared/struct/shr_direction.erl index bd61b7d..f0793b3 100644 --- a/src/map/struct/map_direction.erl +++ b/src/shared/struct/shr_direction.erl @@ -1,4 +1,4 @@ --module(map_direction). +-module(shr_direction). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/battle/struct/btl_location.erl b/src/shared/struct/shr_location.erl index 9670cb0..ec62ff7 100644 --- a/src/battle/struct/btl_location.erl +++ b/src/shared/struct/shr_location.erl @@ -1,4 +1,4 @@ --module(btl_location). +-module(shr_location). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -44,7 +44,7 @@ validate ({X, Y}) -> -spec get_nowhere () -> type(). get_nowhere () -> nowhere. --spec apply_direction (btl_direction:enum(), type()) -> type(). +-spec apply_direction (shr_direction:enum(), type()) -> type(). apply_direction (left, {X, Y}) -> validate({(X - 1), Y}); apply_direction (right, {X, Y}) -> diff --git a/src/map/struct/map_map.erl b/src/shared/struct/shr_map.erl index b8d37c9..a57ed32 100644 --- a/src/map/struct/map_map.erl +++ b/src/shared/struct/shr_map.erl @@ -1,4 +1,4 @@ --module(map_map). +-module(shr_map). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -9,9 +9,9 @@ ( map, { - owner :: binary(), - width :: integer(), - height :: integer(), + owner :: shr_player:id(), + width :: non_neg_integer(), + height :: non_neg_integer(), tile_instances :: shr_tile:instances_tuple() } ). @@ -31,10 +31,13 @@ get_width/1, get_height/1, get_tile_instances/1, - get_tile_instance/2 + get_tile_instance/2, + + get_used_tile_ids/1 ] ). +%%%% Fields -export ( [ @@ -44,10 +47,10 @@ ] ). +%%%% Utility -export ( [ - from_list/4, update_from_list/4, default/1 ] @@ -59,7 +62,7 @@ -spec location_to_index ( non_neg_integer(), - map_location:type() + shr_location:type() ) -> ('error' | non_neg_integer()). location_to_index (ArrayWidth, {X, Y}) -> @@ -74,23 +77,24 @@ location_to_index (ArrayWidth, {X, Y}) -> %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors --spec get_owner (type()) -> binary(). +-spec get_owner (type()) -> shr_player:id(). get_owner (Map) -> Map#map.owner. --spec get_width (type()) -> integer(). +-spec get_width (type()) -> non_neg_integer(). get_width (Map) -> Map#map.width. --spec get_height (type()) -> integer(). +-spec get_height (type()) -> non_neg_integer(). get_height (Map) -> Map#map.height. -spec get_tile_instances (type()) -> shr_tile:instances_tuple(). get_tile_instances (Map) -> Map#map.tile_instances. --spec get_tile_instance (map_location:type(), type()) -> shr_tile:instance(). +-spec get_tile_instance (shr_location:type(), type()) -> shr_tile:instance(). get_tile_instance (Location, Map) -> TileIX = location_to_index(Map#map.width, Location), element((TileIX + 1), Map#map.tile_instances). +%%%% Fields -spec get_width_field () -> non_neg_integer(). get_width_field () -> #map.width. @@ -100,24 +104,24 @@ get_height_field () -> #map.height. -spec get_tile_instances_field () -> non_neg_integer(). get_tile_instances_field () -> #map.tile_instances. --spec from_list - ( - binary(), - non_neg_integer(), - non_neg_integer(), - list(list(binary())) - ) - -> type(). -from_list (Owner, Width, Height, List) -> - TileInstances = lists:map(fun shr_tile:instance_from_binary_list/1, List), - - #map - { - owner = Owner, - width = Width, - height = Height, - tile_instances = list_to_tuple(TileInstances) - }. +%%%% Utility +-spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:class_id()). +get_used_tile_ids (Map) -> + UsedTileIDs = + lists:foldl + ( + fun (TileInstance, CurrentTileIDs) -> + ordsets:add_element + ( + shr_tile:extract_main_class_id(TileInstance), + CurrentTileIDs + ) + end, + ordsets:new(), + tuple_to_list(Map#map.tile_instances) + ), + + UsedTileIDs. -spec update_from_list ( diff --git a/src/shared/struct/shr_map_summary.erl b/src/shared/struct/shr_map_summary.erl index 554b988..745193c 100644 --- a/src/shared/struct/shr_map_summary.erl +++ b/src/shared/struct/shr_map_summary.erl @@ -7,7 +7,7 @@ ( map_summary, { - id :: binary(), + id :: shr_map:id(), name :: binary() } ). @@ -65,7 +65,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec new (binary(), binary()) -> type(). +-spec new (shr_map:id(), binary()) -> type(). new (ID, Name) -> #map_summary { @@ -74,13 +74,13 @@ new (ID, Name) -> }. %%%% Accessors --spec get_id (type()) -> binary(). +-spec get_id (type()) -> shr_map:id(). get_id (MapSummary) -> MapSummary#map_summary.id. -spec get_name (type()) -> binary(). get_name (MapSummary) -> MapSummary#map_summary.name. --spec set_id (binary(), type()) -> type(). +-spec set_id (shr_map:id(), type()) -> type(). set_id (Val, MapSummary) -> MapSummary#map_summary{ id = Val }. -spec set_name (binary(), type()) -> type(). |