Debian Codegraph @

code/cgame/cg_weapons.c

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // cg_weapons.c -- events and effects dealing with weapons
24 #include "cg_local.h"
25
26 /*
27 ==========================
28 CG_MachineGunEjectBrass
29 ==========================
30 */
31 static void CG_MachineGunEjectBrass( centity_t *cent ) {
32 localEntity_t *le;
33 refEntity_t *re;
34 vec3_t velocity, xvelocity;
35 vec3_t offset, xoffset;
36 float waterScale = 1.0f;
37 vec3_t v[3];
38
39 if ( cg_brassTime.integer <= 0 ) {
40 return;
41 }
42
43 le = CG_AllocLocalEntity();
44 re = &le->refEntity;
45
46 velocity[0] = 0;
47 velocity[1] = -50 + 40 * crandom();
48 velocity[2] = 100 + 50 * crandom();
49
50 le->leType = LE_FRAGMENT;
51 le->startTime = cg.time;
52 le->endTime = le->startTime + cg_brassTime.integer + ( cg_brassTime.integer / 4 ) * random();
53
54 le->pos.trType = TR_GRAVITY;
55 le->pos.trTime = cg.time - (rand()&15);
56
57 AnglesToAxis( cent->lerpAngles, v );
58
59 offset[0] = 8;
60 offset[1] = -4;
61 offset[2] = 24;
62
63 xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0];
64 xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1];
65 xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2];
66 VectorAdd( cent->lerpOrigin, xoffset, re->origin );
67
68 VectorCopy( re->origin, le->pos.trBase );
69
70 if ( CG_PointContents( re->origin, -1 ) & CONTENTS_WATER ) {
71 waterScale = 0.10f;
72 }
73
74 xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0];
75 xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1];
76 xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2];
77 VectorScale( xvelocity, waterScale, le->pos.trDelta );
78
79 AxisCopy( axisDefault, re->axis );
80 re->hModel = cgs.media.machinegunBrassModel;
81
82 le->bounceFactor = 0.4 * waterScale;
83
84 le->angles.trType = TR_LINEAR;
85 le->angles.trTime = cg.time;
86 le->angles.trBase[0] = rand()&31;
87 le->angles.trBase[1] = rand()&31;
88 le->angles.trBase[2] = rand()&31;
89 le->angles.trDelta[0] = 2;
90 le->angles.trDelta[1] = 1;
91 le->angles.trDelta[2] = 0;
92
93 le->leFlags = LEF_TUMBLE;
94 le->leBounceSoundType = LEBS_BRASS;
95 le->leMarkType = LEMT_NONE;
96 }
97
98
99
100 /*
101 ==========================
102 CG_ShotgunEjectBrass
103 ==========================
104 */
105 static void CG_ShotgunEjectBrass( centity_t *cent ) {
106 localEntity_t *le;
107 refEntity_t *re;
108 vec3_t velocity, xvelocity;
109 vec3_t offset, xoffset;
110 vec3_t v[3];
111 int i;
112
113 if ( cg_brassTime.integer <= 0 ) {
114 return;
115 }
116
117 for ( i = 0; i < 2; i++ ) {
118 float waterScale = 1.0f;
119
120 le = CG_AllocLocalEntity();
121 re = &le->refEntity;
122
123 velocity[0] = 60 + 60 * crandom();
124 if ( i == 0 ) {
125 velocity[1] = 40 + 10 * crandom();
126 } else {
127 velocity[1] = -40 + 10 * crandom();
128 }
129 velocity[2] = 100 + 50 * crandom();
130
131 le->leType = LE_FRAGMENT;
132 le->startTime = cg.time;
133 le->endTime = le->startTime + cg_brassTime.integer*3 + cg_brassTime.integer * random();
134
135 le->pos.trType = TR_GRAVITY;
136 le->pos.trTime = cg.time;
137
138 AnglesToAxis( cent->lerpAngles, v );
139
140 offset[0] = 8;
141 offset[1] = 0;
142 offset[2] = 24;
143
144 xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0];
145 xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1];
146 xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2];
147 VectorAdd( cent->lerpOrigin, xoffset, re->origin );
148 VectorCopy( re->origin, le->pos.trBase );
149 if ( CG_PointContents( re->origin, -1 ) & CONTENTS_WATER ) {
150 waterScale = 0.10f;
151 }
152
153 xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0];
154 xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1];
155 xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2];
156 VectorScale( xvelocity, waterScale, le->pos.trDelta );
157
158 AxisCopy( axisDefault, re->axis );
159 re->hModel = cgs.media.shotgunBrassModel;
160 le->bounceFactor = 0.3f;
161
162 le->angles.trType = TR_LINEAR;
163 le->angles.trTime = cg.time;
164 le->angles.trBase[0] = rand()&31;
165 le->angles.trBase[1] = rand()&31;
166 le->angles.trBase[2] = rand()&31;
167 le->angles.trDelta[0] = 1;
168 le->angles.trDelta[1] = 0.5;
169 le->angles.trDelta[2] = 0;
170
171 le->leFlags = LEF_TUMBLE;
172 le->leBounceSoundType = LEBS_SHELL; // LEILEI shell noises
173 le->leMarkType = LEMT_NONE;
174 }
175 }
176
177
178 //#ifdef MISSIONPACK
179 /*
180 ==========================
181 CG_NailgunEjectBrass
182 ==========================
183 */
184 static void CG_NailgunEjectBrass( centity_t *cent ) {
185 localEntity_t *smoke;
186 vec3_t origin;
187 vec3_t v[3];
188 vec3_t offset;
189 vec3_t xoffset;
190 vec3_t up;
191
192 AnglesToAxis( cent->lerpAngles, v );
193
194 offset[0] = 0;
195 offset[1] = -12;
196 offset[2] = 24;
197
198 xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0];
199 xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1];
200 xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2];
201 VectorAdd( cent->lerpOrigin, xoffset, origin );
202
203 VectorSet( up, 0, 0, 64 );
204
205 smoke = CG_SmokePuff( origin, up, 32, 1, 1, 1, 0.33f, 700, cg.time, 0, 0, cgs.media.smokePuffShader );
206 // use the optimized local entity add
207 smoke->leType = LE_SCALE_FADE;
208 }
209 //#endif
210
211
212 /*
213 ==========================
214 CG_RailTrail
215 ==========================
216 */
217 void CG_RailTrail (clientInfo_t *ci, vec3_t start, vec3_t end) {
218 vec3_t axis[36], move, move2, next_move, vec, temp;
219 float len;
220 int i, j, skip;
221
222 localEntity_t *le;
223 refEntity_t *re;
224
225 #define RADIUS 4
226 #define ROTATION 1
227 #define SPACING 5
228
229 start[2] -= 4;
230
231 le = CG_AllocLocalEntity();
232 re = &le->refEntity;
233
234 le->leType = LE_FADE_RGB;
235 le->startTime = cg.time;
236 le->endTime = cg.time + cg_railTrailTime.value;
237 le->lifeRate = 1.0 / (le->endTime - le->startTime);
238
239 re->shaderTime = cg.time / 1000.0f;
240 re->reType = RT_RAIL_CORE;
241 re->customShader = cgs.media.railCoreShader;
242
243 VectorCopy(start, re->origin);
244 VectorCopy(end, re->oldorigin);
245
246 re->shaderRGBA[0] = ci->color1[0] * 255;
247 re->shaderRGBA[1] = ci->color1[1] * 255;
248 re->shaderRGBA[2] = ci->color1[2] * 255;
249 re->shaderRGBA[3] = 255;
250
251 le->color[0] = ci->color1[0] * 0.75;
252 le->color[1] = ci->color1[1] * 0.75;
253 le->color[2] = ci->color1[2] * 0.75;
254 le->color[3] = 1.0f;
255
256 AxisClear( re->axis );
257
258 if (cg_oldRail.integer)
259 {
260 // nudge down a bit so it isn't exactly in center
261 re->origin[2] -= 8;
262 re->oldorigin[2] -= 8;
263 return;
264 }
265
266 VectorCopy (start, move);
267 VectorSubtract (end, start, vec);
268 len = VectorNormalize (vec);
269 PerpendicularVector(temp, vec);
270 for (i = 0 ; i < 36; i++)
271 {
272 RotatePointAroundVector(axis[i], vec, temp, i * 10);//banshee 2.4 was 10
273 }
274
275 VectorMA(move, 20, vec, move);
276 VectorCopy(move, next_move);
277 VectorScale (vec, SPACING, vec);
278
279 skip = -1;
280
281 j = 18;
282 for (i = 0; i < len; i += SPACING)
283 {
284 if (i != skip)
285 {
286 skip = i + SPACING;
287 le = CG_AllocLocalEntity();
288 re = &le->refEntity;
289 le->leFlags = LEF_PUFF_DONT_SCALE;
290 le->leType = LE_MOVE_SCALE_FADE;
291 le->startTime = cg.time;
292 le->endTime = cg.time + (i>>1) + 600;
293 le->lifeRate = 1.0 / (le->endTime - le->startTime);
294
295 re->shaderTime = cg.time / 1000.0f;
296 re->reType = RT_SPRITE;
297 re->radius = 1.1f;
298 re->customShader = cgs.media.railRingsShader;
299
300 re->shaderRGBA[0] = ci->color2[0] * 255;
301 re->shaderRGBA[1] = ci->color2[1] * 255;
302 re->shaderRGBA[2] = ci->color2[2] * 255;
303 re->shaderRGBA[3] = 255;
304
305 le->color[0] = ci->color2[0] * 0.75;
306 le->color[1] = ci->color2[1] * 0.75;
307 le->color[2] = ci->color2[2] * 0.75;
308 le->color[3] = 1.0f;
309
310 le->pos.trType = TR_LINEAR;
311 le->pos.trTime = cg.time;
312
313 VectorCopy( move, move2);
314 VectorMA(move2, RADIUS , axis[j], move2);
315 VectorCopy(move2, le->pos.trBase);
316
317 le->pos.trDelta[0] = axis[j][0]*6;
318 le->pos.trDelta[1] = axis[j][1]*6;
319 le->pos.trDelta[2] = axis[j][2]*6;
320 }
321
322 VectorAdd (move, vec, move);
323
324 j = (j + ROTATION) % 36;
325 }
326 }
327
328 /*
329 ==========================
330 CG_OldRocketTrail (for the crappy old rocket trail.)
331 ==========================
332 */
333 static void CG_OldRocketTrail( centity_t *ent, const weaponInfo_t *wi ) {
334 int step;
335 vec3_t origin, lastPos;
336 int t;
337 int startTime, contents;
338 int lastContents;
339 entityState_t *es;
340 vec3_t up;
341 localEntity_t *smoke;
342
343 if ( cg_noProjectileTrail.integer ) {
344 return;
345 }
346
347 up[0] = 0;
348 up[1] = 0;
349 up[2] = 0;
350
351 step = 50;
352
353 es = &ent->currentState;
354 startTime = ent->trailTime;
355 t = step * ( (startTime + step) / step );
356
357 BG_EvaluateTrajectory( &es->pos, cg.time, origin );
358 contents = CG_PointContents( origin, -1 );
359
360 // if object (e.g. grenade) is stationary, don't toss up smoke
361 if ( es->pos.trType == TR_STATIONARY ) {
362 ent->trailTime = cg.time;
363 return;
364 }
365
366 BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
367 lastContents = CG_PointContents( lastPos, -1 );
368
369 ent->trailTime = cg.time;
370
371 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
372 if ( contents & lastContents & CONTENTS_WATER ) {
373 CG_BubbleTrail( lastPos, origin, 8 );
374 }
375 return;
376 }
377
378 for ( ; t <= ent->trailTime ; t += step ) {
379 BG_EvaluateTrajectory( &es->pos, t, lastPos );
380
381 smoke = CG_SmokePuff( lastPos, up,
382 wi->trailRadius,
383 1, 1, 1, 0.33f,
384 wi->wiTrailTime,
385 t,
386 0,
387 0,
388 cgs.media.smokePuffShader );
389 // use the optimized local entity add
390 smoke->leType = LE_SCALE_FADE;
391 }
392
393 }
394
395 /*
396 ==========================
397 CG_LeiSmokeTrail
398 ==========================
399 */
400
401 static void CG_LeiSmokeTrail( centity_t *ent, const weaponInfo_t *wi ) {
402 int step;
403 vec3_t origin, lastPos;
404 int t;
405 int startTime, contents;
406 int lastContents;
407 entityState_t *es;
408 vec3_t up;
409 localEntity_t *smoke;
410 int therando;
411 int theradio;
412
413 if ( cg_noProjectileTrail.integer ) {
414 return;
415 }
416
417 up[0] = 5 - 10 * crandom();
418 up[1] = 5 - 10 * crandom();
419 up[2] = 8 - 5 * crandom();
420
421 step = 18;
422
423 es = &ent->currentState;
424 startTime = ent->trailTime;
425 t = step * ( (startTime + step) / step );
426
427 BG_EvaluateTrajectory( &es->pos, cg.time, origin );
428 contents = CG_PointContents( origin, -1 );
429
430 // if object (e.g. grenade) is stationary, don't toss up smoke
431 if ( es->pos.trType == TR_STATIONARY ) {
432 ent->trailTime = cg.time;
433 return;
434 }
435
436 BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
437 lastContents = CG_PointContents( lastPos, -1 );
438
439 ent->trailTime = cg.time;
440
441 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
442 if ( contents & lastContents & CONTENTS_WATER ) {
443 CG_BubbleTrail( lastPos, origin, 8 );
444 }
445 return;
446 }
447
448 for ( ; t <= ent->trailTime ; t += step ) {
449 BG_EvaluateTrajectory( &es->pos, t, lastPos );
450 therando = crandom() * 4;
451
452 theradio = wi->trailRadius * (rand() * 0.7); // what is this doing here
453 if (therando == 3) smoke = CG_SmokePuff( lastPos, up, 27, 1, 1, 1, 0.9f, wi->wiTrailTime, t, 0, 0, cgs.media.lsmkShader1 );
454 else if (therando == 1) smoke = CG_SmokePuff( lastPos, up, 27, 1, 1, 1, 0.9f, wi->wiTrailTime, t, 0, 0, cgs.media.lsmkShader2 );
455 else if (therando == 2) smoke = CG_SmokePuff( lastPos, up, 27, 1, 1, 1, 0.9f, wi->wiTrailTime, t, 0, 0, cgs.media.lsmkShader3 );
456 else smoke = CG_SmokePuff( lastPos, up, 27, 1, 1, 1, 0.9f, wi->wiTrailTime, t, 0, 0, cgs.media.lsmkShader4 );
457 // use the optimized local entity add
458 smoke->leType = LE_MOVE_SCALE_FADE;
459 //smoke->trType = TR_GRAVITY;
460 }
461
462 }
463
464
465 static void CG_LeiPlasmaTrail( centity_t *ent, const weaponInfo_t *wi ) {
466 int step;
467 vec3_t origin, lastPos;
468 int t;
469 int startTime, contents;
470 int lastContents;
471 entityState_t *es;
472 vec3_t up;
473 localEntity_t *smoke;
474
475 if ( cg_noProjectileTrail.integer ) {
476 return;
477 }
478
479 up[0] = 0;
480 up[1] = 0;
481 up[2] = 0;
482
483 step = 16;
484
485 es = &ent->currentState;
486 startTime = ent->trailTime;
487 t = step * ( (startTime + step) / step );
488
489 BG_EvaluateTrajectory( &es->pos, cg.time, origin );
490 contents = CG_PointContents( origin, -1 );
491
492 // if object (e.g. grenade) is stationary, don't toss up smoke
493 if ( es->pos.trType == TR_STATIONARY ) {
494 ent->trailTime = cg.time;
495 return;
496 }
497
498 BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
499 lastContents = CG_PointContents( lastPos, -1 );
500
501 ent->trailTime = cg.time;
502
503 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
504 return;
505 }
506
507 for ( ; t <= ent->trailTime ; t += step ) {
508 BG_EvaluateTrajectory( &es->pos, t, lastPos );
509
510 smoke = CG_SmokePuff( lastPos, up, 27, 1, 1, 1, 0.9f, wi->wiTrailTime, t, 0, 0, cgs.media.lsmkShader1 );
511 // use the optimized local entity add
512 smoke->leType = LE_SCALE_FADE;
513 //smoke->trType = TR_GRAVITY;
514 }
515
516 }
517
518
519 //#ifdef MISSIONPACK
520 /*
521 ==========================
522 CG_NailTrail
523 ==========================
524 */
525 static void CG_NailTrail( centity_t *ent, const weaponInfo_t *wi ) {
526 int step;
527 vec3_t origin, lastPos;
528 int t;
529 int startTime, contents;
530 int lastContents;
531 entityState_t *es;
532 vec3_t up;
533 localEntity_t *smoke;
534
535 if ( cg_noProjectileTrail.integer ) {
536 return;
537 }
538
539 up[0] = 0;
540 up[1] = 0;
541 up[2] = 0;
542
543 step = 50;
544
545 es = &ent->currentState;
546 startTime = ent->trailTime;
547 t = step * ( (startTime + step) / step );
548
549 BG_EvaluateTrajectory( &es->pos, cg.time, origin );
550 contents = CG_PointContents( origin, -1 );
551
552 // if object (e.g. grenade) is stationary, don't toss up smoke
553 if ( es->pos.trType == TR_STATIONARY ) {
554 ent->trailTime = cg.time;
555 return;
556 }
557
558 BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
559 lastContents = CG_PointContents( lastPos, -1 );
560
561 ent->trailTime = cg.time;
562
563 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
564 if ( contents & lastContents & CONTENTS_WATER ) {
565 CG_BubbleTrail( lastPos, origin, 8 );
566 }
567 return;
568 }
569
570 for ( ; t <= ent->trailTime ; t += step ) {
571 BG_EvaluateTrajectory( &es->pos, t, lastPos );
572
573 smoke = CG_SmokePuff( lastPos, up,
574 wi->trailRadius,
575 1, 1, 1, 0.33f,
576 wi->wiTrailTime,
577 t,
578 0,
579 0,
580 cgs.media.nailPuffShader );
581 // use the optimized local entity add
582 smoke->leType = LE_SCALE_FADE;
583 }
584
585 }
586 //#endif
587
588 /*
589 ==========================
590 CG_NailTrail
591 ==========================
592 */
593 static void CG_OldPlasmaTrail( centity_t *cent, const weaponInfo_t *wi ) {
594 localEntity_t *le;
595 refEntity_t *re;
596 entityState_t *es;
597 vec3_t velocity, xvelocity, origin;
598 vec3_t offset, xoffset;
599 vec3_t v[3];
600 int t, startTime, step;
601
602 float waterScale = 1.0f;
603
604 if ( cg_noProjectileTrail.integer || cg_oldPlasma.integer ) {
605 return;
606 }
607
608 step = 50;
609
610 es = &cent->currentState;
611 startTime = cent->trailTime;
612 t = step * ( (startTime + step) / step );
613
614 BG_EvaluateTrajectory( &es->pos, cg.time, origin );
615
616 le = CG_AllocLocalEntity();
617 re = &le->refEntity;
618
619 velocity[0] = 60 - 120 * crandom();
620 velocity[1] = 40 - 80 * crandom();
621 velocity[2] = 100 - 200 * crandom();
622
623 le->leType = LE_MOVE_SCALE_FADE;
624 le->leFlags = LEF_TUMBLE;
625 le->leBounceSoundType = LEBS_NONE;
626 le->leMarkType = LEMT_NONE;
627
628 le->startTime = cg.time;
629 le->endTime = le->startTime + 600;
630
631 le->pos.trType = TR_GRAVITY;
632 le->pos.trTime = cg.time;
633
634 AnglesToAxis( cent->lerpAngles, v );
635
636 offset[0] = 2;
637 offset[1] = 2;
638 offset[2] = 2;
639
640 xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0];
641 xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1];
642 xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2];
643
644 VectorAdd( origin, xoffset, re->origin );
645 VectorCopy( re->origin, le->pos.trBase );
646
647 if ( CG_PointContents( re->origin, -1 ) & CONTENTS_WATER ) {
648 waterScale = 0.10f;
649 }
650
651 xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0];
652 xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1];
653 xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2];
654 VectorScale( xvelocity, waterScale, le->pos.trDelta );
655
656 AxisCopy( axisDefault, re->axis );
657 re->shaderTime = cg.time / 1000.0f;
658 re->reType = RT_SPRITE;
659 re->radius = 0.25f;
660 re->customShader = cgs.media.railRingsShader;
661 le->bounceFactor = 0.3f;
662
663
664 re->shaderRGBA[0] = wi->flashDlightColor[0] * 63;
665 re->shaderRGBA[1] = wi->flashDlightColor[1] * 63;
666 re->shaderRGBA[2] = wi->flashDlightColor[2] * 63;
667 re->shaderRGBA[3] = 63;
668
669 le->color[0] = wi->flashDlightColor[0] * 0.2;
670 le->color[1] = wi->flashDlightColor[1] * 0.2;
671 le->color[2] = wi->flashDlightColor[2] * 0.2;
672 le->color[3] = 0.25f;
673
674 le->angles.trType = TR_LINEAR;
675 le->angles.trTime = cg.time;
676 le->angles.trBase[0] = rand()&31;
677 le->angles.trBase[1] = rand()&31;
678 le->angles.trBase[2] = rand()&31;
679 le->angles.trDelta[0] = 1;
680 le->angles.trDelta[1] = 0.5;
681 le->angles.trDelta[2] = 0;
682
683 }
684 /*
685 ==========================
686 CG_GrappleTrail
687 ==========================
688 */
689 void CG_GrappleTrail( centity_t *ent, const weaponInfo_t *wi ) {
690 vec3_t origin;
691 entityState_t *es;
692 vec3_t forward, up;
693 refEntity_t beam;
694
695 es = &ent->currentState;
696
697 BG_EvaluateTrajectory( &es->pos, cg.time, origin );
698 ent->trailTime = cg.time;
699
700 memset( &beam, 0, sizeof( beam ) );
701 //FIXME adjust for muzzle position
702 VectorCopy ( cg_entities[ ent->currentState.otherEntityNum ].lerpOrigin, beam.origin );
703 beam.origin[2] += 26;
704 AngleVectors( cg_entities[ ent->currentState.otherEntityNum ].lerpAngles, forward, NULL, up );
705 VectorMA( beam.origin, -6, up, beam.origin );
706 VectorCopy( origin, beam.oldorigin );
707
708 if (Distance( beam.origin, beam.oldorigin ) < 64 )
709 return; // Don't draw if close
710
711 beam.reType = RT_RAIL_CORE;
712 beam.customShader = cgs.media.grappleShader;
713
714 AxisClear( beam.axis );
715 beam.shaderRGBA[0] = 0xff;
716 beam.shaderRGBA[1] = 0xff;
717 beam.shaderRGBA[2] = 0xff;
718 beam.shaderRGBA[3] = 0xff;
719 trap_R_AddRefEntityToScene( &beam );
720 }
721
722 /*
723 ==========================
724 CG_GrenadeTrail
725 ==========================
726 */
727 // LEILEI enhancment
728 static void CG_RocketTrail( centity_t *ent, const weaponInfo_t *wi ) {
729
730 if (cg_leiEnhancement.integer) {
731 CG_LeiSmokeTrail( ent, wi );
732 }
733 else
734 {
735 CG_OldRocketTrail( ent, wi );
736 }
737 }
738
739 static void CG_PlasmaTrail( centity_t *ent, const weaponInfo_t *wi ) {
740
741 if (cg_leiEnhancement.integer) {
742 CG_LeiPlasmaTrail( ent, wi );
743 }
744 else
745 {
746 CG_OldPlasmaTrail( ent, wi );
747 }
748 }
749
750
751 static void CG_GrenadeTrail( centity_t *ent, const weaponInfo_t *wi ) {
752 CG_RocketTrail( ent, wi );
753 }
754
755
756
757
758
759
760 /*
761 =================
762 CG_RegisterWeapon
763
764 The server says this item is used on this level
765 =================
766 */
767 void CG_RegisterWeapon( int weaponNum ) {
768 weaponInfo_t *weaponInfo;
769 gitem_t *item, *ammo;
770 char path[MAX_QPATH];
771 vec3_t mins, maxs;
772 int i;
773
774 weaponInfo = &cg_weapons[weaponNum];
775
776 if ( weaponNum == 0 ) {
777 return;
778 }
779
780 if ( weaponInfo->registered ) {
781 return;
782 }
783
784 memset( weaponInfo, 0, sizeof( *weaponInfo ) );
785 weaponInfo->registered = qtrue;
786
787 for ( item = bg_itemlist + 1 ; item->classname ; item++ ) {
788 if ( item->giType == IT_WEAPON && item->giTag == weaponNum ) {
789 weaponInfo->item = item;
790 break;
791 }
792 }
793 if ( !item->classname ) {
794 CG_Error( "Couldn't find weapon %i", weaponNum );
795 }
796 CG_RegisterItemVisuals( item - bg_itemlist );
797
798 // load cmodel before model so filecache works
799 weaponInfo->weaponModel = trap_R_RegisterModel( item->world_model[0] );
800
801 // calc midpoint for rotation
802 trap_R_ModelBounds( weaponInfo->weaponModel, mins, maxs );
803 for ( i = 0 ; i < 3 ; i++ ) {
804 weaponInfo->weaponMidpoint[i] = mins[i] + 0.5 * ( maxs[i] - mins[i] );
805 }
806
807 weaponInfo->weaponIcon = trap_R_RegisterShader( item->icon );
808 weaponInfo->ammoIcon = trap_R_RegisterShader( item->icon );
809
810 for ( ammo = bg_itemlist + 1 ; ammo->classname ; ammo++ ) {
811 if ( ammo->giType == IT_AMMO && ammo->giTag == weaponNum ) {
812 break;
813 }
814 }
815 if ( ammo->classname && ammo->world_model[0] ) {
816 weaponInfo->ammoModel = trap_R_RegisterModel( ammo->world_model[0] );
817 }
818
819 Q_strncpyz( path, item->world_model[0], MAX_QPATH );
820 COM_StripExtension(path, path, sizeof(path));
821 strcat( path, "_flash.md3" );
822 weaponInfo->flashModel = trap_R_RegisterModel( path );
823
824 Q_strncpyz( path, item->world_model[0], MAX_QPATH );
825 COM_StripExtension(path, path, sizeof(path));
826 strcat( path, "_barrel.md3" );
827 weaponInfo->barrelModel = trap_R_RegisterModel( path );
828
829 Q_strncpyz( path, item->world_model[0], MAX_QPATH );
830 COM_StripExtension(path, path, sizeof(path));
831 strcat( path, "_hand.md3" );
832 weaponInfo->handsModel = trap_R_RegisterModel( path );
833
834 if ( !weaponInfo->handsModel ) {
835 weaponInfo->handsModel = trap_R_RegisterModel( "models/weapons2/shotgun/shotgun_hand.md3" );
836 }
837
838 weaponInfo->loopFireSound = qfalse;
839
840 switch ( weaponNum ) {
841 case WP_GAUNTLET:
842 MAKERGB( weaponInfo->flashDlightColor, 0.6f, 0.6f, 1.0f );
843 weaponInfo->firingSound = trap_S_RegisterSound( "sound/weapons/melee/fstrun.wav", qfalse );
844 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/melee/fstatck.wav", qfalse );
845 break;
846
847 case WP_LIGHTNING:
848 MAKERGB( weaponInfo->flashDlightColor, 0.6f, 0.6f, 1.0f );
849 weaponInfo->readySound = trap_S_RegisterSound( "sound/weapons/melee/fsthum.wav", qfalse );
850 weaponInfo->firingSound = trap_S_RegisterSound( "sound/weapons/lightning/lg_hum.wav", qfalse );
851
852 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/lightning/lg_fire.wav", qfalse );
853 cgs.media.lightningShader = trap_R_RegisterShader( "lightningBoltNew");
854 cgs.media.lightningExplosionModel = trap_R_RegisterModel( "models/weaphits/crackle.md3" );
855 cgs.media.sfx_lghit1 = trap_S_RegisterSound( "sound/weapons/lightning/lg_hit.wav", qfalse );
856 cgs.media.sfx_lghit2 = trap_S_RegisterSound( "sound/weapons/lightning/lg_hit2.wav", qfalse );
857 cgs.media.sfx_lghit3 = trap_S_RegisterSound( "sound/weapons/lightning/lg_hit3.wav", qfalse );
858
859 break;
860
861 case WP_GRAPPLING_HOOK:
862 MAKERGB( weaponInfo->flashDlightColor, 0.6f, 0.6f, 1.0f );
863 weaponInfo->missileModel = trap_R_RegisterModel( "models/ammo/hook/hook.md3" );
864 weaponInfo->missileTrailFunc = CG_GrappleTrail;
865 weaponInfo->missileDlight = 0;
866 weaponInfo->wiTrailTime = 2000;
867 weaponInfo->trailRadius = 64;
868 MAKERGB( weaponInfo->missileDlightColor, 1, 0.75f, 0 );
869 cgs.media.grappleShader = trap_R_RegisterShader( "grappleRope");
870 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/grapple/grapfire.wav", qfalse );
871 weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/grapple/grappull.wav", qfalse );
872 //cgs.media.lightningShader = trap_R_RegisterShader( "lightningBoltNew");
873 break;
874
875 //#ifdef MISSIONPACK
876 case WP_CHAINGUN:
877 weaponInfo->firingSound = trap_S_RegisterSound( "sound/weapons/vulcan/wvulfire.wav", qfalse );
878 weaponInfo->loopFireSound = qtrue;
879 MAKERGB( weaponInfo->flashDlightColor, 1, 1, 0 );
880 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/vulcan/vulcanf1b.wav", qfalse );
881 weaponInfo->flashSound[1] = trap_S_RegisterSound( "sound/weapons/vulcan/vulcanf2b.wav", qfalse );
882 weaponInfo->flashSound[2] = trap_S_RegisterSound( "sound/weapons/vulcan/vulcanf3b.wav", qfalse );
883 weaponInfo->flashSound[3] = trap_S_RegisterSound( "sound/weapons/vulcan/vulcanf4b.wav", qfalse );
884 weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass;
885 cgs.media.bulletExplosionShader = trap_R_RegisterShader( "bulletExplosion" );
886 break;
887 //#endif
888
889 case WP_MACHINEGUN:
890 MAKERGB( weaponInfo->flashDlightColor, 1, 1, 0 );
891 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/machinegun/machgf1b.wav", qfalse );
892 weaponInfo->flashSound[1] = trap_S_RegisterSound( "sound/weapons/machinegun/machgf2b.wav", qfalse );
893 weaponInfo->flashSound[2] = trap_S_RegisterSound( "sound/weapons/machinegun/machgf3b.wav", qfalse );
894 weaponInfo->flashSound[3] = trap_S_RegisterSound( "sound/weapons/machinegun/machgf4b.wav", qfalse );
895 weaponInfo->ejectBrassFunc = CG_MachineGunEjectBrass;
896 cgs.media.bulletExplosionShader = trap_R_RegisterShader( "bulletExplosion" );
897 break;
898
899 case WP_SHOTGUN:
900 MAKERGB( weaponInfo->flashDlightColor, 1, 1, 0 );
901 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/shotgun/sshotf1b.wav", qfalse );
902 weaponInfo->ejectBrassFunc = CG_ShotgunEjectBrass;
903 break;
904
905 case WP_ROCKET_LAUNCHER:
906 weaponInfo->missileModel = trap_R_RegisterModel( "models/ammo/rocket/rocket.md3" );
907 weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/rocket/rockfly.wav", qfalse );
908 weaponInfo->missileTrailFunc = CG_RocketTrail;
909 weaponInfo->missileDlight = 200;
910 weaponInfo->wiTrailTime = 2000;
911 weaponInfo->trailRadius = 64;
912
913 MAKERGB( weaponInfo->missileDlightColor, 1, 0.75f, 0 );
914 MAKERGB( weaponInfo->flashDlightColor, 1, 0.75f, 0 );
915
916 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/rocket/rocklf1a.wav", qfalse );
917 cgs.media.rocketExplosionShader = trap_R_RegisterShader( "rocketExplosion" );
918 break;
919
920 //#ifdef MISSIONPACK
921 case WP_PROX_LAUNCHER:
922 weaponInfo->missileModel = trap_R_RegisterModel( "models/weaphits/proxmine.md3" );
923 weaponInfo->missileTrailFunc = CG_GrenadeTrail;
924 weaponInfo->wiTrailTime = 700;
925 weaponInfo->trailRadius = 32;
926 MAKERGB( weaponInfo->flashDlightColor, 1, 0.70f, 0 );
927 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/proxmine/wstbfire.wav", qfalse );
928 cgs.media.grenadeExplosionShader = trap_R_RegisterShader( "grenadeExplosion" );
929 break;
930 //#endif
931
932 case WP_GRENADE_LAUNCHER:
933 weaponInfo->missileModel = trap_R_RegisterModel( "models/ammo/grenade1.md3" );
934 weaponInfo->missileTrailFunc = CG_GrenadeTrail;
935 weaponInfo->wiTrailTime = 700;
936 weaponInfo->trailRadius = 32;
937 MAKERGB( weaponInfo->flashDlightColor, 1, 0.70f, 0 );
938 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/grenade/grenlf1a.wav", qfalse );
939 cgs.media.grenadeExplosionShader = trap_R_RegisterShader( "grenadeExplosion" );
940 break;
941
942 //#ifdef MISSIONPACK
943 case WP_NAILGUN:
944 weaponInfo->ejectBrassFunc = CG_NailgunEjectBrass;
945 weaponInfo->missileTrailFunc = CG_NailTrail;
946 // weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/nailgun/wnalflit.wav", qfalse );
947 weaponInfo->trailRadius = 16;
948 weaponInfo->wiTrailTime = 250;
949 weaponInfo->missileModel = trap_R_RegisterModel( "models/weaphits/nail.md3" );
950 MAKERGB( weaponInfo->flashDlightColor, 1, 0.75f, 0 );
951 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/nailgun/wnalfire.wav", qfalse );
952 break;
953 //#endif
954
955 case WP_PLASMAGUN:
956 // weaponInfo->missileModel = cgs.media.invulnerabilityPowerupModel;
957 weaponInfo->missileTrailFunc = CG_PlasmaTrail;
958 weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/plasma/lasfly.wav", qfalse );
959 MAKERGB( weaponInfo->flashDlightColor, 0.6f, 0.6f, 1.0f );
960 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/plasma/hyprbf1a.wav", qfalse );
961 cgs.media.plasmaExplosionShader = trap_R_RegisterShader( "plasmaExplosion" );
962 cgs.media.railRingsShader = trap_R_RegisterShader( "railDisc" );
963 break;
964
965 case WP_RAILGUN:
966 weaponInfo->readySound = trap_S_RegisterSound( "sound/weapons/railgun/rg_hum.wav", qfalse );
967 MAKERGB( weaponInfo->flashDlightColor, 1, 0.5f, 0 );
968 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/railgun/railgf1a.wav", qfalse );
969 cgs.media.railExplosionShader = trap_R_RegisterShader( "railExplosion" );
970 cgs.media.railRingsShader = trap_R_RegisterShader( "railDisc" );
971 cgs.media.railCoreShader = trap_R_RegisterShader( "railCore" );
972 break;
973
974 case WP_BFG:
975 weaponInfo->readySound = trap_S_RegisterSound( "sound/weapons/bfg/bfg_hum.wav", qfalse );
976 MAKERGB( weaponInfo->flashDlightColor, 1, 0.7f, 1 );
977 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/bfg/bfg_fire.wav", qfalse );
978 cgs.media.bfgExplosionShader = trap_R_RegisterShader( "bfgExplosion" );
979 weaponInfo->missileModel = trap_R_RegisterModel( "models/weaphits/bfg.md3" );
980 weaponInfo->missileSound = trap_S_RegisterSound( "sound/weapons/rocket/rockfly.wav", qfalse );
981 break;
982
983 default:
984 MAKERGB( weaponInfo->flashDlightColor, 1, 1, 1 );
985 weaponInfo->flashSound[0] = trap_S_RegisterSound( "sound/weapons/rocket/rocklf1a.wav", qfalse );
986 break;
987 }
988 }
989
990 /*
991 =================
992 CG_RegisterItemVisuals
993
994 The server says this item is used on this level
995 =================
996 */
997 void CG_RegisterItemVisuals( int itemNum ) {
998 itemInfo_t *itemInfo;
999 gitem_t *item;
1000
1001 if ( itemNum < 0 || itemNum >= bg_numItems ) {
1002 CG_Error( "CG_RegisterItemVisuals: itemNum %d out of range [0-%d]", itemNum, bg_numItems-1 );
1003 }
1004
1005 itemInfo = &cg_items[ itemNum ];
1006 if ( itemInfo->registered ) {
1007 return;
1008 }
1009
1010 item = &bg_itemlist[ itemNum ];
1011
1012 memset( itemInfo, 0, sizeof( &itemInfo ) );
1013 itemInfo->registered = qtrue;
1014
1015 itemInfo->models[0] = trap_R_RegisterModel( item->world_model[0] );
1016
1017 itemInfo->icon = trap_R_RegisterShader( item->icon );
1018
1019 if ( item->giType == IT_WEAPON ) {
1020 CG_RegisterWeapon( item->giTag );
1021 }
1022
1023 //
1024 // powerups have an accompanying ring or sphere
1025 //
1026 if ( item->giType == IT_POWERUP || item->giType == IT_HEALTH ||
1027 item->giType == IT_ARMOR || item->giType == IT_HOLDABLE ) {
1028 if ( item->world_model[1] ) {
1029 itemInfo->models[1] = trap_R_RegisterModel( item->world_model[1] );
1030 }
1031 }
1032 }
1033
1034
1035 /*
1036 ========================================================================================
1037
1038 VIEW WEAPON
1039
1040 ========================================================================================
1041 */
1042
1043 /*
1044 =================
1045 CG_MapTorsoToWeaponFrame
1046
1047 =================
1048 */
1049 static int CG_MapTorsoToWeaponFrame( clientInfo_t *ci, int frame ) {
1050
1051 // change weapon
1052 if ( frame >= ci->animations[TORSO_DROP].firstFrame
1053 && frame < ci->animations[TORSO_DROP].firstFrame + 9 ) {
1054 return frame - ci->animations[TORSO_DROP].firstFrame + 6;
1055 }
1056
1057 // stand attack
1058 if ( frame >= ci->animations[TORSO_ATTACK].firstFrame
1059 && frame < ci->animations[TORSO_ATTACK].firstFrame + 6 ) {
1060 return 1 + frame - ci->animations[TORSO_ATTACK].firstFrame;
1061 }
1062
1063 // stand attack 2
1064 if ( frame >= ci->animations[TORSO_ATTACK2].firstFrame
1065 && frame < ci->animations[TORSO_ATTACK2].firstFrame + 6 ) {
1066 return 1 + frame - ci->animations[TORSO_ATTACK2].firstFrame;
1067 }
1068
1069 return 0;
1070 }
1071
1072
1073 /*
1074 ==============
1075 CG_CalculateWeaponPosition
1076 ==============
1077 */
1078 static void CG_CalculateWeaponPosition( vec3_t origin, vec3_t angles ) {
1079 float scale;
1080 int delta;
1081 float fracsin;
1082
1083 VectorCopy( cg.refdef.vieworg, origin );
1084 VectorCopy( cg.refdefViewAngles, angles );
1085
1086 // on odd legs, invert some angles
1087 if ( cg.bobcycle & 1 ) {
1088 scale = -cg.xyspeed;
1089 } else {
1090 scale = cg.xyspeed;
1091 }
1092
1093 // gun angles from bobbing
1094 angles[ROLL] += scale * cg.bobfracsin * 0.005;
1095 angles[YAW] += scale * cg.bobfracsin * 0.01;
1096 angles[PITCH] += cg.xyspeed * cg.bobfracsin * 0.005;
1097
1098 // drop the weapon when landing
1099 delta = cg.time - cg.landTime;
1100 if ( delta < LAND_DEFLECT_TIME ) {
1101 origin[2] += cg.landChange*0.25 * delta / LAND_DEFLECT_TIME;
1102 } else if ( delta < LAND_DEFLECT_TIME + LAND_RETURN_TIME ) {
1103 origin[2] += cg.landChange*0.25 *
1104 (LAND_DEFLECT_TIME + LAND_RETURN_TIME - delta) / LAND_RETURN_TIME;
1105 }
1106
1107 #if 0
1108 // drop the weapon when stair climbing
1109 delta = cg.time - cg.stepTime;
1110 if ( delta < STEP_TIME/2 ) {
1111 origin[2] -= cg.stepChange*0.25 * delta / (STEP_TIME/2);
1112 } else if ( delta < STEP_TIME ) {
1113 origin[2] -= cg.stepChange*0.25 * (STEP_TIME - delta) / (STEP_TIME/2);
1114 }
1115 #endif
1116
1117 // idle drift
1118 scale = cg.xyspeed + 40;
1119 fracsin = sin( cg.time * 0.001 );
1120 angles[ROLL] += scale * fracsin * 0.01;
1121 angles[YAW] += scale * fracsin * 0.01;
1122 angles[PITCH] += scale * fracsin * 0.01;
1123 }
1124
1125
1126 /*
1127 ===============
1128 CG_LightningBolt
1129
1130 Origin will be the exact tag point, which is slightly
1131 different than the muzzle point used for determining hits.
1132 The cent should be the non-predicted cent if it is from the player,
1133 so the endpoint will reflect the simulated strike (lagging the predicted
1134 angle)
1135 ===============
1136 */
1137 static void CG_LightningBolt( centity_t *cent, vec3_t origin ) {
1138 trace_t trace;
1139 refEntity_t beam;
1140 vec3_t forward;
1141 vec3_t muzzlePoint, endPoint;
1142
1143 if (cent->currentState.weapon != WP_LIGHTNING) {
1144 return;
1145 }
1146
1147 memset( &beam, 0, sizeof( beam ) );
1148
1149 //unlagged - attack prediction #1
1150 // if the entity is us, unlagged is on server-side, and we've got it on for the lightning gun
1151 if ( (cent->currentState.number == cg.predictedPlayerState.clientNum) && cgs.delagHitscan &&
1152 ( cg_delag.integer & 1 || cg_delag.integer & 8 ) ) {
1153 // always shoot straight forward from our current position
1154 AngleVectors( cg.predictedPlayerState.viewangles, forward, NULL, NULL );
1155 VectorCopy( cg.predictedPlayerState.origin, muzzlePoint );
1156 }
1157 else
1158 //unlagged - attack prediction #1
1159
1160 // CPMA "true" lightning
1161 if ((cent->currentState.number == cg.predictedPlayerState.clientNum) && (cg_trueLightning.value != 0)) {
1162 vec3_t angle;
1163 int i;
1164
1165 //unlagged - true lightning
1166 // might as well fix up true lightning while we're at it
1167 vec3_t viewangles;
1168 VectorCopy( cg.predictedPlayerState.viewangles, viewangles );
1169 //unlagged - true lightning
1170
1171 for (i = 0; i < 3; i++) {
1172 float a = cent->lerpAngles[i] - cg.refdefViewAngles[i];
1173 if (a > 180) {
1174 a -= 360;
1175 }
1176 if (a < -180) {
1177 a += 360;
1178 }
1179
1180 angle[i] = cg.refdefViewAngles[i] + a * (1.0 - cg_trueLightning.value);
1181 if (angle[i] < 0) {
1182 angle[i] += 360;
1183 }
1184 if (angle[i] > 360) {
1185 angle[i] -= 360;
1186 }
1187 }
1188
1189 AngleVectors(angle, forward, NULL, NULL );
1190 //unlagged - true lightning
1191 // VectorCopy(cent->lerpOrigin, muzzlePoint );
1192 // VectorCopy(cg.refdef.vieworg, muzzlePoint );
1193 // *this* is the correct origin for true lightning
1194 VectorCopy(cg.predictedPlayerState.origin, muzzlePoint );
1195 //unlagged - true lightning
1196 } else {
1197 // !CPMA
1198 AngleVectors( cent->lerpAngles, forward, NULL, NULL );
1199 VectorCopy(cent->lerpOrigin, muzzlePoint );
1200 }
1201
1202 // FIXME: crouch
1203 muzzlePoint[2] += DEFAULT_VIEWHEIGHT;
1204
1205 VectorMA( muzzlePoint, 14, forward, muzzlePoint );
1206
1207 // project forward by the lightning range
1208 VectorMA( muzzlePoint, LIGHTNING_RANGE, forward, endPoint );
1209
1210 // see if it hit a wall
1211 CG_Trace( &trace, muzzlePoint, vec3_origin, vec3_origin, endPoint,
1212 cent->currentState.number, MASK_SHOT );
1213
1214 // this is the endpoint
1215 VectorCopy( trace.endpos, beam.oldorigin );
1216
1217 // use the provided origin, even though it may be slightly
1218 // different than the muzzle origin
1219 VectorCopy( origin, beam.origin );
1220
1221 beam.reType = RT_LIGHTNING;
1222 beam.customShader = cgs.media.lightningShader;
1223 trap_R_AddRefEntityToScene( &beam );
1224
1225 // add the impact flare if it hit something
1226 if ( trace.fraction < 1.0 ) {
1227 vec3_t angles;
1228 vec3_t dir;
1229
1230 VectorSubtract( beam.oldorigin, beam.origin, dir );
1231 VectorNormalize( dir );
1232
1233 memset( &beam, 0, sizeof( beam ) );
1234 beam.hModel = cgs.media.lightningExplosionModel;
1235
1236 VectorMA( trace.endpos, -16, dir, beam.origin );
1237
1238 // make a random orientation
1239 angles[0] = rand() % 360;
1240 angles[1] = rand() % 360;
1241 angles[2] = rand() % 360;
1242 AnglesToAxis( angles, beam.axis );
1243 trap_R_AddRefEntityToScene( &beam );
1244 }
1245 }
1246 /*
1247
1248 static void CG_LightningBolt( centity_t *cent, vec3_t origin ) {
1249 trace_t trace;
1250 refEntity_t beam;
1251 vec3_t forward;
1252 vec3_t muzzlePoint, endPoint;
1253
1254 if ( cent->currentState.weapon != WP_LIGHTNING ) {
1255 return;
1256 }
1257
1258 memset( &beam, 0, sizeof( beam ) );
1259
1260 // find muzzle point for this frame
1261 VectorCopy( cent->lerpOrigin, muzzlePoint );
1262 AngleVectors( cent->lerpAngles, forward, NULL, NULL );
1263
1264 // FIXME: crouch
1265 muzzlePoint[2] += DEFAULT_VIEWHEIGHT;
1266
1267 VectorMA( muzzlePoint, 14, forward, muzzlePoint );
1268
1269 // project forward by the lightning range
1270 VectorMA( muzzlePoint, LIGHTNING_RANGE, forward, endPoint );
1271
1272 // see if it hit a wall
1273 CG_Trace( &trace, muzzlePoint, vec3_origin, vec3_origin, endPoint,
1274 cent->currentState.number, MASK_SHOT );
1275
1276 // this is the endpoint
1277 VectorCopy( trace.endpos, beam.oldorigin );
1278
1279 // use the provided origin, even though it may be slightly
1280 // different than the muzzle origin
1281 VectorCopy( origin, beam.origin );
1282
1283 beam.reType = RT_LIGHTNING;
1284 beam.customShader = cgs.media.lightningShader;
1285 trap_R_AddRefEntityToScene( &beam );
1286
1287 // add the impact flare if it hit something
1288 if ( trace.fraction < 1.0 ) {
1289 vec3_t angles;
1290 vec3_t dir;
1291
1292 VectorSubtract( beam.oldorigin, beam.origin, dir );
1293 VectorNormalize( dir );
1294
1295 memset( &beam, 0, sizeof( beam ) );
1296 beam.hModel = cgs.media.lightningExplosionModel;
1297
1298 VectorMA( trace.endpos, -16, dir, beam.origin );
1299
1300 // make a random orientation
1301 angles[0] = rand() % 360;
1302 angles[1] = rand() % 360;
1303 angles[2] = rand() % 360;
1304 AnglesToAxis( angles, beam.axis );
1305 trap_R_AddRefEntityToScene( &beam );
1306 }
1307 }
1308 */
1309
1310 /*
1311 ===============
1312 CG_SpawnRailTrail
1313
1314 Origin will be the exact tag point, which is slightly
1315 different than the muzzle point used for determining hits.
1316 ===============
1317 */
1318 static void CG_SpawnRailTrail( centity_t *cent, vec3_t origin ) {
1319 clientInfo_t *ci;
1320
1321 if ( cent->currentState.weapon != WP_RAILGUN ) {
1322 return;
1323 }
1324 if ( !cent->pe.railgunFlash ) {
1325 return;
1326 }
1327 cent->pe.railgunFlash = qtrue;
1328 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1329 CG_RailTrail( ci, origin, cent->pe.railgunImpact );
1330 }
1331
1332
1333 /*
1334 ======================
1335 CG_MachinegunSpinAngle
1336 ======================
1337 */
1338 #define SPIN_SPEED 0.9
1339 #define COAST_TIME 1000
1340 static float CG_MachinegunSpinAngle( centity_t *cent ) {
1341 int delta;
1342 float angle;
1343 float speed;
1344
1345 delta = cg.time - cent->pe.barrelTime;
1346 if ( cent->pe.barrelSpinning ) {
1347 angle = cent->pe.barrelAngle + delta * SPIN_SPEED;
1348 } else {
1349 if ( delta > COAST_TIME ) {
1350 delta = COAST_TIME;
1351 }
1352
1353 speed = 0.5 * ( SPIN_SPEED + (float)( COAST_TIME - delta ) / COAST_TIME );
1354 angle = cent->pe.barrelAngle + delta * speed;
1355 }
1356
1357 if ( cent->pe.barrelSpinning == !(cent->currentState.eFlags & EF_FIRING) ) {
1358 cent->pe.barrelTime = cg.time;
1359 cent->pe.barrelAngle = AngleMod( angle );
1360 cent->pe.barrelSpinning = !!(cent->currentState.eFlags & EF_FIRING);
1361 //#ifdef MISSIONPACK
1362 if ( cent->currentState.weapon == WP_CHAINGUN && !cent->pe.barrelSpinning ) {
1363 trap_S_StartSound( NULL, cent->currentState.number, CHAN_WEAPON, trap_S_RegisterSound( "sound/weapons/vulcan/wvulwind.wav", qfalse ) );
1364 }
1365 //#endif
1366 }
1367
1368 return angle;
1369 }
1370
1371
1372 /*
1373 ========================
1374 CG_AddWeaponWithPowerups
1375 ========================
1376 */
1377 static void CG_AddWeaponWithPowerups( refEntity_t *gun, int powerups ) {
1378 // add powerup effects
1379 if ( powerups & ( 1 << PW_INVIS ) ) {
1380 if( (cgs.dmflags & DF_INVIS) == 0) {
1381 gun->customShader = cgs.media.invisShader;
1382 trap_R_AddRefEntityToScene( gun );
1383 }
1384 } else {
1385 trap_R_AddRefEntityToScene( gun );
1386
1387 if ( powerups & ( 1 << PW_BATTLESUIT ) ) {
1388 gun->customShader = cgs.media.battleWeaponShader;
1389 trap_R_AddRefEntityToScene( gun );
1390 }
1391 if ( powerups & ( 1 << PW_QUAD ) ) {
1392 gun->customShader = cgs.media.quadWeaponShader;
1393 trap_R_AddRefEntityToScene( gun );
1394 }
1395 }
1396 }
1397
1398
1399 /*
1400 =============
1401 CG_AddPlayerWeapon
1402
1403 Used for both the view weapon (ps is valid) and the world modelother character models (ps is NULL)
1404 The main player will have this called for BOTH cases, so effects like light and
1405 sound should only be done on the world model case.
1406 =============
1407 */
1408 void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent, int team ) {
1409 refEntity_t gun;
1410 refEntity_t barrel;
1411 refEntity_t flash;
1412 vec3_t angles;
1413 weapon_t weaponNum;
1414 weaponInfo_t *weapon;
1415 centity_t *nonPredictedCent;
1416 orientation_t lerped;
1417
1418 weaponNum = cent->currentState.weapon;
1419
1420 CG_RegisterWeapon( weaponNum );
1421 weapon = &cg_weapons[weaponNum];
1422
1423 // add the weapon
1424 memset( &gun, 0, sizeof( gun ) );
1425 VectorCopy( parent->lightingOrigin, gun.lightingOrigin );
1426 gun.shadowPlane = parent->shadowPlane;
1427 gun.renderfx = parent->renderfx;
1428
1429 // set custom shading for railgun refire rate
1430 if ( ps || cent->currentState.clientNum == cg.predictedPlayerState.clientNum ) {
1431 if ( cg.predictedPlayerState.weapon == WP_RAILGUN
1432 && cg.predictedPlayerState.weaponstate == WEAPON_FIRING ) {
1433 float f;
1434
1435 f = (float)cg.predictedPlayerState.weaponTime / 1500;
1436 gun.shaderRGBA[1] = 0;
1437 gun.shaderRGBA[0] =
1438 gun.shaderRGBA[2] = 255 * ( 1.0 - f );
1439 } else {
1440 gun.shaderRGBA[0] = 255;
1441 gun.shaderRGBA[1] = 255;
1442 gun.shaderRGBA[2] = 255;
1443 gun.shaderRGBA[3] = 255;
1444 }
1445 }
1446
1447 gun.hModel = weapon->weaponModel;
1448 if (!gun.hModel) {
1449 return;
1450 }
1451
1452 if ( !ps ) {
1453 // add weapon ready sound
1454 cent->pe.lightningFiring = qfalse;
1455 if ( ( cent->currentState.eFlags & EF_FIRING ) && weapon->firingSound ) {
1456 // lightning gun and guantlet make a different sound when fire is held down
1457 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->firingSound );
1458 cent->pe.lightningFiring = qtrue;
1459 } else if ( weapon->readySound ) {
1460 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->readySound );
1461 }
1462 }
1463
1464 trap_R_LerpTag(&lerped, parent->hModel, parent->oldframe, parent->frame,
1465 1.0 - parent->backlerp, "tag_weapon");
1466 VectorCopy(parent->origin, gun.origin);
1467
1468 VectorMA(gun.origin, lerped.origin[0], parent->axis[0], gun.origin);
1469
1470 // Make weapon appear left-handed for 2 and centered for 3
1471 if(ps && cg_drawGun.integer == 2)
1472 VectorMA(gun.origin, -lerped.origin[1], parent->axis[1], gun.origin);
1473 else if(!ps || cg_drawGun.integer != 3)
1474 VectorMA(gun.origin, lerped.origin[1], parent->axis[1], gun.origin);
1475
1476 VectorMA(gun.origin, lerped.origin[2], parent->axis[2], gun.origin);
1477
1478 MatrixMultiply(lerped.axis, ((refEntity_t *)parent)->axis, gun.axis);
1479 gun.backlerp = parent->backlerp;
1480
1481 CG_AddWeaponWithPowerups( &gun, cent->currentState.powerups );
1482
1483 // add the spinning barrel
1484 if ( weapon->barrelModel ) {
1485 memset( &barrel, 0, sizeof( barrel ) );
1486 VectorCopy( parent->lightingOrigin, barrel.lightingOrigin );
1487 barrel.shadowPlane = parent->shadowPlane;
1488 barrel.renderfx = parent->renderfx;
1489
1490 barrel.hModel = weapon->barrelModel;
1491 angles[YAW] = 0;
1492 angles[PITCH] = 0;
1493 angles[ROLL] = CG_MachinegunSpinAngle( cent );
1494 AnglesToAxis( angles, barrel.axis );
1495
1496 CG_PositionRotatedEntityOnTag( &barrel, &gun, weapon->weaponModel, "tag_barrel" );
1497
1498 CG_AddWeaponWithPowerups( &barrel, cent->currentState.powerups );
1499 }
1500
1501 // make sure we aren't looking at cg.predictedPlayerEntity for LG
1502 nonPredictedCent = &cg_entities[cent->currentState.clientNum];
1503
1504 // if the index of the nonPredictedCent is not the same as the clientNum
1505 // then this is a fake player (like on teh single player podiums), so
1506 // go ahead and use the cent
1507 if( ( nonPredictedCent - cg_entities ) != cent->currentState.clientNum ) {
1508 nonPredictedCent = cent;
1509 }
1510
1511 // add the flash
1512 if ( ( weaponNum == WP_LIGHTNING || weaponNum == WP_GAUNTLET || weaponNum == WP_GRAPPLING_HOOK )
1513 && ( nonPredictedCent->currentState.eFlags & EF_FIRING ) )
1514 {
1515 // continuous flash
1516 } else {
1517 // impulse flash
1518 if ( cg.time - cent->muzzleFlashTime > MUZZLE_FLASH_TIME && !cent->pe.railgunFlash ) {
1519 return;
1520 }
1521 }
1522
1523 memset( &flash, 0, sizeof( flash ) );
1524 VectorCopy( parent->lightingOrigin, flash.lightingOrigin );
1525 flash.shadowPlane = parent->shadowPlane;
1526 flash.renderfx = parent->renderfx;
1527
1528 flash.hModel = weapon->flashModel;
1529 if (!flash.hModel) {
1530 return;
1531 }
1532 angles[YAW] = 0;
1533 angles[PITCH] = 0;
1534 angles[ROLL] = crandom() * 10;
1535 AnglesToAxis( angles, flash.axis );
1536
1537 // colorize the railgun blast
1538 if ( weaponNum == WP_RAILGUN ) {
1539 clientInfo_t *ci;
1540
1541 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1542 flash.shaderRGBA[0] = 255 * ci->color1[0];
1543 flash.shaderRGBA[1] = 255 * ci->color1[1];
1544 flash.shaderRGBA[2] = 255 * ci->color1[2];
1545 }
1546
1547 CG_PositionRotatedEntityOnTag( &flash, &gun, weapon->weaponModel, "tag_flash");
1548 trap_R_AddRefEntityToScene( &flash );
1549
1550 if ( ps || cg.renderingThirdPerson ||
1551 cent->currentState.number != cg.predictedPlayerState.clientNum ) {
1552 // add lightning bolt
1553 CG_LightningBolt( nonPredictedCent, flash.origin );
1554
1555 // add rail trail
1556 CG_SpawnRailTrail( cent, flash.origin );
1557
1558 if ( weapon->flashDlightColor[0] || weapon->flashDlightColor[1] || weapon->flashDlightColor[2] ) {
1559 trap_R_AddLightToScene( flash.origin, 300 + (rand()&31), weapon->flashDlightColor[0],
1560 weapon->flashDlightColor[1], weapon->flashDlightColor[2] );
1561 }
1562 }
1563 }
1564
1565 /*
1566 ==============
1567 CG_AddViewWeapon
1568
1569 Add the weapon, and flash for the player's view
1570 ==============
1571 */
1572 void CG_AddViewWeapon( playerState_t *ps ) {
1573 refEntity_t hand;
1574 centity_t *cent;
1575 clientInfo_t *ci;
1576 float fovOffset;
1577 vec3_t angles;
1578 weaponInfo_t *weapon;
1579
1580 if ( ps->persistant[PERS_TEAM] == TEAM_SPECTATOR ) {
1581 return;
1582 }
1583
1584 if ( ps->pm_type == PM_INTERMISSION ) {
1585 return;
1586 }
1587
1588 // no gun if in third person view or a camera is active
1589 //if ( cg.renderingThirdPerson || cg.cameraMode) {
1590 if ( cg.renderingThirdPerson ) {
1591 return;
1592 }
1593
1594
1595 // allow the gun to be completely removed
1596 if ( !cg_drawGun.integer ) {
1597 vec3_t origin;
1598
1599 if ( cg.predictedPlayerState.eFlags & EF_FIRING ) {
1600 // special hack for lightning gun...
1601 VectorCopy( cg.refdef.vieworg, origin );
1602 VectorMA( origin, -8, cg.refdef.viewaxis[2], origin );
1603 CG_LightningBolt( &cg_entities[ps->clientNum], origin );
1604 }
1605 return;
1606 }
1607
1608 // don't draw if testing a gun model
1609 if ( cg.testGun ) {
1610 return;
1611 }
1612
1613 // drop gun lower at higher fov
1614 if ( cg_fov.integer > 90 ) {
1615 fovOffset = -0.2 * ( cg_fov.integer - 90 );
1616 } else {
1617 fovOffset = 0;
1618 }
1619
1620 cent = &cg.predictedPlayerEntity; // &cg_entities[cg.snap->ps.clientNum];
1621 CG_RegisterWeapon( ps->weapon );
1622 weapon = &cg_weapons[ ps->weapon ];
1623
1624 memset (&hand, 0, sizeof(hand));
1625
1626 // set up gun position
1627 CG_CalculateWeaponPosition( hand.origin, angles );
1628
1629 VectorMA( hand.origin, cg_gun_x.value, cg.refdef.viewaxis[0], hand.origin );
1630 VectorMA( hand.origin, cg_gun_y.value, cg.refdef.viewaxis[1], hand.origin );
1631 VectorMA( hand.origin, (cg_gun_z.value+fovOffset), cg.refdef.viewaxis[2], hand.origin );
1632
1633 AnglesToAxis( angles, hand.axis );
1634
1635 // map torso animations to weapon animations
1636 if ( cg_gun_frame.integer ) {
1637 // development tool
1638 hand.frame = hand.oldframe = cg_gun_frame.integer;
1639 hand.backlerp = 0;
1640 } else {
1641 // get clientinfo for animation map
1642 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1643 hand.frame = CG_MapTorsoToWeaponFrame( ci, cent->pe.torso.frame );
1644 hand.oldframe = CG_MapTorsoToWeaponFrame( ci, cent->pe.torso.oldFrame );
1645 hand.backlerp = cent->pe.torso.backlerp;
1646 }
1647
1648 hand.hModel = weapon->handsModel;
1649 hand.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON | RF_MINLIGHT;
1650
1651 // add everything onto the hand
1652 CG_AddPlayerWeapon( &hand, ps, &cg.predictedPlayerEntity, ps->persistant[PERS_TEAM] );
1653 }
1654
1655 /*
1656 ==============================================================================
1657
1658 WEAPON SELECTION
1659
1660 ==============================================================================
1661 */
1662
1663 /*
1664 ===================
1665 CG_DrawWeaponSelect
1666 ===================
1667 */
1668 void CG_DrawWeaponSelect( void ) {
1669 int i;
1670 int bits;
1671 int count;
1672 float *color;
1673 vec4_t realColor;
1674
1675
1676
1677 // don't display if dead
1678 if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) {
1679 return;
1680 }
1681
1682 color = CG_FadeColor( cg.weaponSelectTime, WEAPON_SELECT_TIME );
1683
1684 //Elimination: Always show weapon bar
1685 if(cg_alwaysWeaponBar.integer) {
1686 realColor[0] = 1.0;
1687 realColor[1] = 1.0;
1688 realColor[2] = 1.0;
1689 realColor[3] = 1.0;
1690 color = realColor;
1691 }
1692
1693 if ( !color ) {
1694 return;
1695 }
1696 trap_R_SetColor( color );
1697
1698 // showing weapon select clears pickup item display, but not the blend blob
1699 cg.itemPickupTime = 0;
1700
1701 // count the number of weapons owned
1702 bits = cg.snap->ps.stats[ STAT_WEAPONS ];
1703 count = 0;
1704 for ( i = 1 ; i < MAX_WEAPONS ; i++ ) {
1705 if ( bits & ( 1 << i ) ) {
1706 count++;
1707 }
1708 }
1709
1710 switch(cg_weaponBarStyle.integer){
1711 case 0:
1712 CG_DrawWeaponBar0(count,bits);
1713 break;
1714 case 1:
1715 CG_DrawWeaponBar1(count,bits);
1716 break;
1717 case 2:
1718 CG_DrawWeaponBar2(count,bits, color);
1719 break;
1720 case 3:
1721 CG_DrawWeaponBar3(count,bits, color);
1722 break;
1723 case 4:
1724 CG_DrawWeaponBar4(count,bits, color);
1725 break;
1726 case 5:
1727 CG_DrawWeaponBar5(count,bits, color);
1728 break;
1729 case 6:
1730 CG_DrawWeaponBar6(count,bits, color);
1731 break;
1732 case 7:
1733 CG_DrawWeaponBar7(count,bits, color);
1734 break;
1735 }
1736 trap_R_SetColor(NULL);
1737 return;
1738 }
1739
1740 /*
1741 ===============
1742 CG_DrawWeaponBar0
1743 ===============
1744 */
1745
1746 void CG_DrawWeaponBar0(int count, int bits){
1747
1748 int y = 380;
1749 int x = 320 - count * 20;
1750 int i;
1751
1752 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
1753 //Sago: Do mad change of grapple placement:
1754 if(i==10)
1755 continue;
1756 if(i==0)
1757 i=10;
1758 if ( !( bits & ( 1 << i ) ) ) {
1759 if(i==10)
1760 i=0;
1761 continue;
1762 }
1763
1764 CG_RegisterWeapon( i );
1765 // draw weapon icon
1766 CG_DrawPic( x, y, 32, 32, cg_weapons[i].weaponIcon );
1767
1768 // draw selection marker
1769 if ( i == cg.weaponSelect ) {
1770 CG_DrawPic( x-4, y-4, 40, 40, cgs.media.selectShader );
1771 }
1772
1773 // no ammo cross on top
1774 if ( !cg.snap->ps.ammo[ i ] ) {
1775 CG_DrawPic( x, y, 32, 32, cgs.media.noammoShader );
1776 }
1777
1778 x += 40;
1779 //Sago: Undo mad change of weapons
1780 if(i==10)
1781 i=0;
1782 }
1783 }
1784
1785 /*
1786 ===============
1787 CG_DrawWeaponBar1
1788 ===============
1789 */
1790
1791 void CG_DrawWeaponBar1(int count, int bits){
1792
1793 int y = 380;
1794 int x = 320 - count * 20;
1795 int i;
1796 int ammo;
1797 int br;
1798 int max;
1799 float red[4];
1800 float yellow[4];
1801 float green[4];
1802
1803 red[0] = 1.0f;
1804 red[1] = 0;
1805 red[2] = 0;
1806 red[3] = 1.0f;
1807
1808 yellow[0] = 1.0f;
1809 yellow[1] = 0.6f;
1810 yellow[2] = 0;
1811 yellow[3] = 1.0f;
1812
1813 green[0] = 0;
1814 green[1] = 1.0f;
1815 green[2] = 0;
1816 green[3] = 1.0f;
1817
1818 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
1819 //Sago: Do mad change of grapple placement:
1820 if(i==10)
1821 continue;
1822 if(i==0)
1823 i=10;
1824 if ( !( bits & ( 1 << i ) ) ) {
1825 if(i==10)
1826 i=0;
1827 continue;
1828 }
1829
1830 ammo=cg.snap->ps.ammo[i];
1831
1832 switch(i) {
1833 case WP_MACHINEGUN: max = 100; break;
1834 case WP_SHOTGUN: max = 10; break;
1835 case WP_GRENADE_LAUNCHER: max = 10; break;
1836 case WP_ROCKET_LAUNCHER: max = 10; break;
1837 case WP_LIGHTNING: max = 100; break;
1838 case WP_RAILGUN: max = 10; break;
1839 case WP_PLASMAGUN: max = 50; break;
1840 case WP_BFG: max = 10; break;
1841 case WP_NAILGUN: max = 10; break;
1842 case WP_PROX_LAUNCHER: max = 5; break;
1843 case WP_CHAINGUN: max = 100; break;
1844 default: max = 1; break;
1845 }
1846
1847 ammo = (ammo*100)/max;
1848 if(ammo >=100)
1849 ammo=100;
1850
1851 br=ammo*32/100;
1852
1853 if(i!=WP_GAUNTLET && i!=WP_GRAPPLING_HOOK){
1854 if(ammo <= 20)
1855 CG_FillRect( x, y+38, br,4, red);
1856 if(ammo > 20 && ammo <= 50)
1857 CG_FillRect( x, y+38, br, 4, yellow);
1858 if(ammo > 50)
1859 CG_FillRect( x, y+38, br, 4, green);
1860 }
1861
1862 CG_RegisterWeapon( i );
1863 // draw weapon icon
1864 CG_DrawPic( x, y, 32, 32, cg_weapons[i].weaponIcon );
1865
1866 // draw selection marker
1867 if ( i == cg.weaponSelect ) {
1868 CG_DrawPic( x-4, y-4, 40, 40, cgs.media.selectShader );
1869 }
1870
1871 // no ammo cross on top
1872 if ( !cg.snap->ps.ammo[ i ] ) {
1873 CG_DrawPic( x, y, 32, 32, cgs.media.noammoShader );
1874 }
1875
1876 x += 40;
1877 //Sago: Undo mad change of weapons
1878 if(i==10)
1879 i=0;
1880 }
1881 }
1882
1883 /*
1884 ===============
1885 CG_DrawWeaponBar2
1886 ===============
1887 */
1888
1889 void CG_DrawWeaponBar2(int count, int bits, float *color){
1890
1891 int y = 200 + count * 12;
1892 int x = 0;
1893 int i;
1894 int w;
1895 char *s;
1896 float red[4];
1897 float yellow[4];
1898 float blue[4];
1899
1900 red[0] = 1.0f;
1901 red[1] = 0;
1902 red[2] = 0;
1903 red[3] = 0.4f;
1904
1905 yellow[0] = 1.0f;
1906 yellow[1] = 1.0f;
1907 yellow[2] = 0;
1908 yellow[3] = 1.0f;
1909
1910 blue[0] = 0;
1911 blue[1] = 0;
1912 blue[2] = 1.0f;
1913 blue[3] = 0.4f;
1914
1915 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
1916 //Sago: Do mad change of grapple placement:
1917 if(i==10)
1918 continue;
1919 if(i==0)
1920 i=10;
1921 if ( !( bits & ( 1 << i ) ) ) {
1922 if(i==10)
1923 i=0;
1924 continue;
1925 }
1926
1927 if(cg.snap->ps.ammo[i]){
1928 if ( i == cg.weaponSelect) {
1929 CG_FillRect( x, y, 50, 24, blue );
1930 CG_DrawRect( x, y, 50, 24, 2, yellow);
1931 }
1932 else{
1933 CG_FillRect( x, y,50, 24, blue );
1934 }
1935 }
1936 else{
1937 if ( i == cg.weaponSelect) {
1938 CG_FillRect( x, y, 50, 24, red );
1939 CG_DrawRect( x, y, 50, 24, 2, yellow);
1940 }
1941 else{
1942 CG_FillRect( x, y,50, 24, red );
1943 }
1944 }
1945
1946 CG_RegisterWeapon( i );
1947 // draw weapon icon
1948 CG_DrawPic( x+2, y+4, 16, 16, cg_weapons[i].weaponIcon );
1949
1950 /** Draw Weapon Ammo **/
1951 if(cg.snap->ps.ammo[ i ]!=-1){
1952 s = va("%i", cg.snap->ps.ammo[ i ] );
1953 w = CG_DrawStrlen( s ) * SMALLCHAR_WIDTH;
1954 CG_DrawSmallStringColor(x - w/2 + 32, y+4, s, color);
1955 }
1956
1957 y -= 24;
1958 //Sago: Undo mad change of weapons
1959 if(i==10)
1960 i=0;
1961 }
1962 }
1963
1964 /*
1965 ===============
1966 CG_DrawWeaponBar3
1967 ===============
1968 */
1969
1970 void CG_DrawWeaponBar3(int count, int bits, float *color){
1971
1972 int y = 200 + count * 12;
1973 int x = 0;
1974 int i;
1975 int ammo;
1976 int max;
1977 int br;
1978 int w;
1979 char *s;
1980 float red[4];
1981 float yellow[4];
1982 float green[4];
1983 float blue[4];
1984
1985 red[0] = 1.0f;
1986 red[1] = 0;
1987 red[2] = 0;
1988 red[3] = 0.4f;
1989
1990 yellow[0] = 1.0f;
1991 yellow[1] = 1.0f;
1992 yellow[2] = 0;
1993 yellow[3] = 1.0f;
1994
1995 green[0] = 0;
1996 green[1] = 1.0f;
1997 green[2] = 0;
1998 green[3] = 1.0f;
1999
2000 blue[0] = 0;
2001 blue[1] = 0;
2002 blue[2] = 1.0f;
2003 blue[3] = 0.4f;
2004
2005 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2006 //Sago: Do mad change of grapple placement:
2007 if(i==10)
2008 continue;
2009 if(i==0)
2010 i=10;
2011 if ( !( bits & ( 1 << i ) ) ) {
2012 if(i==10)
2013 i=0;
2014 continue;
2015 }
2016
2017 ammo=cg.snap->ps.ammo[i];
2018
2019 switch(i) {
2020 case WP_MACHINEGUN: max = 100; break;
2021 case WP_SHOTGUN: max = 10; break;
2022 case WP_GRENADE_LAUNCHER: max = 10; break;
2023 case WP_ROCKET_LAUNCHER: max = 10; break;
2024 case WP_LIGHTNING: max = 100; break;
2025 case WP_RAILGUN: max = 10; break;
2026 case WP_PLASMAGUN: max = 50; break;
2027 case WP_BFG: max = 10; break;
2028 case WP_NAILGUN: max = 10; break;
2029 case WP_PROX_LAUNCHER: max = 5; break;
2030 case WP_CHAINGUN: max = 100; break;
2031 default: max = 1; break;
2032 }
2033
2034 ammo = (ammo*100)/max;
2035 if(ammo >=100)
2036 ammo=100;
2037
2038 br=ammo*20/100;
2039
2040 if(i!=WP_GAUNTLET && i!=WP_GRAPPLING_HOOK){
2041 if(ammo <= 20)
2042 CG_FillRect( 51, y+2+20-br, 4,br, red);
2043 if(ammo > 20 && ammo <= 50)
2044 CG_FillRect( 51, y+2+20-br, 4,br, yellow);
2045 if(ammo > 50)
2046 CG_FillRect( 51, y+2+20-br, 4,br, green);
2047 }
2048
2049 if(cg.snap->ps.ammo[i]){
2050 if ( i == cg.weaponSelect) {
2051 CG_FillRect( x, y, 50, 24, blue );
2052 CG_DrawRect( x, y, 50, 24, 2, yellow);
2053 }
2054 else{
2055 CG_FillRect( x, y,50, 24, blue );
2056 }
2057 }
2058 else{
2059 if ( i == cg.weaponSelect) {
2060 CG_FillRect( x, y, 50, 24, red );
2061 CG_DrawRect( x, y, 50, 24, 2, yellow);
2062 }
2063 else{
2064 CG_FillRect( x, y,50, 24, red );
2065 }
2066 }
2067 CG_RegisterWeapon( i );
2068 // draw weapon icon
2069 CG_DrawPic( x+2, y+4, 16, 16, cg_weapons[i].weaponIcon );
2070
2071 /** Draw Weapon Ammo **/
2072 if(cg.snap->ps.ammo[ i ]!=-1){
2073 s = va("%i", cg.snap->ps.ammo[ i ] );
2074 w = CG_DrawStrlen( s ) * SMALLCHAR_WIDTH;
2075 CG_DrawSmallStringColor(x - w/2 + 32, y+4, s, color);
2076 }
2077
2078 y -= 24;
2079 //Sago: Undo mad change of weapons
2080 if(i==10)
2081 i=0;
2082 }
2083 }
2084
2085 /*
2086 ===============
2087 CG_DrawWeaponBar4
2088 ===============
2089 */
2090
2091 void CG_DrawWeaponBar4(int count, int bits, float *color){
2092
2093 int y = 200 + count * 12;
2094 int x = 0;
2095 int i;
2096 float ammo;
2097 int max;
2098 int w;
2099 char *s;
2100 float boxColor[4];
2101 float yellow[4];
2102
2103 boxColor[1]=0;
2104 boxColor[3]=0.4f;
2105
2106 yellow[0] = 1.0f;
2107 yellow[1] = 1.0f;
2108 yellow[2] = 0;
2109 yellow[3] = 1.0f;
2110
2111 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2112 //Sago: Do mad change of grapple placement:
2113 if(i==10)
2114 continue;
2115 if(i==0)
2116 i=10;
2117 if ( !( bits & ( 1 << i ) ) ) {
2118 if(i==10)
2119 i=0;
2120 continue;
2121 }
2122
2123 ammo=cg.snap->ps.ammo[i];
2124
2125 switch(i) {
2126 case WP_MACHINEGUN: max = 100; break;
2127 case WP_SHOTGUN: max = 10; break;
2128 case WP_GRENADE_LAUNCHER: max = 10; break;
2129 case WP_ROCKET_LAUNCHER: max = 10; break;
2130 case WP_LIGHTNING: max = 100; break;
2131 case WP_RAILGUN: max = 10; break;
2132 case WP_PLASMAGUN: max = 50; break;
2133 case WP_BFG: max = 10; break;
2134 case WP_NAILGUN: max = 10; break;
2135 case WP_PROX_LAUNCHER: max = 5; break;
2136 case WP_CHAINGUN: max = 100; break;
2137 default: max = 1; break;
2138 }
2139
2140 ammo = (ammo*100)/max;
2141
2142 if((ammo >=100) || (ammo < 0))
2143 ammo=100;
2144
2145 boxColor[2]=(ammo/100.0f)*1.0f;
2146 boxColor[0]=1.0f-(ammo/100.0f)*1.0f;
2147
2148 if ( i == cg.weaponSelect) {
2149 CG_FillRect( x, y, 50, 24, boxColor );
2150 CG_DrawRect( x, y, 50, 24, 2, yellow);
2151 }
2152 else{
2153 CG_FillRect( x, y,50, 24, boxColor );
2154 }
2155 CG_RegisterWeapon( i );
2156 // draw weapon icon
2157 CG_DrawPic( x+2, y+4, 16, 16, cg_weapons[i].weaponIcon );
2158
2159 /** Draw Weapon Ammo **/
2160 if(cg.snap->ps.ammo[ i ]!=-1){
2161 s = va("%i", cg.snap->ps.ammo[ i ] );
2162 w = CG_DrawStrlen( s ) * SMALLCHAR_WIDTH;
2163 CG_DrawSmallStringColor(x - w/2 + 32, y+4, s, color);
2164 }
2165
2166 y -= 24;
2167 //Sago: Undo mad change of weapons
2168 if(i==10)
2169 i=0;
2170 }
2171 }
2172
2173 /*
2174 ===============
2175 CG_DrawWeaponBar5
2176 ===============
2177 */
2178
2179 void CG_DrawWeaponBar5(int count, int bits, float *color){
2180
2181 int y = 380;
2182 int x = 320 - count * 15;
2183 int i;
2184 int w;
2185 char *s;
2186 float red[4];
2187 float yellow[4];
2188 float blue[4];
2189
2190 red[0] = 1.0f;
2191 red[1] = 0;
2192 red[2] = 0;
2193 red[3] = 0.4f;
2194
2195 yellow[0] = 1.0f;
2196 yellow[1] = 1.0f;
2197 yellow[2] = 0;
2198 yellow[3] = 1.0f;
2199
2200 blue[0] = 0;
2201 blue[1] = 0;
2202 blue[2] = 1.0f;
2203 blue[3] = 0.4f;
2204
2205 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2206 //Sago: Do mad change of grapple placement:
2207 if(i==10)
2208 continue;
2209 if(i==0)
2210 i=10;
2211 if ( !( bits & ( 1 << i ) ) ) {
2212 if(i==10)
2213 i=0;
2214 continue;
2215 }
2216
2217 if(cg.snap->ps.ammo[i]){
2218 if ( i == cg.weaponSelect) {
2219 CG_FillRect( x, y , 30 , 38, blue );
2220 CG_DrawRect( x, y, 30 ,38 ,2, yellow);
2221 }
2222 else{
2223 CG_FillRect( x, y,30, 38, blue );
2224 }
2225 }
2226 else{
2227 if ( i == cg.weaponSelect) {
2228 CG_FillRect( x, y , 30 , 38, red );
2229 CG_DrawRect( x , y, 30,38,2, yellow);
2230 }
2231 else{
2232 CG_FillRect( x, y,30, 38, red );
2233 }
2234 }
2235 CG_RegisterWeapon( i );
2236 CG_DrawPic( x+7, y+2, 16, 16, cg_weapons[i].weaponIcon );
2237
2238 if(cg.snap->ps.ammo[ i ]!=-1){
2239 s = va("%i", cg.snap->ps.ammo[ i ] );
2240 w = CG_DrawStrlen( s ) * SMALLCHAR_WIDTH;
2241 CG_DrawSmallStringColor(x - w/2 + 15, y+20, s, color);
2242 }
2243
2244 x += 30;
2245 //Sago: Undo mad change of weapons
2246 if(i==10)
2247 i=0;
2248 }
2249 }
2250
2251 /*
2252 ===============
2253 CG_DrawWeaponBar6
2254 ===============
2255 */
2256
2257 void CG_DrawWeaponBar6(int count, int bits, float *color){
2258
2259 int y = 380;
2260 int x = 320 - count * 15;
2261 int i;
2262 int ammo;
2263 int max;
2264 int br;
2265 int w;
2266 char *s;
2267 float red[4];
2268 float yellow[4];
2269 float green[4];
2270 float blue[4];
2271
2272 red[0] = 1.0f;
2273 red[1] = 0;
2274 red[2] = 0;
2275 red[3] = 0.4f;
2276
2277 yellow[0] = 1.0f;
2278 yellow[1] = 1.0f;
2279 yellow[2] = 0;
2280 yellow[3] = 1.0f;
2281
2282 green[0] = 0;
2283 green[1] = 1.0f;
2284 green[2] = 0;
2285 green[3] = 1.0f;
2286
2287 blue[0] = 0;
2288 blue[1] = 0;
2289 blue[2] = 1.0f;
2290 blue[3] = 0.4f;
2291
2292 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2293 //Sago: Do mad change of grapple placement:
2294 if(i==10)
2295 continue;
2296 if(i==0)
2297 i=10;
2298 if ( !( bits & ( 1 << i ) ) ) {
2299 if(i==10)
2300 i=0;
2301 continue;
2302 }
2303
2304 ammo=cg.snap->ps.ammo[i];
2305
2306 switch(i) {
2307 case WP_MACHINEGUN: max = 100; break;
2308 case WP_SHOTGUN: max = 10; break;
2309 case WP_GRENADE_LAUNCHER: max = 10; break;
2310 case WP_ROCKET_LAUNCHER: max = 10; break;
2311 case WP_LIGHTNING: max = 100; break;
2312 case WP_RAILGUN: max = 10; break;
2313 case WP_PLASMAGUN: max = 50; break;
2314 case WP_BFG: max = 10; break;
2315 case WP_NAILGUN: max = 10; break;
2316 case WP_PROX_LAUNCHER: max = 5; break;
2317 case WP_CHAINGUN: max = 100; break;
2318 default: max = 1; break;
2319 }
2320
2321 ammo = (ammo*100)/max;
2322
2323 if(ammo >=100)
2324 ammo=100;
2325
2326 br=ammo*26/100;
2327
2328 if(i!=WP_GAUNTLET && i!=WP_GRAPPLING_HOOK){
2329 if(ammo <= 20)
2330 CG_FillRect( x+2, y +40, br, 4, red);
2331 if(ammo > 20 && ammo <= 50)
2332 CG_FillRect( x+2, y+40, br, 4, yellow);
2333 if(ammo > 50)
2334 CG_FillRect( x+2, y+40, br, 4, green);
2335 }
2336
2337 if(cg.snap->ps.ammo[i]){
2338 if ( i == cg.weaponSelect) {
2339 CG_FillRect( x, y , 30 , 38, blue );
2340 CG_DrawRect( x, y, 30 ,38 ,2, yellow);
2341 }
2342 else{
2343 CG_FillRect( x, y,30, 38, blue );
2344 }
2345 }
2346 else{
2347 if ( i == cg.weaponSelect) {
2348 CG_FillRect( x, y , 30 , 38, red );
2349 CG_DrawRect( x , y, 30,38,2, yellow);
2350 }
2351 else{
2352 CG_FillRect( x, y,30, 38, red );
2353 }
2354 }
2355 CG_RegisterWeapon( i );
2356 CG_DrawPic( x+7, y+2, 16, 16, cg_weapons[i].weaponIcon );
2357
2358 if(cg.snap->ps.ammo[ i ]!=-1){
2359 s = va("%i", cg.snap->ps.ammo[ i ] );
2360 w = CG_DrawStrlen( s ) * SMALLCHAR_WIDTH;
2361 CG_DrawSmallStringColor(x - w/2 + 15, y+20, s, color);
2362 }
2363
2364 x += 30;
2365 //Sago: Undo mad change of weapons
2366 if(i==10)
2367 i=0;
2368 }
2369 }
2370
2371 /*
2372 ===============
2373 CG_DrawWeaponBar7
2374 ===============
2375 */
2376
2377 void CG_DrawWeaponBar7(int count, int bits, float *color){
2378
2379 int y = 380;
2380 int x = 320 - count * 15;
2381 int i;
2382 float ammo;
2383 float max;
2384 int w;
2385 char *s;
2386 float yellow[4];
2387 float boxColor[4];
2388
2389 boxColor[1]=0;
2390 boxColor[3]=0.4f;
2391
2392 yellow[0] = 1.0f;
2393 yellow[1] = 1.0f;
2394 yellow[2] = 0;
2395 yellow[3] = 1.0f;
2396
2397 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2398 //Sago: Do mad change of grapple placement:
2399 if(i==10)
2400 continue;
2401 if(i==0)
2402 i=10;
2403 if ( !( bits & ( 1 << i ) ) ) {
2404 if(i==10)
2405 i=0;
2406 continue;
2407 }
2408
2409 ammo=cg.snap->ps.ammo[i];
2410
2411 switch(i) {
2412 case WP_MACHINEGUN: max = 100; break;
2413 case WP_SHOTGUN: max = 10; break;
2414 case WP_GRENADE_LAUNCHER: max = 10; break;
2415 case WP_ROCKET_LAUNCHER: max = 10; break;
2416 case WP_LIGHTNING: max = 100; break;
2417 case WP_RAILGUN: max = 10; break;
2418 case WP_PLASMAGUN: max = 50; break;
2419 case WP_BFG: max = 10; break;
2420 case WP_NAILGUN: max = 10; break;
2421 case WP_PROX_LAUNCHER: max = 5; break;
2422 case WP_CHAINGUN: max = 100; break;
2423 default: max = 1; break;
2424 }
2425
2426 ammo = (ammo*100)/max;
2427
2428 if((ammo >=100) || (ammo < 0))
2429 ammo=100;
2430
2431 boxColor[2]=(ammo/100.0f)*1.0f;
2432 boxColor[0]=1.0f-(ammo/100.0f)*1.0f;
2433
2434 if ( i == cg.weaponSelect) {
2435 CG_FillRect( x, y , 30 , 38, boxColor );
2436 CG_DrawRect( x, y, 30 ,38 ,2, yellow);
2437 }
2438 else{
2439 CG_FillRect( x, y,30, 38, boxColor );
2440 }
2441 CG_RegisterWeapon( i );
2442 CG_DrawPic( x+7, y+2, 16, 16, cg_weapons[i].weaponIcon );
2443
2444 if(cg.snap->ps.ammo[ i ]!=-1){
2445 s = va("%i", cg.snap->ps.ammo[ i ] );
2446 w = CG_DrawStrlen( s ) * SMALLCHAR_WIDTH;
2447 CG_DrawSmallStringColor(x - w/2 + 15, y+20, s, color);
2448 }
2449
2450 x += 30;
2451 //Sago: Undo mad change of weapons
2452 if(i==10)
2453 i=0;
2454 }
2455 }
2456
2457
2458 /*
2459 ===============
2460 CG_WeaponSelectable
2461 ===============
2462 */
2463 static qboolean CG_WeaponSelectable( int i ) {
2464 if ( !cg.snap->ps.ammo[i] ) {
2465 return qfalse;
2466 }
2467 if ( ! (cg.snap->ps.stats[ STAT_WEAPONS ] & ( 1 << i ) ) ) {
2468 return qfalse;
2469 }
2470
2471 return qtrue;
2472 }
2473
2474 /*
2475 ===============
2476 CG_NextWeapon_f
2477 ===============
2478 */
2479 void CG_NextWeapon_f( void ) {
2480 int i;
2481 int original;
2482
2483 if ( !cg.snap ) {
2484 return;
2485 }
2486 if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
2487 return;
2488 }
2489
2490 cg.weaponSelectTime = cg.time;
2491 original = cg.weaponSelect;
2492 //Part of mad hook select code:
2493 if(cg.weaponSelect == WP_GRAPPLING_HOOK)
2494 cg.weaponSelect = 0;
2495
2496 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2497 cg.weaponSelect++;
2498 if ( cg.weaponSelect == MAX_WEAPONS ) {
2499 cg.weaponSelect = 0;
2500 }
2501 if ( cg.weaponSelect == WP_GAUNTLET ) {
2502 continue; // never cycle to gauntlet
2503 }
2504 //Sago: Mad change of grapple order
2505 if( cg.weaponSelect == WP_GRAPPLING_HOOK) {
2506 continue;
2507 }
2508 if( cg.weaponSelect == 0)
2509 cg.weaponSelect = WP_GRAPPLING_HOOK;
2510 if ( cg.weaponSelect == WP_GRAPPLING_HOOK && !cg_cyclegrapple.integer ) {
2511 cg.weaponSelect = 0;
2512 continue; // never cycle to grapple unless the client wants it
2513 }
2514 if ( CG_WeaponSelectable( cg.weaponSelect ) ) {
2515 break;
2516 }
2517 if( cg.weaponSelect == WP_GRAPPLING_HOOK)
2518 cg.weaponSelect = 0;
2519 }
2520 if ( i == MAX_WEAPONS ) {
2521 cg.weaponSelect = original;
2522 }
2523 }
2524
2525 /*
2526 ===============
2527 CG_PrevWeapon_f
2528 ===============
2529 */
2530 void CG_PrevWeapon_f( void ) {
2531 int i;
2532 int original;
2533
2534 if ( !cg.snap ) {
2535 return;
2536 }
2537 if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
2538 return;
2539 }
2540
2541 cg.weaponSelectTime = cg.time;
2542 original = cg.weaponSelect;
2543 //Part of mad hook select code:
2544 if(cg.weaponSelect == WP_GRAPPLING_HOOK)
2545 cg.weaponSelect = 0;
2546
2547 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
2548 cg.weaponSelect--;
2549 if ( cg.weaponSelect == -1 ) {
2550 cg.weaponSelect = MAX_WEAPONS - 1;
2551 }
2552 if ( cg.weaponSelect == WP_GAUNTLET ) {
2553 continue; // never cycle to gauntlet
2554 }
2555 //Sago: Mad change of grapple order
2556 if( cg.weaponSelect == WP_GRAPPLING_HOOK) {
2557 continue;
2558 }
2559 if( cg.weaponSelect == 0)
2560 cg.weaponSelect = WP_GRAPPLING_HOOK;
2561 if ( cg.weaponSelect == WP_GRAPPLING_HOOK && !cg_cyclegrapple.integer ) {
2562 cg.weaponSelect = 0;
2563 continue; // never cycle to grapple unless the client wants it
2564 }
2565 if ( CG_WeaponSelectable( cg.weaponSelect ) ) {
2566 break;
2567 }
2568 if( cg.weaponSelect == WP_GRAPPLING_HOOK)
2569 cg.weaponSelect = 0;
2570 }
2571 if ( i == MAX_WEAPONS ) {
2572 cg.weaponSelect = original;
2573 }
2574 }
2575
2576 /*
2577 ===============
2578 CG_Weapon_f
2579 ===============
2580 */
2581 void CG_Weapon_f( void ) {
2582 int num;
2583
2584 if ( !cg.snap ) {
2585 return;
2586 }
2587 if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
2588 return;
2589 }
2590
2591 num = atoi( CG_Argv( 1 ) );
2592
2593 if ( num < 1 || num > MAX_WEAPONS-1 ) {
2594 return;
2595 }
2596
2597 cg.weaponSelectTime = cg.time;
2598
2599 if ( ! ( cg.snap->ps.stats[STAT_WEAPONS] & ( 1 << num ) ) ) {
2600 return; // don't have the weapon
2601 }
2602
2603 cg.weaponSelect = num;
2604 }
2605
2606 /*
2607 ===================
2608 CG_OutOfAmmoChange
2609
2610 The current weapon has just run out of ammo
2611 ===================
2612 */
2613 void CG_OutOfAmmoChange( void ) {
2614 int i;
2615
2616 cg.weaponSelectTime = cg.time;
2617
2618 for ( i = MAX_WEAPONS-1 ; i > 0 ; i-- ) {
2619 if ( CG_WeaponSelectable( i ) && i != WP_GRAPPLING_HOOK ) {
2620 cg.weaponSelect = i;
2621 break;
2622 }
2623 }
2624 }
2625
2626
2627
2628 /*
2629 ===================================================================================================
2630
2631 WEAPON EVENTS
2632
2633 ===================================================================================================
2634 */
2635
2636 /*
2637 ================
2638 CG_FireWeapon
2639
2640 Caused by an EV_FIRE_WEAPON event
2641 ================
2642 */
2643 void CG_FireWeapon( centity_t *cent ) {
2644 entityState_t *ent;
2645 int c;
2646 weaponInfo_t *weap;
2647
2648 if((cgs.gametype == GT_ELIMINATION || cgs.gametype == GT_CTF_ELIMINATION) && cgs.roundStartTime>=cg.time)
2649 return; //if we havn't started in ELIMINATION then do not fire
2650
2651 ent = &cent->currentState;
2652 if ( ent->weapon == WP_NONE ) {
2653 return;
2654 }
2655 if ( ent->weapon >= WP_NUM_WEAPONS ) {
2656 CG_Error( "CG_FireWeapon: ent->weapon >= WP_NUM_WEAPONS" );
2657 return;
2658 }
2659 weap = &cg_weapons[ ent->weapon ];
2660
2661 // mark the entity as muzzle flashing, so when it is added it will
2662 // append the flash to the weapon model
2663 cent->muzzleFlashTime = cg.time;
2664
2665 // lightning gun only does this this on initial press
2666 if ( ent->weapon == WP_LIGHTNING ) {
2667 if ( cent->pe.lightningFiring ) {
2668 return;
2669 }
2670 }
2671
2672 // play quad sound if needed
2673 if ( cent->currentState.powerups & ( 1 << PW_QUAD ) ) {
2674 trap_S_StartSound (NULL, cent->currentState.number, CHAN_ITEM, cgs.media.quadSound );
2675 }
2676
2677 // play a sound
2678 for ( c = 0 ; c < 4 ; c++ ) {
2679 if ( !weap->flashSound[c] ) {
2680 break;
2681 }
2682 }
2683 if ( c > 0 ) {
2684 c = rand() % c;
2685 if ( weap->flashSound[c] )
2686 {
2687 trap_S_StartSound( NULL, ent->number, CHAN_WEAPON, weap->flashSound[c] );
2688 }
2689 }
2690
2691 // do brass ejection
2692 if ( weap->ejectBrassFunc && cg_brassTime.integer > 0 ) {
2693 weap->ejectBrassFunc( cent );
2694 }
2695
2696 //unlagged - attack prediction #1
2697 CG_PredictWeaponEffects( cent );
2698 //unlagged - attack prediction #1
2699 }
2700
2701
2702 /*
2703 ==========================
2704 CG_Explosionia LEILEI
2705 ==========================
2706
2707 static void CG_Explosionia ( centity_t *cent ) {
2708 localEntity_t *le;
2709 ec3_t velocity, xvelocity;
2710 vec3_t offset, xoffset;
2711 float waterScale = 1.0f;
2712 vec3_t v[3];
2713
2714 if ( cg_brassTime.integer <= 0 ) {
2715 return;
2716 }
2717
2718 le = CG_AllocLocalEntity();
2719
2720
2721 velocity[0] = -50 + 100 * crandom();
2722 velocity[1] = -50 + 100 * crandom();
2723 velocity[2] = -50 + 100 * crandom();
2724
2725 le->leType = LE_FALL_SCALE_FADE;
2726 le->startTime = cg.time;
2727 le->endTime = le->startTime + cg_brassTime.integer + ( cg_brassTime.integer / 4 ) * random();
2728
2729 //le->pos.trType = TR_GRAVITY;
2730 le->pos.trTime = cg.time - (rand()&15);
2731
2732 AnglesToAxis( cent->lerpAngles, v );
2733
2734 offset[0] = 8;
2735 offset[1] = -4;
2736 offset[2] = 24;
2737
2738 xoffset[0] = offset[0] * v[0][0] + offset[1] * v[1][0] + offset[2] * v[2][0];
2739 xoffset[1] = offset[0] * v[0][1] + offset[1] * v[1][1] + offset[2] * v[2][1];
2740 xoffset[2] = offset[0] * v[0][2] + offset[1] * v[1][2] + offset[2] * v[2][2];
2741 VectorAdd( cent->lerpOrigin, xoffset, re->origin );
2742
2743 VectorCopy( re->origin, le->pos.trBase );
2744
2745 if ( CG_PointContents( re->origin, -1 ) & CONTENTS_WATER ) {
2746 waterScale = 0.10f;
2747 }
2748
2749 xvelocity[0] = velocity[0] * v[0][0] + velocity[1] * v[1][0] + velocity[2] * v[2][0];
2750 xvelocity[1] = velocity[0] * v[0][1] + velocity[1] * v[1][1] + velocity[2] * v[2][1];
2751 xvelocity[2] = velocity[0] * v[0][2] + velocity[1] * v[1][2] + velocity[2] * v[2][2];
2752 VectorScale( xvelocity, waterScale, le->pos.trDelta );
2753
2754 le->bounceFactor = 0.4 * waterScale;
2755
2756 le->angles.trType = TR_LINEAR;
2757 le->angles.trTime = cg.time;
2758 le->angles.trBase[0] = rand()&31;
2759 le->angles.trBase[1] = rand()&31;
2760 le->angles.trBase[2] = rand()&31;
2761 le->angles.trDelta[0] = 2;
2762 le->angles.trDelta[1] = 1;
2763 le->angles.trDelta[2] = 0;
2764 le = CG_SmokePuff( le->origin, le->velocity,
2765 30, // radius
2766 1, 1, 1, 1, // color
2767 2000, // trailTime
2768 cg.time, // startTime
2769 0, // fadeInTime
2770 0, // flags
2771 cgs.media.lbumShader1 );
2772 le->leFlags = LEF_TUMBLE;
2773 le->leBounceSoundType = LEBS_NONE;
2774 le->leMarkType = LEMT_NONE;
2775 }
2776
2777 */
2778
2779 /*
2780 =================
2781 CG_MissileHitWall
2782
2783 Caused by an EV_MISSILE_MISS event, or directly by local bullet tracing
2784 =================
2785 */
2786 void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, impactSound_t soundType ) {
2787 qhandle_t mod;
2788 qhandle_t mark;
2789 qhandle_t shader;
2790 sfxHandle_t sfx;
2791 float radius;
2792 float light;
2793 vec3_t lightColor;
2794 localEntity_t *le;
2795 int r;
2796 qboolean alphaFade;
2797 qboolean isSprite;
2798 int duration;
2799 vec3_t sprOrg;
2800 vec3_t sprVel;
2801
2802 mark = 0;
2803 radius = 32;
2804 sfx = 0;
2805 mod = 0;
2806 shader = 0;
2807 light = 0;
2808 lightColor[0] = 1;
2809 lightColor[1] = 1;
2810 lightColor[2] = 0;
2811
2812 // set defaults
2813 isSprite = qfalse;
2814 duration = 600;
2815
2816 switch ( weapon ) {
2817 default:
2818 //#ifdef MISSIONPACK
2819 case WP_NAILGUN:
2820 if( soundType == IMPACTSOUND_FLESH ) {
2821 sfx = cgs.media.sfx_nghitflesh;
2822 } else if( soundType == IMPACTSOUND_METAL ) {
2823 sfx = cgs.media.sfx_nghitmetal;
2824 } else {
2825 sfx = cgs.media.sfx_nghit;
2826 }
2827 mark = cgs.media.holeMarkShader;
2828 radius = 12;
2829 break;
2830 //#endif
2831 case WP_LIGHTNING:
2832 // no explosion at LG impact, it is added with the beam
2833 r = rand() & 3;
2834 if ( r < 2 ) {
2835 sfx = cgs.media.sfx_lghit2;
2836 } else if ( r == 2 ) {
2837 sfx = cgs.media.sfx_lghit1;
2838 } else {
2839 sfx = cgs.media.sfx_lghit3;
2840 }
2841 mark = cgs.media.holeMarkShader;
2842 radius = 12;
2843 break;
2844 //#ifdef MISSIONPACK
2845 case WP_PROX_LAUNCHER:
2846 mod = cgs.media.dishFlashModel;
2847 shader = cgs.media.grenadeExplosionShader;
2848 sfx = cgs.media.sfx_proxexp;
2849 mark = cgs.media.burnMarkShader;
2850 radius = 64;
2851 light = 300;
2852 isSprite = qtrue;
2853 // LEILEI START enhancement
2854 if (cg_leiEnhancement.integer) {
2855 // some more fireball, fireball, fireball, fire fire!
2856 VectorMA( origin, 24, dir, sprOrg );
2857 VectorScale( dir, 64, sprVel );
2858 lightColor[0] = 0.7; // subtler explosion colors
2859 lightColor[1] = 0.6;
2860 lightColor[2] = 0.4;
2861 VectorMA( origin, 4, dir, sprOrg );
2862 VectorScale( dir, 2, sprVel );
2863 VectorMA( origin, 4, dir, sprOrg );
2864 VectorScale( dir, 42, sprVel );
2865 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 700, 10, 108 );
2866 VectorMA( origin, 4, dir, sprOrg );
2867 VectorScale( dir, 82, sprVel );
2868 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 400, 11, 158 );
2869 VectorMA( origin, -5, dir, sprOrg );
2870 VectorScale( dir, 182, sprVel );
2871 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 600, 47, 88 );
2872 VectorMA( origin, -5, dir, sprOrg );
2873 VectorScale( dir, 64, sprVel );
2874 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 110, 72, 28 );
2875 mod = 0; // turns off the sprite (unfortunately, disables dlight)
2876 }
2877 // LEILEI END enhancement
2878
2879 break;
2880 //#endif
2881 case WP_GRENADE_LAUNCHER:
2882 mod = cgs.media.dishFlashModel;
2883 shader = cgs.media.grenadeExplosionShader;
2884 sfx = cgs.media.sfx_rockexp;
2885 mark = cgs.media.burnMarkShader;
2886 radius = 64;
2887 light = 300;
2888 isSprite = qtrue;
2889 // LEILEI START enhancement
2890 if (cg_leiEnhancement.integer) {
2891 // some more fireball, fireball, fireball, fire fire!
2892 VectorMA( origin, 24, dir, sprOrg );
2893 VectorScale( dir, 64, sprVel );
2894 lightColor[0] = 0.7; // subtler explosion colors
2895 lightColor[1] = 0.6;
2896 lightColor[2] = 0.4;
2897 VectorMA( origin, 4, dir, sprOrg );
2898 VectorScale( dir, 2, sprVel );
2899 VectorMA( origin, 4, dir, sprOrg );
2900 VectorScale( dir, 42, sprVel );
2901 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 700, 10, 108 );
2902 VectorMA( origin, 4, dir, sprOrg );
2903 VectorScale( dir, 82, sprVel );
2904 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 400, 11, 158 );
2905 VectorMA( origin, -5, dir, sprOrg );
2906 VectorScale( dir, 182, sprVel );
2907 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 600, 47, 88 );
2908 VectorMA( origin, -5, dir, sprOrg );
2909 VectorScale( dir, 64, sprVel );
2910 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 110, 72, 28 );
2911 mod = 0; // turns off the sprite (unfortunately, disables dlight)
2912 }
2913 // LEILEI END enhancement
2914 break;
2915 case WP_ROCKET_LAUNCHER:
2916 mod = cgs.media.dishFlashModel;
2917 shader = cgs.media.rocketExplosionShader;
2918 sfx = cgs.media.sfx_rockexp;
2919 mark = cgs.media.burnMarkShader;
2920 radius = 64;
2921 light = 300;
2922 isSprite = qtrue;
2923 duration = 1000;
2924 lightColor[0] = 1;
2925 lightColor[1] = 0.75;
2926 lightColor[2] = 0.0;
2927 if (!cg_oldRocket.integer) {
2928 // explosion sprite animation
2929 VectorMA( origin, 24, dir, sprOrg );
2930 VectorScale( dir, 64, sprVel );
2931
2932 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 1400, 20, 30 );
2933 }
2934 // LEILEI START enhancement
2935 if (cg_leiEnhancement.integer) {
2936 // some more fireball, fireball, fireball, fire fire!
2937 VectorMA( origin, 24, dir, sprOrg );
2938 VectorScale( dir, 64, sprVel );
2939 lightColor[0] = 0.7; // subtler explosion colors
2940 lightColor[1] = 0.6;
2941 lightColor[2] = 0.4;
2942 VectorMA( origin, 4, dir, sprOrg );
2943 VectorScale( dir, 2, sprVel );
2944 VectorMA( origin, 4, dir, sprOrg );
2945 VectorScale( dir, 42, sprVel );
2946 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 700, 10, 108 );
2947 VectorMA( origin, 4, dir, sprOrg );
2948 VectorScale( dir, 82, sprVel );
2949 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 400, 11, 158 );
2950 VectorMA( origin, -5, dir, sprOrg );
2951 VectorScale( dir, 182, sprVel );
2952 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 600, 47, 88 );
2953 VectorMA( origin, -5, dir, sprOrg );
2954 VectorScale( dir, 64, sprVel );
2955 CG_ParticleExplosion( "explode1", sprOrg, sprVel, 110, 72, 28 );
2956 mod = 0; // turns off the sprite (unfortunately, disables dlight)
2957 }
2958 // LEILEI END enhancement
2959 break;
2960 case WP_RAILGUN:
2961 mod = cgs.media.ringFlashModel;
2962 shader = cgs.media.railExplosionShader;
2963 sfx = cgs.media.sfx_plasmaexp;
2964 mark = cgs.media.energyMarkShader;
2965 radius = 24;
2966 break;
2967 case WP_PLASMAGUN:
2968 mod = cgs.media.ringFlashModel;
2969 shader = cgs.media.plasmaExplosionShader;
2970 sfx = cgs.media.sfx_plasmaexp;
2971 mark = cgs.media.energyMarkShader;
2972 radius = 16;
2973 break;
2974 case WP_BFG:
2975 mod = cgs.media.dishFlashModel;
2976 shader = cgs.media.bfgExplosionShader;
2977 sfx = cgs.media.sfx_rockexp;
2978 mark = cgs.media.burnMarkShader;
2979 radius = 32;
2980 isSprite = qtrue;
2981 break;
2982 case WP_SHOTGUN:
2983 mod = cgs.media.bulletFlashModel;
2984 shader = cgs.media.bulletExplosionShader;
2985 mark = cgs.media.bulletMarkShader;
2986 #if 0
2987 //Some problems here
2988 if (cg_leiEnhancement.integer) {
2989 if( soundType == IMPACTSOUND_FLESH ) {
2990 mark = cgs.media.lbldShader2;
2991 } else if( soundType == IMPACTSOUND_METAL ) {
2992 r = rand() & 4; if ( r < 3 ) { mark = cgs.media.lmarkmetal1;
2993 } else if ( r == 2 ) { mark = cgs.media.lmarkmetal2;
2994 } else if ( r == 1 ) { mark = cgs.media.lmarkmetal3;
2995 } else { mark = cgs.media.lmarkmetal4; }
2996 } else {
2997 r = rand() & 4; if ( r < 3 ) { mark = cgs.media.lmarkbullet1;
2998 } else if ( r == 2 ) { mark = cgs.media.lmarkbullet2;
2999 } else if ( r == 1 ) { mark = cgs.media.lmarkbullet3;
3000 } else { mark = cgs.media.lmarkbullet4;
3001 } }
3002 }
3003 #endif
3004 sfx = 0;
3005 radius = 4;
3006 break;
3007
3008 //#ifdef MISSIONPACK
3009 case WP_CHAINGUN:
3010 mod = cgs.media.bulletFlashModel;
3011 if( soundType == IMPACTSOUND_FLESH ) {
3012 sfx = cgs.media.sfx_chghitflesh;
3013 } else if( soundType == IMPACTSOUND_METAL ) {
3014 sfx = cgs.media.sfx_chghitmetal;
3015 } else {
3016 sfx = cgs.media.sfx_chghit;
3017 }
3018
3019 mark = cgs.media.bulletMarkShader;
3020 #if 0
3021 //Some problems here
3022 if (cg_leiEnhancement.integer) {
3023
3024 if( soundType == IMPACTSOUND_FLESH ) {
3025 mark = cgs.media.lbldShader2;
3026 } else if( soundType == IMPACTSOUND_METAL ) {
3027 r = rand() & 4; if ( r < 3 ) { mark = cgs.media.lmarkmetal1;
3028 } else if ( r == 2 ) { mark = cgs.media.lmarkmetal2;
3029 } else if ( r == 1 ) { mark = cgs.media.lmarkmetal3;
3030 } else { mark = cgs.media.lmarkmetal4; }
3031 } else {
3032 r = rand() & 4; if ( r < 3 ) { mark = cgs.media.lmarkbullet1;
3033 } else if ( r == 2 ) { mark = cgs.media.lmarkbullet2;
3034 } else if ( r == 1 ) { mark = cgs.media.lmarkbullet3;
3035 } else { mark = cgs.media.lmarkbullet4; }
3036 }
3037 }
3038 #endif
3039 r = rand() & 3;
3040 if ( r < 2 ) {
3041 sfx = cgs.media.sfx_ric1;
3042 } else if ( r == 2 ) {
3043 sfx = cgs.media.sfx_ric2;
3044 } else {
3045 sfx = cgs.media.sfx_ric3;
3046 }
3047
3048 radius = 8;
3049 break;
3050 //#endif
3051
3052 case WP_MACHINEGUN:
3053 mod = cgs.media.bulletFlashModel;
3054 shader = cgs.media.bulletExplosionShader;
3055 mark = cgs.media.bulletMarkShader;
3056 #if 0
3057 //Some problems here
3058 if (cg_leiEnhancement.integer) {
3059 if( soundType == IMPACTSOUND_FLESH ) {
3060 mark = cgs.media.lbldShader2;
3061 } else if( soundType == IMPACTSOUND_METAL ) {
3062 r = rand() & 4; if ( r < 3 ) { mark = cgs.media.lmarkmetal1;
3063 } else if ( r == 2 ) { mark = cgs.media.lmarkmetal2;
3064 } else if ( r == 1 ) { mark = cgs.media.lmarkmetal3;
3065 } else { mark = cgs.media.lmarkmetal4; }
3066 } else {
3067 r = rand() & 4; if ( r < 3 ) { mark = cgs.media.lmarkbullet1;
3068 } else if ( r == 2 ) { mark = cgs.media.lmarkbullet2;
3069 } else if ( r == 1 ) { mark = cgs.media.lmarkbullet3;
3070 } else { mark = cgs.media.lmarkbullet4;
3071 }
3072 VectorMA( origin, 4, dir, sprOrg );
3073 VectorScale( dir, 82, sprVel );
3074
3075 }
3076 }
3077 #endif
3078 r = rand() & 3;
3079 if ( r == 0 ) {
3080 sfx = cgs.media.sfx_ric1;
3081 } else if ( r == 1 ) {
3082 sfx = cgs.media.sfx_ric2;
3083 } else {
3084 sfx = cgs.media.sfx_ric3;
3085 }
3086
3087 radius = 8;
3088 break;
3089 }
3090
3091 if ( sfx ) {
3092 trap_S_StartSound( origin, ENTITYNUM_WORLD, CHAN_AUTO, sfx );
3093 }
3094
3095 //
3096 // create the explosion
3097 //
3098 if ( mod ) {
3099 le = CG_MakeExplosion( origin, dir,
3100 mod, shader,
3101 duration, isSprite );
3102 le->light = light;
3103 VectorCopy( lightColor, le->lightColor );
3104 if ( weapon == WP_RAILGUN ) {
3105 // colorize with client color
3106 VectorCopy( cgs.clientinfo[clientNum].color1, le->color );
3107 le->refEntity.shaderRGBA[0] = le->color[0] * 0xff;
3108 le->refEntity.shaderRGBA[1] = le->color[1] * 0xff;
3109 le->refEntity.shaderRGBA[2] = le->color[2] * 0xff;
3110 le->refEntity.shaderRGBA[3] = 0xff;
3111 }
3112 }
3113
3114 //
3115 // impact mark
3116 //
3117 alphaFade = (mark == cgs.media.energyMarkShader); // plasma fades alpha, all others fade color
3118 if ( weapon == WP_RAILGUN ) {
3119 float *color;
3120
3121 // colorize with client color
3122 color = cgs.clientinfo[clientNum].color1;
3123 CG_ImpactMark( mark, origin, dir, random()*360, color[0],color[1], color[2],1, alphaFade, radius, qfalse );
3124 } else {
3125 CG_ImpactMark( mark, origin, dir, random()*360, 1,1,1,1, alphaFade, radius, qfalse );
3126 }
3127 }
3128
3129
3130 /*
3131 =================
3132 CG_MissileHitPlayer
3133 =================
3134 */
3135 void CG_MissileHitPlayer( int weapon, vec3_t origin, vec3_t dir, int entityNum ) {
3136 // LEILEI ENHANCEMENT
3137 if (cg_leiEnhancement.integer) {
3138 CG_SmokePuff( origin, dir, 22, 1, 1, 1, 1.0f, 900, cg.time, 0, 0, cgs.media.lbldShader1 );
3139 CG_SpurtBlood( origin, dir, 1);
3140 // CG_SpurtBlood( origin, dir, 4);
3141 // CG_SpurtBlood( origin, dir, -12);
3142 }
3143
3144 else
3145 CG_Bleed( origin, entityNum );
3146
3147 // some weapons will make an explosion with the blood, while
3148 // others will just make the blood
3149 switch ( weapon ) {
3150 case WP_GRENADE_LAUNCHER:
3151 case WP_ROCKET_LAUNCHER:
3152 //#ifdef MISSIONPACK
3153 case WP_NAILGUN:
3154 case WP_CHAINGUN:
3155 case WP_PROX_LAUNCHER:
3156 //#endif
3157 CG_MissileHitWall( weapon, 0, origin, dir, IMPACTSOUND_FLESH );
3158 break;
3159 default:
3160 break;
3161 }
3162 }
3163
3164
3165
3166 /*
3167 ============================================================================
3168
3169 SHOTGUN TRACING
3170
3171 ============================================================================
3172 */
3173
3174 /*
3175 ================
3176 CG_ShotgunPellet
3177 ================
3178 */
3179 static void CG_ShotgunPellet( vec3_t start, vec3_t end, int skipNum ) {
3180 trace_t tr;
3181 int sourceContentType, destContentType;
3182
3183 // LEILEI ENHACNEMENT
3184 localEntity_t *smoke;
3185 vec3_t kapow;
3186
3187
3188
3189 CG_Trace( &tr, start, NULL, NULL, end, skipNum, MASK_SHOT );
3190
3191 sourceContentType = CG_PointContents( start, 0 );
3192 destContentType = CG_PointContents( tr.endpos, 0 );
3193
3194 // FIXME: should probably move this cruft into CG_BubbleTrail
3195 if ( sourceContentType == destContentType ) {
3196 if ( sourceContentType & CONTENTS_WATER ) {
3197 CG_BubbleTrail( start, tr.endpos, 32 );
3198 }
3199 } else if ( sourceContentType & CONTENTS_WATER ) {
3200 trace_t trace;
3201
3202 trap_CM_BoxTrace( &trace, end, start, NULL, NULL, 0, CONTENTS_WATER );
3203 CG_BubbleTrail( start, trace.endpos, 32 );
3204
3205 // LEILEI ENHANCEMENT
3206 if (cg_leiEnhancement.integer) {
3207 // Water Splash
3208 VectorCopy( trace.plane.normal, kapow );
3209
3210 kapow[0] = kapow[0] * (crandom() * 22);
3211 kapow[1] = kapow[1] * (crandom() * 22);
3212 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3213 smoke = CG_SmokePuff( trace.endpos, kapow, 14, 1, 1, 1, 1.0f, 400, cg.time, 0, 0, cgs.media.lsplShader );
3214 smoke = CG_SmokePuff( trace.endpos, kapow, 6, 1, 1, 1, 1.0f, 200, cg.time, 0, 0, cgs.media.lsplShader );
3215 smoke = CG_SmokePuff( trace.endpos, kapow, 10, 1, 1, 1, 1.0f, 300, cg.time, 0, 0, cgs.media.lsplShader );
3216
3217 }
3218 // END LEIHANCMENET
3219 } else if ( destContentType & CONTENTS_WATER ) {
3220 trace_t trace;
3221
3222 trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, CONTENTS_WATER );
3223 CG_BubbleTrail( tr.endpos, trace.endpos, 32 );
3224
3225 // LEILEI ENHANCEMENT
3226 if (cg_leiEnhancement.integer) {
3227 // Water Splash
3228 VectorCopy( trace.plane.normal, kapow );
3229
3230 kapow[0] = kapow[0] * (crandom() * 22);
3231 kapow[1] = kapow[1] * (crandom() * 22);
3232 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3233 smoke = CG_SmokePuff( trace.endpos, kapow, 14, 1, 1, 1, 1.0f, 400, cg.time, 0, 0, cgs.media.lsplShader );
3234 smoke = CG_SmokePuff( trace.endpos, kapow, 6, 1, 1, 1, 1.0f, 200, cg.time, 0, 0, cgs.media.lsplShader );
3235 smoke = CG_SmokePuff( trace.endpos, kapow, 10, 1, 1, 1, 1.0f, 300, cg.time, 0, 0, cgs.media.lsplShader );
3236 }
3237 // END LEIHANCMENET
3238 }
3239
3240 if ( tr.surfaceFlags & SURF_NOIMPACT ) {
3241 return;
3242 }
3243
3244 if ( cg_entities[tr.entityNum].currentState.eType == ET_PLAYER ) {
3245 CG_MissileHitPlayer( WP_SHOTGUN, tr.endpos, tr.plane.normal, tr.entityNum );
3246 } else {
3247 if ( tr.surfaceFlags & SURF_NOIMPACT ) {
3248 // SURF_NOIMPACT will not make a flame puff or a mark
3249 return;
3250 }
3251 if ( tr.surfaceFlags & SURF_METALSTEPS ) {
3252 CG_MissileHitWall( WP_SHOTGUN, 0, tr.endpos, tr.plane.normal, IMPACTSOUND_METAL );
3253 // LEILEI ENHANCEMENT
3254 if (cg_leiEnhancement.integer) {
3255 VectorCopy( tr.plane.normal, kapow );
3256
3257 kapow[0] = kapow[0] * (crandom() * 65 + 37);
3258 kapow[1] = kapow[1] * (crandom() * 65 + 37);
3259 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3260 CG_LeiSparks(tr.endpos, tr.plane.normal, 800, 0, 0, 7);
3261 CG_LeiSparks(tr.endpos, tr.plane.normal, 800, 0, 0, 3);
3262 CG_LeiSparks(tr.endpos, tr.plane.normal, 800, 0, 0, 1);
3263
3264 }
3265 // END LEIHANCMENET
3266 } else {
3267 CG_MissileHitWall( WP_SHOTGUN, 0, tr.endpos, tr.plane.normal, IMPACTSOUND_DEFAULT );
3268
3269 // LEILEI ENHANCEMENT
3270 if (cg_leiEnhancement.integer) {
3271 VectorCopy( tr.plane.normal, kapow );
3272
3273 kapow[0] = kapow[0] * (crandom() * 65 + 37);
3274 kapow[1] = kapow[1] * (crandom() * 65 + 37);
3275 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3276 CG_LeiSparks(tr.endpos, tr.plane.normal, 800, 0, 0, 7);
3277 CG_LeiSparks(tr.endpos, tr.plane.normal, 800, 0, 0, 2);
3278
3279 smoke = CG_SmokePuff( tr.endpos, kapow, 21, 1, 1, 1, 0.9f, 1200, cg.time, 0, 0, cgs.media.lsmkShader2 );
3280 //smoke = CG_SmokePuff( tr.endpos, kapow, 21, 1, 1, 1, 0.9f, 1200, cg.time, 0, 0, cgs.media.lbumShader1 );
3281 #if 0
3282 CG_LeiPuff(tr.endpos, kapow, 500, 0, 0, 177, 6);
3283 CG_LeiPuff(tr.endpos, tr.plane.normal, 500, 0, 0, 127, 12);
3284 CG_LeiPuff(tr.endpos, tr.plane.normal, 500, 0, 0, 77, 16);
3285 CG_LeiPuff(tr.endpos, tr.plane.normal, 500, 0, 0, 127, 12);
3286 CG_LeiPuff(tr.endpos, tr.plane.normal, 500, 0, 0, 77, 16);
3287 CG_LeiPuff(tr.endpos, tr.plane.normal, 500, 0, 0, 127, 12);
3288 CG_LeiPuff(tr.endpos, tr.plane.normal, 500, 0, 0, 77, 16);
3289 #endif
3290 }
3291 // END LEIHANCMENET
3292 }
3293 }
3294 }
3295
3296 /*
3297 ================
3298 CG_ShotgunPattern
3299
3300 Perform the same traces the server did to locate the
3301 hit splashes
3302 ================
3303 */
3304 //unlagged - attack prediction
3305 // made this non-static for access from cg_unlagged.c
3306 void CG_ShotgunPattern( vec3_t origin, vec3_t origin2, int seed, int otherEntNum ) {
3307 int i;
3308 float r, u;
3309 vec3_t end;
3310 vec3_t forward, right, up;
3311
3312 // derive the right and up vectors from the forward vector, because
3313 // the client won't have any other information
3314 VectorNormalize2( origin2, forward );
3315 PerpendicularVector( right, forward );
3316 CrossProduct( forward, right, up );
3317
3318 // generate the "random" spread pattern
3319 for ( i = 0 ; i < DEFAULT_SHOTGUN_COUNT ; i++ ) {
3320 r = Q_crandom( &seed ) * DEFAULT_SHOTGUN_SPREAD * 16;
3321 u = Q_crandom( &seed ) * DEFAULT_SHOTGUN_SPREAD * 16;
3322 VectorMA( origin, 8192 * 16, forward, end);
3323 VectorMA (end, r, right, end);
3324 VectorMA (end, u, up, end);
3325
3326 CG_ShotgunPellet( origin, end, otherEntNum );
3327 }
3328 }
3329
3330 /*
3331 ==============
3332 CG_ShotgunFire
3333 ==============
3334 */
3335 void CG_ShotgunFire( entityState_t *es ) {
3336 vec3_t v;
3337 int contents;
3338
3339 VectorSubtract( es->origin2, es->pos.trBase, v );
3340 VectorNormalize( v );
3341 VectorScale( v, 32, v );
3342 VectorAdd( es->pos.trBase, v, v );
3343 if ( cgs.glconfig.hardwareType != GLHW_RAGEPRO ) {
3344 // ragepro can't alpha fade, so don't even bother with smoke
3345 vec3_t up;
3346 vec3_t forward;
3347
3348 contents = CG_PointContents( es->pos.trBase, 0 );
3349 if ( !( contents & CONTENTS_WATER ) ) {
3350 VectorSet( up, 0, 0, 8 );
3351 // LEILEI ENHANCEMENT
3352 if (cg_leiEnhancement.integer) {
3353 // Shotgun puffy
3354 CG_LeiSparks(v, forward, 1500, 0, 0, 7);
3355 CG_LeiSparks(v, forward, 1500, 0, 0, 7);
3356 CG_LeiSparks(v, forward, 1500, 0, 0, 7);
3357 CG_LeiSparks(v, forward, 1500, 0, 0, 7);
3358 CG_LeiSparks(v, forward, 1500, 0, 0, 7);
3359 CG_LeiSparks(v, forward, 1500, 0, 0, 7);
3360 /* VectorSet( up, 4, 4, 4 );
3361 up[0] = up[0] * (crandom() * 22 + 44); up[1] = up[1] * (crandom() * 22 + 44); up[2] = up[2] * (crandom() * 22 + 44);
3362 CG_SmokePuff( v, up, 14, 1, 1, 1, 0.4f, 900, cg.time, 0, 0, cgs.media.lsmkShader1 );
3363 up[0] = up[0] * (crandom() * 22 + 44); up[1] = up[1] * (crandom() * 22 + 44); up[2] = up[2] * (crandom() * 22 + 44);
3364 CG_SmokePuff( v, up, 14, 1, 1, 1, 0.4f, 900, cg.time, 0, 0, cgs.media.lsmkShader2 );
3365 up[0] = up[0] * (crandom() * 22 + 44); up[1] = up[1] * (crandom() * 22 + 44); up[2] = up[2] * (crandom() * 22 + 44);
3366 CG_SmokePuff( v, up, 14, 1, 1, 1, 0.4f, 900, cg.time, 0, 0, cgs.media.lsmkShader3 );
3367 up[0] = up[0] * (crandom() * 22 + 44); up[1] = up[1] * (crandom() * 22 + 44); up[2] = up[2] * (crandom() * 22 + 44);
3368 CG_SmokePuff( v, up, 14, 1, 1, 1, 0.4f, 900, cg.time, 0, 0, cgs.media.lsmkShader4 );
3369 */
3370 }
3371 else
3372
3373 // END LEIHANCMENET
3374
3375 CG_SmokePuff( v, up, 32, 1, 1, 1, 0.33f, 900, cg.time, 0, LEF_PUFF_DONT_SCALE, cgs.media.shotgunSmokePuffShader );
3376
3377 }
3378 }
3379 CG_ShotgunPattern( es->pos.trBase, es->origin2, es->eventParm, es->otherEntityNum );
3380 }
3381
3382 /*
3383 ============================================================================
3384
3385 BULLETS
3386
3387 ============================================================================
3388 */
3389
3390
3391 /*
3392 ===============
3393 CG_Tracer
3394 ===============
3395 */
3396 void CG_Tracer( vec3_t source, vec3_t dest ) {
3397 vec3_t forward, right;
3398 polyVert_t verts[4];
3399 vec3_t line;
3400 float len, begin, end;
3401 vec3_t start, finish;
3402 vec3_t midpoint;
3403
3404 // tracer
3405 VectorSubtract( dest, source, forward );
3406 len = VectorNormalize( forward );
3407
3408 // start at least a little ways from the muzzle
3409 if ( len < 100 ) {
3410 return;
3411 }
3412 begin = 50 + random() * (len - 60);
3413 end = begin + cg_tracerLength.value;
3414 if ( end > len ) {
3415 end = len;
3416 }
3417 VectorMA( source, begin, forward, start );
3418 VectorMA( source, end, forward, finish );
3419
3420 line[0] = DotProduct( forward, cg.refdef.viewaxis[1] );
3421 line[1] = DotProduct( forward, cg.refdef.viewaxis[2] );
3422
3423 VectorScale( cg.refdef.viewaxis[1], line[1], right );
3424 VectorMA( right, -line[0], cg.refdef.viewaxis[2], right );
3425 VectorNormalize( right );
3426
3427 VectorMA( finish, cg_tracerWidth.value, right, verts[0].xyz );
3428 verts[0].st[0] = 0;
3429 verts[0].st[1] = 1;
3430 verts[0].modulate[0] = 255;
3431 verts[0].modulate[1] = 255;
3432 verts[0].modulate[2] = 255;
3433 verts[0].modulate[3] = 255;
3434
3435 VectorMA( finish, -cg_tracerWidth.value, right, verts[1].xyz );
3436 verts[1].st[0] = 1;
3437 verts[1].st[1] = 0;
3438 verts[1].modulate[0] = 255;
3439 verts[1].modulate[1] = 255;
3440 verts[1].modulate[2] = 255;
3441 verts[1].modulate[3] = 255;
3442
3443 VectorMA( start, -cg_tracerWidth.value, right, verts[2].xyz );
3444 verts[2].st[0] = 1;
3445 verts[2].st[1] = 1;
3446 verts[2].modulate[0] = 255;
3447 verts[2].modulate[1] = 255;
3448 verts[2].modulate[2] = 255;
3449 verts[2].modulate[3] = 255;
3450
3451 VectorMA( start, cg_tracerWidth.value, right, verts[3].xyz );
3452 verts[3].st[0] = 0;
3453 verts[3].st[1] = 0;
3454 verts[3].modulate[0] = 255;
3455 verts[3].modulate[1] = 255;
3456 verts[3].modulate[2] = 255;
3457 verts[3].modulate[3] = 255;
3458
3459 trap_R_AddPolyToScene( cgs.media.tracerShader, 4, verts );
3460
3461 midpoint[0] = ( start[0] + finish[0] ) * 0.5;
3462 midpoint[1] = ( start[1] + finish[1] ) * 0.5;
3463 midpoint[2] = ( start[2] + finish[2] ) * 0.5;
3464
3465 // add the tracer sound
3466 trap_S_StartSound( midpoint, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.tracerSound );
3467
3468 }
3469
3470
3471 /*
3472 ======================
3473 CG_CalcMuzzlePoint
3474 ======================
3475 */
3476 static qboolean CG_CalcMuzzlePoint( int entityNum, vec3_t muzzle ) {
3477 vec3_t forward;
3478 centity_t *cent;
3479 int anim;
3480
3481 if ( entityNum == cg.snap->ps.clientNum ) {
3482 VectorCopy( cg.snap->ps.origin, muzzle );
3483 muzzle[2] += cg.snap->ps.viewheight;
3484 AngleVectors( cg.snap->ps.viewangles, forward, NULL, NULL );
3485 VectorMA( muzzle, 14, forward, muzzle );
3486 return qtrue;
3487 }
3488
3489 cent = &cg_entities[entityNum];
3490 if ( !cent->currentValid ) {
3491 return qfalse;
3492 }
3493
3494 VectorCopy( cent->currentState.pos.trBase, muzzle );
3495
3496 AngleVectors( cent->currentState.apos.trBase, forward, NULL, NULL );
3497 anim = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT;
3498 if ( anim == LEGS_WALKCR || anim == LEGS_IDLECR ) {
3499 muzzle[2] += CROUCH_VIEWHEIGHT;
3500 } else {
3501 muzzle[2] += DEFAULT_VIEWHEIGHT;
3502 }
3503
3504 VectorMA( muzzle, 14, forward, muzzle );
3505
3506 return qtrue;
3507
3508 }
3509
3510 /*
3511 ======================
3512 CG_Bullet
3513
3514 Renders bullet effects.
3515 ======================
3516 */
3517 void CG_Bullet( vec3_t end, int sourceEntityNum, vec3_t normal, qboolean flesh, int fleshEntityNum ) {
3518 trace_t trace;
3519 int sourceContentType, destContentType;
3520 vec3_t start;
3521 // LEILEI ENHACNEMENT
3522 localEntity_t *smoke;
3523 vec3_t kapew;
3524 vec3_t kapow;
3525
3526
3527
3528
3529 // if the shooter is currently valid, calc a source point and possibly
3530 // do trail effects
3531 if ( sourceEntityNum >= 0 && cg_tracerChance.value > 0 ) {
3532 if ( CG_CalcMuzzlePoint( sourceEntityNum, start ) ) {
3533 sourceContentType = CG_PointContents( start, 0 );
3534 destContentType = CG_PointContents( end, 0 );
3535
3536 // do a complete bubble trail if necessary
3537 if ( ( sourceContentType == destContentType ) && ( sourceContentType & CONTENTS_WATER ) ) {
3538 CG_BubbleTrail( start, end, 32 );
3539 }
3540 // bubble trail from water into air
3541 else if ( ( sourceContentType & CONTENTS_WATER ) ) {
3542 trap_CM_BoxTrace( &trace, end, start, NULL, NULL, 0, CONTENTS_WATER );
3543 CG_BubbleTrail( start, trace.endpos, 32 );
3544
3545
3546 // LEILEI ENHANCEMENT
3547 if (cg_leiEnhancement.integer) {
3548 // Water Splash
3549 VectorCopy( trace.plane.normal, kapow );
3550 kapow[0] = kapow[0] * (crandom() * 22);
3551 kapow[1] = kapow[1] * (crandom() * 22);
3552 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3553 smoke = CG_SmokePuff( trace.endpos, kapow, 14, 1, 1, 1, 1.0f, 400, cg.time, 0, 0, cgs.media.lsplShader );
3554 smoke = CG_SmokePuff( trace.endpos, kapow, 6, 1, 1, 1, 1.0f, 200, cg.time, 0, 0, cgs.media.lsplShader );
3555 smoke = CG_SmokePuff( trace.endpos, kapow, 10, 1, 1, 1, 1.0f, 300, cg.time, 0, 0, cgs.media.lsplShader );
3556 // CG_LeiSplash2(trace.endpos, kapow, 900, 0, 0, 444);
3557
3558 }
3559 // END LEIHANCMENET
3560
3561
3562 }
3563 // bubble trail from air into water
3564 else if ( ( destContentType & CONTENTS_WATER ) ) {
3565 trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, CONTENTS_WATER );
3566 CG_BubbleTrail( trace.endpos, end, 32 );
3567
3568 // LEILEI ENHANCEMENT
3569 if (cg_leiEnhancement.integer) {
3570 // Water Splash
3571 VectorCopy( trace.plane.normal, kapow );
3572
3573 kapow[0] = kapow[0] * (crandom() * 22);
3574 kapow[1] = kapow[1] * (crandom() * 22);
3575 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3576 smoke = CG_SmokePuff( trace.endpos, kapow, 14, 1, 1, 1, 1.0f, 400, cg.time, 0, 0, cgs.media.lsplShader );
3577 smoke = CG_SmokePuff( trace.endpos, kapow, 6, 1, 1, 1, 1.0f, 200, cg.time, 0, 0, cgs.media.lsplShader );
3578 smoke = CG_SmokePuff( trace.endpos, kapow, 10, 1, 1, 1, 1.0f, 300, cg.time, 0, 0, cgs.media.lsplShader );
3579 //CG_LeiSplash2(trace.endpos, kapow, 500, 0, 0, 1);
3580 }
3581 // END LEIHANCMENET
3582 }
3583
3584 // draw a tracer
3585 if ( random() < cg_tracerChance.value ) {
3586 CG_Tracer( start, end );
3587 }
3588 }
3589 }
3590
3591 // impact splash and mark
3592 if ( flesh ) {
3593 // LEILEI ENHANCEMENT
3594 if (cg_leiEnhancement.integer) {
3595
3596
3597 // Blood Hack
3598 VectorCopy( normal, kapow );
3599
3600 kapow[0] = kapow[0] * (crandom() * 65 + 37);
3601 kapow[1] = kapow[1] * (crandom() * 65 + 37);
3602 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3603 VectorCopy( kapow, kapew );
3604
3605 kapew[0] = kapew[0] * (crandom() * 2 + 37);
3606 kapew[1] = kapew[1] * (crandom() * 2 + 37);
3607 kapew[2] = kapew[2] * (crandom() * 2 + 37);
3608
3609 CG_SmokePuff( end, kapow, 6, 1, 1, 1, 1.0f, 600, cg.time, 0, 0, cgs.media.lbldShader1 );
3610 // CG_SpurtBlood( end, kapow, 2);
3611 CG_SpurtBlood( end, kapew, 1);
3612 //CG_Particle_Bleed(cgs.media.lbldShader1,kapew,'0 0 0', 0, 100);
3613 // CG_Particle_Bleed(cgs.media.lbldShader1,kapew,kapow, 0, 100);
3614 // CG_Particle_BloodCloud(self,end,'0 0 0');
3615
3616 if (cg_leiSuperGoreyAwesome.integer) {
3617 CG_SpurtBlood( end, kapow, -2);
3618 }
3619 }
3620
3621 else
3622 CG_Bleed( end, fleshEntityNum );
3623 } else {
3624 CG_MissileHitWall( WP_MACHINEGUN, 0, end, normal, IMPACTSOUND_DEFAULT );
3625
3626 // LEILEI ENHANCEMENT
3627 if (cg_leiEnhancement.integer) {
3628
3629 // Smoke puff
3630 VectorCopy( normal, kapow );
3631
3632 kapow[0] = kapow[0] * (crandom() * 65 + 37);
3633 kapow[1] = kapow[1] * (crandom() * 65 + 37);
3634 kapow[2] = kapow[2] * (crandom() * 65 + 37);
3635 VectorCopy( kapow, kapew );
3636
3637 kapew[0] = kapew[0] * (crandom() * 65 + 37);
3638 kapew[1] = kapew[1] * (crandom() * 65 + 37);
3639 kapew[2] = kapew[2] * (crandom() * 65 + 37);
3640
3641
3642 smoke = CG_SmokePuff( end, kapow, 14, 1, 1, 1, 1.0f, 600, cg.time, 0, 0, cgs.media.lsmkShader1 );
3643 // CG_LeiSparks(end, normal, 600, 0, 0, 177);
3644 // CG_LeiSparks(end, normal, 600, 0, 0, 155);
3645 // CG_LeiSparks(end, normal, 600, 0, 0, 444);
3646 // CG_LeiSparks(trace.endpos, trace.plane.normal, 800, 0, 0, 7);
3647 // CG_LeiSparks(trace.endpos, trace.plane.normal, 800, 0, 0, 3);
3648 // CG_LeiSparks(trace.endpos, trace.plane.normal, 800, 0, 0, 1);
3649
3650 }
3651 // END LEIHANCMENET
3652 }
3653
3654 }