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