Reformat g_combat.c

This commit is contained in:
Yamagi Burmeister 2011-10-13 06:37:06 +00:00
parent 9abb572aff
commit 943e91e300

View file

@ -1,98 +1,126 @@
/* /*
Copyright (C) 1997-2001 Id Software, Inc. * Copyright (C) 1997-2001 Id Software, Inc.
*
This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or modify
modify it under the terms of the GNU General Public License * it under the terms of the GNU General Public License as published by
as published by the Free Software Foundation; either version 2 * the Free Software Foundation; either version 2 of the License, or (at
of the License, or (at your option) any later version. * your option) any later version.
*
This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, but
but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
See the GNU General Public License for more details. * See the GNU General Public License for more details.
*
You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/ *
// g_combat.c * =======================================================================
*
* Combat code like damage, death and so on.
*
* =======================================================================
*/
#include "header/local.h" #include "header/local.h"
/* /*
============ * Returns true if the inflictor can
CanDamage * directly damage the target. Used for
* explosions and melee attacks.
Returns true if the inflictor can directly damage the target. Used for */
explosions and melee attacks. qboolean
============ CanDamage(edict_t *targ, edict_t *inflictor)
*/
qboolean CanDamage (edict_t *targ, edict_t *inflictor)
{ {
vec3_t dest; vec3_t dest;
trace_t trace; trace_t trace;
// bmodels need special checking because their origin is 0,0,0 /* bmodels need special checking because their origin is 0,0,0 */
if (targ->movetype == MOVETYPE_PUSH) if (targ->movetype == MOVETYPE_PUSH)
{ {
VectorAdd (targ->absmin, targ->absmax, dest); VectorAdd(targ->absmin, targ->absmax, dest);
VectorScale (dest, 0.5, dest); VectorScale(dest, 0.5, dest);
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID); trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0) if (trace.fraction == 1.0)
{
return true; return true;
}
if (trace.ent == targ) if (trace.ent == targ)
{
return true; return true;
}
return false; return false;
} }
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, targ->s.origin, inflictor, MASK_SOLID); trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
if (trace.fraction == 1.0) targ->s.origin, inflictor, MASK_SOLID);
return true;
VectorCopy (targ->s.origin, dest); if (trace.fraction == 1.0)
{
return true;
}
VectorCopy(targ->s.origin, dest);
dest[0] += 15.0; dest[0] += 15.0;
dest[1] += 15.0; dest[1] += 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID); trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
if (trace.fraction == 1.0) dest, inflictor, MASK_SOLID);
return true;
VectorCopy (targ->s.origin, dest); if (trace.fraction == 1.0)
{
return true;
}
VectorCopy(targ->s.origin, dest);
dest[0] += 15.0; dest[0] += 15.0;
dest[1] -= 15.0; dest[1] -= 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID); trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
if (trace.fraction == 1.0) dest, inflictor, MASK_SOLID);
return true;
VectorCopy (targ->s.origin, dest); if (trace.fraction == 1.0)
{
return true;
}
VectorCopy(targ->s.origin, dest);
dest[0] -= 15.0; dest[0] -= 15.0;
dest[1] += 15.0; dest[1] += 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID); trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
if (trace.fraction == 1.0) dest, inflictor, MASK_SOLID);
return true;
VectorCopy (targ->s.origin, dest); if (trace.fraction == 1.0)
{
return true;
}
VectorCopy(targ->s.origin, dest);
dest[0] -= 15.0; dest[0] -= 15.0;
dest[1] -= 15.0; dest[1] -= 15.0;
trace = gi.trace (inflictor->s.origin, vec3_origin, vec3_origin, dest, inflictor, MASK_SOLID); trace = gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
if (trace.fraction == 1.0) dest, inflictor, MASK_SOLID);
return true;
if (trace.fraction == 1.0)
{
return true;
}
return false; return false;
} }
void
/* Killed(edict_t *targ, edict_t *inflictor, edict_t *attacker,
============ int damage, vec3_t point)
Killed
============
*/
void Killed (edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{ {
if (targ->health < -999) if (targ->health < -999)
{
targ->health = -999; targ->health = -999;
}
targ->enemy = attacker; targ->enemy = attacker;
@ -101,93 +129,101 @@ void Killed (edict_t *targ, edict_t *inflictor, edict_t *attacker, int damage, v
if (!(targ->monsterinfo.aiflags & AI_GOOD_GUY)) if (!(targ->monsterinfo.aiflags & AI_GOOD_GUY))
{ {
level.killed_monsters++; level.killed_monsters++;
if (coop->value && attacker->client) if (coop->value && attacker->client)
{
attacker->client->resp.score++; attacker->client->resp.score++;
// medics won't heal monsters that they kill themselves }
/* medics won't heal monsters that they kill themselves */
if (strcmp(attacker->classname, "monster_medic") == 0) if (strcmp(attacker->classname, "monster_medic") == 0)
{
targ->owner = attacker; targ->owner = attacker;
}
} }
} }
if (targ->movetype == MOVETYPE_PUSH || targ->movetype == MOVETYPE_STOP || targ->movetype == MOVETYPE_NONE) if ((targ->movetype == MOVETYPE_PUSH) ||
{ // doors, triggers, etc (targ->movetype == MOVETYPE_STOP) || (targ->movetype == MOVETYPE_NONE))
targ->die (targ, inflictor, attacker, damage, point); {
/* doors, triggers, etc */
targ->die(targ, inflictor, attacker, damage, point);
return; return;
} }
if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD)) if ((targ->svflags & SVF_MONSTER) && (targ->deadflag != DEAD_DEAD))
{ {
targ->touch = NULL; targ->touch = NULL;
monster_death_use (targ); monster_death_use(targ);
} }
targ->die (targ, inflictor, attacker, damage, point); targ->die(targ, inflictor, attacker, damage, point);
} }
void
/* SpawnDamage(int type, vec3_t origin, vec3_t normal, int damage)
================
SpawnDamage
================
*/
void SpawnDamage (int type, vec3_t origin, vec3_t normal, int damage)
{ {
if (damage > 255) if (damage > 255)
{
damage = 255; damage = 255;
gi.WriteByte (svc_temp_entity); }
gi.WriteByte (type);
gi.WritePosition (origin); gi.WriteByte(svc_temp_entity);
gi.WriteDir (normal); gi.WriteByte(type);
gi.multicast (origin, MULTICAST_PVS); gi.WritePosition(origin);
gi.WriteDir(normal);
gi.multicast(origin, MULTICAST_PVS);
} }
/* /*
============ * targ entity that is being damaged
T_Damage * inflictor entity that is causing the damage
* attacker entity that caused the inflictor to damage targ
targ entity that is being damaged *
inflictor entity that is causing the damage * dir direction of the attack
attacker entity that caused the inflictor to damage targ * point point at which the damage is being inflicted
example: targ=monster, inflictor=rocket, attacker=player * normal normal vector from that point
* damage amount of damage being inflicted
dir direction of the attack * knockback force to be applied against targ as a result of the damage
point point at which the damage is being inflicted *
normal normal vector from that point * dflags these flags are used to control how T_Damage works
damage amount of damage being inflicted * DAMAGE_RADIUS damage was indirect (from a nearby explosion)
knockback force to be applied against targ as a result of the damage * DAMAGE_NO_ARMOR armor does not protect from this damage
* DAMAGE_ENERGY damage is from an energy based weapon
dflags these flags are used to control how T_Damage works * DAMAGE_NO_KNOCKBACK do not affect velocity, just view angles
DAMAGE_RADIUS damage was indirect (from a nearby explosion) * DAMAGE_BULLET damage is from a bullet (used for ricochets)
DAMAGE_NO_ARMOR armor does not protect from this damage * DAMAGE_NO_PROTECTION kills godmode, armor, everything
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) static int
DAMAGE_NO_PROTECTION kills godmode, armor, everything CheckPowerArmor(edict_t *ent, vec3_t point, vec3_t normal,
============ int damage, int dflags)
*/
static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int dflags)
{ {
gclient_t *client; gclient_t *client;
int save; int save;
int power_armor_type; int power_armor_type;
int index = 0; int index = 0;
int damagePerCell; int damagePerCell;
int pa_te_type; int pa_te_type;
int power = 0; int power = 0;
int power_used; int power_used;
if (!damage) if (!damage)
{
return 0; return 0;
}
client = ent->client; client = ent->client;
if (dflags & DAMAGE_NO_ARMOR) if (dflags & DAMAGE_NO_ARMOR)
{
return 0; return 0;
}
if (client) if (client)
{ {
power_armor_type = PowerArmorType (ent); power_armor_type = PowerArmorType(ent);
if (power_armor_type != POWER_ARMOR_NONE) if (power_armor_type != POWER_ARMOR_NONE)
{ {
index = ITEM_INDEX(FindItem("Cells")); index = ITEM_INDEX(FindItem("Cells"));
@ -201,26 +237,36 @@ static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damag
index = 0; index = 0;
} }
else else
{
return 0; return 0;
}
if (power_armor_type == POWER_ARMOR_NONE) if (power_armor_type == POWER_ARMOR_NONE)
{
return 0; return 0;
}
if (!power) if (!power)
{
return 0; return 0;
}
if (power_armor_type == POWER_ARMOR_SCREEN) if (power_armor_type == POWER_ARMOR_SCREEN)
{ {
vec3_t vec; vec3_t vec;
float dot; float dot;
vec3_t forward; 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);
// 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) if (dot <= 0.3)
{
return 0; return 0;
}
damagePerCell = 1; damagePerCell = 1;
pa_te_type = TE_SCREEN_SPARKS; pa_te_type = TE_SCREEN_SPARKS;
@ -228,92 +274,132 @@ static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damag
} }
else else
{ {
damagePerCell = 1; // power armor is weaker in CTF damagePerCell = 1; /* power armor is weaker in CTF */
pa_te_type = TE_SHIELD_SPARKS; pa_te_type = TE_SHIELD_SPARKS;
damage = (2 * damage) / 3; damage = (2 * damage) / 3;
} }
save = power * damagePerCell; save = power * damagePerCell;
if (!save)
return 0;
if (save > damage)
save = damage;
SpawnDamage (pa_te_type, point, normal, save); if (!save)
{
return 0;
}
if (save > damage)
{
save = damage;
}
SpawnDamage(pa_te_type, point, normal, save);
ent->powerarmor_time = level.time + 0.2; ent->powerarmor_time = level.time + 0.2;
power_used = save / damagePerCell; power_used = save / damagePerCell;
if (client) if (client)
{
client->pers.inventory[index] -= power_used; client->pers.inventory[index] -= power_used;
}
else else
{
ent->monsterinfo.power_armor_power -= power_used; ent->monsterinfo.power_armor_power -= power_used;
}
return save; return save;
} }
static int CheckArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int te_sparks, int dflags) static int
CheckArmor(edict_t *ent, vec3_t point, vec3_t normal,
int damage, int te_sparks, int dflags)
{ {
gclient_t *client; gclient_t *client;
int save; int save;
int index; int index;
gitem_t *armor; gitem_t *armor;
if (!damage) if (!damage)
{
return 0; return 0;
}
client = ent->client; client = ent->client;
if (!client) if (!client)
{
return 0; return 0;
}
if (dflags & DAMAGE_NO_ARMOR) if (dflags & DAMAGE_NO_ARMOR)
{
return 0; return 0;
}
index = ArmorIndex(ent);
index = ArmorIndex (ent);
if (!index) if (!index)
{
return 0; return 0;
}
armor = GetItemByIndex (index); armor = GetItemByIndex(index);
if (dflags & DAMAGE_ENERGY) if (dflags & DAMAGE_ENERGY)
save = ceil(((gitem_armor_t *)armor->info)->energy_protection*damage); {
save = ceil(((gitem_armor_t *)armor->info)->energy_protection * damage);
}
else else
save = ceil(((gitem_armor_t *)armor->info)->normal_protection*damage); {
save = ceil(((gitem_armor_t *)armor->info)->normal_protection * damage);
}
if (save >= client->pers.inventory[index]) if (save >= client->pers.inventory[index])
{
save = client->pers.inventory[index]; save = client->pers.inventory[index];
}
if (!save) if (!save)
{
return 0; return 0;
}
client->pers.inventory[index] -= save; client->pers.inventory[index] -= save;
SpawnDamage (te_sparks, point, normal, save); SpawnDamage(te_sparks, point, normal, save);
return save; return save;
} }
void M_ReactToDamage (edict_t *targ, edict_t *attacker) void
M_ReactToDamage(edict_t *targ, edict_t *attacker)
{ {
if (!(attacker->client) && !(attacker->svflags & SVF_MONSTER)) if (!(attacker->client) && !(attacker->svflags & SVF_MONSTER))
{
return; return;
}
if (attacker == targ || attacker == targ->enemy) if ((attacker == targ) || (attacker == targ->enemy))
{
return; return;
}
// if we are a good guy monster and our attacker is a player /* if we are a good guy monster and our
// or another good guy, do not get mad at them attacker is a player or another good
guy, do not get mad at them */
if (targ->monsterinfo.aiflags & AI_GOOD_GUY) if (targ->monsterinfo.aiflags & AI_GOOD_GUY)
{ {
if (attacker->client || (attacker->monsterinfo.aiflags & AI_GOOD_GUY)) if (attacker->client || (attacker->monsterinfo.aiflags & AI_GOOD_GUY))
{
return; return;
}
} }
// 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 is a client, get mad at them because he's good and we're not
if (attacker->client) if (attacker->client)
{ {
// this can only happen in coop (both new and old enemies are clients) /* this can only happen in coop (both
// only switch if can't see the current enemy new and old enemies are clients)
only switch if can't see the
current enemy */
if (targ->enemy && targ->enemy->client) if (targ->enemy && targ->enemy->client)
{ {
if (visible(targ, targ->enemy)) if (visible(targ, targ->enemy))
@ -321,273 +407,358 @@ void M_ReactToDamage (edict_t *targ, edict_t *attacker)
targ->oldenemy = attacker; targ->oldenemy = attacker;
return; return;
} }
targ->oldenemy = targ->enemy; targ->oldenemy = targ->enemy;
} }
targ->enemy = attacker; targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED)) if (!(targ->monsterinfo.aiflags & AI_DUCKED))
FoundTarget (targ); {
FoundTarget(targ);
}
return; return;
} }
// it's the same base (walk/swim/fly) type and a different classname and it's not a tank /* it's the same base (walk/swim/fly) type
// (they spray too much), get mad at them and a different classname and it's not a tank
if (((targ->flags & (FL_FLY|FL_SWIM)) == (attacker->flags & (FL_FLY|FL_SWIM))) && (they spray too much), get mad at them */
(strcmp (targ->classname, attacker->classname) != 0) && if (((targ->flags & (FL_FLY | FL_SWIM)) ==
(strcmp(attacker->classname, "monster_tank") != 0) && (attacker->flags & (FL_FLY | FL_SWIM))) &&
(strcmp(attacker->classname, "monster_supertank") != 0) && (strcmp(targ->classname, attacker->classname) != 0) &&
(strcmp(attacker->classname, "monster_makron") != 0) && (strcmp(attacker->classname, "monster_tank") != 0) &&
(strcmp(attacker->classname, "monster_jorg") != 0) ) (strcmp(attacker->classname, "monster_supertank") != 0) &&
(strcmp(attacker->classname, "monster_makron") != 0) &&
(strcmp(attacker->classname, "monster_jorg") != 0))
{ {
if (targ->enemy) if (targ->enemy)
{
if (targ->enemy->client) if (targ->enemy->client)
{
targ->oldenemy = targ->enemy; targ->oldenemy = targ->enemy;
}
}
targ->enemy = attacker; targ->enemy = attacker;
if (!(targ->monsterinfo.aiflags & AI_DUCKED)) if (!(targ->monsterinfo.aiflags & AI_DUCKED))
FoundTarget (targ); {
FoundTarget(targ);
}
} }
else else /* otherwise get mad at whoever they are mad at (help our buddy) */
// otherwise get mad at whoever they are mad at (help our buddy)
{ {
if (targ->enemy) if (targ->enemy)
{
if (targ->enemy->client) if (targ->enemy->client)
{
targ->oldenemy = targ->enemy; targ->oldenemy = targ->enemy;
}
}
targ->enemy = attacker->enemy; targ->enemy = attacker->enemy;
FoundTarget (targ); FoundTarget(targ);
} }
} }
qboolean CheckTeamDamage (edict_t *targ, edict_t *attacker) qboolean
CheckTeamDamage(edict_t *targ, edict_t *attacker)
{ {
//ZOID
if (ctf->value && targ->client && attacker->client) if (ctf->value && targ->client && attacker->client)
if (targ->client->resp.ctf_team == attacker->client->resp.ctf_team && {
targ != attacker) if ((targ->client->resp.ctf_team == attacker->client->resp.ctf_team) &&
(targ != attacker))
{
return true; return true;
//ZOID }
}
//FIXME make the next line real and uncomment this block
return false; return false;
} }
void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod) void
T_Damage(edict_t *targ, edict_t *inflictor, edict_t *attacker,
vec3_t dir, vec3_t point, vec3_t normal, int damage,
int knockback, int dflags, int mod)
{ {
gclient_t *client; gclient_t *client;
int take; int take;
int save; int save;
int asave; int asave;
int psave; int psave;
int te_sparks; int te_sparks;
if (!targ->takedamage) if (!targ->takedamage)
return;
// 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)) return;
}
/* 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))
{ {
if ((int)(dmflags->value) & DF_NO_FRIENDLY_FIRE) if ((int)(dmflags->value) & DF_NO_FRIENDLY_FIRE)
{
damage = 0; damage = 0;
}
else else
{
mod |= MOD_FRIENDLY_FIRE; mod |= MOD_FRIENDLY_FIRE;
}
} }
} }
meansOfDeath = mod; meansOfDeath = mod;
// easy mode takes half damage /* easy mode takes half damage */
if (skill->value == 0 && deathmatch->value == 0 && targ->client) if ((skill->value == 0) && (deathmatch->value == 0) && targ->client)
{ {
damage *= 0.5; damage *= 0.5;
if (!damage) if (!damage)
{
damage = 1; damage = 1;
}
} }
client = targ->client; client = targ->client;
if (dflags & DAMAGE_BULLET) if (dflags & DAMAGE_BULLET)
{
te_sparks = TE_BULLET_SPARKS; te_sparks = TE_BULLET_SPARKS;
}
else else
{
te_sparks = TE_SPARKS; te_sparks = TE_SPARKS;
}
VectorNormalize(dir); VectorNormalize(dir);
// bonus damage for suprising a monster /* bonus damage for suprising a monster */
if (!(dflags & DAMAGE_RADIUS) && (targ->svflags & SVF_MONSTER) && (attacker->client) && (!targ->enemy) && (targ->health > 0)) if (!(dflags & DAMAGE_RADIUS) && (targ->svflags & SVF_MONSTER) &&
(attacker->client) && (!targ->enemy) && (targ->health > 0))
{
damage *= 2; damage *= 2;
}
//ZOID /* strength tech */
//strength tech
damage = CTFApplyStrength(attacker, damage); damage = CTFApplyStrength(attacker, damage);
//ZOID
if (targ->flags & FL_NO_KNOCKBACK) if (targ->flags & FL_NO_KNOCKBACK)
{
knockback = 0; knockback = 0;
}
// figure momentum add /* figure momentum add */
if (!(dflags & DAMAGE_NO_KNOCKBACK)) if (!(dflags & DAMAGE_NO_KNOCKBACK))
{ {
if ((knockback) && (targ->movetype != MOVETYPE_NONE) && (targ->movetype != MOVETYPE_BOUNCE) && (targ->movetype != MOVETYPE_PUSH) && (targ->movetype != MOVETYPE_STOP)) if ((knockback) && (targ->movetype != MOVETYPE_NONE) &&
(targ->movetype != MOVETYPE_BOUNCE) &&
(targ->movetype != MOVETYPE_PUSH) &&
(targ->movetype != MOVETYPE_STOP))
{ {
vec3_t kvel; vec3_t kvel;
float mass; float mass;
if (targ->mass < 50) if (targ->mass < 50)
{
mass = 50; mass = 50;
}
else else
{
mass = targ->mass; mass = targ->mass;
}
if (targ->client && attacker == targ) if (targ->client && (attacker == targ))
VectorScale (dir, 1600.0 * (float)knockback / mass, kvel); // the rocket jump hack... {
VectorScale(dir, 1600.0 * (float)knockback / mass, kvel); /* the rocket jump hack... */
}
else else
VectorScale (dir, 500.0 * (float)knockback / mass, kvel); {
VectorScale(dir, 500.0 * (float)knockback / mass, kvel);
}
VectorAdd (targ->velocity, kvel, targ->velocity); VectorAdd(targ->velocity, kvel, targ->velocity);
} }
} }
take = damage; take = damage;
save = 0; save = 0;
// check for godmode /* check for godmode */
if ( (targ->flags & FL_GODMODE) && !(dflags & DAMAGE_NO_PROTECTION) ) if ((targ->flags & FL_GODMODE) && !(dflags & DAMAGE_NO_PROTECTION))
{ {
take = 0; take = 0;
save = damage; save = damage;
SpawnDamage (te_sparks, point, normal, save); SpawnDamage(te_sparks, point, normal, save);
} }
// check for invincibility /* check for invincibility */
if ((client && client->invincible_framenum > level.framenum ) && !(dflags & DAMAGE_NO_PROTECTION)) if ((client &&
(client->invincible_framenum > level.framenum)) &&
!(dflags & DAMAGE_NO_PROTECTION))
{ {
if (targ->pain_debounce_time < level.time) if (targ->pain_debounce_time < level.time)
{ {
gi.sound(targ, CHAN_ITEM, gi.soundindex("items/protect4.wav"), 1, ATTN_NORM, 0); gi.sound(targ, CHAN_ITEM, gi.soundindex("items/protect4.wav"), 1, ATTN_NORM, 0);
targ->pain_debounce_time = level.time + 2; targ->pain_debounce_time = level.time + 2;
} }
take = 0; take = 0;
save = damage; save = damage;
} }
//ZOID /* team armor protect */
//team armor protect
if (ctf->value && targ->client && attacker->client && if (ctf->value && targ->client && attacker->client &&
targ->client->resp.ctf_team == attacker->client->resp.ctf_team && (targ->client->resp.ctf_team == attacker->client->resp.ctf_team) &&
targ != attacker && ((int)dmflags->value & DF_ARMOR_PROTECT)) { (targ != attacker) && ((int)dmflags->value & DF_ARMOR_PROTECT))
{
psave = asave = 0; psave = asave = 0;
} else { }
//ZOID else
psave = CheckPowerArmor (targ, point, normal, take, dflags); {
psave = CheckPowerArmor(targ, point, normal, take, dflags);
take -= psave; take -= psave;
asave = CheckArmor (targ, point, normal, take, te_sparks, dflags); asave = CheckArmor(targ, point, normal, take, te_sparks, dflags);
take -= asave; take -= asave;
} }
//treat cheat/powerup savings the same as armor /* treat cheat/powerup savings the same as armor */
asave += save; asave += save;
//ZOID /* resistance tech */
//resistance tech
take = CTFApplyResistance(targ, take); take = CTFApplyResistance(targ, take);
//ZOID
// team damage avoidance /* team damage avoidance */
if (!(dflags & DAMAGE_NO_PROTECTION) && CheckTeamDamage (targ, attacker)) if (!(dflags & DAMAGE_NO_PROTECTION) && CheckTeamDamage(targ, attacker))
{
return; return;
}
//ZOID
CTFCheckHurtCarrier(targ, attacker); CTFCheckHurtCarrier(targ, attacker);
//ZOID
// do the damage /* do the damage */
if (take) if (take)
{ {
if ((targ->svflags & SVF_MONSTER) || (client)) if ((targ->svflags & SVF_MONSTER) || (client))
SpawnDamage (TE_BLOOD, point, normal, take); {
SpawnDamage(TE_BLOOD, point, normal, take);
}
else else
SpawnDamage (te_sparks, point, normal, take); {
SpawnDamage(te_sparks, point, normal, take);
}
if (!CTFMatchSetup()) if (!CTFMatchSetup())
{
targ->health = targ->health - take; targ->health = targ->health - take;
}
if (targ->health <= 0) if (targ->health <= 0)
{ {
if ((targ->svflags & SVF_MONSTER) || (client)) if ((targ->svflags & SVF_MONSTER) || (client))
{
targ->flags |= FL_NO_KNOCKBACK; targ->flags |= FL_NO_KNOCKBACK;
Killed (targ, inflictor, attacker, take, point); }
Killed(targ, inflictor, attacker, take, point);
return; return;
} }
} }
if (targ->svflags & SVF_MONSTER) if (targ->svflags & SVF_MONSTER)
{ {
M_ReactToDamage (targ, attacker); M_ReactToDamage(targ, attacker);
if (!(targ->monsterinfo.aiflags & AI_DUCKED) && (take)) if (!(targ->monsterinfo.aiflags & AI_DUCKED) && (take))
{ {
targ->pain (targ, attacker, knockback, take); targ->pain(targ, attacker, knockback, take);
// nightmare mode monsters don't go into pain frames often
/* nightmare mode monsters don't go into pain frames often */
if (skill->value == 3) if (skill->value == 3)
{
targ->pain_debounce_time = level.time + 5; targ->pain_debounce_time = level.time + 5;
}
} }
} }
else if (client) else if (client)
{ {
if (!(targ->flags & FL_GODMODE) && (take) && !CTFMatchSetup()) if (!(targ->flags & FL_GODMODE) && (take) && !CTFMatchSetup())
targ->pain (targ, attacker, knockback, take); {
targ->pain(targ, attacker, knockback, take);
}
} }
else if (take) else if (take)
{ {
if (targ->pain) if (targ->pain)
targ->pain (targ, attacker, knockback, take); {
targ->pain(targ, attacker, knockback, take);
}
} }
// add to the damage inflicted on a player this frame /* add to the damage inflicted on a
// the total will be turned into screen blends and view angle kicks player this frame the total will
// at the end of the frame be turned into screen blends and
view angle kicks at the end of
the frame */
if (client) if (client)
{ {
client->damage_parmor += psave; client->damage_parmor += psave;
client->damage_armor += asave; client->damage_armor += asave;
client->damage_blood += take; client->damage_blood += take;
client->damage_knockback += knockback; client->damage_knockback += knockback;
VectorCopy (point, client->damage_from); VectorCopy(point, client->damage_from);
} }
} }
void
/* T_RadiusDamage(edict_t *inflictor, edict_t *attacker, float damage,
============ edict_t *ignore, float radius, int mod)
T_RadiusDamage
============
*/
void T_RadiusDamage (edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod)
{ {
float points; float points;
edict_t *ent = NULL; edict_t *ent = NULL;
vec3_t v; vec3_t v;
vec3_t dir; vec3_t dir;
while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL) while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL)
{ {
if (ent == ignore) if (ent == ignore)
{
continue; continue;
if (!ent->takedamage) }
continue;
if (!ent->takedamage)
{
continue;
}
VectorAdd(ent->mins, ent->maxs, v);
VectorMA(ent->s.origin, 0.5, v, v);
VectorSubtract(inflictor->s.origin, v, v);
points = damage - 0.5 * VectorLength(v);
VectorAdd (ent->mins, ent->maxs, v);
VectorMA (ent->s.origin, 0.5, v, v);
VectorSubtract (inflictor->s.origin, v, v);
points = damage - 0.5 * VectorLength (v);
if (ent == attacker) if (ent == attacker)
{
points = points * 0.5; points = points * 0.5;
}
if (points > 0) if (points > 0)
{ {
if (CanDamage (ent, inflictor)) if (CanDamage(ent, inflictor))
{ {
VectorSubtract (ent->s.origin, inflictor->s.origin, dir); VectorSubtract(ent->s.origin, inflictor->s.origin, dir);
T_Damage (ent, inflictor, attacker, dir, inflictor->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod); T_Damage(ent, inflictor, attacker, dir, inflictor->s.origin,
vec3_origin, (int)points, (int)points, DAMAGE_RADIUS,
mod);
} }
} }
} }