author | unc0rr |
Sat, 12 Dec 2015 23:38:18 +0300 | |
branch | qmlfrontend |
changeset 11457 | 78860824b5a5 |
parent 11456 | 6e9b12864856 |
child 11458 | e7c7ca0c1556 |
permissions | -rw-r--r-- |
10406 | 1 |
unit uFLGameConfig; |
2 |
interface |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
3 |
uses uFLTypes; |
10406 | 4 |
|
10430 | 5 |
procedure resetGameConfig; cdecl; |
6 |
procedure runQuickGame; cdecl; |
|
10448 | 7 |
procedure runLocalGame; cdecl; |
10430 | 8 |
procedure getPreview; cdecl; |
10406 | 9 |
|
10430 | 10 |
procedure setSeed(seed: PChar); cdecl; |
11 |
function getSeed: PChar; cdecl; |
|
10456 | 12 |
procedure setTheme(themeName: PChar); cdecl; |
10612 | 13 |
procedure setScript(scriptName: PChar); cdecl; |
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
14 |
procedure setScheme(schemeName: PChar); cdecl; |
10888 | 15 |
procedure setAmmo(ammoName: PChar); cdecl; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
16 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
17 |
procedure tryAddTeam(teamName: PChar); cdecl; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
18 |
procedure tryRemoveTeam(teamName: PChar); cdecl; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
19 |
procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl; |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
20 |
|
11436 | 21 |
procedure netSetSeed(seed: shortstring); |
22 |
procedure netSetTheme(themeName: shortstring); |
|
23 |
procedure netSetScript(scriptName: shortstring); |
|
11438 | 24 |
procedure netSetFeatureSize(fsize: LongInt); |
25 |
procedure netSetMapGen(mapgen: LongInt); |
|
26 |
procedure netSetMap(map: shortstring); |
|
27 |
procedure netSetMazeSize(mazesize: LongInt); |
|
28 |
procedure netSetTemplate(template: LongInt); |
|
11442 | 29 |
procedure netSetAmmo(name: shortstring; definition: ansistring); |
11445 | 30 |
procedure netSetScheme(scheme: TScheme); |
11447 | 31 |
procedure netAddTeam(team: TTeam); |
11449 | 32 |
procedure netAcceptedTeam(teamName: shortstring); |
11447 | 33 |
procedure netSetTeamColor(team: shortstring; color: Longword); |
11448 | 34 |
procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword); |
35 |
procedure netRemoveTeam(teamName: shortstring); |
|
36 |
procedure netResetTeams(); |
|
11438 | 37 |
procedure updatePreviewIfNeeded; |
11436 | 38 |
|
11439 | 39 |
procedure sendConfig(config: PGameConfig); |
11456 | 40 |
procedure runNetGame(); |
10426 | 41 |
|
11439 | 42 |
implementation |
11449 | 43 |
uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue, uFLNet; |
10426 | 44 |
|
10432 | 45 |
var |
46 |
currentConfig: TGameConfig; |
|
11438 | 47 |
previewNeedsUpdate: boolean; |
10432 | 48 |
|
11436 | 49 |
function getScriptPath(scriptName: shortstring): shortstring; |
50 |
begin |
|
51 |
getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua' |
|
52 |
end; |
|
10430 | 53 |
|
10432 | 54 |
procedure sendConfig(config: PGameConfig); |
55 |
var i: Longword; |
|
56 |
begin |
|
57 |
with config^ do |
|
10430 | 58 |
begin |
10432 | 59 |
case gameType of |
60 |
gtPreview: begin |
|
11436 | 61 |
if script <> 'Normal' then |
62 |
ipcToEngine('escript ' + getScriptPath(script)); |
|
10432 | 63 |
ipcToEngine('eseed ' + seed); |
64 |
ipcToEngine('e$mapgen ' + intToStr(mapgen)); |
|
11452
2572afe532af
Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents:
11451
diff
changeset
|
65 |
if (mapgen = 1) or (mapgen = 2) then |
11455
0c75fa9ce340
- Use queues instead of single buffer to communicate between threads
unc0rr
parents:
11452
diff
changeset
|
66 |
ipcToEngine('e$maze_size ' + intToStr(mazeSize)) |
11452
2572afe532af
Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents:
11451
diff
changeset
|
67 |
else |
2572afe532af
Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents:
11451
diff
changeset
|
68 |
ipcToEngine('e$template_filter ' + intToStr(template)); |
11439 | 69 |
ipcToEngine('e$feature_size ' + intToStr(featureSize)); |
10432 | 70 |
end; |
71 |
gtLocal: begin |
|
11436 | 72 |
if script <> 'Normal' then |
73 |
ipcToEngine('escript ' + getScriptPath(script)); |
|
10432 | 74 |
ipcToEngine('eseed ' + seed); |
75 |
ipcToEngine('e$mapgen ' + intToStr(mapgen)); |
|
11452
2572afe532af
Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents:
11451
diff
changeset
|
76 |
if (mapgen = 1) or (mapgen = 2) then |
11455
0c75fa9ce340
- Use queues instead of single buffer to communicate between threads
unc0rr
parents:
11452
diff
changeset
|
77 |
ipcToEngine('e$maze_size ' + intToStr(mazeSize)) |
11452
2572afe532af
Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents:
11451
diff
changeset
|
78 |
else |
2572afe532af
Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents:
11451
diff
changeset
|
79 |
ipcToEngine('e$template_filter ' + intToStr(template)); |
11439 | 80 |
ipcToEngine('e$feature_size ' + intToStr(featureSize)); |
10456 | 81 |
ipcToEngine('e$theme ' + theme); |
10612 | 82 |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
83 |
sendSchemeConfig(scheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
84 |
|
10432 | 85 |
i:= 0; |
86 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
87 |
begin |
|
11442 | 88 |
sendTeamConfig(teams[i]); |
10892 | 89 |
sendAmmoConfig(config^.ammo); |
10432 | 90 |
inc(i) |
91 |
end; |
|
92 |
end; |
|
93 |
end; |
|
94 |
||
95 |
ipcToEngine('!'); |
|
96 |
end; |
|
97 |
end; |
|
10426 | 98 |
|
99 |
procedure resetGameConfig; cdecl; |
|
10450 | 100 |
var i: Longword; |
10406 | 101 |
begin |
10450 | 102 |
with currentConfig do |
103 |
begin |
|
11436 | 104 |
script:= 'Normal'; |
105 |
||
10450 | 106 |
for i:= 0 to 7 do |
107 |
teams[i].hogsNumber:= 0 |
|
108 |
end |
|
10406 | 109 |
end; |
110 |
||
10430 | 111 |
procedure setSeed(seed: PChar); cdecl; |
112 |
begin |
|
11436 | 113 |
sendUI(mtSeed, @seed[1], length(seed)); |
10430 | 114 |
currentConfig.seed:= seed |
115 |
end; |
|
116 |
||
117 |
function getSeed: PChar; cdecl; |
|
118 |
begin |
|
119 |
getSeed:= str2PChar(currentConfig.seed) |
|
120 |
end; |
|
121 |
||
10450 | 122 |
function getUnusedColor: Longword; |
10448 | 123 |
var i, c: Longword; |
124 |
fColorMatched: boolean; |
|
125 |
begin |
|
126 |
c:= 0; |
|
127 |
i:= 0; |
|
128 |
repeat |
|
129 |
repeat |
|
10450 | 130 |
fColorMatched:= (currentConfig.teams[i].hogsNumber > 0) and (currentConfig.teams[i].color = c); |
10448 | 131 |
inc(i) |
132 |
until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched; |
|
133 |
||
134 |
if fColorMatched then |
|
135 |
begin |
|
136 |
i:= 0; |
|
137 |
inc(c) |
|
138 |
end; |
|
139 |
until not fColorMatched; |
|
140 |
||
10450 | 141 |
getUnusedColor:= c |
10448 | 142 |
end; |
143 |
||
10430 | 144 |
procedure runQuickGame; cdecl; |
10426 | 145 |
begin |
10432 | 146 |
with currentConfig do |
147 |
begin |
|
148 |
gameType:= gtLocal; |
|
149 |
arguments[0]:= ''; |
|
150 |
arguments[1]:= '--internal'; |
|
10448 | 151 |
arguments[2]:= '--nomusic'; |
10432 | 152 |
argumentsNumber:= 3; |
10426 | 153 |
|
10432 | 154 |
teams[0]:= createRandomTeam; |
10450 | 155 |
teams[0].color:= 0; |
10432 | 156 |
teams[1]:= createRandomTeam; |
10450 | 157 |
teams[1].color:= 1; |
11429 | 158 |
teams[1].botLevel:= 3; |
10432 | 159 |
|
11439 | 160 |
queueExecution(currentConfig); |
10432 | 161 |
end; |
10426 | 162 |
end; |
163 |
||
10448 | 164 |
|
10430 | 165 |
procedure getPreview; cdecl; |
10426 | 166 |
begin |
11438 | 167 |
previewNeedsUpdate:= false; |
168 |
||
10426 | 169 |
with currentConfig do |
170 |
begin |
|
171 |
gameType:= gtPreview; |
|
172 |
arguments[0]:= ''; |
|
173 |
arguments[1]:= '--internal'; |
|
174 |
arguments[2]:= '--landpreview'; |
|
175 |
argumentsNumber:= 3; |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
176 |
|
11439 | 177 |
queueExecution(currentConfig); |
10426 | 178 |
end; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
179 |
end; |
10426 | 180 |
|
10448 | 181 |
procedure runLocalGame; cdecl; |
182 |
begin |
|
183 |
with currentConfig do |
|
184 |
begin |
|
185 |
gameType:= gtLocal; |
|
186 |
arguments[0]:= ''; |
|
187 |
arguments[1]:= '--internal'; |
|
188 |
arguments[2]:= '--nomusic'; |
|
189 |
argumentsNumber:= 3; |
|
190 |
||
11439 | 191 |
queueExecution(currentConfig); |
10448 | 192 |
end; |
193 |
end; |
|
194 |
||
11456 | 195 |
procedure runNetGame(); |
196 |
begin |
|
197 |
with currentConfig do |
|
198 |
begin |
|
199 |
gameType:= gtNet; |
|
200 |
arguments[0]:= ''; |
|
201 |
arguments[1]:= '--internal'; |
|
202 |
arguments[2]:= '--nomusic'; |
|
203 |
argumentsNumber:= 3; |
|
204 |
||
205 |
queueExecution(currentConfig); |
|
206 |
end; |
|
207 |
end; |
|
208 |
||
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
209 |
procedure tryAddTeam(teamName: PChar); cdecl; |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
210 |
var msg: ansistring; |
10446 | 211 |
i, hn, hedgehogsNumber: Longword; |
212 |
team: PTeam; |
|
10450 | 213 |
c: Longword; |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
214 |
begin |
11449 | 215 |
team:= teamByName(teamName); |
216 |
if team = nil then exit; |
|
217 |
||
218 |
if isConnected then |
|
219 |
sendTeam(team^) |
|
220 |
else |
|
10446 | 221 |
with currentConfig do |
222 |
begin |
|
223 |
hedgehogsNumber:= 0; |
|
224 |
i:= 0; |
|
225 |
||
226 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
227 |
begin |
|
228 |
inc(i); |
|
229 |
inc(hedgehogsNumber, teams[i].hogsNumber) |
|
230 |
end; |
|
231 |
||
232 |
// no free space for a team or reached hogs number maximum |
|
233 |
if (i > 7) or (hedgehogsNumber >= 48) then exit; |
|
234 |
||
10448 | 235 |
c:= getUnusedColor; |
236 |
||
10446 | 237 |
teams[i]:= team^; |
238 |
||
239 |
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber; |
|
240 |
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber; |
|
241 |
teams[i].hogsNumber:= hn; |
|
10448 | 242 |
|
243 |
teams[i].color:= c; |
|
10446 | 244 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
245 |
msg:= '0' + #10 + teamName; |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
246 |
sendUI(mtAddPlayingTeam, @msg[1], length(msg)); |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
247 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
248 |
msg:= teamName + #10 + colorsSet[teams[i].color]; |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
249 |
sendUI(mtTeamColor, @msg[1], length(msg)); |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
250 |
|
11448 | 251 |
msg:= teamName + #10 + IntToStr(hn); |
252 |
sendUI(mtHedgehogsNumber, @msg[1], length(msg)); |
|
253 |
||
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
254 |
msg:= teamName; |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
255 |
sendUI(mtRemoveTeam, @msg[1], length(msg)) |
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
256 |
end |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
257 |
end; |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
258 |
|
10448 | 259 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
260 |
procedure tryRemoveTeam(teamName: PChar); cdecl; |
11451 | 261 |
var i: Longword; |
10448 | 262 |
tn: shortstring; |
11451 | 263 |
isLocal: boolean; |
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
264 |
begin |
10448 | 265 |
with currentConfig do |
266 |
begin |
|
267 |
i:= 0; |
|
268 |
tn:= teamName; |
|
269 |
while (i < 8) and (teams[i].teamName <> tn) do |
|
270 |
inc(i); |
|
271 |
||
272 |
// team not found??? |
|
273 |
if (i > 7) then exit; |
|
274 |
||
11451 | 275 |
isLocal:= not teams[i].extDriven; |
276 |
||
277 |
if isConnected and not isLocal then |
|
278 |
exit; // we cannot remove this team |
|
279 |
||
10448 | 280 |
while (i < 7) and (teams[i + 1].hogsNumber > 0) do |
281 |
begin |
|
282 |
teams[i]:= teams[i + 1]; |
|
283 |
inc(i) |
|
284 |
end; |
|
285 |
||
286 |
teams[i].hogsNumber:= 0 |
|
287 |
end; |
|
288 |
||
11451 | 289 |
sendUI(mtRemovePlayingTeam, @tn[1], length(tn)); |
290 |
if isConnected then |
|
291 |
removeTeam(tn); |
|
292 |
if isLocal then |
|
293 |
sendUI(mtAddTeam, @tn[1], length(tn)) |
|
10444
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
294 |
end; |
47a6231f1fc1
Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents:
10432
diff
changeset
|
295 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
296 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
297 |
procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
298 |
var i, dc: Longword; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
299 |
tn: shortstring; |
11448 | 300 |
msg: ansistring; |
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
301 |
begin |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
302 |
with currentConfig do |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
303 |
begin |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
304 |
i:= 0; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
305 |
tn:= teamName; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
306 |
while (i < 8) and (teams[i].teamName <> tn) do |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
307 |
inc(i); |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
308 |
// team not found??? |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
309 |
if (i > 7) then exit; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
310 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
311 |
if dir >= 0 then dc:= 1 else dc:= 8; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
312 |
teams[i].color:= (teams[i].color + dc) mod 9; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
313 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
314 |
msg:= tn + #10 + colorsSet[teams[i].color]; |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
315 |
sendUI(mtTeamColor, @msg[1], length(msg)) |
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
316 |
end |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
317 |
end; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
318 |
|
10456 | 319 |
procedure setTheme(themeName: PChar); cdecl; |
320 |
begin |
|
321 |
currentConfig.theme:= themeName |
|
322 |
end; |
|
323 |
||
10612 | 324 |
procedure setScript(scriptName: PChar); cdecl; |
325 |
begin |
|
11436 | 326 |
currentConfig.script:= scriptName |
10612 | 327 |
end; |
328 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
329 |
procedure setScheme(schemeName: PChar); cdecl; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
330 |
var scheme: PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
331 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
332 |
scheme:= schemeByName(schemeName); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
333 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
334 |
if scheme <> nil then |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
335 |
currentConfig.scheme:= scheme^ |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
336 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
337 |
|
10888 | 338 |
procedure setAmmo(ammoName: PChar); cdecl; |
339 |
var ammo: PAmmo; |
|
340 |
begin |
|
341 |
ammo:= ammoByName(ammoName); |
|
342 |
||
343 |
if ammo <> nil then |
|
10892 | 344 |
currentConfig.ammo:= ammo^ |
10888 | 345 |
end; |
346 |
||
11436 | 347 |
procedure netSetSeed(seed: shortstring); |
348 |
begin |
|
349 |
if seed <> currentConfig.seed then |
|
350 |
begin |
|
351 |
currentConfig.seed:= seed; |
|
11437 | 352 |
sendUI(mtSeed, @seed[1], length(seed)); |
353 |
||
354 |
getPreview() |
|
11436 | 355 |
end |
356 |
end; |
|
357 |
||
358 |
procedure netSetTheme(themeName: shortstring); |
|
359 |
begin |
|
360 |
if themeName <> currentConfig.theme then |
|
361 |
begin |
|
362 |
currentConfig.theme:= themeName; |
|
363 |
sendUI(mtTheme, @themeName[1], length(themeName)) |
|
364 |
end |
|
365 |
end; |
|
366 |
||
367 |
procedure netSetScript(scriptName: shortstring); |
|
368 |
begin |
|
369 |
if scriptName <> currentConfig.script then |
|
370 |
begin |
|
11438 | 371 |
previewNeedsUpdate:= true; |
11436 | 372 |
currentConfig.script:= scriptName; |
373 |
sendUI(mtScript, @scriptName[1], length(scriptName)) |
|
374 |
end |
|
375 |
end; |
|
376 |
||
11438 | 377 |
procedure netSetFeatureSize(fsize: LongInt); |
378 |
var s: shortstring; |
|
379 |
begin |
|
380 |
if fsize <> currentConfig.featureSize then |
|
381 |
begin |
|
382 |
previewNeedsUpdate:= true; |
|
383 |
currentConfig.featureSize:= fsize; |
|
384 |
s:= IntToStr(fsize); |
|
385 |
sendUI(mtFeatureSize, @s[1], length(s)) |
|
386 |
end |
|
387 |
end; |
|
388 |
||
389 |
procedure netSetMapGen(mapgen: LongInt); |
|
390 |
var s: shortstring; |
|
391 |
begin |
|
392 |
if mapgen <> currentConfig.mapgen then |
|
393 |
begin |
|
394 |
previewNeedsUpdate:= true; |
|
395 |
currentConfig.mapgen:= mapgen; |
|
396 |
s:= IntToStr(mapgen); |
|
397 |
sendUI(mtMapGen, @s[1], length(s)) |
|
398 |
end |
|
399 |
end; |
|
400 |
||
401 |
procedure netSetMap(map: shortstring); |
|
402 |
begin |
|
403 |
sendUI(mtMap, @map[1], length(map)) |
|
404 |
end; |
|
405 |
||
406 |
procedure netSetMazeSize(mazesize: LongInt); |
|
407 |
var s: shortstring; |
|
408 |
begin |
|
409 |
if mazesize <> currentConfig.mazesize then |
|
410 |
begin |
|
411 |
previewNeedsUpdate:= true; |
|
412 |
currentConfig.mazesize:= mazesize; |
|
413 |
s:= IntToStr(mazesize); |
|
414 |
sendUI(mtMazeSize, @s[1], length(s)) |
|
415 |
end |
|
416 |
end; |
|
417 |
||
418 |
procedure netSetTemplate(template: LongInt); |
|
419 |
var s: shortstring; |
|
420 |
begin |
|
421 |
if template <> currentConfig.template then |
|
422 |
begin |
|
423 |
previewNeedsUpdate:= true; |
|
424 |
currentConfig.template:= template; |
|
425 |
s:= IntToStr(template); |
|
426 |
sendUI(mtTemplate, @s[1], length(s)) |
|
427 |
end |
|
428 |
end; |
|
429 |
||
430 |
procedure updatePreviewIfNeeded; |
|
431 |
begin |
|
432 |
if previewNeedsUpdate then |
|
433 |
getPreview |
|
434 |
end; |
|
435 |
||
11442 | 436 |
procedure netSetAmmo(name: shortstring; definition: ansistring); |
437 |
var ammo: TAmmo; |
|
438 |
i: LongInt; |
|
439 |
begin |
|
440 |
ammo.ammoName:= name; |
|
441 |
i:= length(definition) div 4; |
|
442 |
ammo.a:= copy(definition, 1, i); |
|
443 |
ammo.b:= copy(definition, i + 1, i); |
|
444 |
ammo.c:= copy(definition, i * 2 + 1, i); |
|
445 |
ammo.d:= copy(definition, i * 3 + 1, i); |
|
446 |
||
447 |
currentConfig.ammo:= ammo; |
|
448 |
sendUI(mtAmmo, @name[1], length(name)) |
|
449 |
end; |
|
450 |
||
11445 | 451 |
procedure netSetScheme(scheme: TScheme); |
452 |
begin |
|
453 |
currentConfig.scheme:= scheme; |
|
454 |
sendUI(mtScheme, @scheme.schemeName[1], length(scheme.schemeName)) |
|
455 |
end; |
|
456 |
||
11447 | 457 |
procedure netAddTeam(team: TTeam); |
458 |
var msg: ansistring; |
|
459 |
i, hn, hedgehogsNumber: Longword; |
|
460 |
c: Longword; |
|
461 |
begin |
|
462 |
with currentConfig do |
|
463 |
begin |
|
464 |
hedgehogsNumber:= 0; |
|
465 |
i:= 0; |
|
466 |
||
467 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
468 |
begin |
|
469 |
inc(i); |
|
470 |
inc(hedgehogsNumber, teams[i].hogsNumber) |
|
471 |
end; |
|
472 |
||
473 |
// no free space for a team - server bug??? |
|
474 |
if (i > 7) or (hedgehogsNumber >= 48) then exit; |
|
475 |
||
476 |
c:= getUnusedColor; |
|
477 |
||
478 |
teams[i]:= team; |
|
11449 | 479 |
teams[i].extDriven:= true; |
11447 | 480 |
|
481 |
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber; |
|
482 |
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber; |
|
483 |
teams[i].hogsNumber:= hn; |
|
484 |
||
485 |
teams[i].color:= c; |
|
486 |
||
487 |
msg:= '0' + #10 + team.teamName; |
|
488 |
sendUI(mtAddPlayingTeam, @msg[1], length(msg)); |
|
489 |
||
490 |
msg:= team.teamName + #10 + colorsSet[teams[i].color]; |
|
491 |
sendUI(mtTeamColor, @msg[1], length(msg)); |
|
492 |
end |
|
493 |
end; |
|
494 |
||
11449 | 495 |
procedure netAcceptedTeam(teamName: shortstring); |
496 |
var msg: ansistring; |
|
497 |
i, hn, hedgehogsNumber: Longword; |
|
498 |
c: Longword; |
|
499 |
team: PTeam; |
|
500 |
begin |
|
501 |
with currentConfig do |
|
502 |
begin |
|
503 |
team:= teamByName(teamName); |
|
504 |
// no such team??? |
|
505 |
if team = nil then exit; |
|
506 |
||
507 |
hedgehogsNumber:= 0; |
|
508 |
i:= 0; |
|
509 |
||
510 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
511 |
begin |
|
512 |
inc(i); |
|
513 |
inc(hedgehogsNumber, teams[i].hogsNumber) |
|
514 |
end; |
|
515 |
||
516 |
// no free space for a team - server bug??? |
|
517 |
if (i > 7) or (hedgehogsNumber >= 48) then exit; |
|
518 |
||
519 |
c:= getUnusedColor; |
|
520 |
||
521 |
teams[i]:= team^; |
|
522 |
teams[i].extDriven:= false; |
|
523 |
||
524 |
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber; |
|
525 |
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber; |
|
526 |
teams[i].hogsNumber:= hn; |
|
527 |
||
528 |
teams[i].color:= c; |
|
529 |
||
530 |
msg:= '0' + #10 + teamName; |
|
531 |
sendUI(mtAddPlayingTeam, @msg[1], length(msg)); |
|
532 |
||
533 |
msg:= teamName + #10 + colorsSet[teams[i].color]; |
|
534 |
sendUI(mtTeamColor, @msg[1], length(msg)); |
|
535 |
||
536 |
msg:= teamName; |
|
537 |
sendUI(mtRemoveTeam, @msg[1], length(msg)) |
|
538 |
end |
|
539 |
end; |
|
540 |
||
11448 | 541 |
procedure netRemoveTeam(teamName: shortstring); |
542 |
var msg: shortstring; |
|
543 |
i: Longword; |
|
544 |
tn: shortstring; |
|
545 |
isLocal: boolean; |
|
546 |
begin |
|
547 |
with currentConfig do |
|
548 |
begin |
|
549 |
i:= 0; |
|
550 |
tn:= teamName; |
|
551 |
while (i < 8) and (teams[i].teamName <> tn) do |
|
552 |
inc(i); |
|
553 |
||
554 |
// team not found??? |
|
555 |
if (i > 7) then exit; |
|
556 |
||
557 |
isLocal:= not teams[i].extDriven; |
|
558 |
||
559 |
while (i < 7) and (teams[i + 1].hogsNumber > 0) do |
|
560 |
begin |
|
561 |
teams[i]:= teams[i + 1]; |
|
562 |
inc(i) |
|
563 |
end; |
|
564 |
||
565 |
teams[i].hogsNumber:= 0 |
|
566 |
end; |
|
567 |
||
568 |
msg:= teamName; |
|
569 |
||
570 |
sendUI(mtRemovePlayingTeam, @msg[1], length(msg)); |
|
571 |
if isLocal then |
|
572 |
sendUI(mtAddTeam, @msg[1], length(msg)) |
|
573 |
end; |
|
574 |
||
11447 | 575 |
procedure netSetTeamColor(team: shortstring; color: Longword); |
576 |
var i: Longword; |
|
11448 | 577 |
msg: ansistring; |
11447 | 578 |
begin |
579 |
with currentConfig do |
|
580 |
begin |
|
581 |
i:= 0; |
|
582 |
||
583 |
while (i < 8) and (teams[i].teamName <> team) do |
|
584 |
inc(i); |
|
585 |
// team not found??? |
|
586 |
if (i > 7) then exit; |
|
587 |
||
588 |
teams[i].color:= color mod 9; |
|
589 |
||
590 |
msg:= team + #10 + colorsSet[teams[i].color]; |
|
591 |
sendUI(mtTeamColor, @msg[1], length(msg)) |
|
592 |
end |
|
593 |
end; |
|
594 |
||
11448 | 595 |
procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword); |
596 |
var i: Longword; |
|
597 |
msg: ansistring; |
|
598 |
begin |
|
599 |
if hogsNumber > 8 then exit; |
|
600 |
||
601 |
with currentConfig do |
|
602 |
begin |
|
603 |
i:= 0; |
|
604 |
||
605 |
while (i < 8) and (teams[i].teamName <> team) do |
|
606 |
inc(i); |
|
607 |
// team not found??? |
|
608 |
if (i > 7) then exit; |
|
609 |
||
610 |
teams[i].hogsNumber:= hogsNumber; |
|
611 |
||
612 |
msg:= team + #10 + IntToStr(hogsNumber); |
|
613 |
sendUI(mtHedgehogsNumber, @msg[1], length(msg)) |
|
614 |
end |
|
615 |
end; |
|
616 |
||
617 |
procedure netResetTeams(); |
|
618 |
var msg: shortstring; |
|
619 |
i: Longword; |
|
620 |
begin |
|
621 |
with currentConfig do |
|
622 |
begin |
|
623 |
i:= 0; |
|
624 |
||
625 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
626 |
begin |
|
627 |
msg:= teams[i].teamName; |
|
628 |
||
629 |
sendUI(mtRemovePlayingTeam, @msg[1], length(msg)); |
|
630 |
if not teams[i].extDriven then |
|
631 |
sendUI(mtAddTeam, @msg[1], length(msg)); |
|
632 |
||
633 |
teams[i].hogsNumber:= 0; |
|
634 |
inc(i) |
|
635 |
end; |
|
636 |
||
637 |
end; |
|
638 |
end; |
|
639 |
||
10406 | 640 |
end. |