Debian Codegraph @

code/cgame/cg_weapons.c

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