| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/battlemap/struct')
| -rw-r--r-- | src/battlemap/struct/bm_character.erl | 13 | ||||
| -rw-r--r-- | src/battlemap/struct/bm_player.erl | 12 | ||||
| -rw-r--r-- | src/battlemap/struct/bm_turn_result.erl | 75 | 
3 files changed, 95 insertions, 5 deletions
| diff --git a/src/battlemap/struct/bm_character.erl b/src/battlemap/struct/bm_character.erl index 1fbd3b1..41c0fb4 100644 --- a/src/battlemap/struct/bm_character.erl +++ b/src/battlemap/struct/bm_character.erl @@ -4,6 +4,7 @@  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -type id() :: non_neg_integer(). +-type rank() :: ('optional' | 'target' | 'commander').  -record  ( @@ -12,6 +13,7 @@        id :: id(),        owner_id :: bm_player:id(),        name :: binary(), +      rank :: rank(),        icon :: binary(),        portrait :: binary(),        attributes :: sh_attributes:type(), @@ -26,7 +28,7 @@  -opaque type() :: #character{}. --export_type([type/0, id/0]). +-export_type([type/0, rank/0, id/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -37,6 +39,7 @@        get_id/1,        get_owner_id/1,        get_name/1, +      get_rank/1,        get_icon/1,        get_portrait/1,        get_attributes/1, @@ -111,6 +114,9 @@ get_owner_id (Char) -> Char#character.owner_id.  -spec get_name (type()) -> binary().  get_name (Char) -> Char#character.name. +-spec get_rank (type()) -> rank(). +get_rank (Char) -> Char#character.rank. +  -spec get_icon (type()) -> binary().  get_icon (Char) -> Char#character.icon. @@ -224,6 +230,11 @@ random (ID, OwnerID, BattlemapWidth, BattlemapHeight, ForbiddenLocations) ->        id = ID,        owner_id = OwnerID,        name = list_to_binary("Char" ++ IDAsListString), +      rank = +         if +            ((ID rem 8) == 0) -> commander; +            true -> optional +         end,        icon = IDAsBinaryString,        portrait = IDAsBinaryString,        attributes = Attributes, diff --git a/src/battlemap/struct/bm_player.erl b/src/battlemap/struct/bm_player.erl index fa877c1..9be2a95 100644 --- a/src/battlemap/struct/bm_player.erl +++ b/src/battlemap/struct/bm_player.erl @@ -9,6 +9,7 @@  (     player,     { +      ix :: non_neg_integer(),        id :: id(),        timeline :: list(any())     } @@ -24,6 +25,7 @@  (     [        get_id/1, +      get_index/1,        get_timeline/1,        add_to_timeline/2,        reset_timeline/1, @@ -35,7 +37,7 @@  -export  (     [ -      new/1 +      new/2     ]  ). @@ -49,6 +51,9 @@  -spec get_id (type()) -> id().  get_id (Player) -> Player#player.id. +-spec get_index (type()) -> non_neg_integer(). +get_index (Player) -> Player#player.ix. +  -spec get_timeline (type()) -> list(any()).  get_timeline (Player) -> Player#player.timeline. @@ -64,10 +69,11 @@ add_to_timeline (NewEvents, Player) ->  -spec reset_timeline (type()) -> type().  reset_timeline (Player) -> Player#player{ timeline = [] }. --spec new (id()) -> type(). -new (ID) -> +-spec new (non_neg_integer(), id()) -> type(). +new (IX, ID) ->     #player     { +      ix = IX,        id = ID,        timeline = []     }. diff --git a/src/battlemap/struct/bm_turn_result.erl b/src/battlemap/struct/bm_turn_result.erl index c3440bd..79fd7f3 100644 --- a/src/battlemap/struct/bm_turn_result.erl +++ b/src/battlemap/struct/bm_turn_result.erl @@ -32,7 +32,38 @@     }  ). --opaque type() :: (#switched_weapon{} | #moved{} | #attacked{}). +-record +( +   player_won, +   { +      player_ix :: non_neg_integer() +   } +). + +-record +( +   player_lost, +   { +      player_ix :: non_neg_integer() +   } +). + +-record +( +   player_turn_started, +   { +      player_ix :: non_neg_integer() +   } +). + +-opaque type() :: ( +   #switched_weapon{} +   | #moved{} +   | #attacked{} +   | #player_won{} +   | #player_lost{} +   | #player_turn_started{} +).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -42,6 +73,9 @@  -export  (     [ +      new_player_won/1, +      new_player_lost/1, +      new_player_turn_started/1,        new_character_switched_weapons/1,        new_character_moved/3,        new_character_attacked/3 @@ -62,6 +96,18 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec new_player_won (non_neg_integer()) -> type(). +new_player_won (PlayerIX) -> +   #player_won { player_ix = PlayerIX }. + +-spec new_player_lost (non_neg_integer()) -> type(). +new_player_lost (PlayerIX) -> +   #player_lost { player_ix = PlayerIX }. + +-spec new_player_turn_started (non_neg_integer()) -> type(). +new_player_turn_started (PlayerIX) -> +   #player_turn_started { player_ix = PlayerIX }. +  -spec new_character_switched_weapons (bm_character:id()) -> type().  new_character_switched_weapons (CharacterIX) ->     #switched_weapon { character_ix = CharacterIX }. @@ -137,6 +183,33 @@ encode (TurnResult) when is_record(TurnResult, attacked) ->           {<<"seq">>, EncodedSequence}        ]     }; +encode (TurnResult) when is_record(TurnResult, player_won) -> +   PlayerIX = TurnResult#player_won.player_ix, + +   { +      [ +         {<<"t">>, <<"pwo">>}, +         {<<"ix">>, PlayerIX} +      ] +   }; +encode (TurnResult) when is_record(TurnResult, player_lost) -> +   PlayerIX = TurnResult#player_lost.player_ix, + +   { +      [ +         {<<"t">>, <<"plo">>}, +         {<<"ix">>, PlayerIX} +      ] +   }; +encode (TurnResult) when is_record(TurnResult, player_turn_started) -> +   PlayerIX = TurnResult#player_turn_started.player_ix, + +   { +      [ +         {<<"t">>, <<"pts">>}, +         {<<"ix">>, PlayerIX} +      ] +   };  encode (Other) ->     io:format("~n invalid encode param\"~p\"~n", [Other]),     true = Other. | 


