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