From 0f037cfd64c4ff6de77bd4ee9db2e148173655fa Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 21 Nov 2024 13:10:17 +0600 Subject: [PATCH] Add WorldRailgunFired --- src/events.cpp | 29 +++++++++++++++++++++++++++++ src/events.h | 3 +++ src/playsim/p_map.cpp | 2 +- wadsrc/static/zscript/events.zs | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/events.cpp b/src/events.cpp index 88f0a2f821..e4d7d1d1af 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -752,6 +752,18 @@ void EventManager::WorldHitscanFired(AActor* actor, const DVector3& AttackPos, c handler->WorldHitscanFired(actor, AttackPos, DamagePosition, Inflictor, flags); } +void EventManager::WorldRailgunFired(AActor* actor, const DVector3& AttackPos, const DVector3& DamagePosition, AActor* Inflictor, int flags) +{ + // don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever. + if (actor->ObjectFlags & OF_EuthanizeMe) + return; + + if (ShouldCallStatic(true)) staticEventManager.WorldRailgunFired(actor, AttackPos, DamagePosition, Inflictor, flags); + + for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) + handler->WorldRailgunFired(actor, AttackPos, DamagePosition, Inflictor, flags); +} + void EventManager::WorldThingGround(AActor* actor, FState* st) { // don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever. @@ -1865,6 +1877,23 @@ void DStaticEventHandler::WorldHitscanFired(AActor* actor, const DVector3& Attac } } +void DStaticEventHandler::WorldRailgunFired(AActor* actor, const DVector3& AttackPos, const DVector3& DamagePosition, AActor* Inflictor, int flags) +{ + IFVIRTUAL(DStaticEventHandler, WorldRailgunFired) + { + // don't create excessive DObjects if not going to be processed anyway + if (isEmpty(func)) return; + FWorldEvent e = owner->SetupWorldEvent(); + e.Thing = actor; + e.AttackPos = AttackPos; + e.DamagePosition = DamagePosition; + e.Inflictor = Inflictor; + e.AttackLineFlags = flags; + VMValue params[2] = { (DStaticEventHandler*)this, &e }; + VMCall(func, params, 2, nullptr, 0); + } +} + void DStaticEventHandler::WorldThingGround(AActor* actor, FState* st) { IFVIRTUAL(DStaticEventHandler, WorldThingGround) diff --git a/src/events.h b/src/events.h index 8a30bdfed4..4a73406f8b 100644 --- a/src/events.h +++ b/src/events.h @@ -315,6 +315,7 @@ public: bool WorldHitscanPreFired(AActor* actor, DAngle angle, double distance, DAngle pitch, int damage, FName damageType, PClassActor *pufftype, int flags, double sz, double offsetforward, double offsetside); bool WorldRailgunPreFired(FName damageType, PClassActor* pufftype, FRailParams* param); void WorldHitscanFired(AActor* actor, const DVector3& AttackPos, const DVector3& DamagePosition, AActor* Inflictor, int flags); + void WorldRailgunFired(AActor* actor, const DVector3& AttackPos, const DVector3& DamagePosition, AActor* Inflictor, int flags); void WorldLinePreActivated(line_t* line, AActor* actor, int activationType, bool* shouldactivate); void WorldLineActivated(line_t* line, AActor* actor, int activationType); int WorldSectorDamaged(sector_t* sector, AActor* source, int damage, FName damagetype, int part, DVector3 position, bool isradius); @@ -485,6 +486,8 @@ struct EventManager bool WorldHitscanPreFired(AActor* actor, DAngle angle, double distance, DAngle pitch, int damage, FName damageType, PClassActor *pufftype, int flags, double sz, double offsetforward, double offsetside); // called when a hitscan attack has been fired void WorldHitscanFired(AActor* actor, const DVector3& AttackPos, const DVector3& DamagePosition, AActor* Inflictor, int flags); + // called when a railgun attack has been fired + void WorldRailgunFired(AActor* actor, const DVector3& AttackPos, const DVector3& DamagePosition, AActor* Inflictor, int flags); // called when a railgun attack has been fired (can be overridden to block it) bool WorldRailgunPreFired(FName damageType, PClassActor* pufftype, FRailParams* param); // called inside AActor::Grind just before the corpse is destroyed diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index f4f85c8ba1..f906f83b51 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -5577,7 +5577,7 @@ void P_RailAttack(FRailParams *p) } } - source->Level->localEventManager->WorldHitscanFired(source, start, trace.HitPos, thepuff, flags); + source->Level->localEventManager->WorldRailgunFired(source, start, trace.HitPos, thepuff, flags); if (thepuff != NULL) { diff --git a/wadsrc/static/zscript/events.zs b/wadsrc/static/zscript/events.zs index cc83ad28ae..b1aaf30c84 100644 --- a/wadsrc/static/zscript/events.zs +++ b/wadsrc/static/zscript/events.zs @@ -167,6 +167,7 @@ class StaticEventHandler : Object native play version("2.4") virtual void WorldThingDestroyed(WorldEvent e) {} virtual bool WorldHitscanPreFired(WorldEvent e) { return false; } virtual bool WorldRailgunPreFired(WorldEvent e) { return false; } + virtual void WorldRailgunFired(WorldEvent e) {} virtual void WorldHitscanFired(WorldEvent e) {} virtual void WorldLinePreActivated(WorldEvent e) {} virtual void WorldLineActivated(WorldEvent e) {}