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