Skip to content

Commit

Permalink
Allow retrieval of the custom Crush state in WorldThingGround
Browse files Browse the repository at this point in the history
  • Loading branch information
nashmuhandes authored and coelckers committed Oct 25, 2020
1 parent 7285c5a commit 6e692e5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/events.cpp
Expand Up @@ -331,16 +331,16 @@ void EventManager::WorldThingDied(AActor* actor, AActor* inflictor)
handler->WorldThingDied(actor, inflictor);
}

void EventManager::WorldThingGround(AActor* actor)
void EventManager::WorldThingGround(AActor* actor, FState* st)
{
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
if (actor->ObjectFlags & OF_EuthanizeMe)
return;

if (ShouldCallStatic(true)) staticEventManager.WorldThingGround(actor);
if (ShouldCallStatic(true)) staticEventManager.WorldThingGround(actor, st);

for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldThingGround(actor);
handler->WorldThingGround(actor, st);
}

void EventManager::WorldThingRevived(AActor* actor)
Expand Down Expand Up @@ -646,6 +646,7 @@ DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamageLineSide);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamagePosition);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamageIsRadius);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, NewDamage);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, CrushedState);

DEFINE_FIELD_X(PlayerEvent, FPlayerEvent, PlayerNumber);
DEFINE_FIELD_X(PlayerEvent, FPlayerEvent, IsReturn);
Expand Down Expand Up @@ -807,14 +808,15 @@ void DStaticEventHandler::WorldThingDied(AActor* actor, AActor* inflictor)
}
}

void DStaticEventHandler::WorldThingGround(AActor* actor)
void DStaticEventHandler::WorldThingGround(AActor* actor, FState* st)
{
IFVIRTUAL(DStaticEventHandler, WorldThingGround)
{
// don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return;
FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor;
e.CrushedState = st;
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
}
Expand Down
6 changes: 4 additions & 2 deletions src/events.h
Expand Up @@ -4,6 +4,7 @@
#include "serializer.h"
#include "d_event.h"
#include "sbar.h"
#include "info.h"

class DStaticEventHandler;
struct EventManager;
Expand Down Expand Up @@ -80,7 +81,7 @@ class DStaticEventHandler : public DObject // make it a part of normal GC proces
void WorldUnloaded();
void WorldThingSpawned(AActor* actor);
void WorldThingDied(AActor* actor, AActor* inflictor);
void WorldThingGround(AActor* actor);
void WorldThingGround(AActor* actor, FState* st);
void WorldThingRevived(AActor* actor);
void WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* source, int damage, FName mod, int flags, DAngle angle);
void WorldThingDestroyed(AActor* actor);
Expand Down Expand Up @@ -163,6 +164,7 @@ struct FWorldEvent
DVector3 DamagePosition;
bool DamageIsRadius; // radius damage yes/no
int NewDamage = 0; // sector/line damaged. allows modifying damage
FState* CrushedState = nullptr; // custom crush state set in thingground
};

struct FPlayerEvent
Expand Down Expand Up @@ -236,7 +238,7 @@ struct EventManager
// called after AActor::Die of each actor.
void WorldThingDied(AActor* actor, AActor* inflictor);
// called inside AActor::Grind just before the corpse is destroyed
void WorldThingGround(AActor* actor);
void WorldThingGround(AActor* actor, FState* st);
// called after AActor::Revive.
void WorldThingRevived(AActor* actor);
// called before P_DamageMobj and before AActor::DamageMobj virtuals.
Expand Down
4 changes: 2 additions & 2 deletions src/playsim/p_mobj.cpp
Expand Up @@ -1204,7 +1204,7 @@ bool AActor::Grind(bool items)
S_Sound (this, CHAN_BODY, 0, "misc/fallingsplat", 1, ATTN_IDLE);
Translation = BloodTranslation;
}
Level->localEventManager->WorldThingGround(this);
Level->localEventManager->WorldThingGround(this, state);
return false;
}
if (!(flags & MF_NOBLOOD))
Expand Down Expand Up @@ -1247,7 +1247,7 @@ bool AActor::Grind(bool items)
gib->Translation = BloodTranslation;
}
S_Sound (this, CHAN_BODY, 0, "misc/fallingsplat", 1, ATTN_IDLE);
Level->localEventManager->WorldThingGround(this);
Level->localEventManager->WorldThingGround(this, nullptr);
}
if (flags & MF_ICECORPSE)
{
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/zscript/events.zs
Expand Up @@ -37,6 +37,7 @@ struct WorldEvent native play version("2.4")
native readonly vector3 DamagePosition;
native readonly bool DamageIsRadius;
native int NewDamage;
native readonly State CrushedState;
}

struct PlayerEvent native play version("2.4")
Expand Down

0 comments on commit 6e692e5

Please sign in to comment.