|
1 unit uFLSchemes; |
|
2 interface |
|
3 uses uFLTypes; |
|
4 |
|
5 function getSchemesList: PPChar; cdecl; |
|
6 procedure freeSchemesList; |
|
7 |
|
8 implementation |
|
9 uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData; |
|
10 |
|
11 const MAX_SCHEME_NAMES = 64; |
|
12 type |
|
13 TScheme = record |
|
14 schemeName: shortstring; |
|
15 end; |
|
16 PScheme = ^TScheme; |
|
17 TSchemeArray = array [0..0] of TScheme; |
|
18 PSchemeArray = ^TSchemeArray; |
|
19 var |
|
20 schemesList: PScheme; |
|
21 schemesNumber: LongInt; |
|
22 listOfSchemeNames: array[0..MAX_SCHEME_NAMES] of PChar; |
|
23 |
|
24 procedure loadSchemes; |
|
25 var f: PFSFile; |
|
26 scheme: PScheme; |
|
27 schemes: PSchemeArray; |
|
28 s: shortstring; |
|
29 l, i: Longword; |
|
30 begin |
|
31 f:= pfsOpenRead('/Config/schemes.ini'); |
|
32 schemesNumber:= 0; |
|
33 |
|
34 if f <> nil then |
|
35 begin |
|
36 while (not pfsEOF(f)) and (schemesNumber = 0) do |
|
37 begin |
|
38 pfsReadLn(f, s); |
|
39 |
|
40 if copy(s, 1, 5) = 'size=' then |
|
41 schemesNumber:= strToInt(midStr(s, 6)); |
|
42 end; |
|
43 |
|
44 //inc(schemesNumber); // add some default schemes |
|
45 |
|
46 schemesList:= GetMem(sizeof(schemesList^) * (schemesNumber + 1)); |
|
47 schemes:= PSchemeArray(schemesList); |
|
48 |
|
49 while (not pfsEOF(f)) do |
|
50 begin |
|
51 pfsReadLn(f, s); |
|
52 |
|
53 i:= 1; |
|
54 while(i <= length(s)) and (s[i] <> '\') do inc(i); |
|
55 |
|
56 if i < length(s) then |
|
57 begin |
|
58 l:= strToInt(copy(s, 1, i - 1)); |
|
59 |
|
60 if (l < schemesNumber) and (l > 0) then |
|
61 begin |
|
62 scheme:= @schemes^[l - 1]; |
|
63 |
|
64 if copy(s, i + 1, 5) = 'name=' then |
|
65 scheme^. schemeName:= midStr(s, i + 6); |
|
66 end; |
|
67 end; |
|
68 end; |
|
69 |
|
70 pfsClose(f) |
|
71 end; |
|
72 { |
|
73 name=AI TEST |
|
74 fortsmode=false |
|
75 divteams=false |
|
76 solidland=false |
|
77 border=false |
|
78 lowgrav=false |
|
79 laser=false |
|
80 invulnerability=false |
|
81 mines=true |
|
82 damagefactor=100 |
|
83 turntime=40 |
|
84 health=100 |
|
85 suddendeath=0 |
|
86 caseprobability=5 |
|
87 vampiric=false |
|
88 karma=false |
|
89 artillery=false |
|
90 minestime=0 |
|
91 landadds=4 |
|
92 randomorder=true |
|
93 king=false |
|
94 placehog=false |
|
95 sharedammo=false |
|
96 disablegirders=false |
|
97 minedudpct=100 |
|
98 explosives=40 |
|
99 disablelandobjects=true |
|
100 aisurvival=true |
|
101 resethealth=false |
|
102 infattack=true |
|
103 resetweps=true |
|
104 perhogammo=false |
|
105 minesnum=0 |
|
106 healthprobability=100 |
|
107 healthcaseamount=50 |
|
108 waterrise=0 |
|
109 healthdecrease=0 |
|
110 disablewind=false |
|
111 morewind=false |
|
112 ropepct=100 |
|
113 tagteam=false |
|
114 getawaytime=100 |
|
115 bottomborder=false |
|
116 worldedge=1 |
|
117 scriptparam=@Invalid() |
|
118 } |
|
119 end; |
|
120 |
|
121 |
|
122 function getSchemesList: PPChar; cdecl; |
|
123 var i, t, l: Longword; |
|
124 scheme: PScheme; |
|
125 begin |
|
126 if schemesList = nil then |
|
127 loadSchemes; |
|
128 |
|
129 t:= schemesNumber; |
|
130 if t >= MAX_SCHEME_NAMES then |
|
131 t:= MAX_SCHEME_NAMES; |
|
132 |
|
133 scheme:= schemesList; |
|
134 for i:= 0 to Pred(t) do |
|
135 begin |
|
136 l:= length(scheme^.schemeName); |
|
137 if l >= 255 then l:= 254; |
|
138 scheme^.schemeName[l + 1]:= #0; |
|
139 listOfSchemeNames[i]:= @scheme^.schemeName[1]; |
|
140 inc(scheme) |
|
141 end; |
|
142 |
|
143 listOfSchemeNames[t]:= nil; |
|
144 |
|
145 getSchemesList:= listOfSchemeNames |
|
146 end; |
|
147 |
|
148 |
|
149 procedure freeSchemesList; |
|
150 begin |
|
151 if schemesList <> nil then |
|
152 FreeMem(schemesList, sizeof(schemesList^) * schemesNumber) |
|
153 end; |
|
154 |
|
155 end. |