author | unc0rr |
Mon, 30 Nov 2015 23:25:18 +0300 | |
branch | qmlfrontend |
changeset 11439 | 23912c93935a |
parent 10821 | efb861d1489e |
child 11445 | 330c14f4ba69 |
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 |
10757 | 113 |
if copy(s, 1, 5) = 'name=' then |
10821 | 114 |
schemes^[l - 1].schemeName:= midStr(s, 6) |
10757 | 115 |
else if copy(s, 1, 12) = 'scriptparam=' then |
10821 | 116 |
schemes^[l - 1].scriptparam:= midStr(s, 13) else |
10757 | 117 |
begin |
118 |
ii:= 0; |
|
119 |
repeat |
|
10821 | 120 |
isFound:= readInt(ints[ii].name, s, PLongInt(ints[ii].param - @tmpScheme + @schemes^[l - 1])^); |
10757 | 121 |
inc(ii) |
122 |
until isFound or (ii > High(ints)); |
|
123 |
||
124 |
if not isFound then |
|
125 |
begin |
|
126 |
ii:= 0; |
|
127 |
repeat |
|
10821 | 128 |
isFound:= readBool(bools[ii].name, s, PBoolean(bools[ii].param - @tmpScheme + @schemes^[l - 1])^); |
10757 | 129 |
inc(ii) |
130 |
until isFound or (ii > High(bools)); |
|
131 |
end; |
|
132 |
end; |
|
10616 | 133 |
end; |
134 |
end; |
|
135 |
end; |
|
136 |
||
137 |
pfsClose(f) |
|
138 |
end; |
|
139 |
end; |
|
140 |
||
141 |
||
142 |
function getSchemesList: PPChar; cdecl; |
|
143 |
var i, t, l: Longword; |
|
144 |
scheme: PScheme; |
|
145 |
begin |
|
146 |
if schemesList = nil then |
|
147 |
loadSchemes; |
|
148 |
||
149 |
t:= schemesNumber; |
|
150 |
if t >= MAX_SCHEME_NAMES then |
|
151 |
t:= MAX_SCHEME_NAMES; |
|
152 |
||
153 |
scheme:= schemesList; |
|
154 |
for i:= 0 to Pred(t) do |
|
155 |
begin |
|
156 |
l:= length(scheme^.schemeName); |
|
157 |
if l >= 255 then l:= 254; |
|
158 |
scheme^.schemeName[l + 1]:= #0; |
|
159 |
listOfSchemeNames[i]:= @scheme^.schemeName[1]; |
|
160 |
inc(scheme) |
|
161 |
end; |
|
162 |
||
163 |
listOfSchemeNames[t]:= nil; |
|
164 |
||
165 |
getSchemesList:= listOfSchemeNames |
|
166 |
end; |
|
167 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
168 |
function schemeByName(s: shortstring): PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
169 |
var i: Longword; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
170 |
scheme: PScheme; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
171 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
172 |
scheme:= schemesList; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
173 |
i:= 0; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
174 |
while (i < schemesNumber) and (scheme^.schemeName <> s) do |
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 |
inc(scheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
177 |
inc(i) |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
178 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
179 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
180 |
if i < schemesNumber then schemeByName:= scheme else schemeByName:= nil |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
181 |
end; |
10616 | 182 |
|
183 |
procedure freeSchemesList; |
|
184 |
begin |
|
185 |
if schemesList <> nil then |
|
10757 | 186 |
FreeMem(schemesList, sizeof(schemesList^) * (schemesNumber + 1)) |
10616 | 187 |
end; |
188 |
||
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
189 |
|
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
190 |
procedure sendSchemeConfig(var scheme: TScheme); |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
191 |
var i: Longword; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
192 |
begin |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
193 |
with scheme do |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
194 |
begin |
10821 | 195 |
if scheme.turntime <> 45 then |
196 |
ipcToEngine('e$turntime ' + inttostr(scheme.turntime * 1000)); |
|
197 |
if scheme.minesnum <> 4 then |
|
198 |
ipcToEngine('e$minesnum ' + inttostr(scheme.minesnum)); |
|
10819
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
199 |
end |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
200 |
end; |
57e21f7621b0
Send selected scheme config on engine initialization (WIP)
unc0rr
parents:
10757
diff
changeset
|
201 |
|
10616 | 202 |
end. |