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