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