author | unc0rr |
Sat, 12 Dec 2015 23:38:18 +0300 | |
branch | qmlfrontend |
changeset 11452 | 78860824b5a5 |
parent 11440 | 330c14f4ba69 |
child 11456 | 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 |
12 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData; |
|
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 |
||
11440 | 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) |
|
11440 | 45 |
, (name: 'airmines'; param: @tmpScheme.airmines) |
10757 | 46 |
); |
11440 | 47 |
const bools: array[0 .. 25] of record |
10757 | 48 |
name: shortstring; |
49 |
param: ^boolean; |
|
50 |
end = ( |
|
51 |
(name: 'fortsmode'; param: @tmpScheme.fortsmode) |
|
52 |
, (name: 'divteams'; param: @tmpScheme.divteams) |
|
53 |
, (name: 'solidland'; param: @tmpScheme.solidland) |
|
54 |
, (name: 'border'; param: @tmpScheme.border) |
|
55 |
, (name: 'lowgrav'; param: @tmpScheme.lowgrav) |
|
56 |
, (name: 'laser'; param: @tmpScheme.laser) |
|
57 |
, (name: 'invulnerability'; param: @tmpScheme.invulnerability) |
|
58 |
, (name: 'mines'; param: @tmpScheme.mines) |
|
59 |
, (name: 'vampiric'; param: @tmpScheme.vampiric) |
|
60 |
, (name: 'karma'; param: @tmpScheme.karma) |
|
61 |
, (name: 'artillery'; param: @tmpScheme.artillery) |
|
62 |
, (name: 'randomorder'; param: @tmpScheme.randomorder) |
|
63 |
, (name: 'king'; param: @tmpScheme.king) |
|
64 |
, (name: 'placehog'; param: @tmpScheme.placehog) |
|
65 |
, (name: 'sharedammo'; param: @tmpScheme.sharedammo) |
|
66 |
, (name: 'disablegirders'; param: @tmpScheme.disablegirders) |
|
67 |
, (name: 'disablewind'; param: @tmpScheme.disablewind) |
|
68 |
, (name: 'morewind'; param: @tmpScheme.morewind) |
|
69 |
, (name: 'tagteam'; param: @tmpScheme.tagteam) |
|
70 |
, (name: 'bottomborder'; param: @tmpScheme.bottomborder) |
|
11440 | 71 |
, (name: 'resethealth'; param: @tmpScheme.resethealth) |
72 |
, (name: 'disablelandobjects'; param: @tmpScheme.disablelandobjects) |
|
73 |
, (name: 'aisurvival'; param: @tmpScheme.aisurvival) |
|
74 |
, (name: 'infattack'; param: @tmpScheme.infattack) |
|
75 |
, (name: 'resetweps'; param: @tmpScheme.resetweps) |
|
76 |
, (name: 'perhogammo'; param: @tmpScheme.perhogammo) |
|
10757 | 77 |
); |
78 |
||
10616 | 79 |
|
80 |
procedure loadSchemes; |
|
81 |
var f: PFSFile; |
|
82 |
scheme: PScheme; |
|
83 |
schemes: PSchemeArray; |
|
84 |
s: shortstring; |
|
10757 | 85 |
l, i, ii: Longword; |
86 |
isFound: boolean; |
|
10616 | 87 |
begin |
88 |
f:= pfsOpenRead('/Config/schemes.ini'); |
|
89 |
schemesNumber:= 0; |
|
90 |
||
91 |
if f <> nil then |
|
92 |
begin |
|
93 |
while (not pfsEOF(f)) and (schemesNumber = 0) do |
|
94 |
begin |
|
95 |
pfsReadLn(f, s); |
|
96 |
||
97 |
if copy(s, 1, 5) = 'size=' then |
|
98 |
schemesNumber:= strToInt(midStr(s, 6)); |
|
99 |
end; |
|
100 |
||
101 |
//inc(schemesNumber); // add some default schemes |
|
102 |
||
103 |
schemesList:= GetMem(sizeof(schemesList^) * (schemesNumber + 1)); |
|
104 |
schemes:= PSchemeArray(schemesList); |
|
105 |
||
106 |
while (not pfsEOF(f)) do |
|
107 |
begin |
|
108 |
pfsReadLn(f, s); |
|
109 |
||
110 |
i:= 1; |
|
111 |
while(i <= length(s)) and (s[i] <> '\') do inc(i); |
|
112 |
||
113 |
if i < length(s) then |
|
114 |
begin |
|
115 |
l:= strToInt(copy(s, 1, i - 1)); |
|
10757 | 116 |
delete(s, 1, i); |
10616 | 117 |
|
10757 | 118 |
if (l <= schemesNumber) and (l > 0) then |
10616 | 119 |
begin |
10757 | 120 |
if copy(s, 1, 5) = 'name=' then |
10821 | 121 |
schemes^[l - 1].schemeName:= midStr(s, 6) |
10757 | 122 |
else if copy(s, 1, 12) = 'scriptparam=' then |
10821 | 123 |
schemes^[l - 1].scriptparam:= midStr(s, 13) else |
10757 | 124 |
begin |
125 |
ii:= 0; |
|
126 |
repeat |
|
10821 | 127 |
isFound:= readInt(ints[ii].name, s, PLongInt(ints[ii].param - @tmpScheme + @schemes^[l - 1])^); |
10757 | 128 |
inc(ii) |
129 |
until isFound or (ii > High(ints)); |
|
130 |
||
131 |
if not isFound then |
|
132 |
begin |
|
133 |
ii:= 0; |
|
134 |
repeat |
|
10821 | 135 |
isFound:= readBool(bools[ii].name, s, PBoolean(bools[ii].param - @tmpScheme + @schemes^[l - 1])^); |
10757 | 136 |
inc(ii) |
137 |
until isFound or (ii > High(bools)); |
|
138 |
end; |
|
139 |
end; |
|
10616 | 140 |
end; |
141 |
end; |
|
142 |
end; |
|
143 |
||
144 |
pfsClose(f) |
|
145 |
end; |
|
146 |
end; |
|
147 |
||
148 |
||
149 |
function getSchemesList: PPChar; cdecl; |
|
150 |
var i, t, l: Longword; |
|
151 |
scheme: PScheme; |
|
152 |
begin |
|
153 |
if schemesList = nil then |
|
154 |
loadSchemes; |
|
155 |
||
156 |
t:= schemesNumber; |
|
157 |
if t >= MAX_SCHEME_NAMES then |
|
158 |
t:= MAX_SCHEME_NAMES; |
|
159 |
||
160 |
scheme:= schemesList; |
|
161 |
for i:= 0 to Pred(t) do |
|
162 |
begin |
|
163 |
l:= length(scheme^.schemeName); |
|
164 |
if l >= 255 then l:= 254; |
|
165 |
scheme^.schemeName[l + 1]:= #0; |
|
166 |
listOfSchemeNames[i]:= @scheme^.schemeName[1]; |
|
167 |
inc(scheme) |
|
168 |
end; |
|
169 |
||
170 |
listOfSchemeNames[t]:= nil; |
|
171 |
||
172 |
getSchemesList:= listOfSchemeNames |
|
173 |
end; |
|
174 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
175 |
function schemeByName(s: shortstring): PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
176 |
var i: Longword; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
177 |
scheme: PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
178 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
179 |
scheme:= schemesList; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
180 |
i:= 0; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
181 |
while (i < schemesNumber) and (scheme^.schemeName <> s) do |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
182 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
183 |
inc(scheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
184 |
inc(i) |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
185 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
186 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
187 |
if i < schemesNumber then schemeByName:= scheme else schemeByName:= nil |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
188 |
end; |
10616 | 189 |
|
190 |
procedure freeSchemesList; |
|
191 |
begin |
|
192 |
if schemesList <> nil then |
|
10757 | 193 |
FreeMem(schemesList, sizeof(schemesList^) * (schemesNumber + 1)) |
10616 | 194 |
end; |
195 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
196 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
197 |
procedure sendSchemeConfig(var scheme: TScheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
198 |
var i: Longword; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
199 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
200 |
with scheme do |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
201 |
begin |
10821 | 202 |
if scheme.turntime <> 45 then |
203 |
ipcToEngine('e$turntime ' + inttostr(scheme.turntime * 1000)); |
|
204 |
if scheme.minesnum <> 4 then |
|
205 |
ipcToEngine('e$minesnum ' + inttostr(scheme.minesnum)); |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
206 |
end |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
207 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
208 |
|
10616 | 209 |
end. |