This repository was archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg_weapon.c
3105 lines (2693 loc) · 80.8 KB
/
g_weapon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "g_local.h"
#define NUKE_QUAKE_TIME 3
#define NUKE_QUAKE_STRENGTH 100
/*
=================
check_dodge
This is a support routine used when a client is firing
a non-instant attack weapon. It checks to see if a
monster's dodge function should be called.
=================
*/
//static void check_dodge (edict_t *self, vec3_t start, vec3_t dir, int speed)
void check_dodge (edict_t *self, vec3_t start, vec3_t dir, int speed) //PGM
{
vec3_t end;
vec3_t v;
trace_t tr;
float eta;
// easy mode only ducks one quarter the time
if (skill->value == 0)
{
if (random() > 0.25)
return;
}
VectorMA (start, 8192, dir, end);
tr = gi.trace (start, NULL, NULL, end, self, MASK_SHOT);
if ((tr.ent) && (tr.ent->svflags & SVF_MONSTER) && (tr.ent->health > 0) && (tr.ent->monsterinfo.dodge) && infront(tr.ent, self))
{
VectorSubtract (tr.endpos, start, v);
eta = (VectorLength(v) - tr.ent->maxs[0]) / speed;
// tr.ent->monsterinfo.dodge (tr.ent, self, eta);
tr.ent->monsterinfo.dodge (tr.ent, self, eta, &tr);
}
}
/*
=================
fire_hit
Used for all impact (hit/punch/slash) attacks
=================
*/
qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick)
{
trace_t tr;
vec3_t forward, right, up;
vec3_t v;
vec3_t point;
float range;
vec3_t dir;
//see if enemy is in range
VectorSubtract (self->enemy->s.origin, self->s.origin, dir);
range = VectorLength(dir);
if (range > aim[0])
return false;
if (aim[1] > self->mins[0] && aim[1] < self->maxs[0])
{
// the hit is straight on so back the range up to the edge of their bbox
range -= self->enemy->maxs[0];
}
else
{
// this is a side hit so adjust the "right" value out to the edge of their bbox
if (aim[1] < 0)
aim[1] = self->enemy->mins[0];
else
aim[1] = self->enemy->maxs[0];
}
VectorMA (self->s.origin, range, dir, point);
tr = gi.trace (self->s.origin, NULL, NULL, point, self, MASK_SHOT);
if (tr.fraction < 1)
{
if (!tr.ent->takedamage)
return false;
// if it will hit any client/monster then hit the one we wanted to hit
if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
tr.ent = self->enemy;
}
AngleVectors(self->s.angles, forward, right, up);
VectorMA (self->s.origin, range, forward, point);
VectorMA (point, aim[1], right, point);
VectorMA (point, aim[2], up, point);
VectorSubtract (point, self->enemy->s.origin, dir);
// do the damage
T_Damage (tr.ent, self, self, dir, point, vec3_origin, damage, kick/2, DAMAGE_NO_KNOCKBACK, MOD_HIT);
if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
return false;
// do our special form of knockback here
VectorMA (self->enemy->absmin, 0.5, self->enemy->size, v);
VectorSubtract (v, point, v);
VectorNormalize (v);
VectorMA (self->enemy->velocity, kick, v, self->enemy->velocity);
if (self->enemy->velocity[2] > 0)
self->enemy->groundentity = NULL;
return true;
}
/*
=================
fire_lead
This is an internal support routine used for bullet/pellet based weapons.
=================
*/
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)
{
trace_t tr;
vec3_t dir;
vec3_t forward, right, up;
vec3_t end;
float r;
float u;
vec3_t water_start;
qboolean water = false;
int content_mask = MASK_SHOT | MASK_WATER;
tr = gi.trace (self->s.origin, NULL, NULL, start, self, MASK_SHOT);
if (!(tr.fraction < 1.0))
{
vectoangles (aimdir, dir);
AngleVectors (dir, forward, right, up);
r = crandom()*hspread;
u = crandom()*vspread;
VectorMA (start, 8192, forward, end);
VectorMA (end, r, right, end);
VectorMA (end, u, up, end);
if (gi.pointcontents (start) & MASK_WATER)
{
water = true;
VectorCopy (start, water_start);
content_mask &= ~MASK_WATER;
}
tr = gi.trace (start, NULL, NULL, end, self, content_mask);
// see if we hit water
if (tr.contents & MASK_WATER)
{
int color;
water = true;
VectorCopy (tr.endpos, water_start);
if (!VectorCompare (start, tr.endpos))
{
if (tr.ent->svflags & SVF_MUD)
color = SPLASH_BROWN_WATER;
else if (tr.contents & CONTENTS_WATER)
{
if (strcmp(tr.surface->name, "*brwater") == 0)
color = SPLASH_BROWN_WATER;
else
color = SPLASH_BLUE_WATER;
}
else if (tr.contents & CONTENTS_SLIME)
color = SPLASH_SLIME;
else if (tr.contents & CONTENTS_LAVA)
color = SPLASH_LAVA;
else
color = SPLASH_UNKNOWN;
if (color != SPLASH_UNKNOWN)
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_SPLASH);
gi.WriteByte (8);
gi.WritePosition (tr.endpos);
gi.WriteDir (tr.plane.normal);
gi.WriteByte (color);
gi.multicast (tr.endpos, MULTICAST_PVS);
}
// change bullet's course when it enters water
VectorSubtract (end, start, dir);
vectoangles (dir, dir);
AngleVectors (dir, forward, right, up);
r = crandom()*hspread*2;
u = crandom()*vspread*2;
VectorMA (water_start, 8192, forward, end);
VectorMA (end, r, right, end);
VectorMA (end, u, up, end);
}
// re-trace ignoring water this time
tr = gi.trace (water_start, NULL, NULL, end, self, MASK_SHOT);
}
}
// send gun puff / flash
if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
{
if (tr.fraction < 1.0)
{
if (tr.ent->takedamage)
{
T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
}
else
{
if (strncmp (tr.surface->name, "sky", 3) != 0)
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (te_impact);
gi.WritePosition (tr.endpos);
gi.WriteDir (tr.plane.normal);
gi.multicast (tr.endpos, MULTICAST_PVS);
if (self->client)
PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
}
}
}
}
// if went through water, determine where the end and make a bubble trail
if (water)
{
vec3_t pos;
VectorSubtract (tr.endpos, water_start, dir);
VectorNormalize (dir);
VectorMA (tr.endpos, -2, dir, pos);
if (gi.pointcontents (pos) & MASK_WATER)
VectorCopy (pos, tr.endpos);
else
tr = gi.trace (pos, NULL, NULL, water_start, tr.ent, MASK_WATER);
VectorAdd (water_start, tr.endpos, pos);
VectorScale (pos, 0.5, pos);
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_BUBBLETRAIL);
gi.WritePosition (water_start);
gi.WritePosition (tr.endpos);
gi.multicast (pos, MULTICAST_PVS);
}
}
/*
=================
fire_bullet
Fires a single round. Used for machinegun and chaingun. Would be fine for
pistols, rifles, etc....
=================
*/
void fire_bullet (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod)
{
fire_lead (self, start, aimdir, damage, kick, TE_GUNSHOT, hspread, vspread, mod);
}
/*
=================
fire_shotgun
Shoots shotgun pellets. Used by shotgun and super shotgun.
=================
*/
void fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod)
{
int i;
for (i = 0; i < count; i++)
fire_lead (self, start, aimdir, damage, kick, TE_SHOTGUN, hspread, vspread, mod);
}
/*
=================
fire_blaster
Fires a single blaster bolt. Used by the blaster and hyper blaster.
=================
*/
void blaster_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
int mod;
int tempevent;
if (other == self->owner)
return;
if (surf && (surf->flags & SURF_SKY))
{
G_FreeEdict (self);
return;
}
// PMM - crash prevention
if (self->owner && self->owner->client)
PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
if (other->takedamage)
{
if (self->spawnflags & 1)
mod = MOD_HYPERBLASTER;
else
mod = MOD_BLASTER;
T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, self->dmg, 1, DAMAGE_ENERGY, mod);
}
else
{
if (self->style == BLASTER_GREEN) //green
tempevent = TE_BLASTER2;
else if (self->style == BLASTER_BLUE) //blue
#ifdef KMQUAKE2_ENGINE_MOD // Knightmare- looks better than flechette
tempevent = TE_BLUEHYPERBLASTER;
#else
tempevent = TE_FLECHETTE;
#endif
#ifdef KMQUAKE2_ENGINE_MOD
else if (self->style == BLASTER_RED) //red
tempevent = TE_REDBLASTER;
#endif
else //standard orange
tempevent = TE_BLASTER;
gi.WriteByte (svc_temp_entity);
gi.WriteByte (tempevent);
gi.WritePosition (self->s.origin);
if (!plane)
gi.WriteDir (vec3_origin);
else
gi.WriteDir (plane->normal);
gi.multicast (self->s.origin, MULTICAST_PVS);
}
G_FreeEdict (self);
}
void fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int effect, qboolean hyper, int color)
{
edict_t *bolt;
trace_t tr;
VectorNormalize (dir);
bolt = G_Spawn();
bolt->svflags = SVF_DEADMONSTER;
// yes, I know it looks weird that projectiles are deadmonsters
// what this means is that when prediction is used against the object
// (blaster/hyperblaster shots), the player won't be solid clipped against
// the object. Right now trying to run into a firing hyperblaster
// is very jerky since you are predicted 'against' the shots.
VectorCopy (start, bolt->s.origin);
VectorCopy (start, bolt->s.old_origin);
vectoangles (dir, bolt->s.angles);
VectorScale (dir, speed, bolt->velocity);
bolt->movetype = MOVETYPE_FLYMISSILE;
bolt->clipmask = MASK_SHOT;
bolt->solid = SOLID_BBOX;
bolt->s.effects |= effect;
bolt->s.renderfx |= RF_NOSHADOW; //Knightmare- no shadow
VectorClear (bolt->mins);
VectorClear (bolt->maxs);
if (color == BLASTER_GREEN) //green
bolt->s.modelindex = gi.modelindex ("models/objects/laser2/tris.md2");
else if (color == BLASTER_BLUE) //blue
bolt->s.modelindex = gi.modelindex ("models/objects/blaser/tris.md2");
else if (color == BLASTER_RED) //red
bolt->s.modelindex = gi.modelindex ("models/objects/rlaser/tris.md2");
else //standard orange
bolt->s.modelindex = gi.modelindex ("models/objects/laser/tris.md2");
bolt->style = color;
bolt->s.sound = gi.soundindex ("misc/lasfly.wav");
bolt->owner = self;
bolt->touch = blaster_touch;
bolt->nextthink = level.time + 4;
bolt->think = G_FreeEdict;
bolt->dmg = damage;
if (hyper)
bolt->spawnflags = 1;
bolt->classname = "bolt";
gi.linkentity (bolt);
if (self->client)
check_dodge (self, bolt->s.origin, dir, speed);
tr = gi.trace (self->s.origin, NULL, NULL, bolt->s.origin, bolt, MASK_SHOT);
if (tr.fraction < 1.0 && !(self->flags & FL_TURRET_OWNER))
{
VectorMA (bolt->s.origin, -10, dir, bolt->s.origin);
bolt->touch (bolt, tr.ent, NULL, NULL);
}
}
// RAFAEL
void fire_blueblaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int effect)
{
edict_t *bolt;
trace_t tr;
VectorNormalize (dir);
bolt = G_Spawn ();
VectorCopy (start, bolt->s.origin);
VectorCopy (start, bolt->s.old_origin);
vectoangles (dir, bolt->s.angles);
VectorScale (dir, speed, bolt->velocity);
bolt->movetype = MOVETYPE_FLYMISSILE;
bolt->clipmask = MASK_SHOT;
bolt->solid = SOLID_BBOX;
bolt->s.effects |= effect;
bolt->s.renderfx |= RF_NOSHADOW; //Knightmare- no shadow
VectorClear (bolt->mins);
VectorClear (bolt->maxs);
bolt->s.modelindex = gi.modelindex ("models/objects/blaser/tris.md2");
bolt->s.sound = gi.soundindex ("misc/lasfly.wav");
bolt->style = BLASTER_BLUE;
bolt->spawnflags |= 1;
bolt->owner = self;
bolt->touch = blaster_touch;
bolt->nextthink = level.time + 4;
bolt->think = G_FreeEdict;
bolt->dmg = damage;
bolt->classname = "bolt";
gi.linkentity (bolt);
if (self->client)
check_dodge (self, bolt->s.origin, dir, speed);
tr = gi.trace (self->s.origin, NULL, NULL, bolt->s.origin, bolt, MASK_SHOT);
if (tr.fraction < 1.0 && !(self->flags & FL_TURRET_OWNER))
{
VectorMA (bolt->s.origin, -10, dir, bolt->s.origin);
bolt->touch (bolt, tr.ent, NULL, NULL);
}
}
// NOTE: SP_bolt should ONLY be used for blaster/hyperblaster bolts that have
// changed maps via trigger_transition. It should NOT be used for map
// entities.
void bolt_delayed_start (edict_t *bolt)
{
if(g_edicts[1].linkcount)
{
VectorScale(bolt->movedir,bolt->moveinfo.speed,bolt->velocity);
bolt->nextthink = level.time + 2;
bolt->think = G_FreeEdict;
gi.linkentity(bolt);
}
else
bolt->nextthink = level.time + FRAMETIME;
}
void SP_bolt (edict_t *bolt)
{
if (bolt->count == 2) //green bolt
bolt->s.modelindex = gi.modelindex ("models/objects/laser2/tris.md2");
else if (bolt->count == 3) //blue bolt
bolt->s.modelindex = gi.modelindex ("models/objects/blaser/tris.md2");
else //orange bolt
bolt->s.modelindex = gi.modelindex ("models/objects/laser/tris.md2");
bolt->s.sound = gi.soundindex ("misc/lasfly.wav");
bolt->touch = blaster_touch;
VectorCopy(bolt->velocity,bolt->movedir);
VectorNormalize(bolt->movedir);
bolt->moveinfo.speed = VectorLength(bolt->velocity);
VectorClear(bolt->velocity);
bolt->think = bolt_delayed_start;
bolt->nextthink = level.time + FRAMETIME;
gi.linkentity(bolt);
}
/*
=================
fire_grenade
=================
*/
// Lazarus additions: next_grenade and prev_grenade linked lists facilitate checking
// for grenades near monsters, so that monsters can evade w/o bogging down the game
void Grenade_Evade (edict_t *monster)
{
edict_t *grenade;
vec3_t grenade_vec;
float grenade_dist, best_r, best_yaw, r;
float yaw;
int i;
vec3_t forward;
vec3_t pos, best_pos;
trace_t tr;
// We assume on entry here that monster is alive and that he's not already
// AI_CHASE_THING
grenade = world->next_grenade;
while(grenade)
{
// we only care about grenades on the ground
if(grenade->inuse && grenade->groundentity)
{
// if it ain't in the PVS, it can't hurt us (I think?)
if(gi.inPVS(grenade->s.origin,monster->s.origin))
{
VectorSubtract(grenade->s.origin,monster->s.origin,grenade_vec);
grenade_dist = VectorNormalize(grenade_vec);
if(grenade_dist <= grenade->dmg_radius)
break;
}
}
grenade = grenade->next_grenade;
}
if(!grenade)
return;
// Find best escape route.
best_r = 9999;
for(i=0; i<8; i++)
{
yaw = anglemod( i*45 );
forward[0] = cos( DEG2RAD(yaw) );
forward[1] = sin( DEG2RAD(yaw) );
forward[2] = 0;
// Estimate of required distance to run. This is conservative.
r = grenade->dmg_radius + grenade_dist*DotProduct(forward,grenade_vec) + monster->size[0] + 16;
if( r < best_r )
{
VectorMA(monster->s.origin,r,forward,pos);
tr = gi.trace(monster->s.origin,monster->mins,monster->maxs,pos,monster,MASK_MONSTERSOLID);
if(tr.fraction < 1.0)
continue;
best_r = r;
best_yaw = yaw;
VectorCopy(tr.endpos,best_pos);
}
}
if(best_r < 9000)
{
edict_t *thing = SpawnThing();
VectorCopy(best_pos,thing->s.origin);
thing->touch_debounce_time = grenade->nextthink;
thing->target_ent = monster;
ED_CallSpawn(thing);
monster->ideal_yaw = best_yaw;
monster->movetarget = monster->goalentity = thing;
monster->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
monster->monsterinfo.aiflags |= (AI_CHASE_THING | AI_EVADE_GRENADE);
monster->monsterinfo.run(monster);
monster->next_grenade = grenade;
}
}
//static void Grenade_Add_To_Chain (edict_t *grenade)
//{
// edict_t *ancestor;
//
// ancestor = world;
// while(ancestor->next_grenade && ancestor->next_grenade->inuse)
// ancestor = ancestor->next_grenade;
// ancestor->next_grenade = grenade;
// grenade->prev_grenade = ancestor;
//}
void Grenade_Remove_From_Chain (edict_t *grenade)
{
if(grenade->prev_grenade)
{
// "prev_grenade" should always be valid for other than player-thrown
// grenades that explode in player's hand
grenade->prev_grenade->next_grenade = grenade->next_grenade;
if(grenade->next_grenade)
grenade->next_grenade->prev_grenade = grenade->prev_grenade;
}
}
//static void Grenade_Explode (edict_t *ent)
void Grenade_Explode (edict_t *ent)
{
vec3_t origin;
int mod;
if (ent->owner->client)
PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
//FIXME: if we are onground then raise our Z just a bit since we are a point?
if (ent->enemy)
{
float points;
vec3_t v;
vec3_t dir;
VectorAdd (ent->enemy->mins, ent->enemy->maxs, v);
VectorMA (ent->enemy->s.origin, 0.5, v, v);
VectorSubtract (ent->s.origin, v, v);
points = ent->dmg - 0.5 * VectorLength (v);
VectorSubtract (ent->enemy->s.origin, ent->s.origin, dir);
if (ent->spawnflags & 1)
mod = MOD_HANDGRENADE;
else
mod = MOD_GRENADE;
T_Damage (ent->enemy, ent, ent->owner, dir, ent->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
}
if (ent->spawnflags & 2)
mod = MOD_HELD_GRENADE;
else if (ent->spawnflags & 1)
mod = MOD_HG_SPLASH;
else
mod = MOD_G_SPLASH;
T_RadiusDamage(ent, ent->owner, ent->dmg, ent->enemy, ent->dmg_radius, mod);
VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
gi.WriteByte (svc_temp_entity);
if (ent->waterlevel)
{
if (ent->groundentity)
gi.WriteByte (TE_GRENADE_EXPLOSION_WATER);
else
gi.WriteByte (TE_ROCKET_EXPLOSION_WATER);
}
else
{
if (ent->groundentity)
gi.WriteByte (TE_GRENADE_EXPLOSION);
else
gi.WriteByte (TE_ROCKET_EXPLOSION);
}
gi.WritePosition (origin);
gi.multicast (ent->s.origin, MULTICAST_PHS);
G_FreeEdict (ent);
}
void Grenade_Touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other == ent->owner)
return;
if (surf && (surf->flags & SURF_SKY))
{
G_FreeEdict (ent);
return;
}
if (!other->takedamage)
{
if (ent->spawnflags & 1)
{
if (random() > 0.5)
gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/hgrenb1a.wav"), 1, ATTN_NORM, 0);
else
gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/hgrenb2a.wav"), 1, ATTN_NORM, 0);
}
else
{
gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/grenlb1b.wav"), 1, ATTN_NORM, 0);
}
return;
}
ent->enemy = other;
Grenade_Explode (ent);
}
void ContactGrenade_Touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other == ent->owner)
return;
if (surf && (surf->flags & SURF_SKY))
{
Grenade_Remove_From_Chain (ent);
G_FreeEdict (ent);
return;
}
if (other->takedamage)
ent->enemy = other;
Grenade_Explode (ent);
}
void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean contact)
{
edict_t *grenade;
vec3_t dir;
vec3_t forward, right, up;
vectoangles (aimdir, dir);
AngleVectors (dir, forward, right, up);
grenade = G_Spawn();
VectorCopy (start, grenade->s.origin);
VectorScale (aimdir, speed, grenade->velocity);
VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
//Knightmare- add player's base velocity to grenade
if (add_velocity_throw->value && self->client)
VectorAdd (grenade->velocity, self->velocity, grenade->velocity);
else if(self->groundentity)
VectorAdd (grenade->velocity, self->groundentity->velocity, grenade->velocity);
VectorSet (grenade->avelocity, 300, 300, 300);
grenade->movetype = MOVETYPE_BOUNCE;
grenade->clipmask = MASK_SHOT;
grenade->solid = SOLID_BBOX;
grenade->s.effects |= EF_GRENADE;
grenade->s.renderfx |= RF_IR_VISIBLE;
VectorClear (grenade->mins);
VectorClear (grenade->maxs);
grenade->s.modelindex = gi.modelindex ("models/objects/grenade/tris.md2");
grenade->owner = self;
if (contact)
grenade->touch = ContactGrenade_Touch;
else
grenade->touch = Grenade_Touch;
grenade->nextthink = level.time + timer;
grenade->think = Grenade_Explode;
grenade->dmg = damage;
grenade->dmg_radius = damage_radius;
grenade->classname = "grenade";
gi.linkentity (grenade);
}
void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held)
{
edict_t *grenade;
vec3_t dir;
vec3_t forward, right, up;
vectoangles (aimdir, dir);
AngleVectors (dir, forward, right, up);
grenade = G_Spawn();
VectorCopy (start, grenade->s.origin);
VectorScale (aimdir, speed, grenade->velocity);
VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
//Knightmare- add player's base velocity to thrown grenade
if (add_velocity_throw->value && self->client)
VectorAdd (grenade->velocity, self->velocity, grenade->velocity);
else if(self->groundentity)
VectorAdd (grenade->velocity, self->groundentity->velocity, grenade->velocity);
VectorSet (grenade->avelocity, 300, 300, 300);
grenade->movetype = MOVETYPE_BOUNCE;
grenade->clipmask = MASK_SHOT;
grenade->solid = SOLID_BBOX;
grenade->s.effects |= EF_GRENADE;
grenade->s.renderfx |= RF_IR_VISIBLE;
VectorClear (grenade->mins);
VectorClear (grenade->maxs);
grenade->s.modelindex = gi.modelindex ("models/objects/grenade2/tris.md2");
grenade->owner = self;
grenade->touch = Grenade_Touch;
grenade->nextthink = level.time + timer;
grenade->think = Grenade_Explode;
grenade->dmg = damage;
grenade->dmg_radius = damage_radius;
grenade->classname = "hgrenade";
if (held)
grenade->spawnflags = 3;
else
grenade->spawnflags = 1;
grenade->s.sound = gi.soundindex("weapons/hgrenc1b.wav");
if (timer <= 0.0)
Grenade_Explode (grenade);
else
{
gi.sound (self, CHAN_WEAPON, gi.soundindex ("weapons/hgrent1a.wav"), 1, ATTN_NORM, 0);
gi.linkentity (grenade);
}
}
// NOTE: SP_grenade and SP_handgrenade should ONLY be used to spawn grenades that change
// maps via a trigger_transition. They should NOT be used for map entities.
void grenade_delayed_start (edict_t *grenade)
{
if(g_edicts[1].linkcount)
{
VectorScale(grenade->movedir,grenade->moveinfo.speed,grenade->velocity);
grenade->movetype = MOVETYPE_BOUNCE;
grenade->nextthink = level.time + 2.5;
grenade->think = Grenade_Explode;
gi.linkentity(grenade);
}
else
grenade->nextthink = level.time + FRAMETIME;
}
void SP_grenade (edict_t *grenade)
{
grenade->s.modelindex = gi.modelindex ("models/objects/grenade/tris.md2");
grenade->touch = Grenade_Touch;
// For SP, freeze grenade until player spawns in
if(game.maxclients == 1)
{
grenade->movetype = MOVETYPE_NONE;
VectorCopy(grenade->velocity,grenade->movedir);
VectorNormalize(grenade->movedir);
grenade->moveinfo.speed = VectorLength(grenade->velocity);
VectorClear(grenade->velocity);
grenade->think = grenade_delayed_start;
grenade->nextthink = level.time + FRAMETIME;
}
else
{
grenade->movetype = MOVETYPE_BOUNCE;
grenade->nextthink = level.time + 2.5;
grenade->think = Grenade_Explode;
}
gi.linkentity (grenade);
}
void handgrenade_delayed_start (edict_t *grenade)
{
if(g_edicts[1].linkcount)
{
VectorScale(grenade->movedir,grenade->moveinfo.speed,grenade->velocity);
grenade->movetype = MOVETYPE_BOUNCE;
grenade->nextthink = level.time + 2.5;
grenade->think = Grenade_Explode;
if(grenade->owner)
gi.sound (grenade->owner, CHAN_WEAPON, gi.soundindex ("weapons/hgrent1a.wav"), 1, ATTN_NORM, 0);
gi.linkentity(grenade);
}
else
grenade->nextthink = level.time + FRAMETIME;
}
void SP_handgrenade (edict_t *grenade)
{
grenade->s.modelindex = gi.modelindex ("models/objects/grenade2/tris.md2");
grenade->touch = Grenade_Touch;
// For SP, freeze grenade until player spawns in
if(game.maxclients == 1)
{
grenade->movetype = MOVETYPE_NONE;
VectorCopy(grenade->velocity,grenade->movedir);
VectorNormalize(grenade->movedir);
grenade->moveinfo.speed = VectorLength(grenade->velocity);
VectorClear(grenade->velocity);
grenade->think = handgrenade_delayed_start;
grenade->nextthink = level.time + FRAMETIME;
}
else
{
grenade->movetype = MOVETYPE_BOUNCE;
grenade->nextthink = level.time + 2.5;
grenade->think = Grenade_Explode;
}
gi.linkentity (grenade);
}
/*
=======================
Shockwave
=======================
*/
void Nuke_Quake (edict_t *self);
void shock_effect_think (edict_t *self)
{
if (++self->s.frame < 19)
self->nextthink = level.time + FRAMETIME;
else
{
self->s.frame = 0;
self->nextthink = level.time + FRAMETIME;
}
self->count--;
//fade out
#ifdef KMQUAKE2_ENGINE_MOD
if (self->count <= 6)
self->s.alpha -= 0.10;
if (self->s.alpha < 0.10)
self->s.alpha = 0.10;
#else
if (self->count == 5)
{
self->s.effects |= EF_SPHERETRANS;
self->s.renderfx &= ~RF_TRANSLUCENT;
}
#endif
//remove after 6 secs
if (self->count == 0)
G_FreeEdict (self);
//inflict field damage on surroundings
T_RadiusDamage(self, self->owner, self->radius_dmg, NULL, self->dmg_radius, MOD_SHOCK_SPLASH);
}
void shock_effect_center_think (edict_t *self)
{
self->nextthink = level.time + FRAMETIME;
if ((self->count % 5) == 0)
{
if (self->count > 10) //double effect for first 40 seconds
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_NUKEBLAST);
gi.WritePosition (self->s.origin);
gi.multicast (self->s.origin, MULTICAST_ALL);
}
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_NUKEBLAST);
gi.WritePosition (self->s.origin);
gi.multicast (self->s.origin, MULTICAST_ALL);
}
//fade out
#ifdef KMQUAKE2_ENGINE_MOD
if (self->count <= 10)
self->s.alpha -= 0.10;
self->s.alpha = max(self->s.alpha, 1/255);
//remove after 5 secs
self->count--;
if (self->count == 0 || self->s.alpha <= 1/255)
G_FreeEdict (self);
#else
if (self->count == 10)
self->s.renderfx |= RF_TRANSLUCENT;
if (self->count == 5)
{
self->s.effects |= EF_SPHERETRANS;
self->s.renderfx &= ~RF_TRANSLUCENT;
}
//remove after 5 secs
self->count--;
if (self->count == 0)
G_FreeEdict (self);
#endif
}
void ShockEffect (edict_t *source, edict_t *attacker, float damage, float radius, cplane_t *plane)
{
edict_t *ent;
edict_t *center;
vec3_t hit_point;
if (plane->normal)
{ //put origin of effect 32 units away from last hit surface
VectorMA (source->s.origin, 32.0, plane->normal, hit_point);
}
ent = G_Spawn();
//same origin as exploding shock sphere
if (plane->normal)
VectorCopy (hit_point, ent->s.origin);
else
VectorCopy (source->s.origin, ent->s.origin);
ent->radius_dmg = shockwave_effect_damage->value;
ent->dmg_radius = shockwave_effect_radius->value;
ent->owner = attacker;
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_NOT;
VectorSet (ent->mins, -8, -8, 8);
VectorSet (ent->maxs, 8, 8, 8);
ent->s.modelindex = gi.modelindex ("models/objects/shockfield/tris.md2");
#ifdef KMQUAKE2_ENGINE_MOD
ent->s.alpha = 0.70;
#else
ent->s.renderfx |= RF_TRANSLUCENT;
#endif
ent->s.renderfx |= RF_NOSHADOW|RF_FULLBRIGHT;
ent->s.effects = EF_FLAG2;
ent->count = 60; //lasts 6 seconds
ent->think = shock_effect_think;
ent->nextthink = level.time + 2 * FRAMETIME;
gi.linkentity (ent);
//center light burst effect
center = G_Spawn();
//same origin as exploding shock sphere
if (plane->normal)
VectorCopy (hit_point, center->s.origin);
else
VectorCopy (source->s.origin, center->s.origin);
center->movetype = MOVETYPE_NONE;
center->solid = SOLID_NOT;
VectorSet (center->mins, -8, -8, 8);
VectorSet (center->maxs, 8, 8, 8);