| 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 |
#include "damage.h" |
| 50 |
|
| 51 |
#include "actors.h" |
| 52 |
#include "campaigns.h" |
| 53 |
#include "game_events.h" |
| 54 |
#include "objs.h" |
| 55 |
|
| 56 |
|
| 57 |
#define MELEE_SPREAD_FACTOR 0.5f |
| 58 |
|
| 59 |
#define MELEE_VEL_SCALE 40.0f |
| 60 |
|
| 61 |
bool CanHitCharacter(const int flags, const int uid, const TActor *actor) |
| 62 |
{ |
| 63 |
|
| 64 |
if (!(flags & FLAGS_HURTALWAYS) && (uid == actor->uid || uid == actor->pilotUID)) |
| 65 |
{ |
| 66 |
return false; |
| 67 |
} |
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
bool CanDamageCharacter( |
| 72 |
const int flags, const TActor *source, const TActor *target, |
| 73 |
const special_damage_e special) |
| 74 |
{ |
| 75 |
if (!CanHitCharacter(flags, source ? source->uid : -1, target)) |
| 76 |
{ |
| 77 |
return false; |
| 78 |
} |
| 79 |
return !ActorIsInvulnerable( |
| 80 |
target, flags, source ? source->PlayerUID : -1, gCampaign.Entry.Mode, |
| 81 |
special); |
| 82 |
} |
| 83 |
|
| 84 |
static void TrackKills(PlayerData *pd, const TActor *victim); |
| 85 |
void DamageActor(TActor *victim, const int power, const int sourceActorUID) |
| 86 |
{ |
| 87 |
const int startingHealth = victim->health; |
| 88 |
InjureActor(victim, power); |
| 89 |
const TActor *source = ActorGetByUID(sourceActorUID); |
| 90 |
|
| 91 |
if (source != NULL) |
| 92 |
{ |
| 93 |
PlayerData *pd = PlayerDataGetByUID(source->PlayerUID); |
| 94 |
if (pd != NULL) |
| 95 |
{ |
| 96 |
if (startingHealth > 0 && victim->health <= 0) |
| 97 |
{ |
| 98 |
TrackKills(pd, victim); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
static void TrackKills(PlayerData *pd, const TActor *victim) |
| 104 |
{ |
| 105 |
if (!IsPVP(gCampaign.Entry.Mode) && |
| 106 |
(victim->PlayerUID >= 0 || |
| 107 |
(victim->flags & (FLAGS_GOOD_GUY | FLAGS_PENALTY)))) |
| 108 |
{ |
| 109 |
pd->Stats.Friendlies++; |
| 110 |
pd->Totals.Friendlies++; |
| 111 |
} |
| 112 |
else if (pd->UID == victim->PlayerUID) |
| 113 |
{ |
| 114 |
pd->Stats.Suicides++; |
| 115 |
pd->Totals.Suicides++; |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
pd->Stats.Kills++; |
| 120 |
pd->Totals.Kills++; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
void DamageMelee(const NActorMelee m) |
| 125 |
{ |
| 126 |
const TActor *a = ActorGetByUID(m.UID); |
| 127 |
if (!a->isInUse) |
| 128 |
return; |
| 129 |
const BulletClass *b = StrBulletClass(m.BulletClass); |
| 130 |
if ((HitType)m.HitType != HIT_NONE && |
| 131 |
HasHitSound((ThingKind)m.TargetKind, m.TargetUID, SPECIAL_NONE, false)) |
| 132 |
{ |
| 133 |
PlayHitSound(b, (HitType)m.HitType, a->Pos); |
| 134 |
} |
| 135 |
if (!gCampaign.IsClient) |
| 136 |
{ |
| 137 |
const Thing *target = |
| 138 |
ThingGetByUID((ThingKind)m.TargetKind, m.TargetUID); |
| 139 |
const struct vec2 vel = svec2_scale( |
| 140 |
svec2_add( |
| 141 |
svec2_normalize(svec2_subtract(target->Pos, a->Pos)), |
| 142 |
svec2( |
| 143 |
RAND_FLOAT(-MELEE_SPREAD_FACTOR, MELEE_SPREAD_FACTOR), |
| 144 |
RAND_FLOAT(-MELEE_SPREAD_FACTOR, MELEE_SPREAD_FACTOR))), |
| 145 |
MELEE_VEL_SCALE); |
| 146 |
Damage( |
| 147 |
vel, b, NULL, |
| 148 |
a->flags, a, (ThingKind)m.TargetKind, m.TargetUID); |
| 149 |
} |
| 150 |
} |