10890
|
1 |
unit uFLAmmo;
|
|
2 |
interface
|
|
3 |
uses uFLTypes;
|
|
4 |
|
|
5 |
function getAmmosList: PPChar; cdecl;
|
|
6 |
procedure freeAmmosList;
|
|
7 |
|
|
8 |
function ammoByName(s: shortstring): PAmmo;
|
|
9 |
procedure sendAmmoConfig(var ammo: TAmmo);
|
|
10 |
|
|
11 |
implementation
|
|
12 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData;
|
|
13 |
|
|
14 |
const MAX_AMMO_NAMES = 64;
|
|
15 |
type
|
|
16 |
TAmmoArray = array [0..0] of TAmmo;
|
|
17 |
PAmmoArray = ^TAmmoArray;
|
|
18 |
var
|
|
19 |
ammoList: PAmmo;
|
|
20 |
ammoNumber: LongInt;
|
|
21 |
listOfAmmoNames: array[0..MAX_AMMO_NAMES] of PChar;
|
|
22 |
|
|
23 |
procedure loadAmmo;
|
|
24 |
var f: PFSFile;
|
|
25 |
ammo: PAmmo;
|
|
26 |
ammos: PAmmoArray;
|
|
27 |
s: ansistring;
|
|
28 |
i: Longword;
|
|
29 |
begin
|
|
30 |
f:= pfsOpenRead('/Config/weapons.ini');
|
|
31 |
ammoNumber:= 0;
|
|
32 |
|
|
33 |
if f <> nil then
|
|
34 |
begin
|
|
35 |
while (not pfsEOF(f)) do
|
|
36 |
begin
|
|
37 |
pfsReadLnA(f, s);
|
|
38 |
|
|
39 |
if (length(s) > 0) and (s[1] <> '[') then
|
|
40 |
inc(ammoNumber);
|
|
41 |
end;
|
|
42 |
|
|
43 |
//inc(ammoNumber); // add some default ammo
|
|
44 |
|
|
45 |
ammoList:= GetMem(sizeof(ammoList^) * (ammoNumber + 1));
|
|
46 |
ammo:= PAmmo(ammoList);
|
|
47 |
pfsSeek(f, 0);
|
|
48 |
|
|
49 |
while (not pfsEOF(f)) do
|
|
50 |
begin
|
|
51 |
pfsReadLnA(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 |
ammo^.ammoName:= copy(s, 1, i - 1);
|
|
59 |
delete(s, 1, i);
|
|
60 |
// TODO: split into 4 shortstrings
|
10892
|
61 |
i:= length(s) div 4;
|
|
62 |
ammo^.a:= copy(s, 1, i);
|
|
63 |
ammo^.b:= copy(s, i + 1, i);
|
|
64 |
ammo^.c:= copy(s, i * 2 + 1, i);
|
|
65 |
ammo^.d:= copy(s, i * 3 + 1, i);
|
10890
|
66 |
inc(ammo)
|
|
67 |
end;
|
|
68 |
end;
|
|
69 |
|
|
70 |
pfsClose(f)
|
|
71 |
end;
|
|
72 |
end;
|
|
73 |
|
|
74 |
|
|
75 |
function getAmmosList: PPChar; cdecl;
|
|
76 |
var i, t, l: Longword;
|
|
77 |
ammo: PAmmo;
|
|
78 |
begin
|
|
79 |
if ammoList = nil then
|
|
80 |
loadAmmo;
|
|
81 |
|
|
82 |
t:= ammoNumber;
|
|
83 |
if t >= MAX_AMMO_NAMES then
|
|
84 |
t:= MAX_AMMO_NAMES;
|
|
85 |
|
|
86 |
ammo:= ammoList;
|
|
87 |
for i:= 0 to Pred(t) do
|
|
88 |
begin
|
|
89 |
l:= length(ammo^.ammoName);
|
|
90 |
if l >= 255 then l:= 254;
|
|
91 |
ammo^.ammoName[l + 1]:= #0;
|
|
92 |
listOfAmmoNames[i]:= @ammo^.ammoName[1];
|
|
93 |
inc(ammo)
|
|
94 |
end;
|
|
95 |
|
|
96 |
listOfAmmoNames[t]:= nil;
|
|
97 |
|
|
98 |
getAmmosList:= listOfAmmoNames
|
|
99 |
end;
|
|
100 |
|
|
101 |
function ammoByName(s: shortstring): PAmmo;
|
|
102 |
var i: Longword;
|
|
103 |
ammo: PAmmo;
|
|
104 |
begin
|
|
105 |
ammo:= ammoList;
|
|
106 |
i:= 0;
|
|
107 |
while (i < ammoNumber) and (ammo^.ammoName <> s) do
|
|
108 |
begin
|
|
109 |
inc(ammo);
|
|
110 |
inc(i)
|
|
111 |
end;
|
|
112 |
|
|
113 |
if i < ammoNumber then ammoByName:= ammo else ammoByName:= nil
|
|
114 |
end;
|
|
115 |
|
|
116 |
procedure freeAmmosList;
|
|
117 |
begin
|
|
118 |
if ammoList <> nil then
|
|
119 |
FreeMem(ammoList, sizeof(ammoList^) * (ammoNumber + 1))
|
|
120 |
end;
|
|
121 |
|
|
122 |
|
|
123 |
procedure sendAmmoConfig(var ammo: TAmmo);
|
|
124 |
var i: Longword;
|
|
125 |
begin
|
|
126 |
with ammo do
|
|
127 |
begin
|
10892
|
128 |
ipcToEngine('eammloadt ' + ammo.a);
|
|
129 |
ipcToEngine('eammprob ' + ammo.b);
|
|
130 |
ipcToEngine('eammdelay ' + ammo.c);
|
|
131 |
ipcToEngine('eammreinf ' + ammo.d);
|
10890
|
132 |
end
|
|
133 |
end;
|
|
134 |
|
|
135 |
end.
|