Debian Codegraph @

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