1 /*
2 * Copyright (C) 1997-2001 Id Software, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59
17 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20 #include "g_local.h"
21
22
23 /*
24 * ================= check_dodge
25 *
26 * This is a support routine used when a client is firing a non-instant attack
27 * weapon. It checks to see if a monster's dodge function should be called.
28 * =================
29 */
30 static void
check_dodge(edict_t * self,vec3_t start,vec3_t dir,int speed)31 check_dodge(edict_t * self, vec3_t start, vec3_t dir, int speed)
32 {
33 vec3_t end;
34 vec3_t v;
35 trace_t tr;
36 float eta;
37
38 /* easy mode only ducks one quarter the time */
39 if (skill->value == 0) {
40 if (random() > 0.25)
41 return;
42 }
43 VectorMA(start, 8192, dir, end);
44 tr = gi.trace(start, NULL, NULL, end, self, MASK_SHOT);
45 if ((tr.ent) && (tr.ent->svflags & SVF_MONSTER) && (tr.ent->health > 0) && (tr.ent->monsterinfo.dodge) && infront(tr.ent, self)) {
46 VectorSubtract(tr.endpos, start, v);
47 eta = (VectorLength(v) - tr.ent->maxs[0]) / speed;
48 tr.ent->monsterinfo.dodge(tr.ent, self, eta);
49 }
50 }
51
52
53 /*
54 * ================= fire_hit
55 *
56 * Used for all impact (hit/punch/slash) attacks =================
57 */
58 qboolean
fire_hit(edict_t * self,vec3_t aim,int damage,int kick)59 fire_hit(edict_t * self, vec3_t aim, int damage, int kick)
60 {
61 trace_t tr;
62 vec3_t forward, right, up;
63 vec3_t v;
64 vec3_t point;
65 float range;
66 vec3_t dir;
67
68 /* see if enemy is in range */
69 VectorSubtract(self->enemy->s.origin, self->s.origin, dir);
70 range = VectorLength(dir);
71 if (range > aim[0])
72 return false;
73
74 if (aim[1] > self->mins[0] && aim[1] < self->maxs[0]) {
75
76 /*
77 * the hit is straight on so back the range up to the edge of
78 * their bbox
79 */
80 range -= self->enemy->maxs[0];
81 } else {
82
83 /*
84 * this is a side hit so adjust the "right" value out to the
85 * edge of their bbox
86 */
87 if (aim[1] < 0)
88 aim[1] = self->enemy->mins[0];
89 else
90 aim[1] = self->enemy->maxs[0];
91 }
92
93 VectorMA(self->s.origin, range, dir, point);
94
95 tr = gi.trace(self->s.origin, NULL, NULL, point, self, MASK_SHOT);
96 if (tr.fraction < 1) {
97 if (!tr.ent->takedamage)
98 return false;
99
100 /*
101 * if it will hit any client/monster then hit the one we
102 * wanted to hit
103 */
104 if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
105 tr.ent = self->enemy;
106 }
107 AngleVectors(self->s.angles, forward, right, up);
108 VectorMA(self->s.origin, range, forward, point);
109 VectorMA(point, aim[1], right, point);
110 VectorMA(point, aim[2], up, point);
111 VectorSubtract(point, self->enemy->s.origin, dir);
112
113 /* do the damage */
114 T_Damage(tr.ent, self, self, dir, point, vec3_origin, damage, kick / 2, DAMAGE_NO_KNOCKBACK, MOD_HIT);
115
116 if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
117 return false;
118
119 /* do our special form of knockback here */
120 VectorMA(self->enemy->absmin, 0.5, self->enemy->size, v);
121 VectorSubtract(v, point, v);
122 VectorNormalize(v);
123 VectorMA(self->enemy->velocity, kick, v, self->enemy->velocity);
124 if (self->enemy->velocity[2] > 0)
125 self->enemy->groundentity = NULL;
126 return true;
127 }
128
129
130 /*
131 * ================= fire_lead
132 *
133 * This is an internal support routine used for bullet/pellet based weapons.
134 * =================
135 */
136 static void
fire_lead(edict_t * self,vec3_t start,vec3_t aimdir,int damage,int kick,int te_impact,int hspread,int vspread,int mod)137 fire_lead(edict_t * self, vec3_t start, vec3_t aimdir, int damage, int kick, int te_impact, int hspread, int vspread, int mod)
138 {
139 trace_t tr;
140 vec3_t dir;
141 vec3_t forward, right, up;
142 vec3_t end;
143 float r;
144 float u;
145 vec3_t water_start;
146 qboolean water = false;
147 int content_mask = MASK_SHOT | MASK_WATER;
148
149 tr = gi.trace(self->s.origin, NULL, NULL, start, self, MASK_SHOT);
150 if (!(tr.fraction < 1.0)) {
151 vectoangles(aimdir, dir);
152 AngleVectors(dir, forward, right, up);
153
154 r = crandom() * hspread;
155 u = crandom() * vspread;
156 VectorMA(start, 8192, forward, end);
157 VectorMA(end, r, right, end);
158 VectorMA(end, u, up, end);
159
160 if (gi.pointcontents(start) & MASK_WATER) {
161 water = true;
162 VectorCopy(start, water_start);
163 content_mask &= ~MASK_WATER;
164 }
165 tr = gi.trace(start, NULL, NULL, end, self, content_mask);
166
167 /* see if we hit water */
168 if (tr.contents & MASK_WATER) {
169 int color;
170
171 water = true;
172 VectorCopy(tr.endpos, water_start);
173
174 if (!VectorCompare(start, tr.endpos)) {
175 if (tr.contents & CONTENTS_WATER) {
176 if (strcmp(tr.surface->name, "*brwater") == 0)
177 color = SPLASH_BROWN_WATER;
178 else
179 color = SPLASH_BLUE_WATER;
180 } else if (tr.contents & CONTENTS_SLIME)
181 color = SPLASH_SLIME;
182 else if (tr.contents & CONTENTS_LAVA)
183 color = SPLASH_LAVA;
184 else
185 color = SPLASH_UNKNOWN;
186
187 if (color != SPLASH_UNKNOWN) {
188 gi.WriteByte(svc_temp_entity);
189 gi.WriteByte(TE_SPLASH);
190 gi.WriteByte(8);
191 gi.WritePosition(tr.endpos);
192 gi.WriteDir(tr.plane.normal);
193 gi.WriteByte(color);
194 gi.multicast(tr.endpos, MULTICAST_PVS);
195 }
196
197 /*
198 * change bullet's course when it enters
199 * water
200 */
201 VectorSubtract(end, start, dir);
202 vectoangles(dir, dir);
203 AngleVectors(dir, forward, right, up);
204 r = crandom() * hspread * 2;
205 u = crandom() * vspread * 2;
206 VectorMA(water_start, 8192, forward, end);
207 VectorMA(end, r, right, end);
208 VectorMA(end, u, up, end);
209 }
210 /* re-trace ignoring water this time */
211 tr = gi.trace(water_start, NULL, NULL, end, self, MASK_SHOT);
212 }
213 }
214 /* send gun puff / flash */
215 if (!((tr.surface) && (tr.surface->flags & SURF_SKY))) {
216 if (tr.fraction < 1.0) {
217 if (tr.ent->takedamage) {
218 T_Damage(tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
219 } else {
220 if (strncmp(tr.surface->name, "sky", 3) != 0) {
221 gi.WriteByte(svc_temp_entity);
222 gi.WriteByte(te_impact);
223 gi.WritePosition(tr.endpos);
224 gi.WriteDir(tr.plane.normal);
225 gi.multicast(tr.endpos, MULTICAST_PVS);
226
227 if (self->client)
228 PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
229 }
230 }
231 }
232 }
233
234 /*
235 * if went through water, determine where the end and make a bubble
236 * trail
237 */
238 if (water) {
239 vec3_t pos;
240
241 VectorSubtract(tr.endpos, water_start, dir);
242 VectorNormalize(dir);
243 VectorMA(tr.endpos, -2, dir, pos);
244 if (gi.pointcontents(pos) & MASK_WATER)
245 VectorCopy(pos, tr.endpos);
246 else
247 tr = gi.trace(pos, NULL, NULL, water_start, tr.ent, MASK_WATER);
248
249 VectorAdd(water_start, tr.endpos, pos);
250 VectorScale(pos, 0.5, pos);
251
252 gi.WriteByte(svc_temp_entity);
253 gi.WriteByte(TE_BUBBLETRAIL);
254 gi.WritePosition(water_start);
255 gi.WritePosition(tr.endpos);
256 gi.multicast(pos, MULTICAST_PVS);
257 }
258 }
259
260
261 /*
262 * ================= fire_bullet
263 *
264 * Fires a single round. Used for machinegun and chaingun. Would be fine for
265 * pistols, rifles, etc.... =================
266 */
267 void
fire_bullet(edict_t * self,vec3_t start,vec3_t aimdir,int damage,int kick,int hspread,int vspread,int mod)268 fire_bullet(edict_t * self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod)
269 {
270 fire_lead(self, start, aimdir, damage, kick, TE_GUNSHOT, hspread, vspread, mod);
271 }
272
273
274 /*
275 * ================= fire_shotgun
276 *
277 * Shoots shotgun pellets. Used by shotgun and super shotgun. =================
278 */
279 void
fire_shotgun(edict_t * self,vec3_t start,vec3_t aimdir,int damage,int kick,int hspread,int vspread,int count,int mod)280 fire_shotgun(edict_t * self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod)
281 {
282 int i;
283
284 for (i = 0; i < count; i++)
285 fire_lead(self, start, aimdir, damage, kick, TE_SHOTGUN, hspread, vspread, mod);
286 }
287
288
289 /*
290 * ================= fire_blaster
291 *
292 * Fires a single blaster bolt. Used by the blaster and hyper blaster.
293 * =================
294 */
295 void
blaster_touch(edict_t * self,edict_t * other,cplane_t * plane,csurface_t * surf)296 blaster_touch(edict_t * self, edict_t * other, cplane_t * plane, csurface_t * surf)
297 {
298 int mod;
299
300 if (other == self->owner)
301 return;
302
303 if (surf && (surf->flags & SURF_SKY)) {
304 G_FreeEdict(self);
305 return;
306 }
307 if (self->owner->client)
308 PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
309
310 if (other->takedamage) {
311 if (self->spawnflags & 1)
312 mod = MOD_HYPERBLASTER;
313 else
314 mod = MOD_BLASTER;
315 T_Damage(other, self, self->owner, self->velocity, self->s.origin, plane->normal, self->dmg, 1, DAMAGE_ENERGY, mod);
316 } else {
317 gi.WriteByte(svc_temp_entity);
318 gi.WriteByte(TE_BLASTER);
319 gi.WritePosition(self->s.origin);
320 if (!plane)
321 gi.WriteDir(vec3_origin);
322 else
323 gi.WriteDir(plane->normal);
324 gi.multicast(self->s.origin, MULTICAST_PVS);
325 }
326
327 G_FreeEdict(self);
328 }
329
330 void
fire_blaster(edict_t * self,vec3_t start,vec3_t dir,int damage,int speed,int effect,qboolean hyper)331 fire_blaster(edict_t * self, vec3_t start, vec3_t dir, int damage, int speed, int effect, qboolean hyper)
332 {
333 edict_t *bolt;
334 trace_t tr;
335
336 VectorNormalize(dir);
337
338 bolt = G_Spawn();
339 bolt->svflags = SVF_DEADMONSTER;
340 /* yes, I know it looks weird that projectiles are deadmonsters */
341 /* what this means is that when prediction is used against the object */
342
343 /*
344 * (blaster/hyperblaster shots), the player won't be solid clipped
345 * against
346 */
347 /* the object. Right now trying to run into a firing hyperblaster */
348 /* is very jerky since you are predicted 'against' the shots. */
349 VectorCopy(start, bolt->s.origin);
350 VectorCopy(start, bolt->s.old_origin);
351 vectoangles(dir, bolt->s.angles);
352 VectorScale(dir, speed, bolt->velocity);
353 bolt->movetype = MOVETYPE_FLYMISSILE;
354 bolt->clipmask = MASK_SHOT;
355 bolt->solid = SOLID_BBOX;
356 #ifdef GAME_MOD
357 if (alt_fire_blaster->value) {
358 bolt->s.effects |= EF_IONRIPPER;
359 } else {
360 bolt->s.effects |= effect;
361 }
362 #else
363 bolt->s.effects |= effect;
364 #endif
365 bolt->s.renderfx |= RF_NOSHADOW;
366 VectorClear(bolt->mins);
367 VectorClear(bolt->maxs);
368 bolt->s.modelindex = gi.modelindex("models/objects/laser/tris.md2");
369 bolt->s.sound = gi.soundindex("misc/lasfly.wav");
370 bolt->owner = self;
371 bolt->touch = blaster_touch;
372 bolt->nextthink = level.time + 2;
373 bolt->think = G_FreeEdict;
374 bolt->dmg = damage;
375 bolt->classname = "bolt";
376 #ifdef GAME_MOD
377 if (alt_fire_blaster->value) {
378 bolt->s.effects |= EF_IONRIPPER;
379 }
380 #endif
381 if (hyper)
382 bolt->spawnflags = 1;
383 gi.linkentity(bolt);
384
385 if (self->client)
386 check_dodge(self, bolt->s.origin, dir, speed);
387
388 tr = gi.trace(self->s.origin, NULL, NULL, bolt->s.origin, bolt, MASK_SHOT);
389 if (tr.fraction < 1.0) {
390 VectorMA(bolt->s.origin, -10, dir, bolt->s.origin);
391 bolt->touch(bolt, tr.ent, NULL, NULL);
392 }
393 }
394
395
396 /*
397 * ================= fire_grenade =================
398 */
399 static void
Grenade_Explode(edict_t * ent)400 Grenade_Explode(edict_t * ent)
401 {
402 vec3_t origin;
403 int mod;
404
405 if (ent->owner->client)
406 PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
407
408 /*
409 * FIXME: if we are onground then raise our Z just a bit since we are
410 * a point?
411 */
412 if (ent->enemy) {
413 float points;
414 vec3_t v;
415 vec3_t dir;
416
417 VectorAdd(ent->enemy->mins, ent->enemy->maxs, v);
418 VectorMA(ent->enemy->s.origin, 0.5, v, v);
419 VectorSubtract(ent->s.origin, v, v);
420 points = ent->dmg - 0.5 * VectorLength(v);
421 VectorSubtract(ent->enemy->s.origin, ent->s.origin, dir);
422 if (ent->spawnflags & 1)
423 mod = MOD_HANDGRENADE;
424 else
425 mod = MOD_GRENADE;
426 T_Damage(ent->enemy, ent, ent->owner, dir, ent->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
427 }
428 if (ent->spawnflags & 2)
429 mod = MOD_HELD_GRENADE;
430 else if (ent->spawnflags & 1)
431 mod = MOD_HG_SPLASH;
432 else
433 mod = MOD_G_SPLASH;
434 T_RadiusDamage(ent, ent->owner, ent->dmg, ent->enemy, ent->dmg_radius, mod);
435
436 VectorMA(ent->s.origin, -0.02, ent->velocity, origin);
437 gi.WriteByte(svc_temp_entity);
438 if (ent->waterlevel) {
439 if (ent->groundentity)
440 gi.WriteByte(TE_GRENADE_EXPLOSION_WATER);
441 else
442 gi.WriteByte(TE_ROCKET_EXPLOSION_WATER);
443 } else {
444 if (ent->groundentity)
445 gi.WriteByte(TE_GRENADE_EXPLOSION);
446 else
447 gi.WriteByte(TE_ROCKET_EXPLOSION);
448 }
449 gi.WritePosition(origin);
450 gi.multicast(ent->s.origin, MULTICAST_PHS);
451
452 G_FreeEdict(ent);
453 }
454
455 static void
Grenade_Touch(edict_t * ent,edict_t * other,cplane_t * plane,csurface_t * surf)456 Grenade_Touch(edict_t * ent, edict_t * other, cplane_t * plane, csurface_t * surf)
457 {
458 if (other == ent->owner)
459 return;
460
461 if (surf && (surf->flags & SURF_SKY)) {
462 G_FreeEdict(ent);
463 return;
464 }
465 if (!other->takedamage) {
466 if (ent->spawnflags & 1) {
467 if (random() > 0.5)
468 gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/hgrenb1a.wav"), 1, ATTN_NORM, 0);
469 else
470 gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/hgrenb2a.wav"), 1, ATTN_NORM, 0);
471 } else {
472 gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/grenlb1b.wav"), 1, ATTN_NORM, 0);
473 }
474 return;
475 }
476 ent->enemy = other;
477 Grenade_Explode(ent);
478 }
479
480 void
fire_grenade(edict_t * self,vec3_t start,vec3_t aimdir,int damage,int speed,float timer,float damage_radius)481 fire_grenade(edict_t * self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius)
482 {
483 edict_t *grenade;
484 vec3_t dir;
485 vec3_t forward, right, up;
486
487 vectoangles(aimdir, dir);
488 AngleVectors(dir, forward, right, up);
489
490 grenade = G_Spawn();
491 VectorCopy(start, grenade->s.origin);
492 VectorScale(aimdir, speed, grenade->velocity);
493 VectorMA(grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
494 VectorMA(grenade->velocity, crandom() * 10.0, right, grenade->velocity);
495 VectorSet(grenade->avelocity, 300, 300, 300);
496 grenade->movetype = MOVETYPE_BOUNCE;
497 grenade->clipmask = MASK_SHOT;
498 grenade->solid = SOLID_BBOX;
499 grenade->s.effects |= EF_GRENADE;
500 VectorClear(grenade->mins);
501 VectorClear(grenade->maxs);
502 grenade->s.modelindex = gi.modelindex("models/objects/grenade/tris.md2");
503 grenade->owner = self;
504 grenade->touch = Grenade_Touch;
505 grenade->nextthink = level.time + timer;
506 grenade->think = Grenade_Explode;
507 grenade->dmg = damage;
508 grenade->dmg_radius = damage_radius;
509 grenade->classname = "grenade";
510
511 gi.linkentity(grenade);
512 }
513
514 void
fire_grenade2(edict_t * self,vec3_t start,vec3_t aimdir,int damage,int speed,float timer,float damage_radius,qboolean held)515 fire_grenade2(edict_t * self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held)
516 {
517 edict_t *grenade;
518 vec3_t dir;
519 vec3_t forward, right, up;
520
521 vectoangles(aimdir, dir);
522 AngleVectors(dir, forward, right, up);
523
524 grenade = G_Spawn();
525 VectorCopy(start, grenade->s.origin);
526 VectorScale(aimdir, speed, grenade->velocity);
527 VectorMA(grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
528 VectorMA(grenade->velocity, crandom() * 10.0, right, grenade->velocity);
529 VectorSet(grenade->avelocity, 300, 300, 300);
530 grenade->movetype = MOVETYPE_BOUNCE;
531 grenade->clipmask = MASK_SHOT;
532 grenade->solid = SOLID_BBOX;
533 grenade->s.effects |= EF_GRENADE;
534 VectorClear(grenade->mins);
535 VectorClear(grenade->maxs);
536 grenade->s.modelindex = gi.modelindex("models/objects/grenade2/tris.md2");
537 grenade->owner = self;
538 grenade->touch = Grenade_Touch;
539 grenade->nextthink = level.time + timer;
540 grenade->think = Grenade_Explode;
541 grenade->dmg = damage;
542 grenade->dmg_radius = damage_radius;
543 grenade->classname = "hgrenade";
544 if (held)
545 grenade->spawnflags = 3;
546 else
547 grenade->spawnflags = 1;
548 grenade->s.sound = gi.soundindex("weapons/hgrenc1b.wav");
549
550 if (timer <= 0.0)
551 Grenade_Explode(grenade);
552 else {
553 gi.sound(self, CHAN_WEAPON, gi.soundindex("weapons/hgrent1a.wav"), 1, ATTN_NORM, 0);
554 gi.linkentity(grenade);
555 }
556 }
557
558
559 /*
560 * ================= fire_rocket =================
561 */
562 void
rocket_touch(edict_t * ent,edict_t * other,cplane_t * plane,csurface_t * surf)563 rocket_touch(edict_t * ent, edict_t * other, cplane_t * plane, csurface_t * surf)
564 {
565 vec3_t origin;
566 int n;
567
568 if (other == ent->owner)
569 return;
570
571 if (surf && (surf->flags & SURF_SKY)) {
572 G_FreeEdict(ent);
573 return;
574 }
575 if (ent->owner->client)
576 PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
577
578 /* calculate position for the explosion entity */
579 VectorMA(ent->s.origin, -0.02, ent->velocity, origin);
580
581 if (other->takedamage) {
582 T_Damage(other, ent, ent->owner, ent->velocity, ent->s.origin, plane->normal, ent->dmg, 0, 0, MOD_ROCKET);
583 } else {
584 /* don't throw any debris in net games */
585 if (!deathmatch->value && !coop->value) {
586 if ((surf) && !(surf->flags & (SURF_WARP | SURF_TRANS33 | SURF_TRANS66 | SURF_FLOWING))) {
587 n = rand() % 5;
588 while (n--)
589 ThrowDebris(ent, "models/objects/debris2/tris.md2", 2, ent->s.origin);
590 }
591 }
592 }
593
594 T_RadiusDamage(ent, ent->owner, ent->radius_dmg, other, ent->dmg_radius, MOD_R_SPLASH);
595
596 gi.WriteByte(svc_temp_entity);
597 if (ent->waterlevel)
598 gi.WriteByte(TE_ROCKET_EXPLOSION_WATER);
599 else
600 gi.WriteByte(TE_ROCKET_EXPLOSION);
601 gi.WritePosition(origin);
602 gi.multicast(ent->s.origin, MULTICAST_PHS);
603
604 G_FreeEdict(ent);
605 }
606
607 void
fire_rocket(edict_t * self,vec3_t start,vec3_t dir,int damage,int speed,float damage_radius,int radius_damage)608 fire_rocket(edict_t * self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage)
609 {
610 edict_t *rocket;
611
612 rocket = G_Spawn();
613 VectorCopy(start, rocket->s.origin);
614 VectorCopy(dir, rocket->movedir);
615 vectoangles(dir, rocket->s.angles);
616 VectorScale(dir, speed, rocket->velocity);
617 rocket->movetype = MOVETYPE_FLYMISSILE;
618 rocket->clipmask = MASK_SHOT;
619 rocket->solid = SOLID_BBOX;
620 rocket->s.effects |= EF_ROCKET;
621 rocket->s.renderfx |= RF_IR_VISIBLE | RF_NOSHADOW;
622 VectorClear(rocket->mins);
623 VectorClear(rocket->maxs);
624 rocket->s.modelindex = gi.modelindex("models/objects/rocket/tris.md2");
625 rocket->owner = self;
626 rocket->touch = rocket_touch;
627 rocket->nextthink = level.time + 8000 / speed;
628 rocket->think = G_FreeEdict;
629 rocket->dmg = damage;
630 rocket->radius_dmg = radius_damage;
631 rocket->dmg_radius = damage_radius;
632 rocket->s.sound = gi.soundindex("weapons/rockfly.wav");
633 rocket->classname = "rocket";
634
635 if (self->client)
636 check_dodge(self, rocket->s.origin, dir, speed);
637
638 gi.linkentity(rocket);
639 }
640
641
642 /*
643 * ================= fire_rail =================
644 */
645 void
fire_rail(edict_t * self,vec3_t start,vec3_t aimdir,int damage,int kick)646 fire_rail(edict_t * self, vec3_t start, vec3_t aimdir, int damage, int kick)
647 {
648 vec3_t from;
649 vec3_t end;
650 trace_t tr;
651 edict_t *ignore;
652 int mask;
653 qboolean water;
654
655 VectorMA(start, 8192, aimdir, end);
656 VectorCopy(start, from);
657 ignore = self;
658 water = false;
659 mask = MASK_SHOT | CONTENTS_SLIME | CONTENTS_LAVA;
660 while (ignore) {
661 tr = gi.trace(from, NULL, NULL, end, ignore, mask);
662
663 if (tr.contents & (CONTENTS_SLIME | CONTENTS_LAVA)) {
664 mask &= ~(CONTENTS_SLIME | CONTENTS_LAVA);
665 water = true;
666 } else {
667
668 /*
669 * ZOID--added so rail goes through SOLID_BBOX
670 * entities (gibs, etc)
671 */
672 if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client) ||
673 (tr.ent->solid == SOLID_BBOX))
674 ignore = tr.ent;
675 else
676 ignore = NULL;
677
678 if ((tr.ent != self) && (tr.ent->takedamage))
679 T_Damage(tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, 0, MOD_RAILGUN);
680 else
681 ignore = NULL;
682 }
683
684 VectorCopy(tr.endpos, from);
685 }
686
687 /* send gun puff / flash */
688 gi.WriteByte(svc_temp_entity);
689 gi.WriteByte(TE_RAILTRAIL);
690 gi.WritePosition(start);
691 gi.WritePosition(tr.endpos);
692 gi.multicast(self->s.origin, MULTICAST_PHS);
693 /* gi.multicast (start, MULTICAST_PHS); */
694 if (water) {
695 gi.WriteByte(svc_temp_entity);
696 gi.WriteByte(TE_RAILTRAIL);
697 gi.WritePosition(start);
698 gi.WritePosition(tr.endpos);
699 gi.multicast(tr.endpos, MULTICAST_PHS);
700 }
701 if (self->client)
702 PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
703 }
704
705
706 /*
707 * ================= fire_bfg =================
708 */
709 void
bfg_explode(edict_t * self)710 bfg_explode(edict_t * self)
711 {
712 edict_t *ent;
713 float points;
714 vec3_t v;
715 float dist;
716
717 if (self->s.frame == 0) {
718 /* the BFG effect */
719 ent = NULL;
720 while ((ent = findradius(ent, self->s.origin, self->dmg_radius)) != NULL) {
721 if (!ent->takedamage)
722 continue;
723 if (ent == self->owner)
724 continue;
725 if (!CanDamage(ent, self))
726 continue;
727 if (!CanDamage(ent, self->owner))
728 continue;
729
730 VectorAdd(ent->mins, ent->maxs, v);
731 VectorMA(ent->s.origin, 0.5, v, v);
732 VectorSubtract(self->s.origin, v, v);
733 dist = VectorLength(v);
734 points = self->radius_dmg * (1.0 - sqrt(dist / self->dmg_radius));
735 if (ent == self->owner)
736 points = points * 0.5;
737
738 gi.WriteByte(svc_temp_entity);
739 gi.WriteByte(TE_BFG_EXPLOSION);
740 gi.WritePosition(ent->s.origin);
741 gi.multicast(ent->s.origin, MULTICAST_PHS);
742 T_Damage(ent, self, self->owner, self->velocity, ent->s.origin, vec3_origin, (int)points, 0, DAMAGE_ENERGY, MOD_BFG_EFFECT);
743 }
744 }
745 self->nextthink = level.time + FRAMETIME;
746 self->s.frame++;
747 if (self->s.frame == 5)
748 self->think = G_FreeEdict;
749 }
750
751 void
bfg_touch(edict_t * self,edict_t * other,cplane_t * plane,csurface_t * surf)752 bfg_touch(edict_t * self, edict_t * other, cplane_t * plane, csurface_t * surf)
753 {
754 if (other == self->owner)
755 return;
756
757 if (surf && (surf->flags & SURF_SKY)) {
758 G_FreeEdict(self);
759 return;
760 }
761 if (self->owner->client)
762 PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
763
764 /* core explosion - prevents firing it into the wall/floor */
765 if (other->takedamage)
766 T_Damage(other, self, self->owner, self->velocity, self->s.origin, plane->normal, 200, 0, 0, MOD_BFG_BLAST);
767 T_RadiusDamage(self, self->owner, 200, other, 100, MOD_BFG_BLAST);
768
769 gi.sound(self, CHAN_VOICE, gi.soundindex("weapons/bfg__x1b.wav"), 1, ATTN_NORM, 0);
770 self->solid = SOLID_NOT;
771 self->touch = NULL;
772 VectorMA(self->s.origin, -1 * FRAMETIME, self->velocity, self->s.origin);
773 VectorClear(self->velocity);
774 self->s.modelindex = gi.modelindex("sprites/s_bfg3.sp2");
775 self->s.frame = 0;
776 self->s.sound = 0;
777 self->s.effects &= ~EF_ANIM_ALLFAST;
778 self->think = bfg_explode;
779 self->nextthink = level.time + FRAMETIME;
780 self->enemy = other;
781
782 gi.WriteByte(svc_temp_entity);
783 gi.WriteByte(TE_BFG_BIGEXPLOSION);
784 gi.WritePosition(self->s.origin);
785 gi.multicast(self->s.origin, MULTICAST_PVS);
786 }
787
788
789 void
bfg_think(edict_t * self)790 bfg_think(edict_t * self)
791 {
792 edict_t *ent;
793 edict_t *ignore;
794 vec3_t point;
795 vec3_t dir;
796 vec3_t start;
797 vec3_t end;
798 int dmg;
799 trace_t tr;
800
801 if (deathmatch->value)
802 dmg = 5;
803 else
804 dmg = 10;
805
806 ent = NULL;
807 while ((ent = findradius(ent, self->s.origin, 256)) != NULL) {
808 if (ent == self)
809 continue;
810
811 if (ent == self->owner)
812 continue;
813
814 if (!ent->takedamage)
815 continue;
816
817 if (!(ent->svflags & SVF_MONSTER) && (!ent->client) && (strcmp(ent->classname, "misc_explobox") != 0))
818 continue;
819
820 VectorMA(ent->absmin, 0.5, ent->size, point);
821
822 VectorSubtract(point, self->s.origin, dir);
823 VectorNormalize(dir);
824
825 ignore = self;
826 VectorCopy(self->s.origin, start);
827 VectorMA(start, 2048, dir, end);
828 while (1) {
829 tr = gi.trace(start, NULL, NULL, end, ignore, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_DEADMONSTER);
830
831 if (!tr.ent)
832 break;
833
834 /* hurt it if we can */
835 if ((tr.ent->takedamage) && !(tr.ent->flags & FL_IMMUNE_LASER) && (tr.ent != self->owner))
836 T_Damage(tr.ent, self, self->owner, dir, tr.endpos, vec3_origin, dmg, 1, DAMAGE_ENERGY, MOD_BFG_LASER);
837
838 /*
839 * if we hit something that's not a monster or player
840 * we're done
841 */
842 if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client)) {
843 gi.WriteByte(svc_temp_entity);
844 gi.WriteByte(TE_LASER_SPARKS);
845 gi.WriteByte(4);
846 gi.WritePosition(tr.endpos);
847 gi.WriteDir(tr.plane.normal);
848 gi.WriteByte(self->s.skinnum);
849 gi.multicast(tr.endpos, MULTICAST_PVS);
850 break;
851 }
852 ignore = tr.ent;
853 VectorCopy(tr.endpos, start);
854 }
855
856 gi.WriteByte(svc_temp_entity);
857 gi.WriteByte(TE_BFG_LASER);
858 gi.WritePosition(self->s.origin);
859 gi.WritePosition(tr.endpos);
860 gi.multicast(self->s.origin, MULTICAST_PHS);
861 }
862
863 self->nextthink = level.time + FRAMETIME;
864 }
865
866
867 void
fire_bfg(edict_t * self,vec3_t start,vec3_t dir,int damage,int speed,float damage_radius)868 fire_bfg(edict_t * self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius)
869 {
870 edict_t *bfg;
871
872 bfg = G_Spawn();
873 VectorCopy(start, bfg->s.origin);
874 VectorCopy(dir, bfg->movedir);
875 vectoangles(dir, bfg->s.angles);
876 VectorScale(dir, speed, bfg->velocity);
877 bfg->movetype = MOVETYPE_FLYMISSILE;
878 bfg->clipmask = MASK_SHOT;
879 bfg->solid = SOLID_BBOX;
880 bfg->s.effects |= EF_BFG | EF_ANIM_ALLFAST;
881 VectorClear(bfg->mins);
882 VectorClear(bfg->maxs);
883 bfg->s.modelindex = gi.modelindex("sprites/s_bfg1.sp2");
884 bfg->owner = self;
885 bfg->touch = bfg_touch;
886 bfg->nextthink = level.time + 8000 / speed;
887 bfg->think = G_FreeEdict;
888 bfg->radius_dmg = damage;
889 bfg->dmg_radius = damage_radius;
890 bfg->classname = "bfg blast";
891 bfg->s.sound = gi.soundindex("weapons/bfg__l1a.wav");
892
893 bfg->think = bfg_think;
894 bfg->nextthink = level.time + FRAMETIME;
895 bfg->teammaster = bfg;
896 bfg->teamchain = NULL;
897
898 if (self->client)
899 check_dodge(self, bfg->s.origin, dir, speed);
900
901 gi.linkentity(bfg);
902 }
903