summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-05-11 18:03:50 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-05-11 18:03:50 +0200
commit2bea185eb9191ddaeb406cd7ff3bcef37fbc4343 (patch)
tree31f205308a462fa82cf9a2443518f7339754a1f5
parentdfa4fa60b4fc5c96573cd75128906c0db593424d (diff)
Passes Dialyzer's checks once again.
-rw-r--r--src/battlemap/src/game-logic/next_turn.erl6
-rw-r--r--src/battlemap/src/game-logic/turn_actions.erl64
-rw-r--r--src/battlemap/src/query/character_turn.erl5
-rw-r--r--src/battlemap/src/struct/attack.erl2
-rw-r--r--src/battlemap/src/struct/attributes.erl2
-rw-r--r--src/battlemap/src/struct/battle.erl2
-rw-r--r--src/battlemap/src/struct/battle_action.erl29
-rw-r--r--src/battlemap/src/struct/battlemap.erl2
-rw-r--r--src/battlemap/src/struct/character.erl2
-rw-r--r--src/battlemap/src/struct/character_instance.erl2
-rw-r--r--src/battlemap/src/struct/character_turn_update.erl2
-rw-r--r--src/battlemap/src/struct/player.erl2
-rw-r--r--src/battlemap/src/struct/statistics.erl2
-rw-r--r--src/battlemap/src/struct/tile.erl2
-rw-r--r--src/battlemap/src/struct/turn_result.erl2
-rw-r--r--src/battlemap/src/struct/weapon.erl2
16 files changed, 87 insertions, 41 deletions
diff --git a/src/battlemap/src/game-logic/next_turn.erl b/src/battlemap/src/game-logic/next_turn.erl
index ee3b59f..03d2cbf 100644
--- a/src/battlemap/src/game-logic/next_turn.erl
+++ b/src/battlemap/src/game-logic/next_turn.erl
@@ -25,7 +25,11 @@ set_player_turn_to_next (Battle) ->
battle:set_current_player_turn(NextPlayerTurn, Battle).
--spec reset_next_player_timeline (battle:type()) -> battle:type().
+-spec reset_next_player_timeline
+ (
+ battle:type()
+ )
+ -> {battle:type(), player:type()}.
reset_next_player_timeline (Battle) ->
NextPlayerTurn = battle:get_current_player_turn(Battle),
NextPlayerIX = player_turn:get_player_ix(NextPlayerTurn),
diff --git a/src/battlemap/src/game-logic/turn_actions.erl b/src/battlemap/src/game-logic/turn_actions.erl
index 4f46771..29886a1 100644
--- a/src/battlemap/src/game-logic/turn_actions.erl
+++ b/src/battlemap/src/game-logic/turn_actions.erl
@@ -102,7 +102,7 @@ get_path_cost_and_destination (Data, Path) ->
-spec assert_character_can_move
(
character_turn_data:type(),
- list(direction:type())
+ non_neg_integer()
)
-> 'ok'.
assert_character_can_move (Data, Cost) ->
@@ -234,20 +234,14 @@ handle_attack_sequence
AttackPlannedEffects
).
--spec handle_attack
+-spec get_attack_sequence
(
- character_turn_update:type(),
- battle_action:type()
+ character_instance:type(),
+ character_instance:type()
)
- -> character_turn_update:type().
-handle_attack (Update, BattleAction) ->
- Data = character_turn_update:get_data(Update),
- Battle = character_turn_data:get_battle(Data),
- CharacterInstance = character_turn_data:get_character_instance(Data),
- CharacterInstanceIX = character_turn_data:get_character_instance_ix(Data),
+ -> list(attack:step()).
+get_attack_sequence (CharacterInstance, TargetCharacterInstance) ->
Character = character_instance:get_character(CharacterInstance),
- TargetIX = battle_action:get_target_ix(BattleAction),
- TargetCharacterInstance = battle:get_character_instance(TargetIX, Battle),
TargetCharacter = character_instance:get_character(TargetCharacterInstance),
Range =
@@ -263,8 +257,25 @@ handle_attack (Update, BattleAction) ->
AttackingWeapon = weapon:from_id(AttackingWeaponID),
DefendingWeapon = weapon:from_id(DefendingWeaponID),
+ attack:get_sequence(Range, AttackingWeapon, DefendingWeapon).
+
+
+-spec handle_attack
+ (
+ character_turn_update:type(),
+ battle_action:type()
+ )
+ -> character_turn_update:type().
+handle_attack (Update, BattleAction) ->
+ Data = character_turn_update:get_data(Update),
+ Battle = character_turn_data:get_battle(Data),
+ CharacterInstance = character_turn_data:get_character_instance(Data),
+ CharacterInstanceIX = character_turn_data:get_character_instance_ix(Data),
+ TargetIX = battle_action:get_target_ix(BattleAction),
+ TargetCharacterInstance = battle:get_character_instance(TargetIX, Battle),
+
AttackSequence =
- attack:get_sequence(Range, AttackingWeapon, DefendingWeapon),
+ get_attack_sequence(CharacterInstance, TargetCharacterInstance),
{AttackEffects, RemainingAttackerHealth, RemainingDefenderHealth} =
handle_attack_sequence
@@ -292,20 +303,27 @@ handle_attack (Update, BattleAction) ->
),
Battle
),
- {
- % TODO: hide that into database_diff structs.
- [], % TODO
- [
+
+ S0Data = character_turn_data:set_battle(UpdatedBattle, Data),
+ S1Data =
+ character_turn_data:set_character_instance
+ (
+ UpdatedCharacterInstance,
+ S0Data
+ ),
+
+ S0Update =
+ character_turn_update:add_to_timeline
+ (
turn_result:new_character_attacked
(
CharacterInstanceIX,
TargetIX,
AttackEffects
- )
- ],
- UpdatedBattle,
- UpdatedCharacterInstance
- }.
+ ),
+ Update
+ ),
+ character_turn_update:set_data(S1Data, S0Update).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -317,7 +335,7 @@ handle_attack (Update, BattleAction) ->
)
-> character_turn_update:type().
handle (Update, BattleAction) ->
- case battle_action:get_type(BattleAction) of
+ case battle_action:get_category(BattleAction) of
move -> handle_move(Update, BattleAction);
switch_weapon -> handle_switch_weapon(Update);
attack -> handle_attack(Update, BattleAction)
diff --git a/src/battlemap/src/query/character_turn.erl b/src/battlemap/src/query/character_turn.erl
index b269084..0814131 100644
--- a/src/battlemap/src/query/character_turn.erl
+++ b/src/battlemap/src/query/character_turn.erl
@@ -119,7 +119,7 @@ finalize_character_instance (Update) ->
DisabledCharacterInstance,
Data
),
- FinalizedData = character_turn_data:cleanup(UpdatedData),
+ FinalizedData = character_turn_data:clean_battle(UpdatedData),
character_turn_update:set_data(FinalizedData, Update).
@@ -164,8 +164,7 @@ update_timeline (Update) ->
)
-> character_turn_update:type().
update_data (Data, Request) ->
- EmptyUpdate = character_turn_update:new(Data),
- PostActionsUpdate = handle_actions(EmptyUpdate, Request),
+ PostActionsUpdate = handle_actions(Data, Request),
PostCharacterTurnUpdate = update_timeline(PostActionsUpdate),
next_turn:update_if_needed(PostCharacterTurnUpdate).
diff --git a/src/battlemap/src/struct/attack.erl b/src/battlemap/src/struct/attack.erl
index bddc3cd..fed6a56 100644
--- a/src/battlemap/src/struct/attack.erl
+++ b/src/battlemap/src/struct/attack.erl
@@ -24,7 +24,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export_type([struct/0, maybe_struct/0, step/0]).
+-export_type([type/0, maybe_type/0, step/0]).
-export
(
diff --git a/src/battlemap/src/struct/attributes.erl b/src/battlemap/src/struct/attributes.erl
index 0d503ee..aca91d3 100644
--- a/src/battlemap/src/struct/attributes.erl
+++ b/src/battlemap/src/struct/attributes.erl
@@ -18,7 +18,7 @@
-opaque type() :: #attributes{}.
--export_type([struct/0]).
+-export_type([type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/battle.erl b/src/battlemap/src/struct/battle.erl
index 4d5be8b..259e7f0 100644
--- a/src/battlemap/src/struct/battle.erl
+++ b/src/battlemap/src/struct/battle.erl
@@ -19,7 +19,7 @@
-opaque type() :: #battle{}.
--export_type([struct/0, id/0]).
+-export_type([type/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/battle_action.erl b/src/battlemap/src/struct/battle_action.erl
index 2b1a89e..b7d80ee 100644
--- a/src/battlemap/src/struct/battle_action.erl
+++ b/src/battlemap/src/struct/battle_action.erl
@@ -29,7 +29,7 @@
-type category() :: ('move' | 'switch_weapon' | 'attack' | 'nothing').
-opaque type() :: (#move{} | #switch_weapon{} | #attack{}).
--export_type([category/0, struct/0]).
+-export_type([category/0, type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -42,6 +42,15 @@
]
).
+-export
+(
+ [
+ get_path/1,
+ get_target_ix/1,
+ get_category/1
+ ]
+).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -62,7 +71,6 @@ decode_atk_action (JSONMap) ->
decode_swp_action (_JSONMap) ->
#switch_weapon{}.
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -83,3 +91,20 @@ can_follow (nothing, move) -> true;
can_follow (switch_weapon, attack) -> true;
can_follow (move, attack) -> true;
can_follow (_, _) -> false.
+
+-spec get_path (type()) -> list(direction:type()).
+get_path (Action) when is_record(Action, move) ->
+ Action#move.path;
+get_path (_) ->
+ [].
+
+-spec get_target_ix (type()) -> non_neg_integer().
+get_target_ix (Action) when is_record(Action, attack) ->
+ Action#attack.target_ix;
+get_target_ix (_) ->
+ [].
+
+-spec get_category (type()) -> category().
+get_category (Action) when is_record(Action, attack) -> attack;
+get_category (Action) when is_record(Action, move) -> move;
+get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon.
diff --git a/src/battlemap/src/struct/battlemap.erl b/src/battlemap/src/struct/battlemap.erl
index e0d30a4..dc6bdc7 100644
--- a/src/battlemap/src/struct/battlemap.erl
+++ b/src/battlemap/src/struct/battlemap.erl
@@ -18,7 +18,7 @@
-opaque type() :: #battlemap{}.
--export_type([struct/0, id/0]).
+-export_type([type/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/character.erl b/src/battlemap/src/struct/character.erl
index 7daaadd..34a44a1 100644
--- a/src/battlemap/src/struct/character.erl
+++ b/src/battlemap/src/struct/character.erl
@@ -22,7 +22,7 @@
-opaque type() :: #character{}.
--export_type([struct/0, id/0]).
+-export_type([type/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/character_instance.erl b/src/battlemap/src/struct/character_instance.erl
index e58723e..912f2cf 100644
--- a/src/battlemap/src/struct/character_instance.erl
+++ b/src/battlemap/src/struct/character_instance.erl
@@ -16,7 +16,7 @@
-opaque type() :: #character_instance{}.
--export_type([struct/0]).
+-export_type([type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/character_turn_update.erl b/src/battlemap/src/struct/character_turn_update.erl
index a6642e4..dda09d9 100644
--- a/src/battlemap/src/struct/character_turn_update.erl
+++ b/src/battlemap/src/struct/character_turn_update.erl
@@ -42,7 +42,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec new (data:type()) -> type().
+-spec new (character_turn_data:type()) -> type().
new (Data) ->
#type
{
diff --git a/src/battlemap/src/struct/player.erl b/src/battlemap/src/struct/player.erl
index 04939cb..4cd073e 100644
--- a/src/battlemap/src/struct/player.erl
+++ b/src/battlemap/src/struct/player.erl
@@ -16,7 +16,7 @@
-opaque type() :: #player{}.
--export_type([struct/0, id/0]).
+-export_type([type/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/statistics.erl b/src/battlemap/src/struct/statistics.erl
index b1e88b8..3406d9a 100644
--- a/src/battlemap/src/struct/statistics.erl
+++ b/src/battlemap/src/struct/statistics.erl
@@ -21,7 +21,7 @@
-opaque type() :: #statistics{}.
--export_type([struct/0]).
+-export_type([type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/tile.erl b/src/battlemap/src/struct/tile.erl
index aea139e..a2e04ee 100644
--- a/src/battlemap/src/struct/tile.erl
+++ b/src/battlemap/src/struct/tile.erl
@@ -6,7 +6,7 @@
-opaque id() :: non_neg_integer().
-opaque type() :: id().
--export_type([struct/0, id/0]).
+-export_type([type/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/battlemap/src/struct/turn_result.erl b/src/battlemap/src/struct/turn_result.erl
index 797c8ca..53ae94e 100644
--- a/src/battlemap/src/struct/turn_result.erl
+++ b/src/battlemap/src/struct/turn_result.erl
@@ -37,7 +37,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export_type([struct/0]).
+-export_type([type/0]).
-export
(
diff --git a/src/battlemap/src/struct/weapon.erl b/src/battlemap/src/struct/weapon.erl
index fa348a0..7d3c874 100644
--- a/src/battlemap/src/struct/weapon.erl
+++ b/src/battlemap/src/struct/weapon.erl
@@ -25,7 +25,7 @@
-opaque type() :: #weapon{}.
--export_type([struct/0, id/0]).
+-export_type([type/0, id/0]).
-export_type
(
[