329 lines
7.2 KiB
C++
329 lines
7.2 KiB
C++
|
|
void() t_missiletouch;
|
|
void() info_player_start;
|
|
void(entity targ, entity attacker) clientobituary;
|
|
|
|
void() monster_death_use;
|
|
|
|
//============================================================================
|
|
|
|
/*
|
|
============
|
|
candamage
|
|
|
|
returns true if the inflictor can directly damage the target. used for
|
|
explosions and melee attacks.
|
|
============
|
|
*/
|
|
float(entity targ, entity inflictor) candamage =
|
|
{
|
|
// bmodels need special checking because their origin is 0,0,0
|
|
if (targ.movetype == movetype_push)
|
|
{
|
|
traceline(inflictor.origin, 0.5 * (targ.absmin + targ.absmax), true, self);
|
|
if (trace_fraction == 1)
|
|
return true;
|
|
if (trace_ent == targ)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
traceline(inflictor.origin, targ.origin, true, self);
|
|
if (trace_fraction == 1)
|
|
return true;
|
|
traceline(inflictor.origin, targ.origin + '15 15 0', true, self);
|
|
if (trace_fraction == 1)
|
|
return true;
|
|
traceline(inflictor.origin, targ.origin + '-15 -15 0', true, self);
|
|
if (trace_fraction == 1)
|
|
return true;
|
|
traceline(inflictor.origin, targ.origin + '-15 15 0', true, self);
|
|
if (trace_fraction == 1)
|
|
return true;
|
|
traceline(inflictor.origin, targ.origin + '15 -15 0', true, self);
|
|
if (trace_fraction == 1)
|
|
return true;
|
|
|
|
return false;
|
|
};
|
|
|
|
|
|
/*
|
|
============
|
|
killed
|
|
============
|
|
*/
|
|
void(entity targ, entity attacker) killed =
|
|
{
|
|
local entity oself;
|
|
|
|
oself = self;
|
|
self = targ;
|
|
|
|
if (self.health < -99)
|
|
self.health = -99; // don't let sbar look bad if a player
|
|
//med
|
|
if (self.charmed)
|
|
{
|
|
self.effects = self.effects - (self.effects & ef_dimlight);
|
|
}
|
|
// self.effects = self.effects - ef_brightfield;
|
|
|
|
if (self.movetype == movetype_push || self.movetype == movetype_none)
|
|
{ // doors, triggers, etc
|
|
self.th_die ();
|
|
self = oself;
|
|
return;
|
|
}
|
|
|
|
self.enemy = attacker;
|
|
|
|
// bump the monster counter
|
|
if (self.flags & fl_monster)
|
|
{
|
|
killed_monsters = killed_monsters + 1;
|
|
writebyte (msg_all, svc_killedmonster);
|
|
}
|
|
|
|
clientobituary(self, attacker);
|
|
|
|
self.takedamage = damage_no;
|
|
self.touch = sub_null;
|
|
|
|
monster_death_use();
|
|
self.th_die ();
|
|
|
|
self = oself;
|
|
};
|
|
|
|
|
|
/*
|
|
============
|
|
t_damage
|
|
|
|
the damage is coming from inflictor, but get mad at attacker
|
|
this should be the only function that ever reduces health.
|
|
============
|
|
*/
|
|
//med 01/10/97 added empathyused variable
|
|
float empathyused;
|
|
void(entity targ, entity inflictor, entity attacker, float damage) t_damage=
|
|
{
|
|
local vector dir;
|
|
local entity oldself;
|
|
local float save;
|
|
local float take;
|
|
|
|
if (!targ.takedamage)
|
|
return;
|
|
|
|
if (discharged && targ.wetsuit_finished )
|
|
return;
|
|
//med moved damage_attacker down a bit
|
|
/*
|
|
dprint("netname = ");
|
|
dprint(attacker.netname);
|
|
dprint(" classname = ");
|
|
dprint(attacker.classname);
|
|
dprint(" classname = ");
|
|
dprint(inflictor.classname);
|
|
dprint("\n");
|
|
*/
|
|
// check for quad damage powerup on the attacker
|
|
if (attacker.super_damage_finished > time)
|
|
damage = damage * 4;
|
|
|
|
|
|
//med
|
|
//check for empathy shields
|
|
if ((targ.items2 & hip_it_empathy_shields) && !(inflictor.items2 & hip_it_empathy_shields) && (targ != attacker))
|
|
{
|
|
empathyused = 1;
|
|
damage = damage/2;
|
|
t_damage (attacker,targ,targ,damage);
|
|
empathyused = 0;
|
|
}
|
|
//med
|
|
// used by buttons and triggers to set activator for target firing
|
|
damage_attacker = attacker;
|
|
|
|
//med
|
|
// used to keep track of what hit us
|
|
damage_inflictor = inflictor;
|
|
|
|
// save damage based on the target's armor level
|
|
|
|
save = ceil(targ.armortype*damage);
|
|
if (save >= targ.armorvalue)
|
|
{
|
|
save = targ.armorvalue;
|
|
targ.armortype = 0; // lost all armor
|
|
targ.items = targ.items - (targ.items & (it_armor1 | it_armor2 | it_armor3));
|
|
}
|
|
|
|
targ.armorvalue = targ.armorvalue - save;
|
|
take = ceil(damage-save);
|
|
|
|
// add to the damage total for clients, which will be sent as a single
|
|
// message at the end of the frame
|
|
// fixme: remove after combining shotgun blasts?
|
|
if (targ.flags & fl_client)
|
|
{
|
|
targ.dmg_take = targ.dmg_take + take;
|
|
targ.dmg_save = targ.dmg_save + save;
|
|
targ.dmg_inflictor = inflictor;
|
|
}
|
|
|
|
// figure momentum add
|
|
if ( (inflictor != world) && (targ.movetype == movetype_walk) )
|
|
{
|
|
dir = targ.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
|
|
dir = normalize(dir);
|
|
targ.velocity = targ.velocity + dir*damage*8;
|
|
}
|
|
|
|
// check for godmode or invincibility
|
|
if (targ.flags & fl_godmode)
|
|
return;
|
|
if (targ.invincible_finished >= time)
|
|
{
|
|
if (self.invincible_sound < time)
|
|
{
|
|
sound (targ, chan_item, "items/protect3.wav", 1, attn_norm);
|
|
self.invincible_sound = time + 2;
|
|
}
|
|
return;
|
|
}
|
|
//med
|
|
if (targ.items2 & hip_it_empathy_shields)
|
|
{
|
|
if (self.empathy_sound < time)
|
|
{
|
|
sound (targ, chan_item, "hipitems/empathy2.wav", 1, attn_norm);
|
|
self.empathy_sound = time + 0.5;
|
|
}
|
|
}
|
|
|
|
// team play damage avoidance
|
|
if ( (teamplay == 1) && (targ.team > 0)&&(targ.team == attacker.team) )
|
|
return;
|
|
|
|
// do the damage
|
|
targ.health = targ.health - take;
|
|
|
|
if (targ.health <= 0)
|
|
{
|
|
killed (targ, attacker);
|
|
return;
|
|
}
|
|
|
|
// react to the damage
|
|
oldself = self;
|
|
self = targ;
|
|
|
|
//med 10/17/96 added charmed stuff
|
|
if ( (self.flags & fl_monster) && attacker != world)
|
|
{
|
|
// get mad unless of the same class (except for soldiers)
|
|
if (self != attacker && attacker != self.enemy && (self.charmer!=attacker))
|
|
{
|
|
if ( (self.classname != attacker.classname)
|
|
|| (self.classname == "monster_army" ) || (self.classname == "monster_armagon" ) )
|
|
{
|
|
if (self.enemy.classname == "player")
|
|
self.oldenemy = self.enemy;
|
|
self.enemy = attacker;
|
|
foundtarget ();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (self.th_pain)
|
|
{
|
|
self.th_pain (attacker, take);
|
|
// nightmare mode monsters don't go into pain frames often
|
|
if (skill == 3)
|
|
self.pain_finished = time + 5;
|
|
}
|
|
|
|
self = oldself;
|
|
};
|
|
|
|
/*
|
|
============
|
|
t_radiusdamage
|
|
============
|
|
*/
|
|
void(entity inflictor, entity attacker, float damage, entity ignore) t_radiusdamage =
|
|
{
|
|
local float points;
|
|
local entity head;
|
|
local vector org;
|
|
|
|
head = findradius(inflictor.origin, damage+40);
|
|
|
|
while (head)
|
|
{
|
|
if (head != ignore)
|
|
{
|
|
if (head.takedamage)
|
|
{
|
|
org = head.origin + (head.mins + head.maxs)*0.5;
|
|
points = 0.5*vlen (inflictor.origin - org);
|
|
if (points < 0)
|
|
points = 0;
|
|
points = damage - points;
|
|
if (head == attacker)
|
|
points = points * 0.5;
|
|
if (points > 0)
|
|
{
|
|
if (candamage (head, inflictor))
|
|
{ // shambler takes half damage from all explosions
|
|
if (head.classname == "monster_shambler")
|
|
t_damage (head, inflictor, attacker, points*0.5);
|
|
else
|
|
t_damage (head, inflictor, attacker, points);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
head = head.chain;
|
|
}
|
|
};
|
|
|
|
/*
|
|
============
|
|
t_beamdamage
|
|
============
|
|
*/
|
|
void(entity attacker, float damage) t_beamdamage =
|
|
{
|
|
local float points;
|
|
local entity head;
|
|
|
|
head = findradius(attacker.origin, damage+40);
|
|
|
|
while (head)
|
|
{
|
|
if (head.takedamage)
|
|
{
|
|
points = 0.5*vlen (attacker.origin - head.origin);
|
|
if (points < 0)
|
|
points = 0;
|
|
points = damage - points;
|
|
if (head == attacker)
|
|
points = points * 0.5;
|
|
if (points > 0)
|
|
{
|
|
if (candamage (head, attacker))
|
|
{
|
|
if (head.classname == "monster_shambler")
|
|
t_damage (head, attacker, attacker, points*0.5);
|
|
else
|
|
t_damage (head, attacker, attacker, points);
|
|
}
|
|
}
|
|
}
|
|
head = head.chain;
|
|
}
|
|
};
|