summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-11-18 10:40:03 +0100 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-11-18 10:40:03 +0100 |
commit | 3fb30b108828e3ad6bf811c0f3372a79ec6e9595 (patch) | |
tree | ef12976907cea83f7ef70168173d487b3cdc018e /src/battle/struct/btl_conditions.erl | |
parent | cc4e39960d3c56fceb2e31c01bf286dccc73615c (diff) |
...
Diffstat (limited to 'src/battle/struct/btl_conditions.erl')
-rw-r--r-- | src/battle/struct/btl_conditions.erl | 146 |
1 files changed, 22 insertions, 124 deletions
diff --git a/src/battle/struct/btl_conditions.erl b/src/battle/struct/btl_conditions.erl index 70ceed6..69f1ac8 100644 --- a/src/battle/struct/btl_conditions.erl +++ b/src/battle/struct/btl_conditions.erl @@ -5,13 +5,6 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -include("tacticians/conditions.hrl"). --type visibility() :: - ( - none - | {limited, ordsets:ordset(non_neg_integer())} % PlayerIXs - | all - ). - -type ref() :: ( {char, non_neg_integer(), non_neg_integer()} @@ -24,8 +17,7 @@ { category :: shr_condition:id(), triggers :: ordsets:ordset(shr_condition:trigger()), - parameters :: btl_condition_parameters:type(any()), - visibility :: visibility() + parameters :: btl_condition_parameters:type(any()) } ). @@ -52,7 +44,6 @@ [ type/0, ref/0, - visibility/0, single/0 ] ). @@ -72,19 +63,15 @@ get_triggers/1, set_triggers/3, % IX, Value, Conditions - ataxia_set_triggers/3, % IX, Value, Conditions - - get_visibility/1, - set_visibility/3, % IX, Value, Conditions - ataxia_set_visibility/3 % IX, Value, Conditions + ataxia_set_triggers/3 % IX, Value, Conditions ] ). -export ( [ - add/5, - ataxia_add/5, + add/4, + ataxia_add/4, remove/2, ataxia_remove/2, new/0 @@ -99,13 +86,6 @@ ] ). --export -( - [ - encode_for/2 - ] -). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -185,31 +165,6 @@ compute_next_index (Conditions) -> Result. --spec encode_single (non_neg_integer(), single()) -> {list({binary(), any()})}. -encode_single (IX, Condition) -> - Module = - shr_condition:get_module - ( - shr_condition:from_id(Condition#btl_cond.category) - ), - - EncodedParameters = - erlang:apply - ( - Module, - encode_parameters, - [ - Condition#btl_cond.parameters - ] - ), - - { - [ - {<<"ix">>, IX}, - {<<"p">>, EncodedParameters} - ] - }. - -spec get_relevant_condition_indices ( shr_condition:trigger(), @@ -227,12 +182,20 @@ get_relevant_condition_indices(Trigger, Conditions) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec get_condition (ref(), btl_character_turn_update:type()) -> single(). +-spec get_condition + ( + ref(), + btl_character_turn_update:type() + ) + -> ({ok, single()} | none). get_condition ({battle, IX}, Update) -> Conditions = btl_battle:get_conditions(btl_character_turn_update:get_battle(Update)), - orddict:fetch(IX, Conditions#btl_conds.collection); + case orddict:find(IX, Conditions#btl_conds.collection) of + error -> none; + Other -> Other + end; get_condition ({char, CharIX, CondIX}, Update) -> Conditions = btl_character:get_conditions @@ -244,53 +207,10 @@ get_condition ({char, CharIX, CondIX}, Update) -> ) ), - orddict:fetch(CondIX, Conditions#btl_conds.collection). - -%%%%%%%%%%%%%%%%%%%% -%%%% Visibility %%%% -%%%%%%%%%%%%%%%%%%%% --spec get_visibility (single()) -> visibility(). -get_visibility (Condition) -> Condition#btl_cond.visibility. - --spec set_visibility (non_neg_integer(), visibility(), type()) -> type(). -set_visibility (IX, NewVisibility, Conditions) -> - Conditions#btl_conds - { - collection = - orddict:update - ( - IX, - fun (Condition) -> - Condition#btl_cond{ visibility = NewVisibility } - end, - Conditions#btl_conds.collection - ) - }. - --spec ataxia_set_visibility - ( - non_neg_integer(), - visibility(), - type() - ) - -> {type(), ataxic:basic()}. -ataxia_set_visibility (IX, NewVisibility, Conditions) -> - { - set_visibility(IX, NewVisibility, Conditions), - ataxic:update_field - ( - #btl_conds.collection, - ataxic_sugar:update_orddict_element - ( - IX, - ataxic:update_field - ( - #btl_cond.visibility, - ataxic:constant(NewVisibility) - ) - ) - ) - }. + case orddict:find(CondIX, Conditions#btl_conds.collection) of + error -> none; + Other -> Other + end. %%%%%%%%%%%%%%%%%% %%%% Triggers %%%% @@ -640,18 +560,16 @@ apply_to_battle shr_condition:id(), ordsets:ordset(shr_condition:trigger()), any(), - visibility(), type() ) -> {type(), non_neg_integer()}. -add (CondID, Triggers, Params, Visibility, Conditions) -> +add (CondID, Triggers, Params, Conditions) -> NewCondition = #btl_cond { category = CondID, triggers = Triggers, - parameters = Params, - visibility = Visibility + parameters = Params }, NewConditionIX = compute_next_index(Conditions), @@ -693,18 +611,16 @@ add (CondID, Triggers, Params, Visibility, Conditions) -> shr_condition:id(), ordsets:ordset(shr_condition:trigger()), any(), - visibility(), type() ) -> {type(), non_neg_integer(), ataxic:basic()}. -ataxia_add (CondID, Triggers, Params, Visibility, Conditions) -> +ataxia_add (CondID, Triggers, Params, Conditions) -> NewCondition = #btl_cond { category = CondID, triggers = Triggers, - parameters = Params, - visibility = Visibility + parameters = Params }, NewConditionIX = compute_next_index(Conditions), @@ -846,21 +762,3 @@ new () -> collection = orddict:new(), from_trigger = orddict:new() }. - --spec encode_for (non_neg_integer(), type()) -> list(any()). -encode_for (PlayerIX, Conditions) -> - lists:filtermap - ( - fun ({IX, Condition}) -> - case Condition#btl_cond.visibility of - none -> false; - all -> encode_single(IX, Condition); - {limited, AllowedPlayerIXs} -> - case ordsets:is_element(PlayerIX, AllowedPlayerIXs) of - false -> false; - true -> {true, encode_single(IX, Condition)} - end - end - end, - orddict:to_list(Conditions#btl_conds.collection) - ). |