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