p_inter.c
/*
=================
=
= P_DamageMobj
=
= Damages both enemies and players
= inflictor is the thing that caused the damage
= 		creature or missile, can be NULL (slime, etc)
= source is the thing to target after taking damage
=		creature or NULL
= Source and inflictor are the same for melee attacks
= source can be null for barrel explosions and other environmental stuff
==================
*/
P_DamageMobj
Damages both enemies and players
inflictor is the thing that caused the damage
creature or missile, can be NULL (slime, etc)
source is the thing to target after taking damage
creature or NULL
Source and inflictor are the same for melee attacks
source can be null for barrel explosions and other environmental stuff
P_DamageMobj Damages both enemies and players inflictor is the thing that caused the damage creature or missile can be NULL ( slime etc ) source is the thing to target after taking damage creature or NULL Source and inflictor are the same for melee attacks source can be null for barrel explosions and other environmental stuff
void P_DamageMobj (mobj_t *target, mobj_t *inflictor, mobj_t *source, int damage)
{
	unsigned	ang, an;
	int			saved;
	player_t	*player;
	fixed_t		thrust;
	const mobjinfo_t* targinfo = &mobjinfo[target->type];
	if ( !(target->flags & MF_SHOOTABLE) )
		return;						
	if (target->health <= 0)
		return;
	if ( target->flags & MF_SKULLFLY )
	{
		target->momx = target->momy = target->momz = 0;
	}
	player = target->player ? &players[target->player - 1] : NULL;
	if (player && gameskill == sk_baby)
		damage >>= 1;				
	if (player && (damage > 30) && player == &players[consoleplayer])
		stbar.specialFace = f_hurtbad;
	if (inflictor && (!source || !source->player 
		|| players[source->player - 1].readyweapon != wp_chainsaw))
	{
		ang = R_PointToAngle2 ( inflictor->x, inflictor->y
			,target->x, target->y);
		thrust = damage*(FRACUNIT>>2)*100/targinfo->mass;
		if ( damage < 40 && damage > target->health && target->z - inflictor->z > 64*FRACUNIT && (P_Random ()&1) )
		{
			ang += ANG180;
			thrust *= 4;
		}
		an = ang >> ANGLETOFINESHIFT;
		thrust >>= 16;
		target->momx += thrust * finecosine(an);
		target->momy += thrust * finesine(an);
	}
	else
		ang = target->angle;
	if (player)
	{
		if ( (player->cheats&CF_GODMODE)||player->powers[pw_invulnerability] )
			return;
		if (player == &players[consoleplayer])
		{
			ang -= target->angle;
			if (ang > 0x30000000 && ang <0x80000000)
				stbar.specialFace = f_faceright;
			else if (ang >0x80000000 && ang < 0xd0000000)
				stbar.specialFace = f_faceleft;
		}
		if (player->armortype)
		{
			if (player->armortype == 1)
				saved = damage/3;
			else
				saved = damage/2;
			if (player->armorpoints <= saved)
			{	
				saved = player->armorpoints;
				player->armortype = 0;
			}
			player->armorpoints -= saved;
			damage -= saved;
		}
		S_StartSound (target,sfx_plpain);
		player->health -= damage;		
		if (player->health < 0)
			player->health = 0;
		player->attacker = source;
		player->damagecount += (damage>>1);	
	}
	target->health -= damage;	
	if (target->health <= 0)
	{
		P_KillMobj (source, target);
		return;
	}
	if ( (P_Random () < targinfo->painchance) && !(target->flags&MF_SKULLFLY) )
	{
		target->flags |= MF_JUSTHIT;		
		P_SetMobjState (target, targinfo->painstate);
	}
	target->reactiontime = 0;		
	if (!target->threshold && source
	&& spr_rotations	
	)
	{	
		target->target = source;
		target->threshold = BASETHRESHOLD;
		if (target->state == targinfo->spawnstate
		&& targinfo->seestate != S_NULL)
			P_SetMobjState (target, targinfo->seestate);
	}
}
void P_DamageMobj ( mobj_t * target , mobj_t * inflictor , mobj_t * source , int damage ) { unsigned ang , an ; int saved ; player_t * player ; fixed_t thrust ; const mobjinfo_t * targinfo = & mobjinfo [ target -> type ] ; if ( ! ( target -> flags & MF_SHOOTABLE ) ) return ; if ( target -> health <= 0 ) return ; if ( target -> flags & MF_SKULLFLY ) { target -> momx = target -> momy = target -> momz = 0 ; } player = target -> player ? & players [ target -> player - 1 ] : NULL ; if ( player && gameskill == sk_baby ) damage >>= 1 ; if ( player && ( damage > 30 ) && player == & players [ consoleplayer ] ) stbar . specialFace = f_hurtbad ; if ( inflictor && ( ! source || ! source -> player || players [ source -> player - 1 ] . readyweapon != wp_chainsaw ) ) { ang = R_PointToAngle2 ( inflictor -> x , inflictor -> y , target -> x , target -> y ) ; thrust = damage * ( FRACUNIT >> 2 ) * 100 / targinfo -> mass ; if ( damage < 40 && damage > target -> health && target -> z - inflictor -> z > 64 * FRACUNIT && ( P_Random ( ) & 1 ) ) { ang += ANG180 ; thrust *= 4 ; } an = ang >> ANGLETOFINESHIFT ; thrust >>= 16 ; target -> momx += thrust * finecosine ( an ) ; target -> momy += thrust * finesine ( an ) ; } else ang = target -> angle ; if ( player ) { if ( ( player -> cheats & CF_GODMODE ) || player -> powers [ pw_invulnerability ] ) return ; if ( player == & players [ consoleplayer ] ) { ang -= target -> angle ; if ( ang > 0x30000000 && ang < 0x80000000 ) stbar . specialFace = f_faceright ; else if ( ang > 0x80000000 && ang < 0xd0000000 ) stbar . specialFace = f_faceleft ; } if ( player -> armortype ) { if ( player -> armortype == 1 ) saved = damage / 3 ; else saved = damage / 2 ; if ( player -> armorpoints <= saved ) { saved = player -> armorpoints ; player -> armortype = 0 ; } player -> armorpoints -= saved ; damage -= saved ; } S_StartSound ( target , sfx_plpain ) ; player -> health -= damage ; if ( player -> health < 0 ) player -> health = 0 ; player -> attacker = source ; player -> damagecount += ( damage >> 1 ) ; } target -> health -= damage ; if ( target -> health <= 0 ) { P_KillMobj ( source , target ) ; return ; } if ( ( P_Random ( ) < targinfo -> painchance ) && ! ( target -> flags & MF_SKULLFLY ) ) { target -> flags |= MF_JUSTHIT ; P_SetMobjState ( target , targinfo -> painstate ) ; } target -> reactiontime = 0 ; if ( ! target -> threshold && source && spr_rotations ) { target -> target = source ; target -> threshold = BASETHRESHOLD ; if ( target -> state == targinfo -> spawnstate && targinfo -> seestate != S_NULL ) P_SetMobjState ( target , targinfo -> seestate ) ; } }
P_DamageMobj
Damages both enemies and players
inflictor is the thing that caused the damage
creature or missile, can be NULL (slime, etc)
source is the thing to target after taking damage
creature or NULL
Source and inflictor are the same for melee attacks
source can be null for barrel explosions and other environmental stuff
P_DamageMobj Damages both enemies and players inflictor is the thing that caused the damage creature or missile can be NULL ( slime etc ) source is the thing to target after taking damage creature or NULL Source and inflictor are the same for melee attacks source can be null for barrel explosions and other environmental stuff
/* shouldn't happen... */ /* take half damage in trainer mode */ /* */ /* kick away unless using the chainsaw */ /* */ /* make fall forwards sometimes */ /* */ /* player specific */ /* */ /* armor is used up */ /* mirror mobj health here for Dave */ /* add damage after armor / invuln */ /* */ /* do the damage */ /*		 */ /* fight back! */ /* we're awake now...	 */ /* don't fight amongst each other without rotations */ /* if not intent on another player, chase after this one */