author | unc0rr |
Mon, 16 Nov 2015 22:57:24 +0300 | |
branch | qmlfrontend |
changeset 11403 | b894922d58cc |
parent 10951 | 89a7f617e091 |
child 11424 | 86c13e5662f1 |
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 |
|
10406 | 21 |
implementation |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
22 |
uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback; |
10406 | 23 |
|
10426 | 24 |
const |
25 |
MAXCONFIGS = 5; |
|
26 |
MAXARGS = 32; |
|
27 |
||
28 |
type |
|
29 |
TGameConfig = record |
|
30 |
seed: shortstring; |
|
31 |
theme: shortstring; |
|
32 |
script: shortstring; |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
33 |
scheme: TScheme; |
10892 | 34 |
ammo: TAmmo; |
10432 | 35 |
mapgen: Longint; |
10426 | 36 |
gameType: TGameType; |
37 |
teams: array[0..7] of TTeam; |
|
38 |
arguments: array[0..Pred(MAXARGS)] of shortstring; |
|
39 |
argv: array[0..Pred(MAXARGS)] of PChar; |
|
40 |
argumentsNumber: Longword; |
|
41 |
end; |
|
42 |
PGameConfig = ^TGameConfig; |
|
43 |
||
10432 | 44 |
var |
45 |
currentConfig: TGameConfig; |
|
46 |
||
10430 | 47 |
|
10432 | 48 |
procedure sendConfig(config: PGameConfig); |
49 |
var i: Longword; |
|
50 |
begin |
|
51 |
with config^ do |
|
10430 | 52 |
begin |
10432 | 53 |
case gameType of |
54 |
gtPreview: begin |
|
10612 | 55 |
if script <> '' then |
56 |
ipcToEngine('escript ' + script); |
|
10432 | 57 |
ipcToEngine('eseed ' + seed); |
58 |
ipcToEngine('e$mapgen ' + intToStr(mapgen)); |
|
59 |
end; |
|
60 |
gtLocal: begin |
|
10612 | 61 |
if script <> '' then |
62 |
ipcToEngine('escript ' + script); |
|
10432 | 63 |
ipcToEngine('eseed ' + seed); |
64 |
ipcToEngine('e$mapgen ' + intToStr(mapgen)); |
|
10456 | 65 |
ipcToEngine('e$theme ' + theme); |
10612 | 66 |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
67 |
sendSchemeConfig(scheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
68 |
|
10432 | 69 |
i:= 0; |
70 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
71 |
begin |
|
10892 | 72 |
sendAmmoConfig(config^.ammo); |
10432 | 73 |
ipcToEngine('eammstore'); |
74 |
sendTeamConfig(teams[i]); |
|
75 |
inc(i) |
|
76 |
end; |
|
77 |
end; |
|
78 |
end; |
|
79 |
||
80 |
ipcToEngine('!'); |
|
81 |
end; |
|
82 |
end; |
|
10426 | 83 |
|
84 |
procedure queueExecution; |
|
85 |
var pConfig: PGameConfig; |
|
86 |
i: Longword; |
|
87 |
begin |
|
88 |
new(pConfig); |
|
89 |
pConfig^:= currentConfig; |
|
90 |
||
91 |
with pConfig^ do |
|
92 |
for i:= 0 to Pred(MAXARGS) do |
|
93 |
begin |
|
94 |
if arguments[i][0] = #255 then |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
95 |
arguments[i][255]:= #0 |
10426 | 96 |
else |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
97 |
arguments[i][byte(arguments[i][0]) + 1]:= #0; |
10426 | 98 |
argv[i]:= @arguments[i][1] |
99 |
end; |
|
100 |
||
101 |
RunEngine(pConfig^.argumentsNumber, @pConfig^.argv); |
|
10432 | 102 |
|
103 |
sendConfig(pConfig) |
|
10426 | 104 |
end; |
105 |
||
106 |
procedure resetGameConfig; cdecl; |
|
10450 | 107 |
var i: Longword; |
10406 | 108 |
begin |
10450 | 109 |
with currentConfig do |
110 |
begin |
|
111 |
for i:= 0 to 7 do |
|
112 |
teams[i].hogsNumber:= 0 |
|
113 |
end |
|
10406 | 114 |
end; |
115 |
||
10430 | 116 |
procedure setSeed(seed: PChar); cdecl; |
117 |
begin |
|
118 |
currentConfig.seed:= seed |
|
119 |
end; |
|
120 |
||
10448 | 121 |
|
10430 | 122 |
function getSeed: PChar; cdecl; |
123 |
begin |
|
124 |
getSeed:= str2PChar(currentConfig.seed) |
|
125 |
end; |
|
126 |
||
10450 | 127 |
function getUnusedColor: Longword; |
10448 | 128 |
var i, c: Longword; |
129 |
fColorMatched: boolean; |
|
130 |
begin |
|
131 |
c:= 0; |
|
132 |
i:= 0; |
|
133 |
repeat |
|
134 |
repeat |
|
10450 | 135 |
fColorMatched:= (currentConfig.teams[i].hogsNumber > 0) and (currentConfig.teams[i].color = c); |
10448 | 136 |
inc(i) |
137 |
until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched; |
|
138 |
||
139 |
if fColorMatched then |
|
140 |
begin |
|
141 |
i:= 0; |
|
142 |
inc(c) |
|
143 |
end; |
|
144 |
until not fColorMatched; |
|
145 |
||
10450 | 146 |
getUnusedColor:= c |
10448 | 147 |
end; |
148 |
||
10430 | 149 |
procedure runQuickGame; cdecl; |
10426 | 150 |
begin |
10432 | 151 |
with currentConfig do |
152 |
begin |
|
153 |
gameType:= gtLocal; |
|
154 |
arguments[0]:= ''; |
|
155 |
arguments[1]:= '--internal'; |
|
10448 | 156 |
arguments[2]:= '--nomusic'; |
10432 | 157 |
argumentsNumber:= 3; |
10426 | 158 |
|
10432 | 159 |
teams[0]:= createRandomTeam; |
10450 | 160 |
teams[0].color:= 0; |
10432 | 161 |
teams[1]:= createRandomTeam; |
10450 | 162 |
teams[1].color:= 1; |
10432 | 163 |
teams[1].botLevel:= 1; |
164 |
||
165 |
queueExecution; |
|
166 |
end; |
|
10426 | 167 |
end; |
168 |
||
10448 | 169 |
|
10430 | 170 |
procedure getPreview; cdecl; |
10426 | 171 |
begin |
172 |
with currentConfig do |
|
173 |
begin |
|
174 |
gameType:= gtPreview; |
|
175 |
arguments[0]:= ''; |
|
176 |
arguments[1]:= '--internal'; |
|
177 |
arguments[2]:= '--landpreview'; |
|
178 |
argumentsNumber:= 3; |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
179 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
180 |
queueExecution; |
10426 | 181 |
end; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
182 |
end; |
10426 | 183 |
|
10448 | 184 |
procedure runLocalGame; cdecl; |
185 |
begin |
|
186 |
with currentConfig do |
|
187 |
begin |
|
188 |
gameType:= gtLocal; |
|
189 |
arguments[0]:= ''; |
|
190 |
arguments[1]:= '--internal'; |
|
191 |
arguments[2]:= '--nomusic'; |
|
192 |
argumentsNumber:= 3; |
|
193 |
||
194 |
queueExecution; |
|
195 |
end; |
|
196 |
end; |
|
197 |
||
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
198 |
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
|
199 |
var msg: ansistring; |
10446 | 200 |
i, hn, hedgehogsNumber: Longword; |
201 |
team: PTeam; |
|
10450 | 202 |
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
|
203 |
begin |
10446 | 204 |
with currentConfig do |
205 |
begin |
|
206 |
hedgehogsNumber:= 0; |
|
207 |
i:= 0; |
|
208 |
||
209 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
210 |
begin |
|
211 |
inc(i); |
|
212 |
inc(hedgehogsNumber, teams[i].hogsNumber) |
|
213 |
end; |
|
214 |
||
215 |
// no free space for a team or reached hogs number maximum |
|
216 |
if (i > 7) or (hedgehogsNumber >= 48) then exit; |
|
217 |
||
218 |
team:= teamByName(teamName); |
|
219 |
if team = nil then exit; |
|
220 |
||
10448 | 221 |
c:= getUnusedColor; |
222 |
||
10446 | 223 |
teams[i]:= team^; |
224 |
||
225 |
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber; |
|
226 |
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber; |
|
227 |
teams[i].hogsNumber:= hn; |
|
10448 | 228 |
|
229 |
teams[i].color:= c; |
|
10446 | 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:= '0' + #10 + teamName; |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
232 |
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
|
233 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
234 |
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
|
235 |
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
|
236 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
237 |
msg:= teamName; |
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
|
10448 | 242 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
243 |
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
|
244 |
var msg: ansistring; |
10448 | 245 |
i: Longword; |
246 |
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
|
247 |
begin |
10448 | 248 |
with currentConfig do |
249 |
begin |
|
250 |
i:= 0; |
|
251 |
tn:= teamName; |
|
252 |
while (i < 8) and (teams[i].teamName <> tn) do |
|
253 |
inc(i); |
|
254 |
||
255 |
// team not found??? |
|
256 |
if (i > 7) then exit; |
|
257 |
||
258 |
while (i < 7) and (teams[i + 1].hogsNumber > 0) do |
|
259 |
begin |
|
260 |
teams[i]:= teams[i + 1]; |
|
261 |
inc(i) |
|
262 |
end; |
|
263 |
||
264 |
teams[i].hogsNumber:= 0 |
|
265 |
end; |
|
266 |
||
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
|
267 |
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
|
268 |
|
10951
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
269 |
sendUI(mtRemovePlayingTeam, @msg[1], length(msg)); |
89a7f617e091
- Move protocol handling events to main thread through qt's main loop
unc0rr
parents:
10892
diff
changeset
|
270 |
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
|
271 |
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
|
272 |
|
10452
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
273 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
tn: shortstring; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
277 |
msg: ansistring; |
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 |
with currentConfig do |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
280 |
begin |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
281 |
i:= 0; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
282 |
tn:= teamName; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
283 |
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
|
284 |
inc(i); |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
285 |
// team not found??? |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
286 |
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
|
287 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
|
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
291 |
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
|
292 |
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
|
293 |
end |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
294 |
end; |
03519fd9f98d
Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents:
10450
diff
changeset
|
295 |
|
10456 | 296 |
procedure setTheme(themeName: PChar); cdecl; |
297 |
begin |
|
298 |
currentConfig.theme:= themeName |
|
299 |
end; |
|
300 |
||
10612 | 301 |
procedure setScript(scriptName: PChar); cdecl; |
302 |
begin |
|
303 |
if scriptName <> 'Normal' then |
|
304 |
currentConfig.script:= '/Scripts/Multiplayer/' + scriptName + '.lua' |
|
305 |
else |
|
306 |
currentConfig.script:= '' |
|
307 |
end; |
|
308 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
309 |
procedure setScheme(schemeName: PChar); cdecl; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
310 |
var scheme: PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
311 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
312 |
scheme:= schemeByName(schemeName); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
313 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
314 |
if scheme <> nil then |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
315 |
currentConfig.scheme:= scheme^ |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
316 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10612
diff
changeset
|
317 |
|
10888 | 318 |
procedure setAmmo(ammoName: PChar); cdecl; |
319 |
var ammo: PAmmo; |
|
320 |
begin |
|
321 |
ammo:= ammoByName(ammoName); |
|
322 |
||
323 |
if ammo <> nil then |
|
10892 | 324 |
currentConfig.ammo:= ammo^ |
10888 | 325 |
end; |
326 |
||
10406 | 327 |
end. |