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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
-module(btl_shim).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export([generate_random_battle/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec generate_random_characters
(
non_neg_integer(),
non_neg_integer(),
non_neg_integer(),
non_neg_integer(),
btl_map:type(),
list(btl_location:type()),
list(btl_character:type())
)
-> list(btl_character:type()).
generate_random_characters
(
0,
0,
_CharactersPerPlayer,
_TotalCharacterCount,
_Map,
_ForbiddenLocations,
Result
) ->
Result;
generate_random_characters
(
MaxPlayerIX,
0,
CharactersPerPlayer,
TotalCharacterCount,
Map,
ForbiddenLocations,
Result
) ->
generate_random_characters
(
(MaxPlayerIX - 1),
CharactersPerPlayer,
CharactersPerPlayer,
TotalCharacterCount,
Map,
ForbiddenLocations,
Result
);
generate_random_characters
(
MaxPlayerIX,
PlayerCharacterCount,
CharactersPerPlayer,
TotalCharacterCount,
Map,
ForbiddenLocations,
Result
) ->
NewCharacter =
btl_character:random
(
TotalCharacterCount,
MaxPlayerIX,
btl_map:get_width(Map),
btl_map:get_height(Map),
ForbiddenLocations
),
Character =
case MaxPlayerIX of
0 -> btl_character:set_is_active(true, NewCharacter);
_ -> NewCharacter
end,
generate_random_characters
(
MaxPlayerIX,
(PlayerCharacterCount - 1),
CharactersPerPlayer,
(TotalCharacterCount + 1),
Map,
[btl_character:get_location(Character)|ForbiddenLocations],
[Character|Result]
).
-spec demo_map () -> list(list(non_neg_integer())).
demo_map () ->
[
[2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0], [2, 0],
[2, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [2, 0], [2, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0], [3, 0], [3, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [2, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [3, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [2, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0], [2, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [3, 0], [2, 0], [1, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [1, 0], [2, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [2, 0],
[2, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [2, 0],
[2, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [3, 0], [3, 0], [1, 0], [3, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [2, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [2, 0],
[2, 0], [3, 0], [3, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [1, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [2, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [3, 0], [3, 0], [2, 0],
[2, 0], [3, 0], [3, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [1, 0], [3, 0], [0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [1, 0], [1, 0], [3, 0], [1, 0], [3, 0], [3, 0], [3, 0], [2, 0],
[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]
].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec generate_random_battle () -> btl_battle:type().
generate_random_battle () ->
%MapWidth = 32, % shr_roll:between(16, 32),
%MapHeight = 32, %shr_roll:between(16, 32),
%Map = btl_map:random(0, MapWidth, MapHeight),
Map = btl_map:from_list(0, 32, 32, demo_map()),
Characters = generate_random_characters(1, 8, 8, 0, Map, [], []),
PlayersAsList = [btl_player:new(0, 8, <<"0">>), btl_player:new(1, 0, <<"1">>)],
{UsedWeaponIDs, UsedArmorIDs} =
lists:foldl
(
fun (Character, {UWIDs, UAIDs}) ->
{MWpID, SWpID} = btl_character:get_weapon_ids(Character),
AID = btl_character:get_armor_id(Character),
{
sets:add_element(MWpID, sets:add_element(SWpID, UWIDs)),
sets:add_element(AID, UAIDs)
}
end,
{sets:new(), sets:new()},
Characters
),
UsedTileIDs =
array:sparse_foldl
(
fun (_IX, TileInstance, CurrentTileIDs) ->
sets:add_element
(
btl_tile:extract_main_class_id(TileInstance),
CurrentTileIDs
)
end,
sets:new(),
btl_map:get_tile_instances(Map)
),
Battle =
btl_battle:new
(
<<"0">>,
PlayersAsList,
Map,
Characters,
sets:to_list(UsedWeaponIDs),
sets:to_list(UsedArmorIDs),
sets:to_list(UsedTileIDs)
),
Battle.
|