This repository has been 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
/
g_combat.c
1485 lines (1344 loc) · 42.6 KB
/
g_combat.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
// g_combat.c
#include "g_local.h"
void M_SetEffects (edict_t *self);
/*
ROGUE
clean up heal targets for medic
*/
void cleanupHealTarget (edict_t *ent)
{
ent->monsterinfo.healer = NULL;
ent->takedamage = DAMAGE_YES;
ent->monsterinfo.aiflags &= ~AI_RESURRECTING;
M_SetEffects (ent);
}
/*
============
CanDamage
Returns true if the inflictor can directly damage the target. Used for
explosions and melee attacks.
============
*/
qboolean CanDamage (edict_t *targ, edict_t *inflictor)
{
vec3_t dest;
trace_t trace;
// bmodels need special checking because their origin is 0,0,0
if (targ->movetype == MOVETYPE_PUSH)
{
VectorAdd (targ->absmin, targ->absmax, dest);
VectorScale (dest, 0.5, dest);
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0 || trace.ent == targ)
return true;
if (trace.ent == targ)
return true;
return false;
}
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, targ->s.origin, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
// Lazarus: This is kinda cheesy, but avoids doing goofy things in a map to make this work. If a LOS
// from inflictor to targ is blocked by a func_tracktrain, AND the targ is riding/driving
// the tracktrain, go ahead and hurt him.
if(trace.ent && (trace.ent->flags & FL_TRACKTRAIN) && ((trace.ent->owner == targ) || (targ->groundentity == trace.ent)) )
return true;
VectorCopy (targ->s.origin, dest);
dest[0] += 15.0;
dest[1] += 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy (targ->s.origin, dest);
dest[0] += 15.0;
dest[1] -= 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy (targ->s.origin, dest);
dest[0] -= 15.0;
dest[1] += 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy (targ->s.origin, dest);
dest[0] -= 15.0;
dest[1] -= 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
return false;
}
/*
============
Killed
============
*/
void Killed (edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
if (targ->health < -999)
targ->health = -999;
if (targ->monsterinfo.aiflags & AI_MEDIC)
{
if (targ->enemy) // god, I hope so
{
cleanupHealTarget (targ->enemy);
}
// clean up self
targ->monsterinfo.aiflags &= ~AI_MEDIC;
targ->enemy = attacker;
}
else
{
targ->enemy = attacker;
}
if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD))
{
// targ->svflags |= SVF_DEADMONSTER; // now treat as a different content type
//ROGUE - free up slot for spawned monster if it's spawned
//if (targ->monsterinfo.aiflags & AI_SPAWNED_CARRIER)
if (targ->monsterinfo.monsterflags & MFL_SPAWNED_CARRIER)
{
if (targ->monsterinfo.commander && targ->monsterinfo.commander->inuse &&
!strcmp(targ->monsterinfo.commander->classname, "monster_carrier"))
{
targ->monsterinfo.commander->monsterinfo.monster_slots++;
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("g_combat: freeing up carrier slot - %d left\n", targ->monsterinfo.commander->monsterinfo.monster_slots);
}
}
//if (targ->monsterinfo.aiflags & AI_SPAWNED_MEDIC_C)
if (targ->monsterinfo.monsterflags & MFL_SPAWNED_MEDIC_C)
{
if (targ->monsterinfo.commander)
{
if (targ->monsterinfo.commander->inuse && !strcmp(targ->monsterinfo.commander->classname, "monster_medic_commander"))
{
targ->monsterinfo.commander->monsterinfo.monster_slots++;
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("g_combat: freeing up medic slot - %d left\n", targ->monsterinfo.commander->monsterinfo.monster_slots);
}
// else
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("my commander is dead! he's a %s\n", targ->monsterinfo.commander->classname);
}
// else if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("My commander is GONE\n");
}
//if (targ->monsterinfo.aiflags & AI_SPAWNED_WIDOW)
if (targ->monsterinfo.monsterflags & MFL_SPAWNED_WIDOW)
{
// need to check this because we can have variable numbers of coop players
if (targ->monsterinfo.commander && targ->monsterinfo.commander->inuse &&
!strncmp(targ->monsterinfo.commander->classname, "monster_widow", 13))
{
if (targ->monsterinfo.commander->monsterinfo.monster_used > 0)
targ->monsterinfo.commander->monsterinfo.monster_used--;
// if ((g_showlogic) && (g_showlogic->value))
// gi.dprintf ("g_combat: freeing up black widow slot - %d used\n", targ->monsterinfo.commander->monsterinfo.monster_used);
}
}
//Rogue
//if (!(targ->monsterinfo.aiflags & AI_GOOD_GUY) && !(targ->monsterinfo.aiflags & AI_DO_NOT_COUNT))
if (!(targ->monsterinfo.aiflags & AI_GOOD_GUY) && !(targ->monsterinfo.monsterflags & MFL_DO_NOT_COUNT))
{
level.killed_monsters++;
if (coop->value && attacker->client)
attacker->client->resp.score++;
// medics won't heal monsters that they kill themselves
// PMM - now they will
// if (strcmp(attacker->classname, "monster_medic") == 0)
// targ->owner = attacker;
}
}
if (targ->movetype == MOVETYPE_PUSH || targ->movetype == MOVETYPE_STOP || targ->movetype == MOVETYPE_NONE)
{ // doors, triggers, etc
targ->die (targ, inflictor, attacker, damage, point);
return;
}
if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD))
{
targ->touch = NULL;
monster_death_use (targ);
}
// Lazarus: disengage from tracktrain
if (targ->vehicle && (targ->vehicle->flags & FL_TRACKTRAIN))
tracktrain_disengage(targ->vehicle);
targ->die (targ, inflictor, attacker, damage, point);
}
/*
================
SpawnDamage
================
*/
void SpawnDamage (int type, vec3_t origin, vec3_t normal, int damage)
{
if (damage > 255)
damage = 255;
gi.WriteByte (svc_temp_entity);
gi.WriteByte (type);
// gi.WriteByte (damage);
gi.WritePosition (origin);
gi.WriteDir (normal);
gi.multicast (origin, MULTICAST_PVS);
}
/*
============
T_Damage
targ entity that is being damaged
inflictor entity that is causing the damage
attacker entity that caused the inflictor to damage targ
example: targ=monster, inflictor=rocket, attacker=player
dir direction of the attack
point point at which the damage is being inflicted
normal normal vector from that point
damage amount of damage being inflicted
knockback force to be applied against targ as a result of the damage
dflags these flags are used to control how T_Damage works
DAMAGE_RADIUS damage was indirect (from a nearby explosion)
DAMAGE_NO_ARMOR armor does not protect from this damage
DAMAGE_ENERGY damage is from an energy based weapon
DAMAGE_NO_KNOCKBACK do not affect velocity, just view angles
DAMAGE_BULLET damage is from a bullet (used for ricochets)
DAMAGE_NO_PROTECTION kills godmode, armor, everything
============
*/
int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int dflags)
{
gclient_t *client;
int save;
int power_armor_type;
int index;
int damagePerCell;
int pa_te_type;
int power;
int power_used;
if (!damage)
return 0;
client = ent->client;
if (dflags & (DAMAGE_NO_ARMOR | DAMAGE_NO_POWER_ARMOR)) // PGM
return 0;
if (client)
{
power_armor_type = PowerArmorType (ent);
if (power_armor_type != POWER_ARMOR_NONE)
{
index = ITEM_INDEX(FindItem("Cells"));
power = client->pers.inventory[index];
}
}
else if (ent->svflags & SVF_MONSTER)
{
power_armor_type = ent->monsterinfo.power_armor_type;
power = ent->monsterinfo.power_armor_power;
}
else
return 0;
if (power_armor_type == POWER_ARMOR_NONE)
return 0;
if (!power)
return 0;
if (power_armor_type == POWER_ARMOR_SCREEN)
{
vec3_t vec;
float dot;
vec3_t forward;
// only works if damage point is in front
AngleVectors (ent->s.angles, forward, NULL, NULL);
VectorSubtract (point, ent->s.origin, vec);
VectorNormalize (vec);
dot = DotProduct (vec, forward);
if (dot <= 0.3)
return 0;
damagePerCell = 1;
pa_te_type = TE_SCREEN_SPARKS;
damage = damage / 3;
}
else
{
damagePerCell = 2;
pa_te_type = TE_SHIELD_SPARKS;
damage = (2 * damage) / 3;
}
// etf rifle
if (dflags & DAMAGE_NO_REG_ARMOR)
save = (power * damagePerCell) / 2;
else
save = power * damagePerCell;
if (!save)
return 0;
if (save > damage)
save = damage;
SpawnDamage (pa_te_type, point, normal, save);
ent->powerarmor_time = level.time + 0.2;
if (dflags & DAMAGE_NO_REG_ARMOR)
power_used = (save / damagePerCell) * 2;
else
power_used = save / damagePerCell;
if (client)
client->pers.inventory[index] -= power_used;
else
ent->monsterinfo.power_armor_power -= power_used;
return save;
}
int CheckArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int te_sparks, int dflags)
{
gclient_t *client;
int save;
int index;
gitem_t *armor;
if (!damage)
return 0;
client = ent->client;
if (!client)
return 0;
// ROGUE - added DAMAGE_NO_REG_ARMOR for atf rifle
if (dflags & (DAMAGE_NO_ARMOR | DAMAGE_NO_REG_ARMOR))
return 0;
index = ArmorIndex (ent);
if (!index)
return 0;
armor = GetItemByIndex (index);
if (dflags & DAMAGE_ENERGY)
save = ceil(((gitem_armor_t *)armor->info)->energy_protection*damage);
else
save = ceil(((gitem_armor_t *)armor->info)->normal_protection*damage);
if (save >= client->pers.inventory[index])
save = client->pers.inventory[index];
if (!save)
return 0;
client->pers.inventory[index] -= save;
SpawnDamage (te_sparks, point, normal, save);
return save;
}
void monster_start_go (edict_t *self);
void target_animate(edict_t *);
void DefendMyFriend (edict_t *self, edict_t *enemy)
{
self->spawnflags &= ~(SF_MONSTER_AMBUSH | SF_MONSTER_SIGHT);
self->enemy = enemy;
self->monsterinfo.aiflags |= AI_TARGET_ANGER;
FoundTarget (self);
}
void CallMyFriends (edict_t *targ, edict_t *attacker)
{
edict_t *teammate;
if(!targ || !attacker)
return;
// Knightmare- skip this for insanes
if (!strcmp(targ->classname, "misc_insane"))
return;
// Lazarus dmgteam stuff
if( (attacker->client && !(attacker->flags & FL_NOTARGET)) || (attacker->svflags & SVF_MONSTER))
{ // the attacker is a player or a monster
if( (targ->svflags & SVF_MONSTER) && (targ->dmgteam) && (targ->health > 0) )
{ // the target is a live monster on a dmgteam
if( !attacker->dmgteam || strcmp(targ->dmgteam,attacker->dmgteam) )
{ // attacker is not on same dmgteam as target
if( !Q_strcasecmp(targ->dmgteam,"player") && attacker->client )
{ // Target is a GOOD_GUY, attacked by the player. Allow self-defense,
// but don't get other dmgteam teammates involved.
// Special case for misc_actors - if ACTOR_BAD_GUY isn't set,
// actor stays on the same team and only taunts player
if(!(targ->monsterinfo.aiflags & AI_ACTOR) || (targ->spawnflags & SF_ACTOR_BAD_GUY))
{
targ->enemy = targ->movetarget = targ->goalentity = attacker;
targ->monsterinfo.aiflags &= ~AI_FOLLOW_LEADER;
if(visible(targ,targ->enemy))
FoundTarget(targ);
else
HuntTarget(targ);
}
}
else if( !(targ->svflags & SVF_MONSTER) || !(attacker->svflags & SVF_MONSTER) ||
(targ->monsterinfo.moreaiflags & AI_FREEFORALL) ||
((targ->monsterinfo.aiflags & AI_GOOD_GUY) != (attacker->monsterinfo.aiflags & AI_GOOD_GUY)) )
{
// Either target is not a monster, or attacker is not a monster, or
// they're both monsters but one is AI_GOOD_GUY and the other is not,
// or we've turned the game into a free-for-all with a target_monsterbattle
teammate = G_Find(NULL,FOFS(dmgteam),targ->dmgteam);
while(teammate)
{
if(teammate != targ)
{
if(teammate->svflags & SVF_MONSTER)
{
if(teammate->health > 0 && (teammate->enemy != attacker) && !(teammate->monsterinfo.aiflags & AI_CHASE_THING))
{
if(!teammate->enemy || !teammate->enemy->dmgteam || !attacker->dmgteam )
{
// If either 1) this teammate doesn't currently have an enemy,
// or 2) the teammate's enemy is not a member of a dmgteam
// or 3) the attacker is not a member of a dmgteam
// then set the attacker as the enemy of this teammate
DefendMyFriend(teammate,attacker);
}
else if(strcmp(teammate->enemy->dmgteam,attacker->dmgteam))
{
// attacker is a member of a team different than the
// current enemy
DefendMyFriend(teammate,attacker);
}
}
}
else if(!(teammate->svflags & SVF_DEADMONSTER))
G_UseTargets(teammate,attacker);
}
teammate = G_Find(teammate,FOFS(dmgteam),targ->dmgteam);
}
}
}
}
}
if( targ->client && (attacker->svflags & SVF_MONSTER) )
{
// target is player; attacker is monster... alert "good guys", if any
// trace_t tr;
edict_t *teammate = NULL;
teammate = G_Find(NULL,FOFS(dmgteam),"player");
while(teammate)
{
if((teammate->health > 0) && !(teammate->monsterinfo.aiflags & AI_CHASE_THING) && (teammate != attacker))
{
// Can teammate see player?
// tr = gi.trace(teammate->s.origin,vec3_origin,vec3_origin,targ->s.origin,teammate,MASK_OPAQUE);
// if(tr.fraction == 1.0)
if(gi.inPVS(teammate->s.origin,targ->s.origin))
{
teammate->enemy = attacker;
FoundTarget(teammate);
if(teammate->monsterinfo.aiflags & AI_ACTOR)
{
teammate->monsterinfo.aiflags |= AI_FOLLOW_LEADER;
teammate->monsterinfo.old_leader = NULL;
teammate->monsterinfo.leader = targ;
}
}
}
teammate = G_Find(teammate,FOFS(dmgteam),"player");
}
}
// If player attacks a GOODGUY, turn GOODGUY stuff off
//Knightmare- gekks and stalkers use different spawnflag
if ( attacker->client && (targ->svflags & SVF_MONSTER)
&& UseSpecialGoodGuyFlag(targ) && (targ->spawnflags & 16) )
{
targ->spawnflags &= ~16;
//Knightmare- don't add to body count
targ->monsterinfo.monsterflags |= MFL_DO_NOT_COUNT;
targ->monsterinfo.aiflags &= ~(AI_GOOD_GUY + AI_FOLLOW_LEADER);
if (targ->dmgteam && !Q_strcasecmp(targ->dmgteam,"player"))
targ->dmgteam = NULL;
}
else if ( attacker->client && (targ->svflags & SVF_MONSTER)
&& UseRegularGoodGuyFlag(targ) && (targ->spawnflags & SF_MONSTER_GOODGUY) )
{
if (!(targ->monsterinfo.aiflags & AI_ACTOR) || (targ->spawnflags & SF_ACTOR_BAD_GUY))
{
targ->spawnflags &= ~SF_MONSTER_GOODGUY;
//Knightmare- don't add to body count
targ->monsterinfo.monsterflags |= MFL_DO_NOT_COUNT;
targ->monsterinfo.aiflags &= ~(AI_GOOD_GUY + AI_FOLLOW_LEADER);
if (targ->dmgteam && !Q_strcasecmp(targ->dmgteam,"player"))
targ->dmgteam = NULL;
}
}
// 1.6.1.3 change - one chance and one chance only to call friends
/* if(targ->dmgteam)
if(Q_strcasecmp(targ->dmgteam,"player"))
targ->dmgteam = NULL; */
}
edict_t *SpawnThing();
void M_ReactToDamage (edict_t *targ, edict_t *attacker, edict_t *inflictor)
{
// pmm
qboolean new_tesla;
qboolean is_turret;
// if (!(attacker->client) && !(attacker->svflags & SVF_MONSTER))
// return;
if( targ->health <= 0 )
return;
// If targ is currently chasing a "thing" or we're running a hint_path test, he
// doesn't really care what else is happening
if (targ->monsterinfo.aiflags & AI_CHASE_THING)
return;
// If targ is a robot camera, ignore damage
if (targ->flags & FL_ROBOT)
return;
is_turret = (attacker->classname && !Q_strcasecmp(attacker->classname,"turret_breach"));
//=======
//ROGUE
// logic for tesla - if you are hit by a tesla, and can't see who you should be mad at (attacker)
// attack the tesla
// also, target the tesla if it's a "new" tesla
if ((inflictor) && (!strcmp(inflictor->classname, "tesla")))
{
new_tesla = MarkTeslaArea(targ, inflictor);
if (new_tesla)
TargetTesla (targ, inflictor);
return;
// FIXME - just ignore teslas when you're TARGET_ANGER or MEDIC
/* if (!(targ->enemy && (targ->monsterinfo.aiflags & (AI_TARGET_ANGER|AI_MEDIC))))
{
// FIXME - coop issues?
if ((!targ->enemy) || (!visible(targ, targ->enemy)))
{
gi.dprintf ("can't see player, switching to tesla\n");
TargetTesla (targ, inflictor);
return;
}
gi.dprintf ("can see player, ignoring tesla\n");
}
else if ((g_showlogic) && (g_showlogic->value))
gi.dprintf ("no enemy, or I'm doing other, more important things, than worrying about a damned tesla!\n");
*/
}
//ROGUE
//=======
// Lazarus - monsters will get mad at and attack turrets.
// For environmental effects (lava, lasers, etc.) - evade
if (!(attacker->client) && !(attacker->svflags & SVF_MONSTER) && !is_turret &&
!(targ->monsterinfo.aiflags & AI_DUCKED) )
{
if (!targ->movetarget || Q_strcasecmp(targ->movetarget->classname,"thing") )
{
int i;
edict_t *thing;
vec3_t atk, dir, best_dir, end, forward;
vec3_t mins, maxs;
vec_t dist, run;
vec_t best_dist=0;
trace_t trace1, trace2;
VectorCopy(targ->mins,mins);
mins[2] += 16; // max step height? not sure about this
if(mins[2] > 0) mins[2] = 0;
VectorCopy(targ->maxs,maxs);
if( (attacker==world) ||
(!Q_strcasecmp(attacker->classname,"func_door") ) ||
(!Q_strcasecmp(attacker->classname,"func_water")) ||
(!Q_strcasecmp(attacker->classname,"func_pushable")) )
{
// Just send the monster straight ahead and hope for the best.
thing = SpawnThing();
VectorCopy(targ->s.angles,thing->s.angles);
AngleVectors(targ->s.angles,dir,NULL,NULL);
for(i=0; i<5; i++)
{
dir[2] = 0.1*i;
VectorNormalize(dir);
VectorMA(targ->s.origin,8192,dir,end);
trace1 = gi.trace(targ->s.origin,mins,maxs,end,targ,MASK_MONSTERSOLID);
dist = trace1.fraction * 8192;
if(dist > best_dist)
{
best_dist = dist;
VectorCopy(dir,best_dir);
}
}
}
else if(!Q_strcasecmp(attacker->classname,"target_laser"))
{
// Send the monster in a direction perpendicular to laser
// path, whichever direction is closest to current angles
thing = SpawnThing();
if(attacker->movedir[2] > 0.7)
{
// Just move straight ahead and hope for the best
AngleVectors(targ->s.angles,best_dir,NULL,NULL);
}
else
{
VectorCopy(attacker->movedir,best_dir);
best_dir[2] = best_dir[0];
best_dir[0] = -best_dir[1];
best_dir[1] = best_dir[2];
best_dir[2] = 0;
AngleVectors(targ->s.angles,dir,NULL,NULL);
if(DotProduct(best_dir,dir) < 0)
VectorNegate(best_dir,best_dir);
}
}
else
{
// Attacked by a point entity or moving brush model
// not covered above. Find a vector that will hide the
// monster from the attacker.
if(!VectorLength(attacker->size))
{
// point entity
VectorCopy(attacker->s.origin,atk);
}
else
{
// brush model... can't rely on origin
VectorMA(attacker->mins,0.5,attacker->size,atk);
}
VectorClear(best_dir);
AngleVectors(targ->s.angles,forward,NULL,NULL);
for(i=0; i<32 && best_dist == 0; i++) {
// Weight escape route tests in favor of forward-facing direction
if(random() > 0.5)
{
dir[0] = forward[0] + 0.5*crandom();
dir[1] = forward[1] + 0.5*crandom();
dir[2] = forward[2];
}
else
{
dir[0] = crandom();
dir[1] = crandom();
dir[2] = 0;
}
VectorNormalize(dir);
VectorMA(targ->s.origin,8192,dir,end);
trace1 = gi.trace(targ->s.origin,mins,maxs,end,targ,MASK_MONSTERSOLID);
trace2 = gi.trace(trace1.endpos,NULL,NULL,atk,targ,MASK_SOLID);
if(trace2.fraction == 1.0) continue;
dist = trace1.fraction * 8192;
if(dist > best_dist)
{
best_dist = dist;
VectorCopy(dir,best_dir);
}
}
if(best_dist == 0.)
return;
thing = SpawnThing();
vectoangles(best_dir,thing->s.angles);
}
if( (!Q_strcasecmp(attacker->classname,"func_door")) ||
(!Q_strcasecmp(attacker->classname,"func_pushable")) )
run = 256;
else
run = 8192;
VectorMA(targ->s.origin,run,best_dir,end);
trace1 = gi.trace(targ->s.origin,mins,maxs,end,targ,MASK_MONSTERSOLID);
dist = trace1.fraction * run;
VectorMA(targ->s.origin, dist, best_dir, thing->s.origin);
// If monster already has an enemy, use a short lifespan for thing
if(targ->enemy)
thing->touch_debounce_time = level.time + 2.0;
else
thing->touch_debounce_time = level.time + max(5.0,dist/50.);
thing->target_ent = targ;
ED_CallSpawn(thing);
targ->movetarget = targ->goalentity = thing;
targ->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
targ->monsterinfo.aiflags |= AI_CHASE_THING;
targ->monsterinfo.run(targ);
}
return;
}
// Lazarus: If in a no-win situation, actors run away
if (targ->monsterinfo.aiflags & AI_ACTOR)
{
if (targ->health < targ->max_health/3)
{
if (attacker->health > attacker->max_health/2)
{
if (attacker->health > targ->health)
{
if(ai_chicken(targ,attacker))
return;
}
}
}
}
if (attacker == targ || attacker == targ->enemy)
return;
// if we are a good guy monster and our attacker is a player
// or another good guy, do not get mad at them
if (targ->monsterinfo.aiflags & AI_GOOD_GUY)
{
if (attacker->client || (attacker->monsterinfo.aiflags & AI_GOOD_GUY))
return;
}
//PGM
// if we're currently mad at something a target_anger made us mad at, ignore
// damage
if (targ->enemy && targ->monsterinfo.aiflags & AI_TARGET_ANGER)
{
float percentHealth;
// make sure whatever we were pissed at is still around.
if(targ->enemy->inuse)
{
percentHealth = (float)(targ->health) / (float)(targ->max_health);
if( targ->enemy->inuse && percentHealth > 0.33)
return;
}
// remove the target anger flag
targ->monsterinfo.aiflags &= ~AI_TARGET_ANGER;
}
//PGM
// PMM
// if we're healing someone, do like above and try to stay with them
if ((targ->enemy) && (targ->monsterinfo.aiflags & AI_MEDIC))
{
float percentHealth;
percentHealth = (float)(targ->health) / (float)(targ->max_health);
// ignore it some of the time
if( targ->enemy->inuse && percentHealth > 0.25)
return;
// remove the medic flag
targ->monsterinfo.aiflags &= ~AI_MEDIC;
cleanupHealTarget (targ->enemy);
}
// PMM
// we now know that we are not both good guys
// if attacker is a client, get mad at them because he's good and we're not
if (attacker->client || is_turret)
{
targ->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
// this can only happen in coop (both new and old enemies are clients)
// only switch if can't see the current enemy
if (targ->enemy && targ->enemy->client)
{
if (visible(targ, targ->enemy))
{
targ->oldenemy = attacker;
return;
}
targ->oldenemy = targ->enemy;
}
targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED) && visible(targ,targ->enemy))
FoundTarget (targ);
else
HuntTarget (targ);
return;
}
// it's the same base (walk/swim/fly) type and a different classname and it's not a tank
// (they spray too much), get mad at them
// PMM
// added medics to this
// FIXME -
// this really should be turned into an AI flag marking appropriate monsters as "don't shoot me"
// this also leads to the problem of tanks and medics being able to, at will, kill monsters with
// no chance of retaliation. My vote is to make those monsters who are designed as "don't shoot me"
// such that they also ignore being shot by monsters as well
/*
if (((targ->flags & (FL_FLY|FL_SWIM)) == (attacker->flags & (FL_FLY|FL_SWIM))) &&
(strcmp (targ->classname, attacker->classname) != 0) &&
(strcmp(attacker->classname, "monster_tank") != 0) &&
(strcmp(attacker->classname, "monster_supertank") != 0) &&
(strcmp(attacker->classname, "monster_makron") != 0) &&
(strcmp(attacker->classname, "monster_jorg") != 0) &&
(strcmp(attacker->classname, "monster_carrier") != 0) &&
(strncmp(attacker->classname, "monster_medic", 12) != 0) ) // this should get medics & medic_commanders
*/
if (((targ->flags & (FL_FLY|FL_SWIM)) == (attacker->flags & (FL_FLY|FL_SWIM))) &&
(strcmp (targ->classname, attacker->classname) != 0) &&
!(attacker->monsterinfo.aiflags & AI_IGNORE_SHOTS) &&
!(targ->monsterinfo.aiflags & AI_IGNORE_SHOTS) )
{
if (targ->enemy && targ->enemy->client)
targ->oldenemy = targ->enemy;
targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED) && visible(targ,targ->enemy))
FoundTarget (targ);
else if (!(targ->monsterinfo.aiflags & AI_DUCKED))
HuntTarget (targ);
return;
}
// if they *meant* to shoot us, then shoot back
else if (attacker->enemy == targ)
{
if (targ->enemy && targ->enemy->client)
targ->oldenemy = targ->enemy;
targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED) && visible(targ,targ->enemy))
FoundTarget (targ);
else
HuntTarget (targ);
return;
}
// otherwise get mad at whoever they are mad at (help our buddy) unless it is us!
else if (attacker->enemy && attacker->enemy != targ)
{
if (targ->enemy && targ->enemy->client)
targ->oldenemy = targ->enemy;
targ->enemy = attacker->enemy;
if (!(targ->monsterinfo.aiflags & AI_DUCKED) && visible(targ,targ->enemy))
FoundTarget (targ);
else if (!(targ->monsterinfo.aiflags & AI_DUCKED) && visible(targ,targ->enemy))
HuntTarget (targ);
else
HuntTarget (targ);
return;
}
}
qboolean CheckTeamDamage (edict_t *targ, edict_t *attacker)
{
//FIXME make the next line real and uncomment this block
// if ((ability to damage a teammate == OFF) && (targ's team == attacker's team))
return false;
}
void monster_start_go (edict_t *self);
void T_Damage (edict_t *in_targ, edict_t *inflictor, edict_t *in_attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod)
{
gclient_t *client;
int take;
int save;
int asave;
int psave;
int te_sparks;
int sphere_notified; // PGM
edict_t *attacker;
edict_t *targ;
targ = in_targ;
if (!targ || !targ->inuse)
return;
if (!targ->takedamage)
return;
sphere_notified = false; // PGM
// Lazarus: If monster/actor is currently being forced to use
// specific animations due to target_animation, release that
// control over it.
if((targ->think == target_animate) && (targ->svflags & SVF_MONSTER))
{
targ->think = monster_think;
targ->nextthink = level.time + FRAMETIME;
}
if (!in_attacker)
attacker = world;
else
attacker = in_attacker;
// If targ is a fake player for the real player viewing camera, get that player
// out of the camera and do the damage to him
if (!Q_strcasecmp(targ->classname,"camplayer"))
{
if (targ->target_ent && targ->target_ent->client && targ->target_ent->client->spycam)
{
if(attacker->enemy == targ)
{
attacker->enemy = targ->target_ent;
attacker->goalentity = NULL;
attacker->movetarget = NULL;
}
targ = targ->target_ent;
camera_off(targ);
if (attacker->svflags & SVF_MONSTER)
{ //Knightmare- gekks and stalkers use different spawnflag
if ( (UseRegularGoodGuyFlag(attacker) && (attacker->spawnflags & SF_MONSTER_GOODGUY))
|| (UseSpecialGoodGuyFlag(attacker) && (attacker->spawnflags & 16)) )
{
if (attacker->enemy == targ)
{
attacker->enemy = NULL;
attacker->monsterinfo.aiflags &= ~AI_FOLLOW_LEADER;
attacker->monsterinfo.attack_finished = 0;
attacker->monsterinfo.pausetime = level.time + 100000000;
if(attacker->monsterinfo.stand)
attacker->monsterinfo.stand(attacker);
}
}
else
{
if(attacker->enemy == targ)
FoundTarget(attacker);
}
}
}
else
return; // don't damage target_monitor camplayer
}
// If targ is a remote turret_driver and attacker is a player, replace turret_driver
// with normal infantry dude and turn TRACK off on corresponding turret_breach
if ( targ->classname && !Q_strcasecmp(targ->classname,"turret_driver") &&
(targ->spawnflags & 1) && (attacker->client) )
{
edict_t *monster;
monster = targ->child;
if(monster)
{
monster->health = targ->health;
if(targ->target_ent)
{
targ->target_ent->spawnflags &= ~4;
targ->target_ent->move_angles[0] = 0;
targ->target_ent->owner = NULL;
}
G_FreeEdict(targ);
monster->solid = SOLID_BBOX;
monster->movetype = MOVETYPE_STEP;
monster->svflags &= ~SVF_NOCLIENT;
monster_start_go (monster);
gi.linkentity (monster);
monster->enemy = attacker;
FoundTarget(monster);
targ = monster;
}
}
// friendly fire avoidance
// if enabled you can't hurt teammates (but you can hurt yourself)
// knockback still occurs
if ((targ != attacker) && ((deathmatch->value && ((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS))) || coop->value))
{
if (OnSameTeam (targ, attacker))
{
// PMM - nukes kill everyone
if (((int)(dmflags->value) & DF_NO_FRIENDLY_FIRE) && (mod != MOD_NUKE))
damage = 0;
else
mod |= MOD_FRIENDLY_FIRE;
}
}
meansOfDeath = mod;
//ROGUE
// allow the deathmatch game to change values
if (deathmatch->value && gamerules && gamerules->value)
{
if(DMGame.ChangeDamage)
damage = DMGame.ChangeDamage(targ, attacker, damage, mod);
if(DMGame.ChangeKnockback)
knockback = DMGame.ChangeKnockback(targ, attacker, knockback, mod);
if(!damage)
return;
}
//ROGUE
// easy mode takes half damage
if (skill->value == 0 && deathmatch->value == 0 && targ->client)
{
damage *= 0.5;