-
Notifications
You must be signed in to change notification settings - Fork 4
/
cl_tent.pas
398 lines (350 loc) · 9.49 KB
/
cl_tent.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// ------------------------------------------------------------------------------
// DelphiQuake, Copyright (C) 2005-2011 by Jim Valavanis
// E-Mail: jimmyvalavanis@yahoo.gr
//
// Copyright (C) 1996-1997 Id Software, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ------------------------------------------------------------------------------
{$I dquake.inc}
unit cl_tent;
interface
uses
sound,
gl_model_h,
client;
procedure CL_ClearTEnts;
procedure CL_InitTEnts;
procedure CL_ParseBeam(m: PBSPModelFile);
procedure CL_ParseTEnt;
function CL_NewTempEntity: Pentity_t;
procedure CL_UpdateTEnts;
implementation
uses
q_delphi,
q_vector,
snd_dma,
mathlib,
common,
cl_main_h,
console,
protocol,
gl_part,
cl_main,
gl_model,
sys_win,
gl_vidnt;
var
num_temp_entities: integer;
cl_temp_entities: array[0..MAX_TEMP_ENTITIES - 1] of entity_t;
cl_beams: array[0..MAX_BEAMS - 1] of beam_t;
cl_sfx_wizhit: Psfx_t;
cl_sfx_knighthit: Psfx_t;
cl_sfx_tink1: Psfx_t;
cl_sfx_ric1: Psfx_t;
cl_sfx_ric2: Psfx_t;
cl_sfx_ric3: Psfx_t;
cl_sfx_r_exp3: Psfx_t;
procedure CL_ClearTEnts;
begin
ZeroMemory(@cl_temp_entities, SizeOf(cl_temp_entities));
ZeroMemory(@cl_beams, SizeOf(cl_beams));
end;
procedure CL_InitTEnts;
begin
cl_sfx_wizhit := S_PrecacheSound('wizard/hit.wav');
cl_sfx_knighthit := S_PrecacheSound('hknight/hit.wav');
cl_sfx_tink1 := S_PrecacheSound('weapons/tink1.wav');
cl_sfx_ric1 := S_PrecacheSound('weapons/ric1.wav');
cl_sfx_ric2 := S_PrecacheSound('weapons/ric2.wav');
cl_sfx_ric3 := S_PrecacheSound('weapons/ric3.wav');
cl_sfx_r_exp3 := S_PrecacheSound('weapons/r_exp3.wav');
end;
function CL_NewTempEntity: Pentity_t;
var
ent: Pentity_t;
begin
if cl_numvisedicts = MAX_VISEDICTS then
begin
result := nil;
exit;
end;
if num_temp_entities = MAX_TEMP_ENTITIES then
begin
result := nil;
exit;
end;
ent := @cl_temp_entities[num_temp_entities];
memset(ent, 0, SizeOf(entity_t));
inc(num_temp_entities);
cl_visedicts[cl_numvisedicts] := ent;
inc(cl_numvisedicts);
ent.colormap := vid.colormap;
result := ent;
end;
procedure CL_ParseTEnt;
var
_type: integer;
pos: TVector3f;
dl: Pdlight_t;
rnd: integer;
colorStart, colorLength: integer;
begin
_type := MSG_ReadByte;
case _type of
TE_WIZSPIKE: // spike hitting wall
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_RunParticleEffect(@pos, @vec3_origin, 20, 30);
S_StartSound(-1, 0, cl_sfx_wizhit, @pos, 1, 1);
end;
TE_KNIGHTSPIKE: // spike hitting wall
begin
pos[0] := MSG_ReadCoord();
pos[1] := MSG_ReadCoord();
pos[2] := MSG_ReadCoord();
R_RunParticleEffect(@pos, @vec3_origin, 226, 20);
S_StartSound(-1, 0, cl_sfx_knighthit, @pos, 1, 1);
end;
TE_SPIKE: // spike hitting wall
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_RunParticleEffect(@pos, @vec3_origin, 0, 10);
if (rand mod 5) <> 0 then
S_StartSound(-1, 0, cl_sfx_tink1, @pos, 1, 1)
else
begin
rnd := rand and 3;
if rnd = 1 then
S_StartSound(-1, 0, cl_sfx_ric1, @pos, 1, 1)
else if rnd = 2 then
S_StartSound(-1, 0, cl_sfx_ric2, @pos, 1, 1)
else
S_StartSound(-1, 0, cl_sfx_ric3, @pos, 1, 1);
end;
end;
TE_SUPERSPIKE: // super spike hitting wall
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_RunParticleEffect(@pos, @vec3_origin, 0, 20);
if (rand mod 5) <> 0 then
S_StartSound(-1, 0, cl_sfx_tink1, @pos, 1, 1)
else
begin
rnd := rand mod 3;
if rnd = 1 then
S_StartSound(-1, 0, cl_sfx_ric1, @pos, 1, 1)
else if rnd = 2 then
S_StartSound(-1, 0, cl_sfx_ric2, @pos, 1, 1)
else
S_StartSound(-1, 0, cl_sfx_ric3, @pos, 1, 1);
end;
end;
TE_GUNSHOT: // bullet hitting wall
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_RunParticleEffect(@pos, @vec3_origin, 0, 20);
end;
TE_EXPLOSION: // rocket explosion
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_ParticleExplosion(@pos);
dl := CL_AllocDlight(0);
VectorCopy(@pos, @dl.origin);
dl.radius := 350;
dl.die := cl.time + 0.5;
dl.decay := 300;
S_StartSound(-1, 0, cl_sfx_r_exp3, @pos, 1, 1);
end;
TE_TAREXPLOSION: // tarbaby explosion
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_BlobExplosion(@pos);
S_StartSound(-1, 0, cl_sfx_r_exp3, @pos, 1, 1);
end;
TE_LIGHTNING1: // lightning bolts
CL_ParseBeam(Mod_ForName('progs/bolt.mdl', true));
TE_LIGHTNING2: // lightning bolts
CL_ParseBeam(Mod_ForName('progs/bolt2.mdl', true));
TE_LIGHTNING3: // lightning bolts
CL_ParseBeam(Mod_ForName('progs/bolt3.mdl', true));
// PGM 01/21/97
TE_BEAM: // grappling hook beam
CL_ParseBeam(Mod_ForName('progs/beam.mdl', true));
// PGM 01/21/97
TE_LAVASPLASH:
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_LavaSplash(@pos);
end;
TE_TELEPORT:
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
R_TeleportSplash(@pos);
end;
TE_EXPLOSION2: // color mapped explosion
begin
pos[0] := MSG_ReadCoord;
pos[1] := MSG_ReadCoord;
pos[2] := MSG_ReadCoord;
colorStart := MSG_ReadByte;
colorLength := MSG_ReadByte;
R_ParticleExplosion2(@pos, colorStart, colorLength);
dl := CL_AllocDlight(0);
VectorCopy(@pos, @dl.origin);
dl.radius := 350;
dl.die := cl.time + 0.5;
dl.decay := 300;
S_StartSound(-1, 0, cl_sfx_r_exp3, @pos, 1, 1);
end;
else
Sys_Error('CL_ParseTEnt: bad type');
end;
end;
procedure CL_ParseBeam(m: PBSPModelFile);
var
ent: integer;
start, _end: TVector3f;
b: Pbeam_t;
i: integer;
begin
ent := MSG_ReadShort;
start[0] := MSG_ReadCoord;
start[1] := MSG_ReadCoord;
start[2] := MSG_ReadCoord;
_end[0] := MSG_ReadCoord;
_end[1] := MSG_ReadCoord;
_end[2] := MSG_ReadCoord;
// override any beam with the same entity
b := @cl_beams[0];
for i := 0 to MAX_BEAMS - 1 do
begin
if b.entity = ent then
begin
b.entity := ent;
b.model := m;
b.endtime := cl.time + 0.2;
VectorCopy(@start, @b.start);
VectorCopy(@_end, @b._end);
exit;
end;
inc(b);
end;
// find a free beam
b := @cl_beams[0];
for i := 0 to MAX_BEAMS - 1 do
begin
if (b.model = nil) or (b.endtime < cl.time) then
begin
b.entity := ent;
b.model := m;
b.endtime := cl.time + 0.2;
VectorCopy(@start, @b.start);
VectorCopy(@_end, @b._end);
exit;
end;
inc(b);
end;
Con_Printf('beam list overflow!'#10);
end;
procedure CL_UpdateTEnts;
var
i: integer;
b: Pbeam_t;
dist, org: TVector3f;
d: single;
ent: Pentity_t;
_yaw, _pitch: single;
_forward: single;
begin
num_temp_entities := 0;
// update lightning
b := @cl_beams[0];
i := 0;
while i < MAX_BEAMS - 1 do
begin
if (b.model = nil) or (b.endtime < cl.time) then
begin
inc(b);
inc(i);
continue;
end;
// if coming from the player, update the start position
if b.entity = cl.viewentity then
VectorCopy(@cl_entities[cl.viewentity].origin, @b.start);
// calculate pitch and yaw
VectorSubtract(@b._end, @b.start, @dist);
if (dist[1] = 0) and (dist[0] = 0) then
begin
_yaw := 0;
if dist[2] > 0 then
_pitch := 90
else
_pitch := 270
end
else
begin
_yaw := intval(fatan2(dist[1], dist[0]) * 180 / M_PI);
if _yaw < 0 then
_yaw := _yaw + 360;
_forward := sqrt(dist[0] * dist[0] + dist[1] * dist[1]);
_pitch := int(fatan2(dist[2], _forward) * 180 / M_PI);
if _pitch < 0 then
_pitch := _pitch + 360;
end;
// add new entities for the lightning
VectorCopy(@b.start, @org);
d := VectorNormalize(@dist);
while d > 0 do
begin
ent := CL_NewTempEntity;
if ent = nil then
exit;
VectorCopy(@org, @ent.origin);
ent.model := b.model;
ent.angles[0] := _pitch;
ent.angles[1] := _yaw;
ent.angles[2] := rand mod 360;
i := 0;
while i < 3 do
begin
org[i] := org[i] + dist[i] * 30;
inc(i);
end;
d := d - 30;
end;
inc(b);
inc(i);
end;
end;
end.