Debian Codegraph @

code/game/g_weapon.c

raw symbols SCIP
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 // g_weapon.c
24 // perform the server side effects of a weapon firing
25
26 #include "g_local.h"
27
28 static float s_quadFactor;
29 static vec3_t forward, right, up;
30 static vec3_t muzzle;
31
32 #define NUM_NAILSHOTS 15
33
34 /*
35 ================
36 G_BounceProjectile
37 ================
38 */
39 void G_BounceProjectile( vec3_t start, vec3_t impact, vec3_t dir, vec3_t endout ) {
40 vec3_t v, newv;
41 float dot;
42
43 VectorSubtract( impact, start, v );
44 dot = DotProduct( v, dir );
45 VectorMA( v, -2*dot, dir, newv );
46
47 VectorNormalize(newv);
48 VectorMA(impact, 8192, newv, endout);
49 }
50
51
52 /*
53 ======================================================================
54
55 GAUNTLET
56
57 ======================================================================
58 */
59
60 void Weapon_Gauntlet( gentity_t *ent ) {
61
62 }
63
64 /*
65 ===============
66 CheckGauntletAttack
67 ===============
68 */
69 qboolean CheckGauntletAttack( gentity_t *ent ) {
70 trace_t tr;
71 vec3_t end;
72 gentity_t *tent;
73 gentity_t *traceEnt;
74 int damage;
75
76 // set aiming directions
77 AngleVectors (ent->client->ps.viewangles, forward, right, up);
78
79 CalcMuzzlePoint ( ent, forward, right, up, muzzle );
80
81 VectorMA (muzzle, 32, forward, end);
82
83 trap_Trace (&tr, muzzle, NULL, NULL, end, ent->s.number, MASK_SHOT);
84 if ( tr.surfaceFlags & SURF_NOIMPACT ) {
85 return qfalse;
86 }
87
88 if ( ent->client->noclip ) {
89 return qfalse;
90 }
91
92 traceEnt = &g_entities[ tr.entityNum ];
93
94 // send blood impact
95 if ( traceEnt->takedamage && traceEnt->client ) {
96 tent = G_TempEntity( tr.endpos, EV_MISSILE_HIT );
97 tent->s.otherEntityNum = traceEnt->s.number;
98 tent->s.eventParm = DirToByte( tr.plane.normal );
99 tent->s.weapon = ent->s.weapon;
100 }
101
102 if ( !traceEnt->takedamage) {
103 return qfalse;
104 }
105
106 if (ent->client->ps.powerups[PW_QUAD] ) {
107 G_AddEvent( ent, EV_POWERUP_QUAD, 0 );
108 s_quadFactor = g_quadfactor.value;
109 } else {
110 s_quadFactor = 1;
111 }
112 #ifdef MISSIONPACK
113 if( ent->client->persistantPowerup && ent->client->persistantPowerup->item && ent->client->persistantPowerup->item->giTag == PW_DOUBLER ) {
114 s_quadFactor *= 2;
115 }
116 #endif
117
118 damage = 50 * s_quadFactor;
119 G_Damage( traceEnt, ent, ent, forward, tr.endpos,
120 damage, 0, MOD_GAUNTLET );
121
122 return qtrue;
123 }
124
125
126 /*
127 ======================================================================
128
129 MACHINEGUN
130
131 ======================================================================
132 */
133
134 /*
135 ======================
136 SnapVectorTowards
137
138 Round a vector to integers for more efficient network
139 transmission, but make sure that it rounds towards a given point
140 rather than blindly truncating. This prevents it from truncating
141 into a wall.
142 ======================
143 */
144 void SnapVectorTowards( vec3_t v, vec3_t to ) {
145 int i;
146
147 for ( i = 0 ; i < 3 ; i++ ) {
148 if ( to[i] <= v[i] ) {
149 v[i] = floor(v[i]);
150 } else {
151 v[i] = ceil(v[i]);
152 }
153 }
154 }
155
156 #ifdef MISSIONPACK
157 #define CHAINGUN_SPREAD 600
158 #define CHAINGUN_DAMAGE 7
159 #endif
160 #define MACHINEGUN_SPREAD 200
161 #define MACHINEGUN_DAMAGE 7
162 #define MACHINEGUN_TEAM_DAMAGE 5 // wimpier MG in teamplay
163
164 void Bullet_Fire (gentity_t *ent, float spread, int damage, int mod ) {
165 trace_t tr;
166 vec3_t end;
167 #ifdef MISSIONPACK
168 vec3_t impactpoint, bouncedir;
169 #endif
170 float r;
171 float u;
172 gentity_t *tent;
173 gentity_t *traceEnt;
174 int i, passent;
175
176 damage *= s_quadFactor;
177
178 r = random() * M_PI * 2.0f;
179 u = sin(r) * crandom() * spread * 16;
180 r = cos(r) * crandom() * spread * 16;
181 VectorMA (muzzle, 8192*16, forward, end);
182 VectorMA (end, r, right, end);
183 VectorMA (end, u, up, end);
184
185 passent = ent->s.number;
186 for (i = 0; i < 10; i++) {
187
188 trap_Trace (&tr, muzzle, NULL, NULL, end, passent, MASK_SHOT);
189 if ( tr.surfaceFlags & SURF_NOIMPACT ) {
190 return;
191 }
192
193 traceEnt = &g_entities[ tr.entityNum ];
194
195 // snap the endpos to integers, but nudged towards the line
196 SnapVectorTowards( tr.endpos, muzzle );
197
198 // send bullet impact
199 if ( traceEnt->takedamage && traceEnt->client ) {
200 tent = G_TempEntity( tr.endpos, EV_BULLET_HIT_FLESH );
201 tent->s.eventParm = traceEnt->s.number;
202 if( LogAccuracyHit( traceEnt, ent ) ) {
203 ent->client->accuracy_hits++;
204 }
205 } else {
206 tent = G_TempEntity( tr.endpos, EV_BULLET_HIT_WALL );
207 tent->s.eventParm = DirToByte( tr.plane.normal );
208 }
209 tent->s.otherEntityNum = ent->s.number;
210
211 if ( traceEnt->takedamage) {
212 #ifdef MISSIONPACK
213 if ( traceEnt->client && traceEnt->client->invulnerabilityTime > level.time ) {
214 if (G_InvulnerabilityEffect( traceEnt, forward, tr.endpos, impactpoint, bouncedir )) {
215 G_BounceProjectile( muzzle, impactpoint, bouncedir, end );
216 VectorCopy( impactpoint, muzzle );
217 // the player can hit him/herself with the bounced rail
218 passent = ENTITYNUM_NONE;
219 }
220 else {
221 VectorCopy( tr.endpos, muzzle );
222 passent = traceEnt->s.number;
223 }
224 continue;
225 }
226 else {
227 #endif
228 G_Damage( traceEnt, ent, ent, forward, tr.endpos,
229 damage, 0, mod);
230 #ifdef MISSIONPACK
231 }
232 #endif
233 }
234 break;
235 }
236 }
237
238
239 /*
240 ======================================================================
241
242 BFG
243
244 ======================================================================
245 */
246
247 void BFG_Fire ( gentity_t *ent ) {
248 gentity_t *m;
249
250 m = fire_bfg (ent, muzzle, forward);
251 m->damage *= s_quadFactor;
252 m->splashDamage *= s_quadFactor;
253
254 // VectorAdd( m->s.pos.trDelta, ent->client->ps.velocity, m->s.pos.trDelta ); // "real" physics
255 }
256
257
258 /*
259 ======================================================================
260
261 SHOTGUN
262
263 ======================================================================
264 */
265
266 // DEFAULT_SHOTGUN_SPREAD and DEFAULT_SHOTGUN_COUNT are in bg_public.h, because
267 // client predicts same spreads
268 #define DEFAULT_SHOTGUN_DAMAGE 10
269
270 qboolean ShotgunPellet( vec3_t start, vec3_t end, gentity_t *ent ) {
271 trace_t tr;
272 int damage, i, passent;
273 gentity_t *traceEnt;
274 #ifdef MISSIONPACK
275 vec3_t impactpoint, bouncedir;
276 #endif
277 vec3_t tr_start, tr_end;
278 qboolean hitClient = qfalse;
279
280 passent = ent->s.number;
281 VectorCopy( start, tr_start );
282 VectorCopy( end, tr_end );
283 for (i = 0; i < 10; i++) {
284 trap_Trace (&tr, tr_start, NULL, NULL, tr_end, passent, MASK_SHOT);
285 traceEnt = &g_entities[ tr.entityNum ];
286
287 // send bullet impact
288 if ( tr.surfaceFlags & SURF_NOIMPACT ) {
289 return qfalse;
290 }
291
292 if ( traceEnt->takedamage) {
293 damage = DEFAULT_SHOTGUN_DAMAGE * s_quadFactor;
294 #ifdef MISSIONPACK
295 if ( traceEnt->client && traceEnt->client->invulnerabilityTime > level.time ) {
296 if (G_InvulnerabilityEffect( traceEnt, forward, tr.endpos, impactpoint, bouncedir )) {
297 G_BounceProjectile( tr_start, impactpoint, bouncedir, tr_end );
298 VectorCopy( impactpoint, tr_start );
299 // the player can hit him/herself with the bounced rail
300 passent = ENTITYNUM_NONE;
301 }
302 else {
303 VectorCopy( tr.endpos, tr_start );
304 passent = traceEnt->s.number;
305 }
306 continue;
307 }
308 #endif
309 if( LogAccuracyHit( traceEnt, ent ) ) {
310 hitClient = qtrue;
311 }
312 G_Damage( traceEnt, ent, ent, forward, tr.endpos, damage, 0, MOD_SHOTGUN);
313 return hitClient;
314 }
315 return qfalse;
316 }
317 return qfalse;
318 }
319
320 // this should match CG_ShotgunPattern
321 void ShotgunPattern( vec3_t origin, vec3_t origin2, int seed, gentity_t *ent ) {
322 int i;
323 float r, u;
324 vec3_t end;
325 vec3_t localForward, localRight, localUp;
326 qboolean hitClient = qfalse;
327
328 // derive the right and up vectors from the forward vector, because
329 // the client won't have any other information
330 VectorNormalize2( origin2, localForward );
331 PerpendicularVector( localRight, localForward );
332 CrossProduct( localForward, localRight, localUp );
333
334 // generate the "random" spread pattern
335 for ( i = 0 ; i < DEFAULT_SHOTGUN_COUNT ; i++ ) {
336 r = Q_crandom( &seed ) * DEFAULT_SHOTGUN_SPREAD * 16;
337 u = Q_crandom( &seed ) * DEFAULT_SHOTGUN_SPREAD * 16;
338 VectorMA( origin, 8192 * 16, localForward, end);
339 VectorMA (end, r, localRight, end);
340 VectorMA (end, u, localUp, end);
341 if( ShotgunPellet( origin, end, ent ) && !hitClient ) {
342 hitClient = qtrue;
343 ent->client->accuracy_hits++;
344 }
345 }
346 }
347
348
349 void weapon_supershotgun_fire (gentity_t *ent) {
350 gentity_t *tent;
351
352 // send shotgun blast
353 tent = G_TempEntity( muzzle, EV_SHOTGUN );
354 VectorScale( forward, 4096, tent->s.origin2 );
355 SnapVector( tent->s.origin2 );
356 tent->s.eventParm = rand() & 255; // seed for spread pattern
357 tent->s.otherEntityNum = ent->s.number;
358
359 ShotgunPattern( tent->s.pos.trBase, tent->s.origin2, tent->s.eventParm, ent );
360 }
361
362
363 /*
364 ======================================================================
365
366 GRENADE LAUNCHER
367
368 ======================================================================
369 */
370
371 void weapon_grenadelauncher_fire (gentity_t *ent) {
372 gentity_t *m;
373
374 // extra vertical velocity
375 forward[2] += 0.2f;
376 VectorNormalize( forward );
377
378 m = fire_grenade (ent, muzzle, forward);
379 m->damage *= s_quadFactor;
380 m->splashDamage *= s_quadFactor;
381
382 // VectorAdd( m->s.pos.trDelta, ent->client->ps.velocity, m->s.pos.trDelta ); // "real" physics
383 }
384
385 /*
386 ======================================================================
387
388 ROCKET
389
390 ======================================================================
391 */
392
393 void Weapon_RocketLauncher_Fire (gentity_t *ent) {
394 gentity_t *m;
395
396 m = fire_rocket (ent, muzzle, forward);
397 m->damage *= s_quadFactor;
398 m->splashDamage *= s_quadFactor;
399
400 // VectorAdd( m->s.pos.trDelta, ent->client->ps.velocity, m->s.pos.trDelta ); // "real" physics
401 }
402
403
404 /*
405 ======================================================================
406
407 PLASMA GUN
408
409 ======================================================================
410 */
411
412 void Weapon_Plasmagun_Fire (gentity_t *ent) {
413 gentity_t *m;
414
415 m = fire_plasma (ent, muzzle, forward);
416 m->damage *= s_quadFactor;
417 m->splashDamage *= s_quadFactor;
418
419 // VectorAdd( m->s.pos.trDelta, ent->client->ps.velocity, m->s.pos.trDelta ); // "real" physics
420 }
421
422 /*
423 ======================================================================
424
425 RAILGUN
426
427 ======================================================================
428 */
429
430
431 /*
432 =================
433 weapon_railgun_fire
434 =================
435 */
436 #define MAX_RAIL_HITS 4
437 void weapon_railgun_fire (gentity_t *ent) {
438 vec3_t end;
439 #ifdef MISSIONPACK
440 vec3_t impactpoint, bouncedir;
441 #endif
442 trace_t trace;
443 gentity_t *tent;
444 gentity_t *traceEnt;
445 int damage;
446 int i;
447 int hits;
448 int unlinked;
449 int passent;
450 gentity_t *unlinkedEntities[MAX_RAIL_HITS];
451
452 damage = 100 * s_quadFactor;
453
454 VectorMA (muzzle, 8192, forward, end);
455
456 // trace only against the solids, so the railgun will go through people
457 unlinked = 0;
458 hits = 0;
459 passent = ent->s.number;
460 do {
461 trap_Trace (&trace, muzzle, NULL, NULL, end, passent, MASK_SHOT );
462 if ( trace.entityNum >= ENTITYNUM_MAX_NORMAL ) {
463 break;
464 }
465 traceEnt = &g_entities[ trace.entityNum ];
466 if ( traceEnt->takedamage ) {
467 #ifdef MISSIONPACK
468 if ( traceEnt->client && traceEnt->client->invulnerabilityTime > level.time ) {
469 if ( G_InvulnerabilityEffect( traceEnt, forward, trace.endpos, impactpoint, bouncedir ) ) {
470 G_BounceProjectile( muzzle, impactpoint, bouncedir, end );
471 // snap the endpos to integers to save net bandwidth, but nudged towards the line
472 SnapVectorTowards( trace.endpos, muzzle );
473 // send railgun beam effect
474 tent = G_TempEntity( trace.endpos, EV_RAILTRAIL );
475 // set player number for custom colors on the railtrail
476 tent->s.clientNum = ent->s.clientNum;
477 VectorCopy( muzzle, tent->s.origin2 );
478 // move origin a bit to come closer to the drawn gun muzzle
479 VectorMA( tent->s.origin2, 4, right, tent->s.origin2 );
480 VectorMA( tent->s.origin2, -1, up, tent->s.origin2 );
481 tent->s.eventParm = 255; // don't make the explosion at the end
482 //
483 VectorCopy( impactpoint, muzzle );
484 // the player can hit him/herself with the bounced rail
485 passent = ENTITYNUM_NONE;
486 }
487 }
488 else {
489 if( LogAccuracyHit( traceEnt, ent ) ) {
490 hits++;
491 }
492 G_Damage (traceEnt, ent, ent, forward, trace.endpos, damage, 0, MOD_RAILGUN);
493 }
494 #else
495 if( LogAccuracyHit( traceEnt, ent ) ) {
496 hits++;
497 }
498 G_Damage (traceEnt, ent, ent, forward, trace.endpos, damage, 0, MOD_RAILGUN);
499 #endif
500 }
501 if ( trace.contents & CONTENTS_SOLID ) {
502 break; // we hit something solid enough to stop the beam
503 }
504 // unlink this entity, so the next trace will go past it
505 trap_UnlinkEntity( traceEnt );
506 unlinkedEntities[unlinked] = traceEnt;
507 unlinked++;
508 } while ( unlinked < MAX_RAIL_HITS );
509
510 // link back in any entities we unlinked
511 for ( i = 0 ; i < unlinked ; i++ ) {
512 trap_LinkEntity( unlinkedEntities[i] );
513 }
514
515 // the final trace endpos will be the terminal point of the rail trail
516
517 // snap the endpos to integers to save net bandwidth, but nudged towards the line
518 SnapVectorTowards( trace.endpos, muzzle );
519
520 // send railgun beam effect
521 tent = G_TempEntity( trace.endpos, EV_RAILTRAIL );
522
523 // set player number for custom colors on the railtrail
524 tent->s.clientNum = ent->s.clientNum;
525
526 VectorCopy( muzzle, tent->s.origin2 );
527 // move origin a bit to come closer to the drawn gun muzzle
528 VectorMA( tent->s.origin2, 4, right, tent->s.origin2 );
529 VectorMA( tent->s.origin2, -1, up, tent->s.origin2 );
530
531 // no explosion at end if SURF_NOIMPACT, but still make the trail
532 if ( trace.surfaceFlags & SURF_NOIMPACT ) {
533 tent->s.eventParm = 255; // don't make the explosion at the end
534 } else {
535 tent->s.eventParm = DirToByte( trace.plane.normal );
536 }
537 tent->s.clientNum = ent->s.clientNum;
538
539 // give the shooter a reward sound if they have made two railgun hits in a row
540 if ( hits == 0 ) {
541 // complete miss
542 ent->client->accurateCount = 0;
543 } else {
544 // check for "impressive" reward sound
545 ent->client->accurateCount += hits;
546 if ( ent->client->accurateCount >= 2 ) {
547 ent->client->accurateCount -= 2;
548 ent->client->ps.persistant[PERS_IMPRESSIVE_COUNT]++;
549 // add the sprite over the player's head
550 ent->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
551 ent->client->ps.eFlags |= EF_AWARD_IMPRESSIVE;
552 ent->client->rewardTime = level.time + REWARD_SPRITE_TIME;
553 }
554 ent->client->accuracy_hits++;
555 }
556
557 }
558
559
560 /*
561 ======================================================================
562
563 GRAPPLING HOOK
564
565 ======================================================================
566 */
567
568 void Weapon_GrapplingHook_Fire (gentity_t *ent)
569 {
570 if (!ent->client->fireHeld && !ent->client->hook)
571 fire_grapple (ent, muzzle, forward);
572
573 ent->client->fireHeld = qtrue;
574 }
575
576 void Weapon_HookFree (gentity_t *ent)
577 {
578 ent->parent->client->hook = NULL;
579 ent->parent->client->ps.pm_flags &= ~PMF_GRAPPLE_PULL;
580 G_FreeEntity( ent );
581 }
582
583 void Weapon_HookThink (gentity_t *ent)
584 {
585 if (ent->enemy) {
586 vec3_t v, oldorigin;
587
588 VectorCopy(ent->r.currentOrigin, oldorigin);
589 v[0] = ent->enemy->r.currentOrigin[0] + (ent->enemy->r.mins[0] + ent->enemy->r.maxs[0]) * 0.5;
590 v[1] = ent->enemy->r.currentOrigin[1] + (ent->enemy->r.mins[1] + ent->enemy->r.maxs[1]) * 0.5;
591 v[2] = ent->enemy->r.currentOrigin[2] + (ent->enemy->r.mins[2] + ent->enemy->r.maxs[2]) * 0.5;
592 SnapVectorTowards( v, oldorigin ); // save net bandwidth
593
594 G_SetOrigin( ent, v );
595 }
596
597 VectorCopy( ent->r.currentOrigin, ent->parent->client->ps.grapplePoint);
598 }
599
600 /*
601 ======================================================================
602
603 LIGHTNING GUN
604
605 ======================================================================
606 */
607
608 void Weapon_LightningFire( gentity_t *ent ) {
609 trace_t tr;
610 vec3_t end;
611 #ifdef MISSIONPACK
612 vec3_t impactpoint, bouncedir;
613 #endif
614 gentity_t *traceEnt, *tent;
615 int damage, i, passent;
616
617 damage = 8 * s_quadFactor;
618
619 passent = ent->s.number;
620 for (i = 0; i < 10; i++) {
621 VectorMA( muzzle, LIGHTNING_RANGE, forward, end );
622
623 trap_Trace( &tr, muzzle, NULL, NULL, end, passent, MASK_SHOT );
624
625 #ifdef MISSIONPACK
626 // if not the first trace (the lightning bounced of an invulnerability sphere)
627 if (i) {
628 // add bounced off lightning bolt temp entity
629 // the first lightning bolt is a cgame only visual
630 //
631 tent = G_TempEntity( muzzle, EV_LIGHTNINGBOLT );
632 VectorCopy( tr.endpos, end );
633 SnapVector( end );
634 VectorCopy( end, tent->s.origin2 );
635 }
636 #endif
637 if ( tr.entityNum == ENTITYNUM_NONE ) {
638 return;
639 }
640
641 traceEnt = &g_entities[ tr.entityNum ];
642
643 if ( traceEnt->takedamage) {
644 #ifdef MISSIONPACK
645 if ( traceEnt->client && traceEnt->client->invulnerabilityTime > level.time ) {
646 if (G_InvulnerabilityEffect( traceEnt, forward, tr.endpos, impactpoint, bouncedir )) {
647 G_BounceProjectile( muzzle, impactpoint, bouncedir, end );
648 VectorCopy( impactpoint, muzzle );
649 VectorSubtract( end, impactpoint, forward );
650 VectorNormalize(forward);
651 // the player can hit him/herself with the bounced lightning
652 passent = ENTITYNUM_NONE;
653 }
654 else {
655 VectorCopy( tr.endpos, muzzle );
656 passent = traceEnt->s.number;
657 }
658 continue;
659 }
660 #endif
661 if( LogAccuracyHit( traceEnt, ent ) ) {
662 ent->client->accuracy_hits++;
663 }
664 G_Damage( traceEnt, ent, ent, forward, tr.endpos, damage, 0, MOD_LIGHTNING);
665 }
666
667 if ( traceEnt->takedamage && traceEnt->client ) {
668 tent = G_TempEntity( tr.endpos, EV_MISSILE_HIT );
669 tent->s.otherEntityNum = traceEnt->s.number;
670 tent->s.eventParm = DirToByte( tr.plane.normal );
671 tent->s.weapon = ent->s.weapon;
672 } else if ( !( tr.surfaceFlags & SURF_NOIMPACT ) ) {
673 tent = G_TempEntity( tr.endpos, EV_MISSILE_MISS );
674 tent->s.eventParm = DirToByte( tr.plane.normal );
675 }
676
677 break;
678 }
679 }
680
681 #ifdef MISSIONPACK
682 /*
683 ======================================================================
684
685 NAILGUN
686
687 ======================================================================
688 */
689
690 void Weapon_Nailgun_Fire (gentity_t *ent) {
691 gentity_t *m;
692 int count;
693
694 for( count = 0; count < NUM_NAILSHOTS; count++ ) {
695 m = fire_nail (ent, muzzle, forward, right, up );
696 m->damage *= s_quadFactor;
697 m->splashDamage *= s_quadFactor;
698 }
699
700 // VectorAdd( m->s.pos.trDelta, ent->client->ps.velocity, m->s.pos.trDelta ); // "real" physics
701 }
702
703
704 /*
705 ======================================================================
706
707 PROXIMITY MINE LAUNCHER
708
709 ======================================================================
710 */
711
712 void weapon_proxlauncher_fire (gentity_t *ent) {
713 gentity_t *m;
714
715 // extra vertical velocity
716 forward[2] += 0.2f;
717 VectorNormalize( forward );
718
719 m = fire_prox (ent, muzzle, forward);
720 m->damage *= s_quadFactor;
721 m->splashDamage *= s_quadFactor;
722
723 // VectorAdd( m->s.pos.trDelta, ent->client->ps.velocity, m->s.pos.trDelta ); // "real" physics
724 }
725
726 #endif
727
728 //======================================================================
729
730
731 /*
732 ===============
733 LogAccuracyHit
734 ===============
735 */
736 qboolean LogAccuracyHit( gentity_t *target, gentity_t *attacker ) {
737 if( !target->takedamage ) {
738 return qfalse;
739 }
740
741 if ( target == attacker ) {
742 return qfalse;
743 }
744
745 if( !target->client ) {
746 return qfalse;
747 }
748
749 if( !attacker->client ) {
750 return qfalse;
751 }
752
753 if( target->client->ps.stats[STAT_HEALTH] <= 0 ) {
754 return qfalse;
755 }
756
757 if ( OnSameTeam( target, attacker ) ) {
758 return qfalse;
759 }
760
761 return qtrue;
762 }
763
764
765 /*
766 ===============
767 CalcMuzzlePoint
768
769 set muzzle location relative to pivoting eye
770 ===============
771 */
772 void CalcMuzzlePoint ( gentity_t *ent, vec3_t localForward, vec3_t localRight, vec3_t localUp, vec3_t muzzlePoint ) {
773 VectorCopy( ent->s.pos.trBase, muzzlePoint );
774 muzzlePoint[2] += ent->client->ps.viewheight;
775 VectorMA( muzzlePoint, 14, localForward, muzzlePoint );
776 // snap to integer coordinates for more efficient network bandwidth usage
777 SnapVector( muzzlePoint );
778 }
779
780 /*
781 ===============
782 CalcMuzzlePointOrigin
783
784 set muzzle location relative to pivoting eye
785 ===============
786 */
787 void CalcMuzzlePointOrigin ( gentity_t *ent, vec3_t origin, vec3_t localForward, vec3_t localRight, vec3_t localUp, vec3_t muzzlePoint ) {
788 VectorCopy( ent->s.pos.trBase, muzzlePoint );
789 muzzlePoint[2] += ent->client->ps.viewheight;
790 VectorMA( muzzlePoint, 14, localForward, muzzlePoint );
791 // snap to integer coordinates for more efficient network bandwidth usage
792 SnapVector( muzzlePoint );
793 }
794
795
796
797 /*
798 ===============
799 FireWeapon
800 ===============
801 */
802 void FireWeapon( gentity_t *ent ) {
803 if (ent->client->ps.powerups[PW_QUAD] ) {
804 s_quadFactor = g_quadfactor.value;
805 } else {
806 s_quadFactor = 1;
807 }
808 #ifdef MISSIONPACK
809 if( ent->client->persistantPowerup && ent->client->persistantPowerup->item && ent->client->persistantPowerup->item->giTag == PW_DOUBLER ) {
810 s_quadFactor *= 2;
811 }
812 #endif
813
814 // track shots taken for accuracy tracking. Grapple is not a weapon and gauntet is just not tracked
815 if( ent->s.weapon != WP_GRAPPLING_HOOK && ent->s.weapon != WP_GAUNTLET ) {
816 #ifdef MISSIONPACK
817 if( ent->s.weapon == WP_NAILGUN ) {
818 ent->client->accuracy_shots += NUM_NAILSHOTS;
819 } else {
820 ent->client->accuracy_shots++;
821 }
822 #else
823 ent->client->accuracy_shots++;
824 #endif
825 }
826
827 // set aiming directions
828 AngleVectors (ent->client->ps.viewangles, forward, right, up);
829
830 CalcMuzzlePointOrigin ( ent, ent->client->oldOrigin, forward, right, up, muzzle );
831
832 // fire the specific weapon
833 switch( ent->s.weapon ) {
834 case WP_GAUNTLET:
835 Weapon_Gauntlet( ent );
836 break;
837 case WP_LIGHTNING:
838 Weapon_LightningFire( ent );
839 break;
840 case WP_SHOTGUN:
841 weapon_supershotgun_fire( ent );
842 break;
843 case WP_MACHINEGUN:
844 if ( g_gametype.integer != GT_TEAM ) {
845 Bullet_Fire( ent, MACHINEGUN_SPREAD, MACHINEGUN_DAMAGE, MOD_MACHINEGUN );
846 } else {
847 Bullet_Fire( ent, MACHINEGUN_SPREAD, MACHINEGUN_TEAM_DAMAGE, MOD_MACHINEGUN );
848 }
849 break;
850 case WP_GRENADE_LAUNCHER:
851 weapon_grenadelauncher_fire( ent );
852 break;
853 case WP_ROCKET_LAUNCHER:
854 Weapon_RocketLauncher_Fire( ent );
855 break;
856 case WP_PLASMAGUN:
857 Weapon_Plasmagun_Fire( ent );
858 break;
859 case WP_RAILGUN:
860 weapon_railgun_fire( ent );
861 break;
862 case WP_BFG:
863 BFG_Fire( ent );
864 break;
865 case WP_GRAPPLING_HOOK:
866 Weapon_GrapplingHook_Fire( ent );
867 break;
868 #ifdef MISSIONPACK
869 case WP_NAILGUN:
870 Weapon_Nailgun_Fire( ent );
871 break;
872 case WP_PROX_LAUNCHER:
873 weapon_proxlauncher_fire( ent );
874 break;
875 case WP_CHAINGUN:
876 Bullet_Fire( ent, CHAINGUN_SPREAD, CHAINGUN_DAMAGE, MOD_CHAINGUN );
877 break;
878 #endif
879 default:
880 // FIXME G_Error( "Bad ent->s.weapon" );
881 break;
882 }
883 }
884
885
886 #ifdef MISSIONPACK
887
888 /*
889 ===============
890 KamikazeRadiusDamage
891 ===============
892 */
893 static void KamikazeRadiusDamage( vec3_t origin, gentity_t *attacker, float damage, float radius ) {
894 float dist;
895 gentity_t *ent;
896 int entityList[MAX_GENTITIES];
897 int numListedEntities;
898 vec3_t mins, maxs;
899 vec3_t v;
900 vec3_t dir;
901 int i, e;
902
903 if ( radius < 1 ) {
904 radius = 1;
905 }
906
907 for ( i = 0 ; i < 3 ; i++ ) {
908 mins[i] = origin[i] - radius;
909 maxs[i] = origin[i] + radius;
910 }
911
912 numListedEntities = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
913
914 for ( e = 0 ; e < numListedEntities ; e++ ) {
915 ent = &g_entities[entityList[ e ]];
916
917 if (!ent->takedamage) {
918 continue;
919 }
920
921 // don't hit things we have already hit
922 if( ent->kamikazeTime > level.time ) {
923 continue;
924 }
925
926 // find the distance from the edge of the bounding box
927 for ( i = 0 ; i < 3 ; i++ ) {
928 if ( origin[i] < ent->r.absmin[i] ) {
929 v[i] = ent->r.absmin[i] - origin[i];
930 } else if ( origin[i] > ent->r.absmax[i] ) {
931 v[i] = origin[i] - ent->r.absmax[i];
932 } else {
933 v[i] = 0;
934 }
935 }
936
937 dist = VectorLength( v );
938 if ( dist >= radius ) {
939 continue;
940 }
941
942 // if( CanDamage (ent, origin) ) {
943 VectorSubtract (ent->r.currentOrigin, origin, dir);
944 // push the center of mass higher than the origin so players
945 // get knocked into the air more
946 dir[2] += 24;
947 G_Damage( ent, NULL, attacker, dir, origin, damage, DAMAGE_RADIUS|DAMAGE_NO_TEAM_PROTECTION, MOD_KAMIKAZE );
948 ent->kamikazeTime = level.time + 3000;
949 // }
950 }
951 }
952
953 /*
954 ===============
955 KamikazeShockWave
956 ===============
957 */
958 static void KamikazeShockWave( vec3_t origin, gentity_t *attacker, float damage, float push, float radius ) {
959 float dist;
960 gentity_t *ent;
961 int entityList[MAX_GENTITIES];
962 int numListedEntities;
963 vec3_t mins, maxs;
964 vec3_t v;
965 vec3_t dir;
966 int i, e;
967
968 if ( radius < 1 )
969 radius = 1;
970
971 for ( i = 0 ; i < 3 ; i++ ) {
972 mins[i] = origin[i] - radius;
973 maxs[i] = origin[i] + radius;
974 }
975
976 numListedEntities = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
977
978 for ( e = 0 ; e < numListedEntities ; e++ ) {
979 ent = &g_entities[entityList[ e ]];
980
981 // don't hit things we have already hit
982 if( ent->kamikazeShockTime > level.time ) {
983 continue;
984 }
985
986 // find the distance from the edge of the bounding box
987 for ( i = 0 ; i < 3 ; i++ ) {
988 if ( origin[i] < ent->r.absmin[i] ) {
989 v[i] = ent->r.absmin[i] - origin[i];
990 } else if ( origin[i] > ent->r.absmax[i] ) {
991 v[i] = origin[i] - ent->r.absmax[i];
992 } else {
993 v[i] = 0;
994 }
995 }
996
997 dist = VectorLength( v );
998 if ( dist >= radius ) {
999 continue;
1000 }
1001
1002 // if( CanDamage (ent, origin) ) {
1003 VectorSubtract (ent->r.currentOrigin, origin, dir);
1004 dir[2] += 24;
1005 G_Damage( ent, NULL, attacker, dir, origin, damage, DAMAGE_RADIUS|DAMAGE_NO_TEAM_PROTECTION, MOD_KAMIKAZE );
1006 //
1007 dir[2] = 0;
1008 VectorNormalize(dir);
1009 if ( ent->client ) {
1010 ent->client->ps.velocity[0] = dir[0] * push;
1011 ent->client->ps.velocity[1] = dir[1] * push;
1012 ent->client->ps.velocity[2] = 100;
1013 }
1014 ent->kamikazeShockTime = level.time + 3000;
1015 // }
1016 }
1017 }
1018
1019 /*
1020 ===============
1021 KamikazeDamage
1022 ===============
1023 */
1024 static void KamikazeDamage( gentity_t *self ) {
1025 int i;
1026 float t;
1027 gentity_t *ent;
1028 vec3_t newangles;
1029
1030 self->count += 100;
1031
1032 if (self->count >= KAMI_SHOCKWAVE_STARTTIME) {
1033 // shockwave push back
1034 t = self->count - KAMI_SHOCKWAVE_STARTTIME;
1035 KamikazeShockWave(self->s.pos.trBase, self->activator, 25, 400, (int) (float) t * KAMI_SHOCKWAVE_MAXRADIUS / (KAMI_SHOCKWAVE_ENDTIME - KAMI_SHOCKWAVE_STARTTIME) );
1036 }
1037 //
1038 if (self->count >= KAMI_EXPLODE_STARTTIME) {
1039 // do our damage
1040 t = self->count - KAMI_EXPLODE_STARTTIME;
1041 KamikazeRadiusDamage( self->s.pos.trBase, self->activator, 400, (int) (float) t * KAMI_BOOMSPHERE_MAXRADIUS / (KAMI_IMPLODE_STARTTIME - KAMI_EXPLODE_STARTTIME) );
1042 }
1043
1044 // either cycle or kill self
1045 if( self->count >= KAMI_SHOCKWAVE_ENDTIME ) {
1046 G_FreeEntity( self );
1047 return;
1048 }
1049 self->nextthink = level.time + 100;
1050
1051 // add earth quake effect
1052 newangles[0] = crandom() * 2;
1053 newangles[1] = crandom() * 2;
1054 newangles[2] = 0;
1055 for (i = 0; i < MAX_CLIENTS; i++)
1056 {
1057 ent = &g_entities[i];
1058 if (!ent->inuse)
1059 continue;
1060 if (!ent->client)
1061 continue;
1062
1063 if (ent->client->ps.groundEntityNum != ENTITYNUM_NONE) {
1064 ent->client->ps.velocity[0] += crandom() * 120;
1065 ent->client->ps.velocity[1] += crandom() * 120;
1066 ent->client->ps.velocity[2] = 30 + random() * 25;
1067 }
1068
1069 ent->client->ps.delta_angles[0] += ANGLE2SHORT(newangles[0] - self->movedir[0]);
1070 ent->client->ps.delta_angles[1] += ANGLE2SHORT(newangles[1] - self->movedir[1]);
1071 ent->client->ps.delta_angles[2] += ANGLE2SHORT(newangles[2] - self->movedir[2]);
1072 }
1073 VectorCopy(newangles, self->movedir);
1074 }
1075
1076 /*
1077 ===============
1078 G_StartKamikaze
1079 ===============
1080 */
1081 void G_StartKamikaze( gentity_t *ent ) {
1082 gentity_t *explosion;
1083 gentity_t *te;
1084 vec3_t snapped;
1085
1086 // start up the explosion logic
1087 explosion = G_Spawn();
1088
1089 explosion->s.eType = ET_EVENTS + EV_KAMIKAZE;
1090 explosion->eventTime = level.time;
1091
1092 if ( ent->client ) {
1093 VectorCopy( ent->s.pos.trBase, snapped );
1094 }
1095 else {
1096 VectorCopy( ent->activator->s.pos.trBase, snapped );
1097 }
1098 SnapVector( snapped ); // save network bandwidth
1099 G_SetOrigin( explosion, snapped );
1100
1101 explosion->classname = "kamikaze";
1102 explosion->s.pos.trType = TR_STATIONARY;
1103
1104 explosion->kamikazeTime = level.time;
1105
1106 explosion->think = KamikazeDamage;
1107 explosion->nextthink = level.time + 100;
1108 explosion->count = 0;
1109 VectorClear(explosion->movedir);
1110
1111 trap_LinkEntity( explosion );
1112
1113 if (ent->client) {
1114 //
1115 explosion->activator = ent;
1116 //
1117 ent->s.eFlags &= ~EF_KAMIKAZE;
1118 // nuke the guy that used it
1119 G_Damage( ent, ent, ent, NULL, NULL, 100000, DAMAGE_NO_PROTECTION, MOD_KAMIKAZE );
1120 }
1121 else {
1122 if ( !strcmp(ent->activator->classname, "bodyque") ) {
1123 explosion->activator = &g_entities[ent->activator->r.ownerNum];
1124 }
1125 else {
1126 explosion->activator = ent->activator;
1127 }
1128 }
1129
1130 // play global sound at all clients
1131 te = G_TempEntity(snapped, EV_GLOBAL_TEAM_SOUND );
1132 te->r.svFlags |= SVF_BROADCAST;
1133 te->s.eventParm = GTS_KAMIKAZE;
1134 }
1135 #endif