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