Debian Codegraph @

code/game/g_weapon.c

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