Add worldlineactivated event, triggered after successful line activation.

This commit is contained in:
Marisa Kirisame 2018-03-17 16:01:47 +01:00 committed by Christoph Oelckers
parent bd7791ad9c
commit 69c6e95b08
4 changed files with 37 additions and 1 deletions

View file

@ -413,6 +413,12 @@ void E_WorldThingDestroyed(AActor* actor)
handler->WorldThingDestroyed(actor);
}
void E_WorldLineActivated(line_t* line, AActor* actor)
{
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
handler->WorldLineActivated(line, actor);
}
void E_PlayerEntered(int num, bool fromhub)
{
// this event can happen during savegamerestore. make sure that local handlers don't receive it.
@ -540,6 +546,7 @@ DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamageSource);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamageType);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamageFlags);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, DamageAngle);
DEFINE_FIELD_X(WorldEvent, FWorldEvent, ActivatedLine);
DEFINE_FIELD_X(PlayerEvent, FPlayerEvent, PlayerNumber);
DEFINE_FIELD_X(PlayerEvent, FPlayerEvent, IsReturn);
@ -626,6 +633,7 @@ DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDied)
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingRevived)
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDamaged)
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDestroyed)
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldLineActivated)
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldLightning)
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldTick)
@ -786,6 +794,21 @@ void DStaticEventHandler::WorldThingDestroyed(AActor* actor)
}
}
void DStaticEventHandler::WorldLineActivated(line_t* line, AActor* actor)
{
IFVIRTUAL(DStaticEventHandler, WorldLineActivated)
{
// don't create excessive DObjects if not going to be processed anyway
if (func == DStaticEventHandler_WorldLineActivated_VMPtr)
return;
FWorldEvent e = E_SetupWorldEvent();
e.Thing = actor;
e.ActivatedLine = line;
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
}
}
void DStaticEventHandler::WorldLightning()
{
IFVIRTUAL(DStaticEventHandler, WorldLightning)

View file

@ -40,6 +40,8 @@ void E_WorldThingRevived(AActor* actor);
void E_WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* source, int damage, FName mod, int flags, DAngle angle);
// called before AActor::Destroy of each actor.
void E_WorldThingDestroyed(AActor* actor);
// called in P_ActivateLine after successful special execution.
void E_WorldLineActivated(line_t* line, AActor* actor);
// same as ACS SCRIPT_Lightning
void E_WorldLightning();
// this executes on every tick, before everything, only when in valid level and not paused
@ -137,6 +139,7 @@ public:
void WorldThingRevived(AActor*);
void WorldThingDamaged(AActor*, AActor*, AActor*, int, FName, int, DAngle);
void WorldThingDestroyed(AActor*);
void WorldLineActivated(line_t*, AActor*);
void WorldLightning();
void WorldTick();
@ -192,6 +195,8 @@ struct FWorldEvent
FName DamageType;
int DamageFlags = 0;
DAngle DamageAngle;
// for lineactivated
line_t* ActivatedLine = nullptr;
};
struct FPlayerEvent
@ -249,4 +254,4 @@ struct FConsoleEvent
bool IsManual;
};
#endif
#endif

View file

@ -188,8 +188,10 @@ bool P_ActivateLine (line_t *line, AActor *mo, int side, int activationType, DVe
{
return false;
}
bool remote = (line->special != 7 && line->special != 8 && (line->special < 11 || line->special > 14));
if (line->locknumber > 0 && !P_CheckKeys (mo, line->locknumber, remote)) return false;
lineActivation = line->activation;
repeat = line->flags & ML_REPEAT_SPECIAL;
buttonSuccess = false;
@ -198,6 +200,9 @@ bool P_ActivateLine (line_t *line, AActor *mo, int side, int activationType, DVe
line->args[1], line->args[2],
line->args[3], line->args[4]);
// [MK] Fire up WorldLineActivated
if ( buttonSuccess ) E_WorldLineActivated(line, mo);
special = line->special;
if (!repeat && buttonSuccess)
{ // clear the special on non-retriggerable lines

View file

@ -25,6 +25,8 @@ struct WorldEvent native play version("2.4")
native readonly Name DamageType;
native readonly EDmgFlags DamageFlags;
native readonly double DamageAngle;
// for lineactivated
native readonly Line ActivatedLine;
}
struct PlayerEvent native play version("2.4")
@ -300,6 +302,7 @@ class StaticEventHandler : Object native play version("2.4")
virtual native void WorldThingRevived(WorldEvent e);
virtual native void WorldThingDamaged(WorldEvent e);
virtual native void WorldThingDestroyed(WorldEvent e);
virtual native void WorldLineActivated(WorldEvent e);
virtual native void WorldLightning(WorldEvent e); // for the sake of completeness.
virtual native void WorldTick();