-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stat_Lib.pas
241 lines (211 loc) · 4.93 KB
/
Stat_Lib.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
unit Stat_Lib;
interface
uses Constants_Lib;
type
TPlayerStat =
record
UID: integer;
dmgGiven: integer;
dmgTaken: integer;
Frags : integer;
Deaths : integer;
Suicides: integer;
Hits, Shots: TWPNArray;
humiliation, impressive, excellent: word;
end;
PPlayerStat= ^TPlayerStat;
procedure Stat_Reset;
procedure Stat_Fix;
function Stat_GetStat(i: integer): PPlayerStat;
function Stat_GetStatCount: integer;
function Stat_Get(UID: integer; cancreate: boolean): PPlayerStat;
function Stat_Create(UID: integer): PPlayerStat;
procedure Stat_Set(UID: integer; ps: TPlayerStat);
//âûñòðåë ïàòðîíà/ñíàðÿäà/ëó÷à
procedure Stat_Shot(weapon, UID: integer);
//ïîïàäàíèå ïàòðîíà/ñíàðÿäà/ëó÷à
procedure Stat_Hit(weapon, UID: integer);//UID ÕÎÇßÈÍÀ ÑÍÀÐßÄÀ!
//íàíåñåíèå óðîíà ïàòðîíîì/ñíàðÿäîì/ëó÷îì
procedure Stat_HitDamage(damage, attacker_UID, defender_UID: integer);
//ñìåðòè è ôðàãè
procedure Stat_Frag(UID: integer);
procedure Stat_MinusFrag(UID: integer);
procedure Stat_Death(UID: integer);
procedure Stat_Suicide(UID: integer);
procedure Stat_Humiliation(UID: integer);
procedure Stat_Impressive(UID: integer);
procedure Stat_Excellent(UID: integer);
implementation
uses Map_Lib;
const
MaxStat = 128;
var
stats: array [0..MaxStat-1] of PPlayerStat;
count: integer;
fixed: boolean;
procedure Stat_Fix;
begin
fixed:=true;
end;
procedure Stat_Reset;
var
i: integer;
begin
fixed:=false;
for i:=0 to count-1 do
Dispose(stats[i]);
count:=0;
end;
function Stat_GetStat(i: integer): PPlayerStat;
begin
Result:=nil;
if (i>=0) and (i<count) then
Result:=stats[i];
end;
function Stat_GetStatCount: integer;
begin
Result:=count;
end;
function CorrectWeapon(weap: integer): boolean;
begin
Result:=(weap>0) and (weap<WPN_Count);
end;
function Stat_Get(UID: integer; cancreate: boolean): PPlayerStat;
var
i: integer;
begin
Result:=nil;
if (UID<0) then Exit;
for i:=0 to count-1 do
if stats[i]^.UID=UID then
begin
Result:=stats[i];
Exit;
end;
if cancreate then
Result:=Stat_Create(UID);
end;
function Stat_Create(UID: integer): PPlayerStat;
begin
Result:=Stat_Get(UID, false);
if Result=nil then
begin
Inc(count);
New(stats[count-1]);
Result:=stats[count-1];
fillchar(result^, Sizeof(TPlayerStat), 0)
end else fillchar(result^, Sizeof(TPlayerStat), 0);
Result^.UID:=UID;
end;
procedure Stat_Set(UID: integer; ps: TPlayerStat);
var
i: integer;
begin
for i:=0 to count-1 do
if stats[i].UID=uid then
begin
stats[i]^:=ps;
ps.UID:=UID;
Exit;
end;
new(stats[count]);
stats[count]^:=ps;
Inc(count);
end;
procedure Stat_Shot(weapon, UID: integer);
var
stat: PPlayerStat;
begin
if not correctweapon(weapon) or fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.Shots[weapon]);
end;
procedure Stat_Hit(weapon, UID: integer);
var
stat: PPlayerStat;
begin
if not correctweapon(weapon) or fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.Hits[weapon]);
end;
procedure Stat_HitDamage(damage, attacker_UID, defender_UID: integer);
var
stat: PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(attacker_UID, false);
if stat<>nil then
Inc(stat^.dmgGiven, damage);
stat:=Stat_Get(defender_UID, false);
if stat<>nil then
Inc(stat^.dmgTaken, damage);
end;
procedure Stat_MinusFrag(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Dec(stat^.frags);
end;
procedure Stat_Frag(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.frags);
end;
procedure Stat_Death(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.deaths);
end;
procedure Stat_Suicide(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
begin
Inc(stat^.suicides);
Dec(stat^.frags);
end;
end;
procedure Stat_Humiliation(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.humiliation);
end;
procedure Stat_Impressive(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.Impressive);
end;
procedure Stat_Excellent(UID: integer);
var
stat:PPlayerStat;
begin
if fixed then Exit;
stat:=Stat_Get(UID, false);
if stat<>nil then
Inc(stat^.Excellent);
end;
end.