| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-04-10 13:01:12 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-04-10 13:01:12 +0200 | 
| commit | 1001c3f6cfefd880c1721f2b80c1795197d05365 (patch) | |
| tree | 8696137b5684547b80129d308bc854a7e74fa0b0 /src/battle | |
| parent | d7032b408c5f66a3cb62c44cf0953abe48c39ef9 (diff) | |
Changing how the server services are organized...
Diffstat (limited to 'src/battle')
| -rw-r--r-- | src/battle/battle_turn.erl | 161 | ||||
| -rw-r--r-- | src/battle/movement.erl | 58 | ||||
| -rw-r--r-- | src/battle/roll.erl | 32 | 
3 files changed, 0 insertions, 251 deletions
| diff --git a/src/battle/battle_turn.erl b/src/battle/battle_turn.erl deleted file mode 100644 index 638e8f9..0000000 --- a/src/battle/battle_turn.erl +++ /dev/null @@ -1,161 +0,0 @@ --module(battle_turn). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( -   [ -      handle_post_play/1, -      store_timeline/2 -   ] -). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec activate_relevant_character_instances -   ( -      list(non_neg_integer()), -      array:array(character_instance:struct()), -      player:id(), -      (-1 | non_neg_integer()) -   ) -   -> {list(non_neg_integer()), array:array(character_instance:struct())}. -activate_relevant_character_instances (IXs, CharacterInstances, _Owner, -1) -> -   {IXs, CharacterInstances}; -activate_relevant_character_instances (IXs, CharacterInstances, Owner, IX) -> -   CharacterInstance = array:get(IX, CharacterInstances), -   Character = character_instance:get_character(CharacterInstance), -   case character:get_owner_id(Character) of -      OwnerID when (OwnerID == Owner) -> -         activate_relevant_character_instances -         ( -            [IX|IXs], -            array:set -            ( -               IX, -               character_instance:set_is_active(true, CharacterInstance), -               CharacterInstances -            ), -            Owner, -            (IX - 1) -         ); - -      _ -> -         activate_relevant_character_instances -         ( -            IXs, -            CharacterInstances, -            Owner, -            (IX - 1) -         ) -   end. - --spec start_next_players_turn (battle:struct()) -> -   {list(non_neg_integer()), battle:struct()}. -start_next_players_turn (Battle) -> -   Players = battle:get_players(Battle), -   PlayerTurn = battle:get_current_player_turn(Battle), -   CurrentPlayerIX = player_turn:get_player_ix(PlayerTurn), -   CurrentTurnNumber = player_turn:get_number(PlayerTurn), -   CharacterInstances = battle:get_character_instances(Battle), - -   NextPlayerIX = ((CurrentPlayerIX + 1) rem (array:size(Players))), -   NextPlayerTurn = -      player_turn:new -      ( -         case NextPlayerIX of -            0 -> (CurrentTurnNumber + 1); -            _ -> CurrentTurnNumber -         end, -         NextPlayerIX -      ), - -   NextPlayer = array:get(NextPlayerIX, Players), -   UpdatedNextPlayer = player:reset_timeline(NextPlayer), - -   {ActivatedCharacterInstanceIXs, UpdatedCharacterInstances} = -      activate_relevant_character_instances -      ( -         [], -         CharacterInstances, -         player:get_id(NextPlayer), -         (array:size(CharacterInstances) - 1) -      ), -   UpdatedBattle = -      battle:set_player -      ( -         NextPlayerIX, -         UpdatedNextPlayer, -         battle:set_character_instances -         ( -            UpdatedCharacterInstances, -            battle:set_current_player_turn -            ( -               NextPlayerTurn, -               Battle -            ) -         ) -      ), -   % TODO: have a diff operation for the player's timeline being reset.  -   {ActivatedCharacterInstanceIXs, UpdatedBattle}. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - --spec store_timeline -   ( -      list(any()), -      battle:struct() -   ) -   -> battle:struct(). -store_timeline (TurnEffects, Battle) -> -   PlayerTurn = battle:get_current_player_turn(Battle), -   PlayerIX = player_turn:get_player_ix(PlayerTurn), -   Player = battle:get_player(PlayerIX, Battle), - -   UpdatedPlayer = player:add_to_timeline(TurnEffects, Player), - -   battle:set_player(PlayerIX, UpdatedPlayer, Battle). - - --spec handle_post_play (battle:struct()) -   -> {database_diff:struct(), battle:struct()}. -handle_post_play (Battle) -> -   CharacterInstances = battle:get_character_instances(Battle), - -   AnActiveCharacterInstanceRemains = -      array:foldl -      ( -         fun (_IX, CharacterInstance, Prev) -> -            (Prev or character_instance:get_is_active(CharacterInstance)) -         end, -         false, -         CharacterInstances -      ), - -   case AnActiveCharacterInstanceRemains of -      true -> -         io:format("~nThere are still active characters.~n"), -         {[], Battle}; - -      false -> -         io:format("~nThere are no more active characters.~n"), -         {UpdatedCharacterInstanceIXs, UpdatedBattle} = -            start_next_players_turn(Battle), -         { -            lists:map -            ( -               fun (IX) -> -                  {set, character_instance, IX, is_active, true} -               end, -               UpdatedCharacterInstanceIXs -            ), -            UpdatedBattle -         } -   end. diff --git a/src/battle/movement.erl b/src/battle/movement.erl deleted file mode 100644 index 588fad9..0000000 --- a/src/battle/movement.erl +++ /dev/null @@ -1,58 +0,0 @@ --module(movement). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([cross/4]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec cross -   ( -      battlemap:struct(), -      list(location:type()), -      list(direction:enum()), -      non_neg_integer(), -      location:type() -   ) -   -> {location:type(), non_neg_integer()}. -cross (_Battlemap, _ForbiddenLocations, [], Cost, Location) -> -   {Location, Cost}; -cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, Location) -> -   NextLocation = location:apply_direction(Step, Location), -   NextTile = battlemap:get_tile_id(NextLocation, Battlemap), -   NextCost = (Cost + tile:get_cost(NextTile)), -   IsForbidden = -      lists:foldl -      ( -         fun (ForbiddenLocation, Prev) -> -            (Prev or (NextLocation == ForbiddenLocation)) -         end, -         false, -         ForbiddenLocations -      ), - -   IsForbidden = false, - -   cross(Battlemap, ForbiddenLocations, NextSteps, NextCost, NextLocation). - --spec cross -   ( -      battlemap:struct(), -      list(location:type()), -      list(direction:enum()), -      location:type() -   ) -   -> {location:type(), non_neg_integer()}. -cross (Battlemap, ForbiddenLocations, Path, Location) -> -   cross(Battlemap, ForbiddenLocations, Path, 0, Location). diff --git a/src/battle/roll.erl b/src/battle/roll.erl deleted file mode 100644 index 074054b..0000000 --- a/src/battle/roll.erl +++ /dev/null @@ -1,32 +0,0 @@ --module(roll). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( -   [ -      percentage/0, -      between/2 -   ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec between (non_neg_integer(), non_neg_integer()) -> non_neg_integer(). -between (Min, Max) -> -   Diff = (Max - Min), -   (Min + (rand:uniform(Diff + 1) - 1)). - --spec percentage () -> 0..100. -percentage () -> -   between(0, 100). | 


