aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-03-12 13:00:59 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-03-12 13:00:59 +0100
commit11a7a03a0088b2c4b8edc394469396d54190dc53 (patch)
tree7856475136a11a60bcf4c2980adfb5624a116b33
parent98203d4d0034dab5db72737bcfb92017a11f3245 (diff)
downloadtacticians-server-11a7a03a0088b2c4b8edc394469396d54190dc53.zip
tacticians-server-11a7a03a0088b2c4b8edc394469396d54190dc53.tar.bz2
Starting to work on the timeline feature.
-rw-r--r--src/battle/battle_turn.erl25
-rw-r--r--src/query/character_turn.erl8
-rw-r--r--src/query/load_state.erl2
-rw-r--r--src/struct/battle.erl74
-rw-r--r--src/struct/player.erl72
5 files changed, 135 insertions, 46 deletions
diff --git a/src/battle/battle_turn.erl b/src/battle/battle_turn.erl
index e295f09..6e8d226 100644
--- a/src/battle/battle_turn.erl
+++ b/src/battle/battle_turn.erl
@@ -57,13 +57,13 @@ activate_relevant_character_instances (IXs, CharacterInstances, Owner, IX) ->
-spec start_next_players_turn (battle:struct()) ->
{list(non_neg_integer()), battle:struct()}.
start_next_players_turn (Battle) ->
- PlayerIDs = battle:get_player_ids(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(PlayerIDs))),
+ NextPlayerIX = ((CurrentPlayerIX + 1) rem (array:size(Players))),
NextPlayerTurn =
player_turn:new
(
@@ -74,24 +74,33 @@ start_next_players_turn (Battle) ->
NextPlayerIX
),
+ NextPlayer = array:get(NextPlayerIX, Players),
+ UpdatedNextPlayer = player:reset_timeline(),
+
{ActivatedCharacterInstanceIXs, UpdatedCharacterInstances} =
activate_relevant_character_instances
(
[],
CharacterInstances,
- array:get(NextPlayerIX, PlayerIDs),
+ player:get_id(NextPlayer),
(array:size(CharacterInstances) - 1)
),
UpdatedBattle =
- battle:set_character_instances
+ battle:set_player
(
- UpdatedCharacterInstances,
- battle:set_current_player_turn
+ NextPlayerIX,
+ UpdatedNextPlayer,
+ battle:set_character_instances
(
- NextPlayerTurn,
- Battle
+ UpdatedCharacterInstances,
+ battle:set_current_player_turn
+ (
+ NextPlayerTurn,
+ Battle
+ )
)
),
+ % TODO: have a diff operation for the player's timeline being reset.
{ActivatedCharacterInstanceIXs, UpdatedBattle}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/query/character_turn.erl b/src/query/character_turn.erl
index a692be1..e796493 100644
--- a/src/query/character_turn.erl
+++ b/src/query/character_turn.erl
@@ -87,11 +87,11 @@ assert_character_instance_can_be_played (RData, Input) ->
(
battle:get_current_player_turn(Battle)
),
- CurrentPlayer = battle:get_player_id(CurrentPlayerIX, Battle),
- CharacterOwner = character:get_owner_id(Character),
+ CurrentPlayer = battle:get_player(CurrentPlayerIX, Battle),
+ CharacterOwnerID = character:get_owner_id(Character),
- PlayerID = CurrentPlayer,
- PlayerID = CharacterOwner,
+ PlayerID = player:get_id(CurrentPlayer),
+ PlayerID = CharacterOwnerID,
true = character_instance:get_is_active(CharacterInstance).
diff --git a/src/query/load_state.erl b/src/query/load_state.erl
index eb27b9e..cc8f28f 100644
--- a/src/query/load_state.erl
+++ b/src/query/load_state.erl
@@ -87,6 +87,8 @@ generate_reply (QueryState, Input) ->
)
)
]
+ ++
+ battle:get_encoded_last_turns_effects(Battle)
).
-spec handle (binary()) -> binary().
diff --git a/src/struct/battle.erl b/src/struct/battle.erl
index 4ee3b51..d668bbb 100644
--- a/src/struct/battle.erl
+++ b/src/struct/battle.erl
@@ -12,9 +12,8 @@
id :: id(),
battlemap :: battlemap:struct(),
character_instances :: array:array(character_instance:struct()),
- player_ids :: array:array(player:id()),
- current_player_turn :: player_turn:struct(),
- last_turns_effects :: list(any())
+ players :: array:array(player:struct()),
+ current_player_turn :: player_turn:struct()
}
).
@@ -33,17 +32,17 @@
get_battlemap/1,
get_character_instances/1,
get_character_instance/2,
- get_player_ids/1,
- get_player_id/2,
+ get_players/1,
+ get_player/2,
get_current_player_turn/1,
- get_last_turns_effects/1,
+ get_encoded_last_turns_effects/1,
set_battlemap/2,
set_character_instances/2,
set_character_instance/3,
- set_player_ids/2,
- set_current_player_turn/2,
- set_last_turns_effects/2
+ set_players/2,
+ set_player/3,
+ set_current_player_turn/2
]
).
@@ -79,21 +78,22 @@ get_character_instances (Battle) ->
get_character_instance (IX, Battle) ->
array:get(IX, Battle#battle.character_instances).
--spec get_player_ids (struct()) -> array:array(player:id()).
-get_player_ids (Battle) ->
- Battle#battle.player_ids.
+-spec get_players (struct()) -> array:array(player:struct()).
+get_players (Battle) ->
+ Battle#battle.players.
--spec get_player_id (non_neg_integer(), struct()) -> player:id().
-get_player_id (IX, Battle) ->
- array:get(IX, Battle#battle.player_ids).
+-spec get_player (non_neg_integer(), struct()) -> player:struct().
+get_player (IX, Battle) ->
+ array:get(IX, Battle#battle.players).
-spec get_current_player_turn (struct()) -> player_turn:struct().
get_current_player_turn (Battle) ->
Battle#battle.current_player_turn.
--spec get_last_turns_effects (struct()) -> list(any()).
-get_last_turns_effects (Battle) ->
- Battle#battle.last_turns_effects.
+-spec get_encoded_last_turns_effects (struct()) -> list(any()).
+get_encoded_last_turns_effects (_Battle) ->
+ % TODO
+ [].
-spec set_battlemap (battlemap:struct(), struct()) -> struct().
set_battlemap (Battlemap, Battle) ->
@@ -133,46 +133,53 @@ set_character_instance (IX, CharacterInstance, Battle) ->
)
}.
--spec set_player_ids
+-spec set_players
(
- array:array(player:id()),
+ array:array(player:struct()),
struct()
)
-> struct().
-set_player_ids (Players, Battle) ->
+set_players (Players, Battle) ->
Battle#battle
{
- player_ids = Players
+ players = Players
}.
--spec set_current_player_turn
+-spec set_player
(
- player_turn:struct(),
+ non_neg_integer(),
+ player:struct(),
struct()
)
-> struct().
-set_current_player_turn (PlayerTurn, Battle) ->
+set_player (IX, Player, Battle) ->
Battle#battle
{
- current_player_turn = PlayerTurn
+ players =
+ array:set
+ (
+ IX,
+ Player,
+ Battle#battle.players
+ )
}.
--spec set_last_turns_effects
+-spec set_current_player_turn
(
- list(any()),
+ player_turn:struct(),
struct()
)
-> struct().
-set_last_turns_effects (Effects, Battle) ->
+set_current_player_turn (PlayerTurn, Battle) ->
Battle#battle
{
- last_turns_effects = Effects
+ current_player_turn = PlayerTurn
}.
-spec random
(
id(),
- list(player:id()),
+ list(player:struct()),
battlemap:struct(),
list(character:struct())
)
@@ -221,7 +228,6 @@ random (ID, PlayersAsList, Battlemap, Characters) ->
id = ID,
battlemap = Battlemap,
character_instances = array:from_list(CharacterInstancesAsList),
- player_ids = array:from_list(PlayersAsList),
- current_player_turn = player_turn:new(0, 0),
- last_turns_effects = []
+ players = array:from_list(PlayersAsList),
+ current_player_turn = player_turn:new(0, 0)
}.
diff --git a/src/struct/player.erl b/src/struct/player.erl
new file mode 100644
index 0000000..824e474
--- /dev/null
+++ b/src/struct/player.erl
@@ -0,0 +1,72 @@
+-module(player).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-type id() :: string().
+
+-record
+(
+ player,
+ {
+ id :: id(),
+ timeline :: list(any())
+ }
+).
+
+-opaque struct() :: #player{}.
+
+-export_type([struct/0, id/0]).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export
+(
+ [
+ get_id/1,
+ get_timeline/1,
+ add_to_timeline/2,
+ reset_timeline/1
+ ]
+).
+
+-export
+(
+ [
+ new/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec get_id (struct()) -> id().
+get_id (Player) -> Player#player.id.
+
+-spec get_timeline (struct()) -> list(any()).
+get_timeline (Player) -> Player#player.timeline.
+
+-spec add_to_timeline (list(any()), struct()) -> struct().
+add_to_timeline (NewEvents, Player) ->
+ OldTimeline = Player#player.timeline,
+
+ Player#player
+ {
+ timeline = (OldTimeline ++ NewEvents)
+ }.
+
+-spec reset_timeline (struct()) -> struct().
+reset_timeline (Player) -> Player#player{ timeline = [] }.
+
+-spec new (id()) -> struct().
+new (ID) ->
+ #player
+ {
+ id = ID,
+ timeline = []
+ }.
+