author | unc0rr |
Sun, 06 Dec 2015 20:07:35 +0300 | |
branch | qmlfrontend |
changeset 11450 | 465b4db35232 |
parent 11449 | 91f8c6ff5bab |
child 11451 | 321d0ce43568 |
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; |
11448 | 242 |
var msg: shortstring; |
10448 | 243 |
i: Longword; |
244 |
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
|
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 |
||
256 |
while (i < 7) and (teams[i + 1].hogsNumber > 0) do |
|
257 |
begin |
|
258 |
teams[i]:= teams[i + 1]; |
|
259 |
inc(i) |
|
260 |
end; |
|
261 |
||
262 |
teams[i].hogsNumber:= 0 |
|
263 |
end; |
|
264 |
||
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 |
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
|
266 |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
267 |
sendUI(mtRemovePlayingTeam, @msg[1], length(msg)); |
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
271 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
272 |
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
|
273 |
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
|
274 |
tn: shortstring; |
11448 | 275 |
msg: ansistring; |
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
276 |
begin |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
277 |
with currentConfig do |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
278 |
begin |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
279 |
i:= 0; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
280 |
tn:= teamName; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
281 |
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
|
282 |
inc(i); |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
283 |
// team not found??? |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
284 |
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
|
285 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
286 |
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
|
287 |
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
|
288 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
289 |
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
|
290 |
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
|
291 |
end |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
292 |
end; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
293 |
|
10456 | 294 |
procedure setTheme(themeName: PChar); cdecl; |
295 |
begin |
|
296 |
currentConfig.theme:= themeName |
|
297 |
end; |
|
298 |
||
10612 | 299 |
procedure setScript(scriptName: PChar); cdecl; |
300 |
begin |
|
11436 | 301 |
currentConfig.script:= scriptName |
10612 | 302 |
end; |
303 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
304 |
procedure setScheme(schemeName: PChar); cdecl; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
305 |
var scheme: PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
306 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
307 |
scheme:= schemeByName(schemeName); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
308 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
309 |
if scheme <> nil then |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
310 |
currentConfig.scheme:= scheme^ |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
311 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
312 |
|
10888 | 313 |
procedure setAmmo(ammoName: PChar); cdecl; |
314 |
var ammo: PAmmo; |
|
315 |
begin |
|
316 |
ammo:= ammoByName(ammoName); |
|
317 |
||
318 |
if ammo <> nil then |
|
10892 | 319 |
currentConfig.ammo:= ammo^ |
10888 | 320 |
end; |
321 |
||
11436 | 322 |
procedure netSetSeed(seed: shortstring); |
323 |
begin |
|
324 |
if seed <> currentConfig.seed then |
|
325 |
begin |
|
326 |
currentConfig.seed:= seed; |
|
11437 | 327 |
sendUI(mtSeed, @seed[1], length(seed)); |
328 |
||
329 |
getPreview() |
|
11436 | 330 |
end |
331 |
end; |
|
332 |
||
333 |
procedure netSetTheme(themeName: shortstring); |
|
334 |
begin |
|
335 |
if themeName <> currentConfig.theme then |
|
336 |
begin |
|
337 |
currentConfig.theme:= themeName; |
|
338 |
sendUI(mtTheme, @themeName[1], length(themeName)) |
|
339 |
end |
|
340 |
end; |
|
341 |
||
342 |
procedure netSetScript(scriptName: shortstring); |
|
343 |
begin |
|
344 |
if scriptName <> currentConfig.script then |
|
345 |
begin |
|
11438 | 346 |
previewNeedsUpdate:= true; |
11436 | 347 |
currentConfig.script:= scriptName; |
348 |
sendUI(mtScript, @scriptName[1], length(scriptName)) |
|
349 |
end |
|
350 |
end; |
|
351 |
||
11438 | 352 |
procedure netSetFeatureSize(fsize: LongInt); |
353 |
var s: shortstring; |
|
354 |
begin |
|
355 |
if fsize <> currentConfig.featureSize then |
|
356 |
begin |
|
357 |
previewNeedsUpdate:= true; |
|
358 |
currentConfig.featureSize:= fsize; |
|
359 |
s:= IntToStr(fsize); |
|
360 |
sendUI(mtFeatureSize, @s[1], length(s)) |
|
361 |
end |
|
362 |
end; |
|
363 |
||
364 |
procedure netSetMapGen(mapgen: LongInt); |
|
365 |
var s: shortstring; |
|
366 |
begin |
|
367 |
if mapgen <> currentConfig.mapgen then |
|
368 |
begin |
|
369 |
previewNeedsUpdate:= true; |
|
370 |
currentConfig.mapgen:= mapgen; |
|
371 |
s:= IntToStr(mapgen); |
|
372 |
sendUI(mtMapGen, @s[1], length(s)) |
|
373 |
end |
|
374 |
end; |
|
375 |
||
376 |
procedure netSetMap(map: shortstring); |
|
377 |
begin |
|
378 |
sendUI(mtMap, @map[1], length(map)) |
|
379 |
end; |
|
380 |
||
381 |
procedure netSetMazeSize(mazesize: LongInt); |
|
382 |
var s: shortstring; |
|
383 |
begin |
|
384 |
if mazesize <> currentConfig.mazesize then |
|
385 |
begin |
|
386 |
previewNeedsUpdate:= true; |
|
387 |
currentConfig.mazesize:= mazesize; |
|
388 |
s:= IntToStr(mazesize); |
|
389 |
sendUI(mtMazeSize, @s[1], length(s)) |
|
390 |
end |
|
391 |
end; |
|
392 |
||
393 |
procedure netSetTemplate(template: LongInt); |
|
394 |
var s: shortstring; |
|
395 |
begin |
|
396 |
if template <> currentConfig.template then |
|
397 |
begin |
|
398 |
previewNeedsUpdate:= true; |
|
399 |
currentConfig.template:= template; |
|
400 |
s:= IntToStr(template); |
|
401 |
sendUI(mtTemplate, @s[1], length(s)) |
|
402 |
end |
|
403 |
end; |
|
404 |
||
405 |
procedure updatePreviewIfNeeded; |
|
406 |
begin |
|
407 |
if previewNeedsUpdate then |
|
408 |
getPreview |
|
409 |
end; |
|
410 |
||
11442 | 411 |
procedure netSetAmmo(name: shortstring; definition: ansistring); |
412 |
var ammo: TAmmo; |
|
413 |
i: LongInt; |
|
414 |
begin |
|
415 |
ammo.ammoName:= name; |
|
416 |
i:= length(definition) div 4; |
|
417 |
ammo.a:= copy(definition, 1, i); |
|
418 |
ammo.b:= copy(definition, i + 1, i); |
|
419 |
ammo.c:= copy(definition, i * 2 + 1, i); |
|
420 |
ammo.d:= copy(definition, i * 3 + 1, i); |
|
421 |
||
422 |
currentConfig.ammo:= ammo; |
|
423 |
sendUI(mtAmmo, @name[1], length(name)) |
|
424 |
end; |
|
425 |
||
11445 | 426 |
procedure netSetScheme(scheme: TScheme); |
427 |
begin |
|
428 |
currentConfig.scheme:= scheme; |
|
429 |
sendUI(mtScheme, @scheme.schemeName[1], length(scheme.schemeName)) |
|
430 |
end; |
|
431 |
||
11447 | 432 |
procedure netAddTeam(team: TTeam); |
433 |
var msg: ansistring; |
|
434 |
i, hn, hedgehogsNumber: Longword; |
|
435 |
c: Longword; |
|
436 |
begin |
|
437 |
with currentConfig do |
|
438 |
begin |
|
439 |
hedgehogsNumber:= 0; |
|
440 |
i:= 0; |
|
441 |
||
442 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
443 |
begin |
|
444 |
inc(i); |
|
445 |
inc(hedgehogsNumber, teams[i].hogsNumber) |
|
446 |
end; |
|
447 |
||
448 |
// no free space for a team - server bug??? |
|
449 |
if (i > 7) or (hedgehogsNumber >= 48) then exit; |
|
450 |
||
451 |
c:= getUnusedColor; |
|
452 |
||
453 |
teams[i]:= team; |
|
11449 | 454 |
teams[i].extDriven:= true; |
11447 | 455 |
|
456 |
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber; |
|
457 |
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber; |
|
458 |
teams[i].hogsNumber:= hn; |
|
459 |
||
460 |
teams[i].color:= c; |
|
461 |
||
462 |
msg:= '0' + #10 + team.teamName; |
|
463 |
sendUI(mtAddPlayingTeam, @msg[1], length(msg)); |
|
464 |
||
465 |
msg:= team.teamName + #10 + colorsSet[teams[i].color]; |
|
466 |
sendUI(mtTeamColor, @msg[1], length(msg)); |
|
467 |
end |
|
468 |
end; |
|
469 |
||
11449 | 470 |
procedure netAcceptedTeam(teamName: shortstring); |
471 |
var msg: ansistring; |
|
472 |
i, hn, hedgehogsNumber: Longword; |
|
473 |
c: Longword; |
|
474 |
team: PTeam; |
|
475 |
begin |
|
476 |
with currentConfig do |
|
477 |
begin |
|
478 |
team:= teamByName(teamName); |
|
479 |
// no such team??? |
|
480 |
if team = nil then exit; |
|
481 |
||
482 |
hedgehogsNumber:= 0; |
|
483 |
i:= 0; |
|
484 |
||
485 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
486 |
begin |
|
487 |
inc(i); |
|
488 |
inc(hedgehogsNumber, teams[i].hogsNumber) |
|
489 |
end; |
|
490 |
||
491 |
// no free space for a team - server bug??? |
|
492 |
if (i > 7) or (hedgehogsNumber >= 48) then exit; |
|
493 |
||
494 |
c:= getUnusedColor; |
|
495 |
||
496 |
teams[i]:= team^; |
|
497 |
teams[i].extDriven:= false; |
|
498 |
||
499 |
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber; |
|
500 |
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber; |
|
501 |
teams[i].hogsNumber:= hn; |
|
502 |
||
503 |
teams[i].color:= c; |
|
504 |
||
505 |
msg:= '0' + #10 + teamName; |
|
506 |
sendUI(mtAddPlayingTeam, @msg[1], length(msg)); |
|
507 |
||
508 |
msg:= teamName + #10 + colorsSet[teams[i].color]; |
|
509 |
sendUI(mtTeamColor, @msg[1], length(msg)); |
|
510 |
||
511 |
msg:= teamName; |
|
512 |
sendUI(mtRemoveTeam, @msg[1], length(msg)) |
|
513 |
end |
|
514 |
end; |
|
515 |
||
11448 | 516 |
procedure netRemoveTeam(teamName: shortstring); |
517 |
var msg: shortstring; |
|
518 |
i: Longword; |
|
519 |
tn: shortstring; |
|
520 |
isLocal: boolean; |
|
521 |
begin |
|
522 |
with currentConfig do |
|
523 |
begin |
|
524 |
i:= 0; |
|
525 |
tn:= teamName; |
|
526 |
while (i < 8) and (teams[i].teamName <> tn) do |
|
527 |
inc(i); |
|
528 |
||
529 |
// team not found??? |
|
530 |
if (i > 7) then exit; |
|
531 |
||
532 |
isLocal:= not teams[i].extDriven; |
|
533 |
||
534 |
while (i < 7) and (teams[i + 1].hogsNumber > 0) do |
|
535 |
begin |
|
536 |
teams[i]:= teams[i + 1]; |
|
537 |
inc(i) |
|
538 |
end; |
|
539 |
||
540 |
teams[i].hogsNumber:= 0 |
|
541 |
end; |
|
542 |
||
543 |
msg:= teamName; |
|
544 |
||
545 |
sendUI(mtRemovePlayingTeam, @msg[1], length(msg)); |
|
546 |
if isLocal then |
|
547 |
sendUI(mtAddTeam, @msg[1], length(msg)) |
|
548 |
end; |
|
549 |
||
11447 | 550 |
procedure netSetTeamColor(team: shortstring; color: Longword); |
551 |
var i: Longword; |
|
11448 | 552 |
msg: ansistring; |
11447 | 553 |
begin |
554 |
with currentConfig do |
|
555 |
begin |
|
556 |
i:= 0; |
|
557 |
||
558 |
while (i < 8) and (teams[i].teamName <> team) do |
|
559 |
inc(i); |
|
560 |
// team not found??? |
|
561 |
if (i > 7) then exit; |
|
562 |
||
563 |
teams[i].color:= color mod 9; |
|
564 |
||
565 |
msg:= team + #10 + colorsSet[teams[i].color]; |
|
566 |
sendUI(mtTeamColor, @msg[1], length(msg)) |
|
567 |
end |
|
568 |
end; |
|
569 |
||
11448 | 570 |
procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword); |
571 |
var i: Longword; |
|
572 |
msg: ansistring; |
|
573 |
begin |
|
574 |
if hogsNumber > 8 then exit; |
|
575 |
||
576 |
with currentConfig do |
|
577 |
begin |
|
578 |
i:= 0; |
|
579 |
||
580 |
while (i < 8) and (teams[i].teamName <> team) do |
|
581 |
inc(i); |
|
582 |
// team not found??? |
|
583 |
if (i > 7) then exit; |
|
584 |
||
585 |
teams[i].hogsNumber:= hogsNumber; |
|
586 |
||
587 |
msg:= team + #10 + IntToStr(hogsNumber); |
|
588 |
sendUI(mtHedgehogsNumber, @msg[1], length(msg)) |
|
589 |
end |
|
590 |
end; |
|
591 |
||
592 |
procedure netResetTeams(); |
|
593 |
var msg: shortstring; |
|
594 |
i: Longword; |
|
595 |
begin |
|
596 |
with currentConfig do |
|
597 |
begin |
|
598 |
i:= 0; |
|
599 |
||
600 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
601 |
begin |
|
602 |
msg:= teams[i].teamName; |
|
603 |
||
604 |
sendUI(mtRemovePlayingTeam, @msg[1], length(msg)); |
|
605 |
if not teams[i].extDriven then |
|
606 |
sendUI(mtAddTeam, @msg[1], length(msg)); |
|
607 |
||
608 |
teams[i].hogsNumber:= 0; |
|
609 |
inc(i) |
|
610 |
end; |
|
611 |
||
612 |
end; |
|
613 |
end; |
|
614 |
||
10406 | 615 |
end. |