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