summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/battle/struct')
-rw-r--r--src/battle/struct/btl_battle.erl10
-rw-r--r--src/battle/struct/btl_battle_action.erl8
-rw-r--r--src/battle/struct/btl_character.erl2
-rw-r--r--src/battle/struct/btl_character_current_data.erl6
-rw-r--r--src/battle/struct/btl_direction.erl38
-rw-r--r--src/battle/struct/btl_location.erl90
-rw-r--r--src/battle/struct/btl_map.erl126
-rw-r--r--src/battle/struct/btl_turn_result.erl12
8 files changed, 19 insertions, 273 deletions
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_location.erl b/src/battle/struct/btl_location.erl
deleted file mode 100644
index 9670cb0..0000000
--- a/src/battle/struct/btl_location.erl
+++ /dev/null
@@ -1,90 +0,0 @@
--module(btl_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 (btl_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/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),
{
[