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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
-module(btl_tile).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
tile,
{
id :: id(),
name :: binary(),
cost :: non_neg_integer(),
class_range_min :: non_neg_integer(),
class_range_max :: non_neg_integer()
}
).
-opaque id() :: non_neg_integer().
-opaque class_id() :: non_neg_integer().
-opaque type() :: #tile{}.
-export_type([type/0, class_id/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
[
get_id/1,
get_name/1,
get_cost/1,
get_range_minimum/1,
get_range_maximum/1,
from_id/1,
cost_when_oob/0
]
).
-export
(
[
class_id_to_type_id/1,
class_id_from_int/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec class_id_to_type_id (class_id()) -> id().
class_id_to_type_id (ClassID) ->
case ClassID of
0 -> 0;
1 -> 1;
2 -> 2;
N when ((N >= 3) and (N =< 17)) -> 3
end.
-spec from_id (id()) -> type().
from_id (0) ->
#tile
{
id = 0,
name = <<"[Grassland] Grass">>,
cost = 6,
class_range_min = 0,
class_range_max = 0
};
from_id (1) ->
#tile
{
id = 1,
name = <<"[Grassland] Mushroom Infestation">>,
cost = 12,
class_range_min = 1,
class_range_max = 1
};
from_id (2) ->
#tile
{
id = 2,
name = <<"[Grassland] Tree Remains">>,
cost = 24,
class_range_min = 2,
class_range_max = 2
};
from_id (3) ->
#tile
{
id = 3,
name = <<"[Grassland] Clear Water">>,
cost = 201,
class_range_min = 3,
class_range_max = 17
};
from_id(_) ->
from_id(0).
-spec cost_when_oob () -> non_neg_integer().
cost_when_oob () -> 255.
-spec get_id (type()) -> non_neg_integer().
get_id (Tile) -> Tile#tile.id.
-spec get_cost (type()) -> non_neg_integer().
get_cost (Tile) -> Tile#tile.cost.
-spec get_name (type()) -> binary().
get_name (Tile) -> Tile#tile.name.
-spec get_range_minimum (type()) -> non_neg_integer().
get_range_minimum (Tile) -> Tile#tile.class_range_min.
-spec get_range_maximum (type()) -> non_neg_integer().
get_range_maximum (Tile) -> Tile#tile.class_range_max.
-spec class_id_from_int (non_neg_integer()) -> id().
class_id_from_int (I) -> I.
|