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
|
|
61 |
ammo^.ammoStr:= s;
|
|
62 |
inc(ammo)
|
|
63 |
end;
|
|
64 |
end;
|
|
65 |
|
|
66 |
pfsClose(f)
|
|
67 |
end;
|
|
68 |
end;
|
|
69 |
|
|
70 |
|
|
71 |
function getAmmosList: PPChar; cdecl;
|
|
72 |
var i, t, l: Longword;
|
|
73 |
ammo: PAmmo;
|
|
74 |
begin
|
|
75 |
if ammoList = nil then
|
|
76 |
loadAmmo;
|
|
77 |
|
|
78 |
t:= ammoNumber;
|
|
79 |
if t >= MAX_AMMO_NAMES then
|
|
80 |
t:= MAX_AMMO_NAMES;
|
|
81 |
|
|
82 |
ammo:= ammoList;
|
|
83 |
for i:= 0 to Pred(t) do
|
|
84 |
begin
|
|
85 |
l:= length(ammo^.ammoName);
|
|
86 |
if l >= 255 then l:= 254;
|
|
87 |
ammo^.ammoName[l + 1]:= #0;
|
|
88 |
listOfAmmoNames[i]:= @ammo^.ammoName[1];
|
|
89 |
inc(ammo)
|
|
90 |
end;
|
|
91 |
|
|
92 |
listOfAmmoNames[t]:= nil;
|
|
93 |
|
|
94 |
getAmmosList:= listOfAmmoNames
|
|
95 |
end;
|
|
96 |
|
|
97 |
function ammoByName(s: shortstring): PAmmo;
|
|
98 |
var i: Longword;
|
|
99 |
ammo: PAmmo;
|
|
100 |
begin
|
|
101 |
ammo:= ammoList;
|
|
102 |
i:= 0;
|
|
103 |
while (i < ammoNumber) and (ammo^.ammoName <> s) do
|
|
104 |
begin
|
|
105 |
inc(ammo);
|
|
106 |
inc(i)
|
|
107 |
end;
|
|
108 |
|
|
109 |
if i < ammoNumber then ammoByName:= ammo else ammoByName:= nil
|
|
110 |
end;
|
|
111 |
|
|
112 |
procedure freeAmmosList;
|
|
113 |
begin
|
|
114 |
if ammoList <> nil then
|
|
115 |
FreeMem(ammoList, sizeof(ammoList^) * (ammoNumber + 1))
|
|
116 |
end;
|
|
117 |
|
|
118 |
|
|
119 |
procedure sendAmmoConfig(var ammo: TAmmo);
|
|
120 |
var i: Longword;
|
|
121 |
begin
|
|
122 |
with ammo do
|
|
123 |
begin
|
|
124 |
//ipcToEngine('e$turntime ' + inttostr(ammo.turntime * 1000));
|
|
125 |
//ipcToEngine('e$minesnum ' + inttostr(ammo.minesnum));
|
|
126 |
end
|
|
127 |
end;
|
|
128 |
|
|
129 |
end.
|