1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
-module(shr_map_marker).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
matk_mrk,
{
character_ix :: non_neg_integer()
}
).
-record
(
spawn_mrk,
{
player_ix :: non_neg_integer()
}
).
-type name() :: binary().
-opaque melee_attack_zone() :: #matk_mrk{}.
-opaque spawn_zone() :: #spawn_mrk{}.
-opaque type() ::
{list(shr_location:type()), (melee_attack_zone() | spawn_zone())}.
-export_type([name/0, type/0, melee_attack_zone/0, spawn_zone/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
[
player_can_see/2,
get_locations/1,
get_name/1
]
).
-export
(
[
decode/1,
encode/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec get_locations (type()) -> list(shr_location:type()).
get_locations ({L, _}) -> L.
-spec encode (type()) -> {list(any())}.
encode ({L, MarkerData}) when is_record(MarkerData, matk_mrk) ->
{
[
{ <<"t">>, <<"matk">> },
{ <<"cix">>, MarkerData#matk_mrk.character_ix },
{ <<"l">>, lists:map(fun shr_location:encode/1, L) }
]
};
encode ({L, MarkerData}) when is_record(MarkerData, spawn_mrk) ->
{
[
{ <<"t">>, <<"spawn">> },
{ <<"pix">>, MarkerData#spawn_mrk.player_ix },
{ <<"l">>, lists:map(fun shr_location:encode/1, L) }
]
}.
-spec decode (map()) -> type().
decode (Map) ->
Data = maps:get(<<"d">>, Map),
{
lists:map(fun shr_location:decode/1, maps:get(<<"l">>, Map)),
(
case maps:get(<<"t">>, Data) of
<<"mtak">> -> #matk_mrk{ character_ix = maps:get(<<"cix">>, Data) };
<<"spawn">> -> #spawn_mrk{ player_ix = maps:get(<<"pix">>, Data) }
end
)
}.
-spec player_can_see (integer(), type()) -> boolean().
player_can_see (PlayerIX, _Marker) -> (PlayerIX >= 0).
-spec get_name (type()) -> binary().
get_name ({_Location, MarkerData}) when is_record(MarkerData, matk_mrk) ->
Prefix = <<"matk_c">>,
CharacterIXString = integer_to_binary(MarkerData#matk_mrk.character_ix),
<<Prefix/binary, CharacterIXString/binary>>;
get_name ({_Location, MarkerData}) when is_record(MarkerData, spawn_mrk) ->
Prefix = <<"spawn_p">>,
PlayerIXString = integer_to_binary(MarkerData#spawn_mrk.player_ix),
<<Prefix/binary, PlayerIXString/binary>>.
|