author | unc0rr |
Wed, 16 Dec 2015 00:20:56 +0300 | |
branch | qmlfrontend |
changeset 11463 | 8318e841648f |
parent 11461 | ab77e2ea2f82 |
permissions | -rw-r--r-- |
10616 | 1 |
unit uFLSchemes; |
2 |
interface |
|
3 |
uses uFLTypes; |
|
4 |
||
5 |
function getSchemesList: PPChar; cdecl; |
|
6 |
procedure freeSchemesList; |
|
7 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
8 |
function schemeByName(s: shortstring): PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
9 |
procedure sendSchemeConfig(var scheme: TScheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
10 |
|
10616 | 11 |
implementation |
11461 | 12 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLThemes; |
10616 | 13 |
|
14 |
const MAX_SCHEME_NAMES = 64; |
|
15 |
type |
|
16 |
TSchemeArray = array [0..0] of TScheme; |
|
17 |
PSchemeArray = ^TSchemeArray; |
|
18 |
var |
|
19 |
schemesList: PScheme; |
|
20 |
schemesNumber: LongInt; |
|
21 |
listOfSchemeNames: array[0..MAX_SCHEME_NAMES] of PChar; |
|
10757 | 22 |
tmpScheme: TScheme; |
23 |
||
11445 | 24 |
const ints: array[0 .. 17] of record |
10757 | 25 |
name: shortstring; |
26 |
param: ^LongInt; |
|
27 |
end = ( |
|
28 |
(name: 'damagefactor'; param: @tmpScheme.damagefactor) |
|
29 |
, (name: 'turntime'; param: @tmpScheme.turntime) |
|
30 |
, (name: 'health'; param: @tmpScheme.health) |
|
31 |
, (name: 'suddendeath'; param: @tmpScheme.suddendeath) |
|
32 |
, (name: 'caseprobability'; param: @tmpScheme.caseprobability) |
|
33 |
, (name: 'minestime'; param: @tmpScheme.minestime) |
|
34 |
, (name: 'landadds'; param: @tmpScheme.landadds) |
|
35 |
, (name: 'minedudpct'; param: @tmpScheme.minedudpct) |
|
36 |
, (name: 'explosives'; param: @tmpScheme.explosives) |
|
37 |
, (name: 'minesnum'; param: @tmpScheme.minesnum) |
|
38 |
, (name: 'healthprobability'; param: @tmpScheme.healthprobability) |
|
39 |
, (name: 'healthcaseamount'; param: @tmpScheme.healthcaseamount) |
|
40 |
, (name: 'waterrise'; param: @tmpScheme.waterrise) |
|
41 |
, (name: 'healthdecrease'; param: @tmpScheme.healthdecrease) |
|
42 |
, (name: 'ropepct'; param: @tmpScheme.ropepct) |
|
43 |
, (name: 'getawaytime'; param: @tmpScheme.getawaytime) |
|
44 |
, (name: 'worldedge'; param: @tmpScheme.worldedge) |
|
11445 | 45 |
, (name: 'airmines'; param: @tmpScheme.airmines) |
10757 | 46 |
); |
11463 | 47 |
const bools: array[0 .. 24] of record |
10757 | 48 |
name: shortstring; |
49 |
param: ^boolean; |
|
11463 | 50 |
flag: Longword; |
10757 | 51 |
end = ( |
11463 | 52 |
(name: 'fortsmode'; param: @tmpScheme.fortsmode; flag: $00001000) |
53 |
, (name: 'divteams'; param: @tmpScheme.divteams; flag: $00000010) |
|
54 |
, (name: 'solidland'; param: @tmpScheme.solidland; flag: $00000004) |
|
55 |
, (name: 'border'; param: @tmpScheme.border; flag: $00000008) |
|
56 |
, (name: 'lowgrav'; param: @tmpScheme.lowgrav; flag: $00000020) |
|
57 |
, (name: 'laser'; param: @tmpScheme.laser; flag: $00000040) |
|
58 |
, (name: 'invulnerability'; param: @tmpScheme.invulnerability; flag: $00000080) |
|
59 |
, (name: 'resethealth'; param: @tmpScheme.resethealth; flag: $00000100) |
|
60 |
, (name: 'vampiric'; param: @tmpScheme.vampiric; flag: $00000200) |
|
61 |
, (name: 'karma'; param: @tmpScheme.karma; flag: $00000400) |
|
62 |
, (name: 'artillery'; param: @tmpScheme.artillery; flag: $00000800) |
|
63 |
, (name: 'randomorder'; param: @tmpScheme.randomorder; flag: $00002000) |
|
64 |
, (name: 'king'; param: @tmpScheme.king; flag: $00004000) |
|
65 |
, (name: 'placehog'; param: @tmpScheme.placehog; flag: $00008000) |
|
66 |
, (name: 'sharedammo'; param: @tmpScheme.sharedammo; flag: $00010000) |
|
67 |
, (name: 'disablegirders'; param: @tmpScheme.disablegirders; flag: $00020000) |
|
68 |
, (name: 'disablewind'; param: @tmpScheme.disablewind; flag: $00800000) |
|
69 |
, (name: 'morewind'; param: @tmpScheme.morewind; flag: $01000000) |
|
70 |
, (name: 'tagteam'; param: @tmpScheme.tagteam; flag: $02000000) |
|
71 |
, (name: 'bottomborder'; param: @tmpScheme.bottomborder; flag: $04000000) |
|
72 |
, (name: 'disablelandobjects'; param: @tmpScheme.disablelandobjects; flag: $00040000) |
|
73 |
, (name: 'aisurvival'; param: @tmpScheme.aisurvival; flag: $00080000) |
|
74 |
, (name: 'infattack'; param: @tmpScheme.infattack; flag: $00100000) |
|
75 |
, (name: 'resetweps'; param: @tmpScheme.resetweps; flag: $00200000) |
|
76 |
, (name: 'perhogammo'; param: @tmpScheme.perhogammo; flag: $00400000) |
|
10757 | 77 |
); |
78 |
||
10616 | 79 |
procedure loadSchemes; |
80 |
var f: PFSFile; |
|
81 |
schemes: PSchemeArray; |
|
82 |
s: shortstring; |
|
10757 | 83 |
l, i, ii: Longword; |
84 |
isFound: boolean; |
|
10616 | 85 |
begin |
86 |
f:= pfsOpenRead('/Config/schemes.ini'); |
|
87 |
schemesNumber:= 0; |
|
88 |
||
89 |
if f <> nil then |
|
90 |
begin |
|
91 |
while (not pfsEOF(f)) and (schemesNumber = 0) do |
|
92 |
begin |
|
93 |
pfsReadLn(f, s); |
|
94 |
||
95 |
if copy(s, 1, 5) = 'size=' then |
|
96 |
schemesNumber:= strToInt(midStr(s, 6)); |
|
97 |
end; |
|
98 |
||
99 |
//inc(schemesNumber); // add some default schemes |
|
100 |
||
101 |
schemesList:= GetMem(sizeof(schemesList^) * (schemesNumber + 1)); |
|
102 |
schemes:= PSchemeArray(schemesList); |
|
103 |
||
104 |
while (not pfsEOF(f)) do |
|
105 |
begin |
|
106 |
pfsReadLn(f, s); |
|
107 |
||
108 |
i:= 1; |
|
109 |
while(i <= length(s)) and (s[i] <> '\') do inc(i); |
|
110 |
||
111 |
if i < length(s) then |
|
112 |
begin |
|
113 |
l:= strToInt(copy(s, 1, i - 1)); |
|
10757 | 114 |
delete(s, 1, i); |
10616 | 115 |
|
10757 | 116 |
if (l <= schemesNumber) and (l > 0) then |
10616 | 117 |
begin |
10757 | 118 |
if copy(s, 1, 5) = 'name=' then |
10821 | 119 |
schemes^[l - 1].schemeName:= midStr(s, 6) |
10757 | 120 |
else if copy(s, 1, 12) = 'scriptparam=' then |
10821 | 121 |
schemes^[l - 1].scriptparam:= midStr(s, 13) else |
10757 | 122 |
begin |
123 |
ii:= 0; |
|
124 |
repeat |
|
10821 | 125 |
isFound:= readInt(ints[ii].name, s, PLongInt(ints[ii].param - @tmpScheme + @schemes^[l - 1])^); |
10757 | 126 |
inc(ii) |
127 |
until isFound or (ii > High(ints)); |
|
128 |
||
129 |
if not isFound then |
|
130 |
begin |
|
131 |
ii:= 0; |
|
132 |
repeat |
|
10821 | 133 |
isFound:= readBool(bools[ii].name, s, PBoolean(bools[ii].param - @tmpScheme + @schemes^[l - 1])^); |
10757 | 134 |
inc(ii) |
135 |
until isFound or (ii > High(bools)); |
|
136 |
end; |
|
137 |
end; |
|
10616 | 138 |
end; |
139 |
end; |
|
140 |
end; |
|
141 |
||
142 |
pfsClose(f) |
|
143 |
end; |
|
144 |
end; |
|
145 |
||
146 |
||
147 |
function getSchemesList: PPChar; cdecl; |
|
148 |
var i, t, l: Longword; |
|
149 |
scheme: PScheme; |
|
150 |
begin |
|
151 |
if schemesList = nil then |
|
152 |
loadSchemes; |
|
153 |
||
154 |
t:= schemesNumber; |
|
155 |
if t >= MAX_SCHEME_NAMES then |
|
156 |
t:= MAX_SCHEME_NAMES; |
|
157 |
||
158 |
scheme:= schemesList; |
|
159 |
for i:= 0 to Pred(t) do |
|
160 |
begin |
|
161 |
l:= length(scheme^.schemeName); |
|
162 |
if l >= 255 then l:= 254; |
|
163 |
scheme^.schemeName[l + 1]:= #0; |
|
164 |
listOfSchemeNames[i]:= @scheme^.schemeName[1]; |
|
165 |
inc(scheme) |
|
166 |
end; |
|
167 |
||
168 |
listOfSchemeNames[t]:= nil; |
|
169 |
||
170 |
getSchemesList:= listOfSchemeNames |
|
171 |
end; |
|
172 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
173 |
function schemeByName(s: shortstring): PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
174 |
var i: Longword; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
175 |
scheme: PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
176 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
177 |
scheme:= schemesList; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
178 |
i:= 0; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
179 |
while (i < schemesNumber) and (scheme^.schemeName <> s) do |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
180 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
181 |
inc(scheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
182 |
inc(i) |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
183 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
184 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
185 |
if i < schemesNumber then schemeByName:= scheme else schemeByName:= nil |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
186 |
end; |
10616 | 187 |
|
188 |
procedure freeSchemesList; |
|
189 |
begin |
|
190 |
if schemesList <> nil then |
|
10757 | 191 |
FreeMem(schemesList, sizeof(schemesList^) * (schemesNumber + 1)) |
10616 | 192 |
end; |
193 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
194 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
195 |
procedure sendSchemeConfig(var scheme: TScheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
196 |
var i: Longword; |
11463 | 197 |
gf: Longword; |
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
198 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
199 |
with scheme do |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
200 |
begin |
11463 | 201 |
if turntime <> 45 then |
202 |
ipcToEngine('e$turntime ' + inttostr(turntime * 1000)); |
|
203 |
if minesnum <> 4 then |
|
204 |
ipcToEngine('e$minesnum ' + inttostr(minesnum)); |
|
205 |
if damagefactor <> 100 then |
|
206 |
ipcToEngine('e$damagepct ' + inttostr(damagefactor)); |
|
207 |
if worldedge > 0 then |
|
208 |
ipcToEngine('e$worldedge ' + inttostr(worldedge)); |
|
209 |
if length(scriptparam) > 0 then |
|
210 |
ipcToEngine('e$scriptparam ' + scriptparam); |
|
211 |
if suddendeath <> 15 then |
|
212 |
ipcToEngine('e$sd_turns ' + inttostr(suddendeath)); |
|
213 |
if waterrise <> 47 then |
|
214 |
ipcToEngine('e$waterrise ' + inttostr(waterrise)); |
|
215 |
if ropepct <> 100 then |
|
216 |
ipcToEngine('e$ropepct ' + inttostr(ropepct)); |
|
217 |
if getawaytime <> 100 then |
|
218 |
ipcToEngine('e$getawaytime ' + inttostr(getawaytime)); |
|
219 |
if caseprobability <> 5 then |
|
220 |
ipcToEngine('e$casefreq ' + inttostr(caseprobability)); |
|
221 |
if healthprobability <> 35 then |
|
222 |
ipcToEngine('e$healthprob ' + inttostr(healthprobability)); |
|
223 |
if minestime <> 3 then |
|
224 |
ipcToEngine('e$minestime ' + inttostr(minestime * 1000)); |
|
225 |
if minedudpct <> 0 then |
|
226 |
ipcToEngine('e$minedudpct ' + inttostr(minedudpct)); |
|
227 |
if explosives <> 2 then |
|
228 |
ipcToEngine('e$explosives ' + inttostr(explosives)); |
|
229 |
if airmines <> 0 then |
|
230 |
ipcToEngine('e$airmines ' + inttostr(airmines)); |
|
231 |
if healthcaseamount <> 25 then |
|
232 |
ipcToEngine('e$hcaseamount ' + inttostr(healthcaseamount)); |
|
233 |
if healthdecrease <> 5 then |
|
234 |
ipcToEngine('e$healthdec ' + inttostr(healthdecrease)); |
|
235 |
||
236 |
gf:= 0; |
|
237 |
||
238 |
for i:= Low(bools) to High(bools) do |
|
239 |
if PBoolean(bools[i].param - @tmpScheme + @scheme)^ then |
|
240 |
gf:= gf or bools[i].flag; |
|
241 |
||
242 |
ipcToEngine('e$gmflags ' + inttostr(gf)); |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
243 |
end |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
244 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
245 |
|
10616 | 246 |
end. |