summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-11-18 10:40:03 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-11-18 10:40:03 +0100
commit3fb30b108828e3ad6bf811c0f3372a79ec6e9595 (patch)
treeef12976907cea83f7ef70168173d487b3cdc018e /src/battle/struct/btl_character.erl
parentcc4e39960d3c56fceb2e31c01bf286dccc73615c (diff)
...
Diffstat (limited to 'src/battle/struct/btl_character.erl')
-rw-r--r--src/battle/struct/btl_character.erl249
1 files changed, 150 insertions, 99 deletions
diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl
index 9769f8f..41f5535 100644
--- a/src/battle/struct/btl_character.erl
+++ b/src/battle/struct/btl_character.erl
@@ -1,33 +1,30 @@
-module(btl_character).
-define(PLAYER_IX_FIELD, <<"pla">>).
--define(RANK_FIELD, <<"rnk">>).
-define(LOCATION_FIELD, <<"lc">>).
-define(CURRENT_HEALTH_FIELD, <<"he">>).
-define(SKILL_POINTS_FIELD, <<"sp">>).
-define(IS_ACTIVE_FIELD, <<"ena">>).
-define(IS_DEFEATED_FIELD, <<"dea">>).
-define(BASE_CHAR_FIELD, <<"bas">>).
--define(CONDITIONS_FIELD, <<"con">>).
+-define(STATUS_INDICATORS, <<"sti">>).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--type rank() :: ('optional' | 'target' | 'commander').
-
-record
(
btl_char_ref,
{
player_ix :: non_neg_integer(),
- rank :: rank(),
location :: shr_location:type(),
current_health :: integer(), %% Negative integers let us reverse attacks.
skill_points :: integer(), %% Negative integers let us reverse skill uses.
is_active :: boolean(),
is_defeated :: boolean(),
base :: shr_character:unresolved(),
- conditions :: btl_conditions:type()
+ conditions :: btl_conditions:type(),
+ status_indicators :: btl_status_indicators:type()
}
).
@@ -36,21 +33,22 @@
btl_char,
{
player_ix :: non_neg_integer(),
- rank :: rank(),
location :: shr_location:type(),
current_health :: integer(), %% Negative integers let us reverse attacks.
skill_points :: integer(), %% Negative integers let us reverse skill uses.
is_active :: boolean(),
is_defeated :: boolean(),
base :: shr_character:type(),
- conditions :: btl_conditions:type()
+ conditions :: btl_conditions:type(),
+ status_indicators :: btl_status_indicators:type()
}
).
-opaque type() :: #btl_char{}.
-opaque unresolved() :: #btl_char_ref{}.
-type either() :: (type() | unresolved()).
--export_type([type/0, unresolved/0, either/0, rank/0]).
+
+-export_type([type/0, unresolved/0, either/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -60,7 +58,6 @@
(
[
get_player_index/1,
- get_rank/1,
get_location/1,
get_current_health/1,
get_skill_points/1,
@@ -69,8 +66,8 @@
get_is_defeated/1,
get_base_character/1,
get_conditions/1,
+ get_status_indicators/1,
- set_rank/2,
set_location/3,
set_current_health/2,
set_skill_points/2,
@@ -78,8 +75,8 @@
set_is_defeated/2,
set_base_character/2,
set_conditions/2,
+ set_status_indicators/2,
- ataxia_set_rank/2,
ataxia_set_location/3,
ataxia_set_current_health/2,
ataxia_set_skill_points/2,
@@ -87,18 +84,20 @@
ataxia_set_is_defeated/2,
ataxia_set_base_character/2,
ataxia_set_conditions/2,
+ ataxia_set_status_indicators/2,
ataxia_set_conditions/3,
+ ataxia_set_status_indicators/3,
ataxia_set_base_character/3,
- get_rank_field/0,
get_current_health_field/0,
get_skill_points_field/0,
get_is_active_field/0,
get_is_defeated_field/0,
get_location_field/0,
get_base_character_field/0,
- get_conditions_field/0
+ get_conditions_field/0,
+ get_status_indicators_field/0
]
).
@@ -147,82 +146,23 @@ handle_max_health_change (OldBaseChar, NewBaseChar, OldHealth) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%% Accessors
+
+%%%% Accessors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%
+%%%% Player Index %%%%
+%%%%%%%%%%%%%%%%%%%%%%
-spec get_player_index (either()) -> non_neg_integer().
get_player_index (#btl_char{ player_ix = R }) -> R;
get_player_index (#btl_char_ref{ player_ix = R }) -> R.
--spec get_rank (either()) -> rank().
-get_rank (#btl_char{ rank = R }) -> R;
-get_rank (#btl_char_ref{ rank = R }) -> R.
-
+%%%%%%%%%%%%%%%%%%
+%%%% Location %%%%
+%%%%%%%%%%%%%%%%%%
-spec get_location (either()) -> shr_location:type().
get_location (#btl_char{ location = R }) -> R;
get_location (#btl_char_ref{ location = R }) -> R.
--spec get_current_health (either()) -> integer().
-get_current_health (#btl_char{ current_health = R }) -> R;
-get_current_health (#btl_char_ref{ current_health = R }) -> R.
-
--spec get_skill_points (either()) -> integer().
-get_skill_points (#btl_char{ skill_points = R }) -> R;
-get_skill_points (#btl_char_ref{ skill_points = R }) -> R.
-
--spec get_is_alive (either()) -> boolean().
-get_is_alive (#btl_char{ current_health = H, is_defeated = D }) ->
- ((not D) and (H > 0));
-get_is_alive (#btl_char_ref{ current_health = H, is_defeated = D }) ->
- ((not D) and (H > 0)).
-
--spec get_is_active (either()) -> boolean().
-get_is_active
-(
- #btl_char{ current_health = H, is_defeated = D, is_active = A }
-) ->
- ((not D) and (H > 0) and A);
-get_is_active
-(
- #btl_char_ref{ current_health = H, is_defeated = D, is_active = A }
-) ->
- ((not D) and (H > 0) and A).
-
--spec get_is_defeated (either()) -> boolean().
-get_is_defeated (#btl_char{ is_defeated = R }) -> R;
-get_is_defeated (#btl_char_ref{ is_defeated = R }) -> R.
-
--spec get_base_character
- (type()) -> shr_character:type();
- (unresolved()) -> shr_character:unresolved().
-get_base_character (#btl_char{ base = R }) -> R;
-get_base_character (#btl_char_ref{ base = R }) -> R.
-
--spec get_conditions
- (type()) -> btl_conditions:type();
- (unresolved()) -> btl_conditions:type().
-get_conditions (#btl_char{ conditions = R }) -> R;
-get_conditions (#btl_char_ref{ conditions = R }) -> R.
-
--spec set_rank
- (rank(), type()) -> type();
- (rank(), unresolved()) -> unresolved().
-set_rank (Rank, Char) when is_record(Char, btl_char) ->
- Char#btl_char{ rank = Rank };
-set_rank (Rank, Char) when is_record(Char, btl_char_ref) ->
- Char#btl_char_ref{ rank = Rank }.
-
--spec ataxia_set_rank
- (rank(), type()) -> {type(), ataxic:basic()};
- (rank(), unresolved()) -> {unresolved(), ataxic:basic()}.
-ataxia_set_rank (Rank, Char) ->
- {
- set_rank(Rank, Char),
- ataxic:update_field
- (
- get_rank_field(),
- ataxic:constant(Rank)
- )
- }.
-
-spec set_location
(
shr_location:type(),
@@ -296,6 +236,19 @@ ataxia_set_location (Location, LocOmnimods, Char) ->
end
}.
+%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Current Health %%%%
+%%%%%%%%%%%%%%%%%%%%%%%%
+-spec get_current_health (either()) -> integer().
+get_current_health (#btl_char{ current_health = R }) -> R;
+get_current_health (#btl_char_ref{ current_health = R }) -> R.
+
+-spec get_is_alive (either()) -> boolean().
+get_is_alive (#btl_char{ current_health = H, is_defeated = D }) ->
+ ((not D) and (H > 0));
+get_is_alive (#btl_char_ref{ current_health = H, is_defeated = D }) ->
+ ((not D) and (H > 0)).
+
-spec set_current_health
(integer(), type()) -> type();
(integer(), unresolved()) -> unresolved().
@@ -317,6 +270,13 @@ ataxia_set_current_health (Health, Char) ->
)
}.
+%%%%%%%%%%%%%%%%%%%%%%
+%%%% Skill Points %%%%
+%%%%%%%%%%%%%%%%%%%%%%
+-spec get_skill_points (either()) -> integer().
+get_skill_points (#btl_char{ skill_points = R }) -> R;
+get_skill_points (#btl_char_ref{ skill_points = R }) -> R.
+
-spec set_skill_points
(integer(), type()) -> type();
(integer(), unresolved()) -> unresolved().
@@ -338,6 +298,21 @@ ataxia_set_skill_points (SkillPoints, Char) ->
)
}.
+%%%%%%%%%%%%%%%%%%%
+%%%% Is Active %%%%
+%%%%%%%%%%%%%%%%%%%
+-spec get_is_active (either()) -> boolean().
+get_is_active
+(
+ #btl_char{ current_health = H, is_defeated = D, is_active = A }
+) ->
+ ((not D) and (H > 0) and A);
+get_is_active
+(
+ #btl_char_ref{ current_health = H, is_defeated = D, is_active = A }
+) ->
+ ((not D) and (H > 0) and A).
+
-spec set_is_active
(boolean(), type()) -> type();
(boolean(), unresolved()) -> unresolved().
@@ -359,6 +334,13 @@ ataxia_set_is_active (Active, Char) ->
)
}.
+%%%%%%%%%%%%%%%%%%%%%
+%%%% Is Defeated %%%%
+%%%%%%%%%%%%%%%%%%%%%
+-spec get_is_defeated (either()) -> boolean().
+get_is_defeated (#btl_char{ is_defeated = R }) -> R;
+get_is_defeated (#btl_char_ref{ is_defeated = R }) -> R.
+
-spec set_is_defeated
(boolean(), type()) -> type();
(boolean(), unresolved()) -> unresolved().
@@ -380,6 +362,15 @@ ataxia_set_is_defeated (Defeated, Char) ->
)
}.
+%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Base Character %%%%
+%%%%%%%%%%%%%%%%%%%%%%%%
+-spec get_base_character
+ (type()) -> shr_character:type();
+ (unresolved()) -> shr_character:unresolved().
+get_base_character (#btl_char{ base = R }) -> R;
+get_base_character (#btl_char_ref{ base = R }) -> R.
+
-spec set_base_character (shr_character:type(), type()) -> type().
set_base_character (NewBaseCharacter, Char) ->
CurrentBaseCharacter = Char#btl_char.base,
@@ -456,6 +447,15 @@ ataxia_set_base_character (NewBaseCharacter, Char) ->
Char
).
+%%%%%%%%%%%%%%%%%%%%
+%%%% Conditions %%%%
+%%%%%%%%%%%%%%%%%%%%
+-spec get_conditions
+ (type()) -> btl_conditions:type();
+ (unresolved()) -> btl_conditions:type().
+get_conditions (#btl_char{ conditions = R }) -> R;
+get_conditions (#btl_char_ref{ conditions = R }) -> R.
+
-spec set_conditions
(btl_conditions:type(), type()) -> type();
(btl_conditions:type(), unresolved()) -> unresolved().
@@ -464,7 +464,6 @@ set_conditions (Conditions, Char) when is_record(Char, btl_char) ->
set_conditions (Conditions, Char) when is_record(Char, btl_char_ref) ->
Char#btl_char_ref{ conditions = Conditions }.
-
-spec ataxia_set_conditions
(
btl_conditions:type(),
@@ -498,37 +497,90 @@ ataxia_set_conditions (Conditions, Char) ->
Char
).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Status Indicators %%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec get_status_indicators
+ (type()) -> btl_status_indicators:type();
+ (unresolved()) -> btl_status_indicators:type().
+get_status_indicators (#btl_char{ status_indicators = R }) -> R;
+get_status_indicators (#btl_char_ref{ status_indicators = R }) -> R.
+
+-spec set_status_indicators
+ (btl_status_indicators:type(), type()) -> type();
+ (btl_status_indicators:type(), unresolved()) -> unresolved().
+set_status_indicators (StatusIndicators, Char) when is_record(Char, btl_char) ->
+ Char#btl_char{ status_indicators = StatusIndicators };
+set_status_indicators (StatusIndicators, Char) when is_record(Char, btl_char_ref) ->
+ Char#btl_char_ref{ status_indicators = StatusIndicators }.
+
+-spec ataxia_set_status_indicators
+ (
+ btl_status_indicators:type(),
+ ataxic:basic(),
+ type()
+ )
+ -> {type(), ataxic:basic()};
+ (
+ btl_status_indicators:type(),
+ ataxic:basic(),
+ unresolved()
+ ) -> {unresolved(), ataxic:basic()}.
+ataxia_set_status_indicators (StatusIndicators, Update, Char) ->
+ {
+ set_status_indicators(StatusIndicators, Char),
+ ataxic:update_field
+ (
+ get_status_indicators_field(),
+ Update
+ )
+ }.
+
+-spec ataxia_set_status_indicators
+ (btl_status_indicators:type(), type()) -> {type(), ataxic:basic()};
+ (
+ btl_status_indicators:type(),
+ unresolved()
+ ) -> {unresolved(), ataxic:basic()}.
+ataxia_set_status_indicators (StatusIndicators, Char) ->
+ ataxia_set_status_indicators
+ (
+ StatusIndicators,
+ ataxic:constant(StatusIndicators),
+ Char
+ ).
+
%%%% Utils
-spec new
(
non_neg_integer(),
- rank(),
shr_location:type(),
shr_character:type(),
- btl_conditions:type()
+ btl_conditions:type(),
+ btl_status_indicators:type()
)
-> type().
new
(
PlayerIX,
- Rank,
Location,
Base,
- Conditions
+ Conditions,
+ StatusIndicators
) ->
Attributes = shr_character:get_attributes(Base),
#btl_char
{
player_ix = PlayerIX,
- rank = Rank,
location = Location,
current_health = shr_attributes:get_health(Attributes),
skill_points = 0,
is_active = (PlayerIX == 0),
is_defeated = false,
base = Base,
- conditions = Conditions
+ conditions = Conditions,
+ status_indicators = StatusIndicators
}.
-spec resolve (shr_omnimods:type(), either()) -> type().
@@ -536,14 +588,14 @@ resolve (LocalOmnimods, CharRef) when is_record(CharRef, btl_char_ref) ->
#btl_char
{
player_ix = CharRef#btl_char_ref.player_ix,
- rank = CharRef#btl_char_ref.rank,
location = CharRef#btl_char_ref.location,
current_health = CharRef#btl_char_ref.current_health,
skill_points = CharRef#btl_char_ref.skill_points,
is_active = CharRef#btl_char_ref.is_active,
is_defeated = CharRef#btl_char_ref.is_defeated,
base = shr_character:resolve(LocalOmnimods, CharRef#btl_char_ref.base),
- conditions = CharRef#btl_char_ref.conditions
+ conditions = CharRef#btl_char_ref.conditions,
+ status_indicators = CharRef#btl_char_ref.status_indicators
};
resolve (_LocalOmnimods, Char) when is_record(Char, btl_char) -> Char.
@@ -552,22 +604,20 @@ to_unresolved (Char) when is_record(Char, btl_char) ->
#btl_char_ref
{
player_ix = Char#btl_char.player_ix,
- rank = Char#btl_char.rank,
location = Char#btl_char.location,
current_health = Char#btl_char.current_health,
skill_points = Char#btl_char.skill_points,
is_active = Char#btl_char.is_active,
is_defeated = Char#btl_char.is_defeated,
base = shr_character:to_unresolved(Char#btl_char.base),
- conditions = Char#btl_char.conditions
+ conditions = Char#btl_char.conditions,
+ status_indicators = Char#btl_char.status_indicators
};
to_unresolved (CharRef) when is_record(CharRef, btl_char_ref) -> CharRef.
-spec is_unresolved (either()) -> boolean().
is_unresolved (Char) -> is_record(Char, btl_char_ref).
--spec get_rank_field() -> non_neg_integer().
-get_rank_field () -> #btl_char_ref.rank.
-spec get_location_field() -> non_neg_integer().
get_location_field () -> #btl_char_ref.location.
-spec get_current_health_field() -> non_neg_integer().
@@ -582,13 +632,14 @@ get_is_defeated_field () -> #btl_char_ref.is_defeated.
get_base_character_field () -> #btl_char_ref.base.
-spec get_conditions_field() -> non_neg_integer().
get_conditions_field () -> #btl_char_ref.conditions.
+-spec get_status_indicators_field() -> non_neg_integer().
+get_status_indicators_field () -> #btl_char_ref.status_indicators.
-spec encode_for (non_neg_integer(), unresolved()) -> {list({binary(), any()})}.
encode_for (RequestingPlayerIX, CharRef) ->
{
[
{?PLAYER_IX_FIELD, CharRef#btl_char_ref.player_ix},
- {?RANK_FIELD, CharRef#btl_char_ref.rank},
{?LOCATION_FIELD, shr_location:encode(CharRef#btl_char_ref.location)},
{?CURRENT_HEALTH_FIELD, CharRef#btl_char_ref.current_health},
{?SKILL_POINTS_FIELD, CharRef#btl_char_ref.skill_points},
@@ -596,11 +647,11 @@ encode_for (RequestingPlayerIX, CharRef) ->
{?IS_DEFEATED_FIELD, CharRef#btl_char_ref.is_defeated},
{?BASE_CHAR_FIELD, shr_character:encode(CharRef#btl_char_ref.base)},
{
- ?CONDITIONS_FIELD,
- btl_conditions:encode_for
+ ?STATUS_INDICATORS,
+ btl_status_indicators:encode_for
(
RequestingPlayerIX,
- CharRef#btl_char_ref.conditions
+ CharRef#btl_char_ref.status_indicators
)
}
]