-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_tent.c
680 lines (624 loc) · 17.2 KB
/
cl_tent.c
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
//**************************************************************************
//**
//** cl_tent.c
//**
//** Client side temporary entity effects.
//**
//** $Header: /H2 Mission Pack/CL_TENT.C 6 3/02/98 2:51p Jweier $
//**
//**************************************************************************
// HEADER FILES ------------------------------------------------------------
#include "quakedef.h"
// MACROS ------------------------------------------------------------------
#define MAX_STREAMS 32
#define MAX_STREAM_ENTITIES 128
#define STREAM_ATTACHED 16
#define STREAM_TRANSLUCENT 32
#define TE_SPIKE 0
#define TE_SUPERSPIKE 1
#define TE_GUNSHOT 2
#define TE_EXPLOSION 3
//#define TE_TAREXPLOSION 4
#define TE_LIGHTNING1 5
#define TE_LIGHTNING2 6
#define TE_WIZSPIKE 7
#define TE_KNIGHTSPIKE 8
#define TE_LIGHTNING3 9
#define TE_LAVASPLASH 10
#define TE_TELEPORT 11
//#define TE_EXPLOSION2 12
#define TE_STREAM_CHAIN 25
#define TE_STREAM_SUNSTAFF1 26
#define TE_STREAM_SUNSTAFF2 27
#define TE_STREAM_LIGHTNING 28
#define TE_STREAM_COLORBEAM 29
#define TE_STREAM_ICECHUNKS 30
#define TE_STREAM_GAZE 31
#define TE_STREAM_FAMINE 32
#define TE_STREAM_LIGHTNING_SMALL 24
// TYPES -------------------------------------------------------------------
typedef struct
{
int type;
int entity;
int tag;
int flags;
int skin;
struct model_s *models[4];
vec3_t source;
vec3_t dest;
vec3_t offset;
float endTime;
float lastTrailTime;
} stream_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void ParseStream(int type);
static stream_t *NewStream(int ent, int tag);
static entity_t *NewStreamEntity(void);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static stream_t cl_Streams[MAX_STREAMS];
static entity_t StreamEntities[MAX_STREAM_ENTITIES];
static int StreamEntityCount;
static sfx_t *cl_sfx_wizhit;
static sfx_t *cl_sfx_knighthit;
static sfx_t *cl_sfx_tink1;
static sfx_t *cl_sfx_ric1;
static sfx_t *cl_sfx_ric2;
static sfx_t *cl_sfx_ric3;
static sfx_t *cl_sfx_r_exp3;
// CODE --------------------------------------------------------------------
//==========================================================================
//
// CL_InitTEnts
//
//==========================================================================
void CL_InitTEnts(void)
{
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");
}
//==========================================================================
//
// CL_ClearTEnts
//
//==========================================================================
void CL_ClearTEnts(void)
{
memset(cl_Streams, 0, sizeof(cl_Streams));
}
//==========================================================================
//
// CL_ParseTEnt
//
//==========================================================================
void CL_ParseTEnt(void)
{
int type;
vec3_t pos;
dlight_t *dl;
int rnd;
type = MSG_ReadByte(net_message);
switch(type)
{
case TE_WIZSPIKE: // spike hitting wall
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_RunParticleEffect (pos, vec3_origin, 20, 30);
// S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
break;
case TE_KNIGHTSPIKE: // spike hitting wall
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_RunParticleEffect (pos, vec3_origin, 226, 20);
// S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
break;
case TE_SPIKE: // spike hitting wall
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_RunParticleEffect (pos, vec3_origin, 0, 10);
if ( rand() % 5 )
S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
else
{
rnd = rand() & 3;
if (rnd == 1)
S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
else if (rnd == 2)
S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
else
S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
}
break;
case TE_SUPERSPIKE: // super spike hitting wall
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_RunParticleEffect (pos, vec3_origin, 0, 20);
if ( rand() % 5 )
S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
else
{
rnd = rand() & 3;
if (rnd == 1)
S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
else if (rnd == 2)
S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
else
S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
}
break;
case TE_GUNSHOT: // bullet hitting wall
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_RunParticleEffect (pos, vec3_origin, 0, 20);
break;
case TE_EXPLOSION: // rocket explosion
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_ParticleExplosion (pos);
break;
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);
break;
/* //jfm:not used
case TE_TAREXPLOSION: // tarbaby explosion
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);
break;
*/
case TE_LIGHTNING1:
case TE_LIGHTNING2:
case TE_LIGHTNING3:
MSG_ReadShort(net_message);
MSG_ReadCoord(net_message);
MSG_ReadCoord(net_message);
MSG_ReadCoord(net_message);
MSG_ReadCoord(net_message);
MSG_ReadCoord(net_message);
MSG_ReadCoord(net_message);
break;
case TE_STREAM_CHAIN:
case TE_STREAM_SUNSTAFF1:
case TE_STREAM_SUNSTAFF2:
case TE_STREAM_LIGHTNING:
case TE_STREAM_LIGHTNING_SMALL:
case TE_STREAM_COLORBEAM:
case TE_STREAM_ICECHUNKS:
case TE_STREAM_GAZE:
case TE_STREAM_FAMINE:
ParseStream(type);
break;
case TE_LAVASPLASH:
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_LavaSplash (pos);
break;
case TE_TELEPORT:
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
R_TeleportSplash (pos);
break;
/* //jfm:not used
case TE_EXPLOSION2: // color mapped explosion
pos[0] = MSG_ReadCoord (net_message);
pos[1] = MSG_ReadCoord (net_message);
pos[2] = MSG_ReadCoord (net_message);
colorStart = MSG_ReadByte (net_message);
colorLength = MSG_ReadByte (net_message);
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);
break;
*/
default:
Sys_Error ("CL_ParseTEnt: bad type");
}
}
//==========================================================================
//
// ParseStream
//
//==========================================================================
static void ParseStream(int type)
{
int ent;
int tag;
int flags;
int skin;
vec3_t source;
vec3_t dest;
stream_t *stream;
float duration;
model_t *models[4];
ent = MSG_ReadShort(net_message);
flags = MSG_ReadByte(net_message);
tag = flags&15;
duration = (float)MSG_ReadByte(net_message)*0.05;
skin = 0;
if(type == TE_STREAM_COLORBEAM)
{
skin = MSG_ReadByte(net_message);
}
source[0] = MSG_ReadCoord(net_message);
source[1] = MSG_ReadCoord(net_message);
source[2] = MSG_ReadCoord(net_message);
dest[0] = MSG_ReadCoord(net_message);
dest[1] = MSG_ReadCoord(net_message);
dest[2] = MSG_ReadCoord(net_message);
models[1] = models[2] = models[3] = NULL;
switch(type)
{
case TE_STREAM_CHAIN:
models[0] = Mod_ForName("models/stchain.mdl", true);
break;
case TE_STREAM_SUNSTAFF1:
models[0] = Mod_ForName("models/stsunsf1.mdl", true);
models[1] = Mod_ForName("models/stsunsf2.mdl", true);
models[2] = Mod_ForName("models/stsunsf3.mdl", true);
models[3] = Mod_ForName("models/stsunsf4.mdl", true);
break;
case TE_STREAM_SUNSTAFF2:
models[0] = Mod_ForName("models/stsunsf5.mdl", true);
models[2] = Mod_ForName("models/stsunsf3.mdl", true);
models[3] = Mod_ForName("models/stsunsf4.mdl", true);
break;
case TE_STREAM_LIGHTNING:
models[0] = Mod_ForName("models/stlghtng.mdl", true);
// duration*=2;
break;
case TE_STREAM_LIGHTNING_SMALL:
models[0] = Mod_ForName("models/stltng2.mdl", true);
// duration*=2;
break;
case TE_STREAM_FAMINE:
models[0] = Mod_ForName("models/fambeam.mdl", true);
break;
case TE_STREAM_COLORBEAM:
models[0] = Mod_ForName("models/stclrbm.mdl", true);
break;
case TE_STREAM_ICECHUNKS:
models[0] = Mod_ForName("models/stice.mdl", true);
break;
case TE_STREAM_GAZE:
models[0] = Mod_ForName("models/stmedgaz.mdl", true);
break;
default:
Sys_Error("ParseStream: bad type");
}
if((stream = NewStream(ent, tag)) == NULL)
{
Con_Printf("stream list overflow\n");
return;
}
stream->type = type;
stream->tag = tag;
stream->flags = flags;
stream->entity = ent;
stream->skin = skin;
stream->models[0] = models[0];
stream->models[1] = models[1];
stream->models[2] = models[2];
stream->models[3] = models[3];
stream->endTime = cl.time+duration;
stream->lastTrailTime = 0;
VectorCopy(source, stream->source);
VectorCopy(dest, stream->dest);
if(flags&STREAM_ATTACHED)
{
VectorSubtract(source, cl_entities[ent].origin, stream->offset);
}
}
//==========================================================================
//
// NewStream
//
//==========================================================================
static stream_t *NewStream(int ent, int tag)
{
int i;
stream_t *stream;
// Search for a stream with matching entity and tag
for(i = 0, stream = cl_Streams; i < MAX_STREAMS; i++, stream++)
{
if(stream->entity == ent && stream->tag == tag)
{
return stream;
}
}
// Search for a free stream
for(i = 0, stream = cl_Streams; i < MAX_STREAMS; i++, stream++)
{
if(!stream->models[0] || stream->endTime < cl.time)
{
return stream;
}
}
return NULL;
}
//==========================================================================
//
// CL_UpdateTEnts
//
//==========================================================================
void CL_UpdateTEnts(void)
{
int i;
stream_t *stream;
vec3_t dist;
vec3_t org;
float d;
entity_t *ent;
float yaw, pitch;
float forward;
int segmentCount;
int offset;
// Update streams
StreamEntityCount = 0;
for(i = 0, stream = cl_Streams; i < MAX_STREAMS; i++, stream++)
{
if(!stream->models[0])// || stream->endTime < cl.time)
{ // Inactive
continue;
}
if(stream->endTime < cl.time)
{ // Inactive
if(stream->type!=TE_STREAM_LIGHTNING&&stream->type!=TE_STREAM_LIGHTNING_SMALL)
continue;
else if(stream->endTime + 0.25 < cl.time)
continue;
}
if(stream->flags&STREAM_ATTACHED&&stream->endTime >= cl.time)
{ // Attach the start position to owner
VectorAdd(cl_entities[stream->entity].origin, stream->offset,
stream->source);
}
VectorSubtract(stream->dest, stream->source, dist);
if(dist[1] == 0 && dist[0] == 0)
{
yaw = 0;
if(dist[2] > 0)
{
pitch = 90;
}
else
{
pitch = 270;
}
}
else
{
yaw = (int)(atan2(dist[1], dist[0])*180/M_PI);
if(yaw < 0)
{
yaw += 360;
}
forward = sqrt(dist[0]*dist[0]+dist[1]*dist[1]);
pitch = (int)(atan2(dist[2], forward)*180/M_PI);
if(pitch < 0)
{
pitch += 360;
}
}
VectorCopy(stream->source, org);
d = VectorNormalize(dist);
segmentCount = 0;
if(stream->type == TE_STREAM_ICECHUNKS)
{
offset = (int)(cl.time*40)%30;
for(i = 0; i < 3; i++)
{
org[i] += dist[i]*offset;
}
}
while(d > 0)
{
ent = NewStreamEntity();
if(!ent)
{
return;
}
VectorCopy(org, ent->origin);
ent->model = stream->models[0];
ent->angles[0] = pitch;
ent->angles[1] = yaw;
switch(stream->type)
{
case TE_STREAM_CHAIN:
ent->angles[2] = 0;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
break;
case TE_STREAM_SUNSTAFF1:
ent->angles[2] = (int)(cl.time*10)%360;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
//ent->frame = (int)(cl.time*20)%20;
ent = NewStreamEntity();
if(!ent)
{
return;
}
VectorCopy(org, ent->origin);
ent->model = stream->models[1];
ent->angles[0] = pitch;
ent->angles[1] = yaw;
ent->angles[2] = (int)(cl.time*50)%360;
ent->drawflags = MLS_ABSLIGHT|DRF_TRANSLUCENT;
ent->abslight = 128;
break;
case TE_STREAM_SUNSTAFF2:
ent->angles[2] = (int)(cl.time*10)%360;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->frame = (int)(cl.time*10)%8;
break;
case TE_STREAM_LIGHTNING:
if(stream->endTime < cl.time)
{//fixme: keep last non-translucent frame and angle
ent->drawflags = MLS_ABSLIGHT|DRF_TRANSLUCENT;
ent->abslight = 128 + (stream->endTime - cl.time)*192;
}
else
{
ent->angles[2] = rand()%360;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->frame = rand()%6;
}
break;
case TE_STREAM_LIGHTNING_SMALL:
if(stream->endTime < cl.time)
{
ent->drawflags = MLS_ABSLIGHT|DRF_TRANSLUCENT;
ent->abslight = 128 + (stream->endTime - cl.time)*192;
}
else
{
ent->angles[2] = rand()%360;
ent->frame = rand()%6;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
}
break;
case TE_STREAM_FAMINE:
ent->angles[2] = rand()%360;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->frame = 0;
break;
case TE_STREAM_COLORBEAM:
ent->angles[2] = 0;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->skinnum = stream->skin;
break;
case TE_STREAM_GAZE:
ent->angles[2] = 0;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->frame = (int)(cl.time*40)%36;
break;
case TE_STREAM_ICECHUNKS:
ent->angles[2] = rand()%360;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->frame = rand()%5;
break;
/* ent->angles[2] = (int)(cl.time*80)%360;
ent->origin[0] += (rand()%4)-2;
ent->origin[1] += (rand()%4)-2;
ent->origin[2] += (rand()%4)-2;
ent->frame = segmentCount%4;
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
if((rand()&255) > 128)
{
break;
}
ent = NewStreamEntity();
if(!ent)
{
return;
}
VectorCopy(org, ent->origin);
ent->model = stream->models[0];
ent->angles[0] = pitch;
ent->angles[1] = yaw;
ent->angles[2] = rand()%360;
ent->origin[0] += (rand()%20)-10;
ent->origin[1] += (rand()%20)-10;
ent->origin[2] += (rand()%20)-10;
ent->frame = 4+(rand()&1);
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
break;
*/
default:
ent->angles[2] = 0;
}
for(i = 0; i < 3; i++)
{
org[i] += dist[i]*30;
}
d -= 30;
segmentCount++;
}
if(stream->type == TE_STREAM_SUNSTAFF1
|| stream->type == TE_STREAM_SUNSTAFF2)
{
if(stream->lastTrailTime+0.2 < cl.time)
{
stream->lastTrailTime = cl.time;
R_SunStaffTrail(stream->source, stream->dest);
}
ent = NewStreamEntity();
if(ent == NULL)
{
return;
}
VectorCopy(stream->dest, ent->origin);
ent->model = stream->models[2];
ent->drawflags = MLS_ABSLIGHT;
ent->abslight = 128;
ent->scale = 80+(rand()&15);
//ent->frame = (int)(cl.time*20)%20;
ent = NewStreamEntity();
if(ent == NULL)
{
return;
}
VectorCopy(stream->dest, ent->origin);
ent->model = stream->models[3];
ent->drawflags = MLS_ABSLIGHT|DRF_TRANSLUCENT;
ent->abslight = 128;
ent->scale = 150+(rand()&15);
}
}
}
//==========================================================================
//
// NewStreamEntity
//
//==========================================================================
static entity_t *NewStreamEntity(void)
{
entity_t *ent;
if(cl_numvisedicts == MAX_VISEDICTS)
{
return NULL;
}
if(StreamEntityCount == MAX_STREAM_ENTITIES)
{
return NULL;
}
ent = &StreamEntities[StreamEntityCount++];
memset(ent, 0, sizeof(*ent));
cl_visedicts[cl_numvisedicts++] = ent;
ent->colormap = 0; //vid.colormap;
return ent;
}