Skip to content

Commit

Permalink
Common|libdoomsday: Damage to mobjs applied via libcommon
Browse files Browse the repository at this point in the history
`Mobj_InflictDamage()` applies damage to a mobj and notifies the
engine via MobjThinkerData.

Particle generator spawning will be handled on client-side by
ClientMobjThinkerData.
  • Loading branch information
skyjake committed Oct 30, 2015
1 parent 5f2ea4f commit 5ed9b06
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
Expand Up @@ -49,6 +49,15 @@ class LIBDOOMSDAY_PUBLIC MobjThinkerData : public ThinkerData
*/
virtual void stateChanged(state_t const *previousState);

/**
* Called whenever the mobj receives damage. This is a notification of
* damage already received.
*
* @param points Amount of damage.
* @param direction If not @c nullptr, identifies the source of the damage.
*/
virtual void damageReceived(int points, mobj_t const *inflictor);

private:
DENG2_PRIVATE(d)
};
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/libdoomsday/src/world/mobjthinkerdata.cpp
Expand Up @@ -70,3 +70,6 @@ void MobjThinkerData::stateChanged(state_t const *)
{
// overridden
}

void MobjThinkerData::damageReceived(int, mobj_t const *)
{}
2 changes: 2 additions & 0 deletions doomsday/apps/plugins/common/include/mobj.h
Expand Up @@ -214,6 +214,8 @@ mobj_t *Mobj_LaunchMissileAtAngle (mobj_t *mob, mobj_t *missile, angle_t angle,
mobj_t *Mobj_LaunchMissile2(mobj_t *mob, mobj_t *missile, coord_t const targetPos[3], coord_t const sourcePos[3], coord_t extraMomZ);
mobj_t *Mobj_LaunchMissile (mobj_t *mob, mobj_t *missile, coord_t const targetPos[3], coord_t const sourcePos[3]/*, coord_t extraMomZ = 0*/);

void Mobj_InflictDamage(mobj_t *mob, mobj_t const *inflictor, int damage);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
12 changes: 12 additions & 0 deletions doomsday/apps/plugins/common/src/mobj.cpp
Expand Up @@ -29,6 +29,7 @@
#include "mobj.h"

#include <cmath>
#include <doomsday/world/mobjthinkerdata.h>
#include <de/mathutil.h>
#include "dmu_lib.h"
#include "mapstatereader.h"
Expand Down Expand Up @@ -1020,3 +1021,14 @@ mobj_t *Mobj_LaunchMissile(mobj_t *mob, mobj_t *missile, coord_t const targetPos
{
return Mobj_LaunchMissile2(mob, missile, targetPos, sourcePos, 0/*no extra z-momentum*/);
}

void Mobj_InflictDamage(mobj_t *mob, mobj_t const *inflictor, int damage)
{
DENG_ASSERT(mob);

// Do the damage.
mob->health -= damage;

// Notify the engine.
THINKER_DATA(mob->thinker, MobjThinkerData).damageReceived(damage, inflictor);
}
6 changes: 1 addition & 5 deletions doomsday/apps/plugins/doom/src/p_inter.c
Expand Up @@ -1249,12 +1249,8 @@ int P_DamageMobj2(mobj_t *target, mobj_t *inflictor, mobj_t *source,
ST_HUDUnHide(player - players, HUE_ON_DAMAGE);
}

// How about some particles, yes?
// Only works when both target and inflictor are real mobjs.
Mobj_SpawnDamageParticleGen(target, inflictor, damage);
Mobj_InflictDamage(target, inflictor, damage);

// Do the damage.
target->health -= damage;
if(target->health > 0)
{ // Still alive, phew!
if((P_Random() < target->info->painChance) &&
Expand Down
6 changes: 1 addition & 5 deletions doomsday/apps/plugins/doom64/src/p_inter.c
Expand Up @@ -1197,12 +1197,8 @@ int P_DamageMobj2(mobj_t *target, mobj_t *inflictor, mobj_t *source,
ST_HUDUnHide(player - players, HUE_ON_DAMAGE);
}

// How about some particles, yes?
// Only works when both target and inflictor are real mobjs.
Mobj_SpawnDamageParticleGen(target, inflictor, damage);
Mobj_InflictDamage(target, inflictor, damage);

// Do the damage.
target->health -= damage;
if(target->health > 0)
{ // Still alive, phew!
if((P_Random() < target->info->painChance) &&
Expand Down
6 changes: 1 addition & 5 deletions doomsday/apps/plugins/heretic/src/p_inter.c
Expand Up @@ -1566,12 +1566,8 @@ int P_DamageMobj2(mobj_t *target, mobj_t *inflictor, mobj_t *source,
ST_HUDUnHide(player - players, HUE_ON_DAMAGE);
}

// How about some particles, yes?
// Only works when both target and inflictor are real mobjs.
Mobj_SpawnDamageParticleGen(target, inflictor, damage);
Mobj_InflictDamage(target, inflictor, damage);

// Do the damage.
target->health -= damage;
if(target->health > 0)
{
// Still alive, phew!
Expand Down
6 changes: 1 addition & 5 deletions doomsday/apps/plugins/hexen/src/p_inter.c
Expand Up @@ -2308,12 +2308,8 @@ int P_DamageMobj2(mobj_t *target, mobj_t *inflictor, mobj_t *source, int damageP
R_UpdateViewFilter(player - players);
}

// How about some particles, yes?
// Only works when both target and inflictor are real mobjs.
Mobj_SpawnDamageParticleGen(target, inflictor, damage);
Mobj_InflictDamage(target, inflictor, damage);

// Do the damage.
target->health -= damage;
if(target->health > 0)
{ // Still alive, phew!
if((P_Random() < target->info->painChance) &&
Expand Down

0 comments on commit 5ed9b06

Please sign in to comment.