Debian Codegraph @

code/game/g_missile.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 #include "g_local.h"
24
25 #define MISSILE_PRESTEP_TIME 50
26
27 /*
28 ================
29 G_BounceMissile
30
31 ================
32 */
33 void G_BounceMissile( gentity_t *ent, trace_t *trace ) {
34 vec3_t velocity;
35 float dot;
36 int hitTime;
37
38 // reflect the velocity on the trace plane
39 hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
40 BG_EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
41 dot = DotProduct( velocity, trace->plane.normal );
42 VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );
43
44 if ( ent->s.eFlags & EF_BOUNCE_HALF ) {
45 VectorScale( ent->s.pos.trDelta, 0.65, ent->s.pos.trDelta );
46 // check for stop
47 if ( trace->plane.normal[2] > 0.2 && VectorLength( ent->s.pos.trDelta ) < 40 ) {
48 G_SetOrigin( ent, trace->endpos );
49 ent->s.time = level.time / 4;
50 return;
51 }
52 }
53
54 VectorAdd( ent->r.currentOrigin, trace->plane.normal, ent->r.currentOrigin);
55 VectorCopy( ent->r.currentOrigin, ent->s.pos.trBase );
56 ent->s.pos.trTime = level.time;
57 }
58
59
60 /*
61 ================
62 G_ExplodeMissile
63
64 Explode a missile without an impact
65 ================
66 */
67 void G_ExplodeMissile( gentity_t *ent ) {
68 vec3_t dir;
69 vec3_t origin;
70
71 BG_EvaluateTrajectory( &ent->s.pos, level.time, origin );
72 SnapVector( origin );
73 G_SetOrigin( ent, origin );
74
75 // we don't have a valid direction, so just point straight up
76 dir[0] = dir[1] = 0;
77 dir[2] = 1;
78
79 ent->s.eType = ET_GENERAL;
80 G_AddEvent( ent, EV_MISSILE_MISS, DirToByte( dir ) );
81
82 ent->freeAfterEvent = qtrue;
83
84 // splash damage
85 if ( ent->splashDamage ) {
86 if( G_RadiusDamage( ent->r.currentOrigin, ent->parent, ent->splashDamage, ent->splashRadius, ent
87 , ent->splashMethodOfDeath ) ) {
88 g_entities[ent->r.ownerNum].client->accuracy_hits++;
89 g_entities[ent->r.ownerNum].client->accuracy[ent->s.weapon][1]++;
90 }
91 }
92
93 trap_LinkEntity( ent );
94 }
95
96 /*
97 ================
98 ProximityMine_Explode
99 ================
100 */
101 static void ProximityMine_Explode( gentity_t *mine ) {
102 G_ExplodeMissile( mine );
103 // if the prox mine has a trigger free it
104 if (mine->activator) {
105 G_FreeEntity(mine->activator);
106 mine->activator = NULL;
107 }
108 }
109
110 /*
111 ================
112 ProximityMine_Die
113 ================
114 */
115 static void ProximityMine_Die( gentity_t *ent, gentity_t *inflictor, gentity_t *attacker, int damage, int mod ) {
116 ent->think = ProximityMine_Explode;
117 ent->nextthink = level.time + 1;
118 }
119
120 /*
121 ================
122 ProximityMine_Trigger
123 ================
124 */
125 void ProximityMine_Trigger( gentity_t *trigger, gentity_t *other, trace_t *trace ) {
126 vec3_t v;
127 gentity_t *mine;
128
129 if( !other->client ) {
130 return;
131 }
132
133 // trigger is a cube, do a distance test now to act as if it's a sphere
134 VectorSubtract( trigger->s.pos.trBase, other->s.pos.trBase, v );
135 if( VectorLength( v ) > trigger->parent->splashRadius ) {
136 return;
137 }
138
139
140 if ( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) {
141 // don't trigger same team mines
142 if (trigger->parent->s.generic1 == other->client->sess.sessionTeam) {
143 return;
144 }
145 }
146
147 // ok, now check for ability to damage so we don't get triggered thru walls, closed doors, etc...
148 if( !CanDamage( other, trigger->s.pos.trBase ) ) {
149 return;
150 }
151
152 // trigger the mine!
153 mine = trigger->parent;
154 mine->s.loopSound = 0;
155 G_AddEvent( mine, EV_PROXIMITY_MINE_TRIGGER, 0 );
156 mine->nextthink = level.time + 500;
157
158 G_FreeEntity( trigger );
159 }
160
161 /*
162 ================
163 ProximityMine_Activate
164 ================
165 */
166 static void ProximityMine_Activate( gentity_t *ent ) {
167 gentity_t *trigger;
168 float r;
169 vec3_t v1;
170 gentity_t *flag;
171 char *c;
172 qboolean nearFlag = qfalse;
173
174 // find the flag
175 switch (ent->s.generic1) {
176 case TEAM_RED:
177 c = "team_CTF_redflag";
178 break;
179 case TEAM_BLUE:
180 c = "team_CTF_blueflag";
181 break;
182 default:
183 c = NULL;
184 }
185
186 if(c) {
187 flag = NULL;
188 while ((flag = G_Find (flag, FOFS(classname), c)) != NULL) {
189 if (!(flag->flags & FL_DROPPED_ITEM))
190 break;
191 }
192
193 if(flag) {
194 VectorSubtract(ent->r.currentOrigin,flag->r.currentOrigin , v1);
195 if(VectorLength(v1) < 500)
196 nearFlag = qtrue;
197 }
198 }
199
200 ent->think = ProximityMine_Explode;
201 if( nearFlag)
202 ent->nextthink = level.time + g_proxMineTimeout.integer/15;
203 else
204 ent->nextthink = level.time + g_proxMineTimeout.integer;
205
206 ent->takedamage = qtrue;
207 ent->health = 1;
208 ent->die = ProximityMine_Die;
209
210 ent->s.loopSound = G_SoundIndex( "sound/weapons/proxmine/wstbtick.wav" );
211
212 // build the proximity trigger
213 trigger = G_Spawn ();
214
215 trigger->classname = "proxmine_trigger";
216
217 r = ent->splashRadius;
218 VectorSet( trigger->r.mins, -r, -r, -r );
219 VectorSet( trigger->r.maxs, r, r, r );
220
221 G_SetOrigin( trigger, ent->s.pos.trBase );
222
223 trigger->parent = ent;
224 trigger->r.contents = CONTENTS_TRIGGER;
225 trigger->touch = ProximityMine_Trigger;
226
227 trap_LinkEntity (trigger);
228
229 // set pointer to trigger so the entity can be freed when the mine explodes
230 ent->activator = trigger;
231 }
232
233 /*
234 ================
235 ProximityMine_ExplodeOnPlayer
236 ================
237 */
238 static void ProximityMine_ExplodeOnPlayer( gentity_t *mine ) {
239 gentity_t *player;
240
241 player = mine->enemy;
242 player->client->ps.eFlags &= ~EF_TICKING;
243
244 if ( player->client->invulnerabilityTime > level.time ) {
245 G_Damage( player, mine->parent, mine->parent, vec3_origin, mine->s.origin, 1000, DAMAGE_NO_KNOCKBACK, MOD_JUICED );
246 player->client->invulnerabilityTime = 0;
247 G_TempEntity( player->client->ps.origin, EV_JUICED );
248 }
249 else {
250 G_SetOrigin( mine, player->s.pos.trBase );
251 // make sure the explosion gets to the client
252 mine->r.svFlags &= ~SVF_NOCLIENT;
253 mine->splashMethodOfDeath = MOD_PROXIMITY_MINE;
254 G_ExplodeMissile( mine );
255 }
256 }
257
258 /*
259 ================
260 ProximityMine_Player
261 ================
262 */
263 static void ProximityMine_Player( gentity_t *mine, gentity_t *player ) {
264 if( mine->s.eFlags & EF_NODRAW ) {
265 return;
266 }
267
268 G_AddEvent( mine, EV_PROXIMITY_MINE_STICK, 0 );
269
270 if( player->s.eFlags & EF_TICKING ) {
271 player->activator->splashDamage += mine->splashDamage;
272 player->activator->splashRadius *= 1.50;
273 mine->think = G_FreeEntity;
274 mine->nextthink = level.time;
275 return;
276 }
277
278 player->client->ps.eFlags |= EF_TICKING;
279 player->activator = mine;
280
281 mine->s.eFlags |= EF_NODRAW;
282 mine->r.svFlags |= SVF_NOCLIENT;
283 mine->s.pos.trType = TR_LINEAR;
284 VectorClear( mine->s.pos.trDelta );
285
286 mine->enemy = player;
287 mine->think = ProximityMine_ExplodeOnPlayer;
288 if ( player->client->invulnerabilityTime > level.time ) {
289 mine->nextthink = level.time + 2 * 1000;
290 }
291 else {
292 mine->nextthink = level.time + 10 * 1000;
293 }
294 }
295
296 /*
297 *=================
298 *ProximityMine_RemoveAll
299 *=================
300 */
301
302 void ProximityMine_RemoveAll() {
303 gentity_t *mine;
304
305 mine = NULL;
306
307 while ((mine = G_Find (mine, FOFS(classname), "prox mine")) != NULL) {
308 mine->think = ProximityMine_Explode;
309 mine->nextthink = level.time + 1;
310 }
311 }
312
313 /*
314 ================
315 G_MissileImpact
316 ================
317 */
318 void G_MissileImpact( gentity_t *ent, trace_t *trace ) {
319 gentity_t *other;
320 qboolean hitClient = qfalse;
321 vec3_t forward, impactpoint, bouncedir;
322 int eFlags;
323 other = &g_entities[trace->entityNum];
324
325 // check for bounce
326 if ( !other->takedamage &&
327 ( ent->s.eFlags & ( EF_BOUNCE | EF_BOUNCE_HALF ) ) ) {
328 G_BounceMissile( ent, trace );
329 G_AddEvent( ent, EV_GRENADE_BOUNCE, 0 );
330 return;
331 }
332
333 if ( other->takedamage ) {
334 if ( ent->s.weapon != WP_PROX_LAUNCHER ) {
335 if ( other->client && other->client->invulnerabilityTime > level.time ) {
336
337 //
338 VectorCopy( ent->s.pos.trDelta, forward );
339 VectorNormalize( forward );
340 if (G_InvulnerabilityEffect( other, forward, ent->s.pos.trBase, impactpoint, bouncedir )) {
341 VectorCopy( bouncedir, trace->plane.normal );
342 eFlags = ent->s.eFlags & EF_BOUNCE_HALF;
343 ent->s.eFlags &= ~EF_BOUNCE_HALF;
344 G_BounceMissile( ent, trace );
345 ent->s.eFlags |= eFlags;
346 }
347 ent->target_ent = other;
348 return;
349 }
350 }
351 }
352 // impact damage
353 if (other->takedamage) {
354 // FIXME: wrong damage direction?
355 if ( ent->damage ) {
356 vec3_t velocity;
357
358 if( LogAccuracyHit( other, &g_entities[ent->r.ownerNum] ) ) {
359 g_entities[ent->r.ownerNum].client->accuracy_hits++;
360 hitClient = qtrue;
361 g_entities[ent->r.ownerNum].client->accuracy[ent->s.weapon][1]++;
362 }
363 BG_EvaluateTrajectoryDelta( &ent->s.pos, level.time, velocity );
364 if ( VectorLength( velocity ) == 0 ) {
365 velocity[2] = 1; // stepped on a grenade
366 }
367 G_Damage (other, ent, &g_entities[ent->r.ownerNum], velocity,
368 ent->s.origin, ent->damage,
369 0, ent->methodOfDeath);
370 }
371 }
372
373 if( ent->s.weapon == WP_PROX_LAUNCHER ) {
374 if( ent->s.pos.trType != TR_GRAVITY ) {
375 return;
376 }
377
378 // if it's a player, stick it on to them (flag them and remove this entity)
379 if( other->s.eType == ET_PLAYER && other->health > 0 ) {
380 ProximityMine_Player( ent, other );
381 return;
382 }
383
384 SnapVectorTowards( trace->endpos, ent->s.pos.trBase );
385 G_SetOrigin( ent, trace->endpos );
386 ent->s.pos.trType = TR_STATIONARY;
387 VectorClear( ent->s.pos.trDelta );
388
389 G_AddEvent( ent, EV_PROXIMITY_MINE_STICK, trace->surfaceFlags );
390
391 ent->think = ProximityMine_Activate;
392 ent->nextthink = level.time + 2000;
393
394 vectoangles( trace->plane.normal, ent->s.angles );
395 ent->s.angles[0] += 90;
396
397 // link the prox mine to the other entity
398 ent->enemy = other;
399 ent->die = ProximityMine_Die;
400 VectorCopy(trace->plane.normal, ent->movedir);
401 VectorSet(ent->r.mins, -4, -4, -4);
402 VectorSet(ent->r.maxs, 4, 4, 4);
403 trap_LinkEntity(ent);
404
405 return;
406 }
407
408 if (!strcmp(ent->classname, "hook")) {
409 gentity_t *nent;
410 vec3_t v;
411
412 nent = G_Spawn();
413 if ( other->takedamage && other->client ) {
414
415 G_AddEvent( nent, EV_MISSILE_HIT, DirToByte( trace->plane.normal ) );
416 nent->s.otherEntityNum = other->s.number;
417
418 ent->enemy = other;
419
420 v[0] = other->r.currentOrigin[0] + (other->r.mins[0] + other->r.maxs[0]) * 0.5;
421 v[1] = other->r.currentOrigin[1] + (other->r.mins[1] + other->r.maxs[1]) * 0.5;
422 v[2] = other->r.currentOrigin[2] + (other->r.mins[2] + other->r.maxs[2]) * 0.5;
423
424 SnapVectorTowards( v, ent->s.pos.trBase ); // save net bandwidth
425 } else {
426 VectorCopy(trace->endpos, v);
427 G_AddEvent( nent, EV_MISSILE_MISS, DirToByte( trace->plane.normal ) );
428 ent->enemy = NULL;
429 }
430
431 SnapVectorTowards( v, ent->s.pos.trBase ); // save net bandwidth
432
433 nent->freeAfterEvent = qtrue;
434 // change over to a normal entity right at the point of impact
435 nent->s.eType = ET_GENERAL;
436 ent->s.eType = ET_GRAPPLE;
437
438 G_SetOrigin( ent, v );
439 G_SetOrigin( nent, v );
440
441 ent->think = Weapon_HookThink;
442 ent->nextthink = level.time + FRAMETIME;
443
444 ent->parent->client->ps.pm_flags |= PMF_GRAPPLE_PULL;
445 VectorCopy( ent->r.currentOrigin, ent->parent->client->ps.grapplePoint);
446
447 trap_LinkEntity( ent );
448 trap_LinkEntity( nent );
449
450 return;
451 }
452
453 // is it cheaper in bandwidth to just remove this ent and create a new
454 // one, rather than changing the missile into the explosion?
455
456 if ( other->takedamage && other->client ) {
457 G_AddEvent( ent, EV_MISSILE_HIT, DirToByte( trace->plane.normal ) );
458 ent->s.otherEntityNum = other->s.number;
459 } else if( trace->surfaceFlags & SURF_METALSTEPS ) {
460 G_AddEvent( ent, EV_MISSILE_MISS_METAL, DirToByte( trace->plane.normal ) );
461 } else {
462 G_AddEvent( ent, EV_MISSILE_MISS, DirToByte( trace->plane.normal ) );
463 }
464
465 ent->freeAfterEvent = qtrue;
466
467 // change over to a normal entity right at the point of impact
468 ent->s.eType = ET_GENERAL;
469
470 SnapVectorTowards( trace->endpos, ent->s.pos.trBase ); // save net bandwidth
471
472 G_SetOrigin( ent, trace->endpos );
473
474 // splash damage (doesn't apply to person directly hit)
475 if ( ent->splashDamage ) {
476 if( G_RadiusDamage( trace->endpos, ent->parent, ent->splashDamage, ent->splashRadius,
477 other, ent->splashMethodOfDeath ) ) {
478 if( !hitClient ) {
479 g_entities[ent->r.ownerNum].client->accuracy_hits++;
480 g_entities[ent->r.ownerNum].client->accuracy[ent->s.weapon][1]++;
481 }
482 }
483 }
484
485 trap_LinkEntity( ent );
486 }
487
488 /*
489 ================
490 G_RunMissile
491 ================
492 */
493 void G_RunMissile( gentity_t *ent ) {
494 vec3_t origin;
495 trace_t tr;
496 int passent;
497
498 // get current position
499 BG_EvaluateTrajectory( &ent->s.pos, level.time, origin );
500
501 // if this missile bounced off an invulnerability sphere
502 if ( ent->target_ent ) {
503 passent = ent->target_ent->s.number;
504 }
505 // prox mines that left the owner bbox will attach to anything, even the owner
506 else if (ent->s.weapon == WP_PROX_LAUNCHER && ent->count) {
507 passent = ENTITYNUM_NONE;
508 }
509 else {
510 // ignore interactions with the missile owner
511 passent = ent->r.ownerNum;
512 }
513 // trace a line from the previous position to the current position
514 trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, origin, passent, ent->clipmask );
515
516 if ( tr.startsolid || tr.allsolid ) {
517 // make sure the tr.entityNum is set to the entity we're stuck in
518 trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, ent->r.currentOrigin, passent, ent->clipmask );
519 tr.fraction = 0;
520 }
521 else {
522 VectorCopy( tr.endpos, ent->r.currentOrigin );
523 }
524
525 trap_LinkEntity( ent );
526
527 if ( tr.fraction != 1 ) {
528 // never explode or bounce on sky
529 if ( tr.surfaceFlags & SURF_NOIMPACT ) {
530 // If grapple, reset owner
531 if (ent->parent && ent->parent->client && ent->parent->client->hook == ent) {
532 ent->parent->client->hook = NULL;
533 }
534 G_FreeEntity( ent );
535 return;
536 }
537 G_MissileImpact( ent, &tr );
538 if ( ent->s.eType != ET_MISSILE ) {
539 return; // exploded
540 }
541 }
542 // if the prox mine wasn't yet outside the player body
543 if (ent->s.weapon == WP_PROX_LAUNCHER && !ent->count) {
544 // check if the prox mine is outside the owner bbox
545 trap_Trace( &tr, ent->r.currentOrigin, ent->r.mins, ent->r.maxs, ent->r.currentOrigin, ENTITYNUM_NONE, ent->clipmask );
546 if (!tr.startsolid || tr.entityNum != ent->r.ownerNum) {
547 ent->count = 1;
548 }
549 }
550 // check think function after bouncing
551 G_RunThink( ent );
552 }
553
554
555 //=============================================================================
556
557 /*
558 =================
559 fire_plasma
560
561 =================
562 */
563 gentity_t *fire_plasma (gentity_t *self, vec3_t start, vec3_t dir) {
564 gentity_t *bolt;
565
566 VectorNormalize (dir);
567
568 bolt = G_Spawn();
569 bolt->classname = "plasma";
570 bolt->nextthink = level.time + 10000;
571 bolt->think = G_ExplodeMissile;
572 bolt->s.eType = ET_MISSILE;
573 bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;
574 bolt->s.weapon = WP_PLASMAGUN;
575 bolt->r.ownerNum = self->s.number;
576 //unlagged - projectile nudge
577 // we'll need this for nudging projectiles later
578 bolt->s.otherEntityNum = self->s.number;
579 //unlagged - projectile nudge
580 bolt->parent = self;
581 bolt->damage = 20;
582 bolt->splashDamage = 15;
583 bolt->splashRadius = 20;
584 bolt->methodOfDeath = MOD_PLASMA;
585 bolt->splashMethodOfDeath = MOD_PLASMA_SPLASH;
586 bolt->clipmask = MASK_SHOT;
587 bolt->target_ent = NULL;
588
589 bolt->s.pos.trType = TR_LINEAR;
590 bolt->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame
591 VectorCopy( start, bolt->s.pos.trBase );
592 VectorScale( dir, 2000, bolt->s.pos.trDelta );
593 SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
594
595 VectorCopy (start, bolt->r.currentOrigin);
596
597 return bolt;
598 }
599
600 //=============================================================================
601
602
603 /*
604 =================
605 fire_grenade
606 =================
607 */
608 gentity_t *fire_grenade (gentity_t *self, vec3_t start, vec3_t dir) {
609 gentity_t *bolt;
610
611 VectorNormalize (dir);
612
613 bolt = G_Spawn();
614 bolt->classname = "grenade";
615 bolt->nextthink = level.time + 2500;
616 bolt->think = G_ExplodeMissile;
617 bolt->s.eType = ET_MISSILE;
618 bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;
619 bolt->s.weapon = WP_GRENADE_LAUNCHER;
620 bolt->s.eFlags = EF_BOUNCE_HALF;
621 bolt->r.ownerNum = self->s.number;
622 //unlagged - projectile nudge
623 // we'll need this for nudging projectiles later
624 bolt->s.otherEntityNum = self->s.number;
625 //unlagged - projectile nudge
626 bolt->parent = self;
627 bolt->damage = 100;
628 bolt->splashDamage = 100;
629 bolt->splashRadius = 150;
630 bolt->methodOfDeath = MOD_GRENADE;
631 bolt->splashMethodOfDeath = MOD_GRENADE_SPLASH;
632 bolt->clipmask = MASK_SHOT;
633 bolt->target_ent = NULL;
634
635 bolt->s.pos.trType = TR_GRAVITY;
636 bolt->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame
637 VectorCopy( start, bolt->s.pos.trBase );
638 VectorScale( dir, 700, bolt->s.pos.trDelta );
639 SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
640
641 VectorCopy (start, bolt->r.currentOrigin);
642
643 return bolt;
644 }
645
646 //=============================================================================
647
648
649 /*
650 =================
651 fire_bfg
652 =================
653 */
654 gentity_t *fire_bfg (gentity_t *self, vec3_t start, vec3_t dir) {
655 gentity_t *bolt;
656
657 VectorNormalize (dir);
658
659 bolt = G_Spawn();
660 bolt->classname = "bfg";
661 bolt->nextthink = level.time + 10000;
662 bolt->think = G_ExplodeMissile;
663 bolt->s.eType = ET_MISSILE;
664 bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;
665 bolt->s.weapon = WP_BFG;
666 bolt->r.ownerNum = self->s.number;
667 //unlagged - projectile nudge
668 // we'll need this for nudging projectiles later
669 bolt->s.otherEntityNum = self->s.number;
670 //unlagged - projectile nudge
671 bolt->parent = self;
672 bolt->damage = 100;
673 bolt->splashDamage = 100;
674 bolt->splashRadius = 120;
675 bolt->methodOfDeath = MOD_BFG;
676 bolt->splashMethodOfDeath = MOD_BFG_SPLASH;
677 bolt->clipmask = MASK_SHOT;
678 bolt->target_ent = NULL;
679
680 bolt->s.pos.trType = TR_LINEAR;
681 bolt->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame
682 VectorCopy( start, bolt->s.pos.trBase );
683 VectorScale( dir, 2000, bolt->s.pos.trDelta );
684 SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
685 VectorCopy (start, bolt->r.currentOrigin);
686
687 return bolt;
688 }
689
690 //=============================================================================
691
692
693 /*
694 =================
695 fire_rocket
696 =================
697 */
698 gentity_t *fire_rocket (gentity_t *self, vec3_t start, vec3_t dir) {
699 gentity_t *bolt;
700
701 VectorNormalize (dir);
702
703 bolt = G_Spawn();
704 bolt->classname = "rocket";
705 bolt->nextthink = level.time + 15000;
706 bolt->think = G_ExplodeMissile;
707 bolt->s.eType = ET_MISSILE;
708 bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;
709 bolt->s.weapon = WP_ROCKET_LAUNCHER;
710 bolt->r.ownerNum = self->s.number;
711 //unlagged - projectile nudge
712 // we'll need this for nudging projectiles later
713 bolt->s.otherEntityNum = self->s.number;
714 //unlagged - projectile nudge
715 bolt->parent = self;
716 bolt->damage = 100;
717 bolt->splashDamage = 100;
718 bolt->splashRadius = 120;
719 bolt->methodOfDeath = MOD_ROCKET;
720 bolt->splashMethodOfDeath = MOD_ROCKET_SPLASH;
721 bolt->clipmask = MASK_SHOT;
722 bolt->target_ent = NULL;
723
724 bolt->s.pos.trType = TR_LINEAR;
725 bolt->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame
726 VectorCopy( start, bolt->s.pos.trBase );
727 VectorScale( dir, 900, bolt->s.pos.trDelta );
728 SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
729 VectorCopy (start, bolt->r.currentOrigin);
730
731 return bolt;
732 }
733
734 /*
735 =================
736 fire_grapple
737 =================
738 */
739 gentity_t *fire_grapple (gentity_t *self, vec3_t start, vec3_t dir) {
740 gentity_t *hook;
741 //unlagged - grapple
742 int hooktime;
743 //unlagged - grapple
744
745 VectorNormalize (dir);
746
747 hook = G_Spawn();
748 hook->classname = "hook";
749 hook->nextthink = level.time + 10000;
750 hook->think = Weapon_HookFree;
751 hook->s.eType = ET_MISSILE;
752 hook->r.svFlags = SVF_USE_CURRENT_ORIGIN;
753 hook->s.weapon = WP_GRAPPLING_HOOK;
754 hook->r.ownerNum = self->s.number;
755 hook->methodOfDeath = MOD_GRAPPLE;
756 hook->clipmask = MASK_SHOT;
757 hook->parent = self;
758 hook->target_ent = NULL;
759
760 //unlagged - grapple
761 // we might want this later
762 hook->s.otherEntityNum = self->s.number;
763
764 // setting the projectile base time back makes the hook's first
765 // step larger
766
767 if ( self->client ) {
768 hooktime = self->client->pers.cmd.serverTime + 50;
769 }
770 else {
771 hooktime = level.time - MISSILE_PRESTEP_TIME;
772 }
773
774 hook->s.pos.trTime = hooktime;
775 //unlagged - grapple
776
777 hook->s.pos.trType = TR_LINEAR;
778 //unlagged - grapple
779 //hook->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame
780 //unlagged - grapple
781 hook->s.otherEntityNum = self->s.number; // use to match beam in client
782 VectorCopy( start, hook->s.pos.trBase );
783 VectorScale( dir, 800, hook->s.pos.trDelta );
784 SnapVector( hook->s.pos.trDelta ); // save net bandwidth
785 VectorCopy (start, hook->r.currentOrigin);
786
787 self->client->hook = hook;
788
789 return hook;
790 }
791
792 /*
793 =================
794 fire_nail
795 =================
796 */
797 #define NAILGUN_SPREAD 500
798
799 gentity_t *fire_nail( gentity_t *self, vec3_t start, vec3_t forward, vec3_t right, vec3_t up ) {
800 gentity_t *bolt;
801 vec3_t dir;
802 vec3_t end;
803 float r, u, scale;
804
805 bolt = G_Spawn();
806 bolt->classname = "nail";
807 bolt->nextthink = level.time + 10000;
808 bolt->think = G_ExplodeMissile;
809 bolt->s.eType = ET_MISSILE;
810 bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;
811 bolt->s.weapon = WP_NAILGUN;
812 bolt->r.ownerNum = self->s.number;
813 //unlagged - projectile nudge
814 // we'll need this for nudging projectiles later
815 bolt->s.otherEntityNum = self->s.number;
816 //unlagged - projectile nudge
817 bolt->parent = self;
818 bolt->damage = 20;
819 bolt->methodOfDeath = MOD_NAIL;
820 bolt->clipmask = MASK_SHOT;
821 bolt->target_ent = NULL;
822
823 bolt->s.pos.trType = TR_LINEAR;
824 bolt->s.pos.trTime = level.time;
825 VectorCopy( start, bolt->s.pos.trBase );
826
827 r = random() * M_PI * 2.0f;
828 u = sin(r) * crandom() * NAILGUN_SPREAD * 16;
829 r = cos(r) * crandom() * NAILGUN_SPREAD * 16;
830 VectorMA( start, 8192 * 16, forward, end);
831 VectorMA (end, r, right, end);
832 VectorMA (end, u, up, end);
833 VectorSubtract( end, start, dir );
834 VectorNormalize( dir );
835
836 scale = 555 + random() * 1800;
837 VectorScale( dir, scale, bolt->s.pos.trDelta );
838 SnapVector( bolt->s.pos.trDelta );
839
840 VectorCopy( start, bolt->r.currentOrigin );
841
842 return bolt;
843 }
844
845
846 /*
847 =================
848 fire_prox
849 =================
850 */
851 gentity_t *fire_prox( gentity_t *self, vec3_t start, vec3_t dir ) {
852 gentity_t *bolt;
853
854 VectorNormalize (dir);
855
856 bolt = G_Spawn();
857 bolt->classname = "prox mine";
858 bolt->nextthink = level.time + 3000;
859 bolt->think = G_ExplodeMissile;
860 bolt->s.eType = ET_MISSILE;
861 bolt->r.svFlags = SVF_USE_CURRENT_ORIGIN;
862 bolt->s.weapon = WP_PROX_LAUNCHER;
863 bolt->s.eFlags = 0;
864 bolt->r.ownerNum = self->s.number;
865 //unlagged - projectile nudge
866 // we'll need this for nudging projectiles later
867 bolt->s.otherEntityNum = self->s.number;
868 //unlagged - projectile nudge
869 bolt->parent = self;
870 bolt->damage = 0;
871 bolt->splashDamage = 100;
872 bolt->splashRadius = 150;
873 bolt->methodOfDeath = MOD_PROXIMITY_MINE;
874 bolt->splashMethodOfDeath = MOD_PROXIMITY_MINE;
875 bolt->clipmask = MASK_SHOT;
876 bolt->target_ent = NULL;
877 // count is used to check if the prox mine left the player bbox
878 // if count == 1 then the prox mine left the player bbox and can attack to it
879 bolt->count = 0;
880
881 //FIXME: we prolly wanna abuse another field
882 bolt->s.generic1 = self->client->sess.sessionTeam;
883
884 bolt->s.pos.trType = TR_GRAVITY;
885 bolt->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame
886 VectorCopy( start, bolt->s.pos.trBase );
887 VectorScale( dir, 700, bolt->s.pos.trDelta );
888 SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
889
890 VectorCopy (start, bolt->r.currentOrigin);
891
892 return bolt;
893 }