author | unc0rr |
Sun, 28 Sep 2014 21:33:14 +0400 | |
branch | qmlfrontend |
changeset 10432 | b0abef0ee78c |
parent 10430 | 899a30018ede |
child 10444 | 47a6231f1fc1 |
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; |
|
7 |
procedure getPreview; cdecl; |
|
10406 | 8 |
|
10430 | 9 |
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; |
10 |
||
11 |
procedure setSeed(seed: PChar); cdecl; |
|
12 |
function getSeed: PChar; cdecl; |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
13 |
|
10406 | 14 |
implementation |
10432 | 15 |
uses uFLIPC, hwengine, uFLUtils, uFLTeams; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
16 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
17 |
var guiCallbackPointer: pointer; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
18 |
guiCallbackFunction: TGUICallback; |
10406 | 19 |
|
10426 | 20 |
const |
21 |
MAXCONFIGS = 5; |
|
22 |
MAXARGS = 32; |
|
23 |
||
24 |
type |
|
25 |
TGameConfig = record |
|
26 |
seed: shortstring; |
|
27 |
theme: shortstring; |
|
28 |
script: shortstring; |
|
10432 | 29 |
mapgen: Longint; |
10426 | 30 |
gameType: TGameType; |
31 |
teams: array[0..7] of TTeam; |
|
32 |
arguments: array[0..Pred(MAXARGS)] of shortstring; |
|
33 |
argv: array[0..Pred(MAXARGS)] of PChar; |
|
34 |
argumentsNumber: Longword; |
|
35 |
end; |
|
36 |
PGameConfig = ^TGameConfig; |
|
37 |
||
10432 | 38 |
var |
39 |
currentConfig: TGameConfig; |
|
40 |
||
10430 | 41 |
|
10432 | 42 |
procedure sendConfig(config: PGameConfig); |
43 |
var i: Longword; |
|
44 |
begin |
|
45 |
with config^ do |
|
10430 | 46 |
begin |
10432 | 47 |
case gameType of |
48 |
gtPreview: begin |
|
49 |
ipcToEngine('eseed ' + seed); |
|
50 |
ipcToEngine('e$mapgen ' + intToStr(mapgen)); |
|
51 |
end; |
|
52 |
gtLocal: begin |
|
53 |
ipcToEngine('eseed ' + seed); |
|
54 |
ipcToEngine('e$mapgen ' + intToStr(mapgen)); |
|
55 |
i:= 0; |
|
56 |
while (i < 8) and (teams[i].hogsNumber > 0) do |
|
57 |
begin |
|
58 |
ipcToEngine('eammloadt 93919294221991210322351110012000000002111001010111110001'); |
|
59 |
ipcToEngine('eammprob 04050405416006555465544647765766666661555101011154111111'); |
|
60 |
ipcToEngine('eammdelay 00000000000002055000000400070040000000002200000006000200'); |
|
61 |
ipcToEngine('eammreinf 13111103121111111231141111111111111112111111011111111111'); |
|
62 |
ipcToEngine('eammstore'); |
|
63 |
sendTeamConfig(teams[i]); |
|
64 |
inc(i) |
|
65 |
end; |
|
66 |
end; |
|
67 |
end; |
|
68 |
||
69 |
ipcToEngine('!'); |
|
70 |
end; |
|
71 |
end; |
|
10426 | 72 |
|
73 |
procedure queueExecution; |
|
74 |
var pConfig: PGameConfig; |
|
75 |
i: Longword; |
|
76 |
begin |
|
77 |
new(pConfig); |
|
78 |
pConfig^:= currentConfig; |
|
79 |
||
80 |
with pConfig^ do |
|
81 |
for i:= 0 to Pred(MAXARGS) do |
|
82 |
begin |
|
83 |
if arguments[i][0] = #255 then |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
84 |
arguments[i][255]:= #0 |
10426 | 85 |
else |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
86 |
arguments[i][byte(arguments[i][0]) + 1]:= #0; |
10426 | 87 |
argv[i]:= @arguments[i][1] |
88 |
end; |
|
89 |
||
90 |
RunEngine(pConfig^.argumentsNumber, @pConfig^.argv); |
|
10432 | 91 |
|
92 |
sendConfig(pConfig) |
|
10426 | 93 |
end; |
94 |
||
95 |
procedure resetGameConfig; cdecl; |
|
10406 | 96 |
begin |
97 |
end; |
|
98 |
||
10430 | 99 |
procedure setSeed(seed: PChar); cdecl; |
100 |
begin |
|
101 |
currentConfig.seed:= seed |
|
102 |
end; |
|
103 |
||
104 |
function getSeed: PChar; cdecl; |
|
105 |
begin |
|
106 |
getSeed:= str2PChar(currentConfig.seed) |
|
107 |
end; |
|
108 |
||
109 |
procedure runQuickGame; cdecl; |
|
10426 | 110 |
begin |
10432 | 111 |
with currentConfig do |
112 |
begin |
|
113 |
gameType:= gtLocal; |
|
114 |
arguments[0]:= ''; |
|
115 |
arguments[1]:= '--internal'; |
|
116 |
arguments[2]:= '--nosound'; |
|
117 |
argumentsNumber:= 3; |
|
10426 | 118 |
|
10432 | 119 |
teams[0]:= createRandomTeam; |
120 |
teams[0].color:= '6341088'; |
|
121 |
teams[1]:= createRandomTeam; |
|
122 |
teams[1].color:= '2113696'; |
|
123 |
teams[1].botLevel:= 1; |
|
124 |
||
125 |
queueExecution; |
|
126 |
end; |
|
10426 | 127 |
end; |
128 |
||
10430 | 129 |
procedure getPreview; cdecl; |
10426 | 130 |
begin |
131 |
with currentConfig do |
|
132 |
begin |
|
133 |
gameType:= gtPreview; |
|
134 |
arguments[0]:= ''; |
|
135 |
arguments[1]:= '--internal'; |
|
136 |
arguments[2]:= '--landpreview'; |
|
137 |
argumentsNumber:= 3; |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
138 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
139 |
queueExecution; |
10426 | 140 |
end; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
141 |
end; |
10426 | 142 |
|
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
143 |
procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword); |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
144 |
begin |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
145 |
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
|
146 |
end; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
147 |
|
10430 | 148 |
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl; |
10428
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
149 |
begin |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
150 |
guiCallbackPointer:= p; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
151 |
guiCallbackFunction:= f; |
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
152 |
|
7c25297720f1
More refactoring: move PoC preview getting code into flib
unc0rr
parents:
10426
diff
changeset
|
153 |
registerIPCCallback(nil, @engineMessageCallback) |
10426 | 154 |
end; |
155 |
||
10406 | 156 |
end. |