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