| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-10-12 22:27:44 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-10-12 22:27:44 +0200 | 
| commit | cdb5923969af99911840eec19373c7f55e5ebf6a (patch) | |
| tree | 21e510bbe07143af77bcaa8cd5112766c0b953f6 /src/battle/struct | |
| parent | 2df0db54d42a54fe5bec35bdf9996376164c23e7 (diff) | |
...
Diffstat (limited to 'src/battle/struct')
| -rw-r--r-- | src/battle/struct/btl_character.erl | 40 | ||||
| -rw-r--r-- | src/battle/struct/btl_condition.erl | 188 | 
2 files changed, 93 insertions, 135 deletions
| diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 7771b1a..bbf94bb 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -25,7 +25,7 @@        is_active :: boolean(),        is_defeated :: boolean(),        base :: shr_character:unresolved(), -      conditions :: orddict:orddict(non_neg_integer(), btl_condition:type()) +      conditions :: btl_condition:collection()     }  ). @@ -40,7 +40,7 @@        is_active :: boolean(),        is_defeated :: boolean(),        base :: shr_character:type(), -      conditions :: orddict:orddict(non_neg_integer(), btl_condition:type()) +      conditions :: btl_condition:collection()     }  ). @@ -98,13 +98,6 @@  -export  (     [ -      get_conditions_on/2 -   ] -). - --export -( -   [        new/5,        resolve/2,        is_unresolved/1, @@ -194,26 +187,11 @@ get_base_character (#btl_char{ base = R }) -> R;  get_base_character (#btl_char_ref{ base = R }) -> R.  -spec get_conditions -   (type()) -> orddict:orddict(non_neg_integer(), btl_condition:type()); +   (type()) -> btl_condition:collection();     (unresolved()) -> orddict:orddict(non_neg_integer(), btl_conditions:type()).  get_conditions (#btl_char{ conditions = R }) -> R;  get_conditions (#btl_char_ref{ conditions = R }) -> R. --spec get_conditions_on -   ( -      shr_condition:trigger(), -      either() -   ) -   -> orddict:orddict(non_neg_integer(), btl_condition:type()). -get_conditions_on (Trigger, Char) -> -   orddict:filter -   ( -      fun (_IX, Condition) -> -         btl_condition:triggers_on(Trigger, Condition) -      end, -      get_conditions(Char) -   ). -  -spec set_rank     (rank(), type()) -> type();     (rank(), unresolved()) -> unresolved(). @@ -449,12 +427,12 @@ ataxia_set_base_character (NewBaseCharacter, Char) ->  -spec set_conditions     ( -      orddict:orddict(non_neg_integer(), btl_condition:type()), +      btl_condition:collection(),        type()     )     -> type();     ( -      orddict:orddict(non_neg_integer(), btl_condition:type()), +      btl_condition:collection(),        unresolved()     )     -> unresolved(). @@ -466,13 +444,13 @@ set_conditions (Conditions, Char) when is_record(Char, btl_char_ref) ->  -spec ataxia_set_conditions     ( -      orddict:orddict(non_neg_integer(), btl_condition:type()), +      btl_condition:collection(),        ataxic:basic(),        type()     )     -> {type(), ataxic:basic()};     ( -      orddict:orddict(non_neg_integer(), btl_condition:type()), +      btl_condition:collection(),        ataxic:basic(),        unresolved()     ) -> {unresolved(), ataxic:basic()}. @@ -488,12 +466,12 @@ ataxia_set_conditions (Conditions, Update, Char) ->  -spec ataxia_set_conditions     ( -      orddict:orddict(non_neg_integer(), btl_condition:type()), +      btl_condition:collection(),        type()     )     -> {type(), ataxic:basic()};     ( -      orddict:orddict(non_neg_integer(), btl_condition:type()), +      btl_condition:collection(),        unresolved()     )     -> {unresolved(), ataxic:basic()}. diff --git a/src/battle/struct/btl_condition.erl b/src/battle/struct/btl_condition.erl index fee7279..13d6387 100644 --- a/src/battle/struct/btl_condition.erl +++ b/src/battle/struct/btl_condition.erl @@ -9,7 +9,7 @@     (        none        | remove -      | {update, type(), ataxic:basic()} +      | {update, ataxic:basic()}     ).  -record @@ -25,8 +25,9 @@  ).  -opaque type() :: #btl_cond{}. +-opaque collection() :: orddict:orddict(non_neg_integer(), type()). --export_type([type/0, update_action/0]). +-export_type([type/0, collection/0, update_action/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -64,11 +65,7 @@  -export  (     [ -      triggers_on/2, -      apply/3, -      recursive_apply/3, -      apply_updates/2, -      ataxia_apply_updates/2 +      ataxia_apply_trigger/3     ]  ). @@ -89,6 +86,42 @@     -> {list({binary(), any()})}.  encode_parameters (_Category, _Parameters) -> {[]}. % TODO. +-spec update_actions_to_ataxic_update +   ( +      list({non_neg_integer(), update_action()}) +   ) +   -> ataxic:basic(). +update_actions_to_ataxic_update (Updates) -> +   AtaxicSequence = +      lists:foldl +      ( +         fun ({IX, Update}, AtaxicUpdates) -> +            case Update of +               none -> AtaxicUpdates; +               remove -> +                  [ +                     ataxic:apply_function +                     ( +                        orddict, +                        erase, +                        [ataxic:constant(IX), ataxic:current_value()] +                     ) +                     |AtaxicUpdates +                  ]; + +               {update, Ataxic} -> +                  [ +                     ataxic_sugar:update_orddict_element(IX, Ataxic) +                     |AtaxicUpdates +                  ] +            end +         end, +         [], +         Updates +      ), + +   ataxic:sequence(AtaxicSequence). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -235,123 +268,70 @@ get_duration_field () -> #btl_cond.duration.  -spec get_parameters_field () -> non_neg_integer().  get_parameters_field () -> #btl_cond.parameters. --spec apply +-spec ataxia_apply_trigger     ( -      type(), -      shr_condition:context(), -      btl_character_turn_update:type() +      shr_condition:context(_ReadOnlyDataType, VolatileDataType), +      btl_character_turn_update:type(), +      collection()     )     ->     { -      shr_condition:context(), -      btl_character_turn_update:type(), -      update_action() +      VolatileDataType, +      ataxic:basic(), +      btl_character_turn_update:type()     }. -apply (Condition, S0Context, S0Update) -> -   Module = shr_condition_selector:get_module(get_category(Condition)), - -   {S1Context, S1Update, UpdateAction} = -      erlang:apply(Module, apply, [S0Context, Condition, S0Update]), - -   {S1Context, S1Update, UpdateAction}. +ataxia_apply_trigger (Context, S0Update, Conditions) -> +   {Trigger, ReadOnlyData, S0VolatileData} = Context, +   RelevantConditions = +      orddict:filter +      ( +         fun (_IX, Condition) -> triggers_on(Trigger, Condition) end, +         Conditions +      ), --spec recursive_apply -   ( -      orddict:orddict(IndexType, type()), -      shr_condition:context(), -      btl_character_turn_update:type() -   ) -   -> -   { -      shr_condition:context(), -      btl_character_turn_update:type(), -      list({IndexType, update_action()}) -   }. -recursive_apply (Conditions, S0Context, S0Update) -> -   {[LastContext, LastUpdate], AllUpdateActions} = +   {LastVolatileData, LastUpdate, AllUpdateActions} =        orddict:fold        ( -         fun (IX, Condition, {Parameters, UpdateActions}) -> -            {NextContext, NextUpdate, UpdateAction} = -               erlang:apply(btl_condition, apply, [Condition|Parameters]), +         fun +         ( +            IX, +            Condition, +            { +               CurrentVolatileData, +               CurrentUpdate, +               UpdateActions +            } +         ) -> +            Module = shr_condition_selector:get_module(get_category(Condition)), +            {NextVolatileData, NextUpdate, UpdateAction} = +               erlang:apply +               ( +                  Module, +                  apply, +                  [ +                     Condition, +                     CurrentUpdate, +                     {Trigger, ReadOnlyData, CurrentVolatileData} +                  ] +               ),              { -               [NextContext, NextUpdate], +               NextVolatileData, +               NextUpdate,                 case UpdateAction of                    none -> UpdateActions;                    _ -> [{IX, UpdateAction}|UpdateActions]                 end              }           end, -         [S0Context, S0Update, []], -         Conditions +         {S0VolatileData, S0Update, []}, +         RelevantConditions        ), -   {LastContext, LastUpdate, AllUpdateActions}. - --spec apply_updates -   ( -      list({IndexType, update_action()}), -      orddict:orddict(IndexType, type()) -   ) -   -> orddict:orddict(IndexType, type()). -apply_updates (Updates, Conditions) -> -   lists:foldl -   ( -      fun ({IX, Update}, CurrentConditions) -> -         case Update of -            none -> CurrentConditions; -            remove -> orddict:erase(IX, CurrentConditions); -            {update, Val, _Ataxic} -> orddict:store(IX, Val, CurrentConditions) -         end -      end, -      Conditions, -      Updates -   ). - --spec ataxia_apply_updates -   ( -      list({IndexType, update_action()}), -      orddict:orddict(IndexType, type()) -   ) -   -> {orddict:orddict(IndexType, type()), ataxic:basic()}. -ataxia_apply_updates (Updates, Conditions) -> -   {FinalConditions, AtaxicSequence} = -      lists:foldl -      ( -         fun ({IX, Update}, {CurrentConditions, AtaxicUpdates}) -> -            case Update of -               none -> {CurrentConditions, AtaxicUpdates}; -               remove -> -                  { -                     orddict:erase(IX, CurrentConditions), -                     [ -                        ataxic:apply_function -                        ( -                           orddict, -                           erase, -                           [ataxic:constant(IX), ataxic:current_value()] -                        ) -                        |AtaxicUpdates -                     ] -                  }; - -               {update, Val, Ataxic} -> -                  { -                     orddict:store(IX, Val, CurrentConditions), -                     [ -                        ataxic_sugar:update_orddict_element(IX, Ataxic) -                        |AtaxicUpdates -                     ] -                  } -            end -         end, -         Conditions, -         Updates -      ), +   ConditionsAtaxiaUpdate = update_actions_to_ataxic_update(AllUpdateActions), -   {FinalConditions, ataxic:sequence(AtaxicSequence)}. +   {LastVolatileData, ConditionsAtaxiaUpdate, LastUpdate}.  -spec encode (type()) -> {list({binary(), any()})}.  encode (Condition) -> {[]}. % TODO | 


