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