summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-05-21 16:39:12 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-05-21 16:39:12 +0200
commit0157365585c1201c53aa29cac84cd977de7434a1 (patch)
tree44c301187f2809be974dbe8afcbc1032002ec1e8 /src/battle/struct/btl_action.erl
parentfb4159dbfb49f71d23c2616e7b8c9be453953883 (diff)
Working on Attacks of Opportunity.
Diffstat (limited to 'src/battle/struct/btl_action.erl')
-rw-r--r--src/battle/struct/btl_action.erl92
1 files changed, 87 insertions, 5 deletions
diff --git a/src/battle/struct/btl_action.erl b/src/battle/struct/btl_action.erl
index 34dd46e..52f41d8 100644
--- a/src/battle/struct/btl_action.erl
+++ b/src/battle/struct/btl_action.erl
@@ -13,6 +13,15 @@
-record
(
+ interrupted_move,
+ {
+ path :: list(shr_direction:enum()),
+ movement_points :: non_neg_integer()
+ }
+).
+
+-record
+(
switch_weapon,
{
}
@@ -26,8 +35,32 @@
}
).
--type category() :: ('move' | 'switch_weapon' | 'attack' | 'nothing').
--opaque type() :: (#move{} | #switch_weapon{} | #attack{}).
+-record
+(
+ defend,
+ {
+ target_ix :: non_neg_integer()
+ }
+).
+
+
+-type category() ::
+ (
+ 'move'
+ | 'interrupted_move'
+ | 'switch_weapon'
+ | 'attack'
+ | 'defend'
+ | 'nothing'
+ ).
+-opaque type() ::
+ (
+ #move{}
+ | #interrupted_move{}
+ | #switch_weapon{}
+ | #attack{}
+ | #defend{}
+ ).
-export_type([category/0, type/0]).
@@ -37,6 +70,7 @@
-export
(
[
+ from_map_marker/2,
maybe_decode_move/1,
maybe_decode_weapon_switch/1,
maybe_decode_attack/1,
@@ -47,7 +81,15 @@
-export
(
[
+ new_interrupted_move/2
+ ]
+).
+
+-export
+(
+ [
get_path/1,
+ get_movement_points/1,
get_target_ix/1,
get_category/1
]
@@ -86,17 +128,57 @@ can_follow (_, _) -> false.
-spec get_path (type()) -> list(shr_direction:type()).
get_path (Action) when is_record(Action, move) ->
Action#move.path;
+get_path (Action) when is_record(Action, interrupted_move) ->
+ Action#interrupted_move.path;
get_path (_) ->
[].
+-spec get_movement_points (type()) -> non_neg_integer().
+get_movement_points (Action) when is_record(Action, interrupted_move) ->
+ Action#interrupted_move.movement_points;
+get_movement_points (_) -> 0.
+
-spec get_target_ix (type()) -> non_neg_integer().
get_target_ix (Action) when is_record(Action, attack) ->
Action#attack.target_ix;
+get_target_ix (Action) when is_record(Action, defend) ->
+ Action#defend.target_ix;
get_target_ix (_) ->
- [].
+ 0.
+
+-spec new_interrupted_move
+ (
+ list(shr_direction:type()),
+ non_neg_integer()
+ )
+ -> type().
+new_interrupted_move (Path, MovementPoints) ->
+ #interrupted_move{ path = Path, movement_points = MovementPoints }.
-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.
-
+get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon;
+get_category (Action) when is_record(Action, interrupted_move) ->
+ interrupted_move;
+get_category (Action) when is_record(Action, defend) ->
+ defend.
+
+-spec from_map_marker
+ (
+ btl_character:type(),
+ shr_map_marker:type()
+ )
+ -> list(type()).
+from_map_marker (_Character, Marker) ->
+ case shr_map_marker:get_category(Marker) of
+ matk ->
+ [
+ #defend
+ {
+ target_ix = shr_map_marker:get_character_index(Marker)
+ }
+ ];
+
+ _ -> []
+ end.