Added CheckReplacee.

- Allows defining of what actor is replacing another for information.
- If multiple arachnotrons, a modder can attribute them as being a replacer of Arachnotron itself, allowing A_BossDeath and GetReplacee to work with it.
This commit is contained in:
Major Cooke 2019-01-27 18:03:04 -06:00 committed by Christoph Oelckers
parent b9e71d6db3
commit b1c508fa6c
4 changed files with 56 additions and 1 deletions

View file

@ -535,6 +535,14 @@ bool E_CheckReplacement( PClassActor *replacee, PClassActor **replacement )
return final;
}
bool E_CheckReplacee(PClassActor **replacee, PClassActor *replacement)
{
bool final = false;
for (DStaticEventHandler *handler = E_FirstEventHandler; handler; handler = handler->next)
handler->CheckReplacee(replacee, replacement, &final);
return final;
}
void E_NewGame(EventHandlerType handlerType)
{
bool isStatic = handlerType == EventHandlerType::Global;
@ -626,6 +634,10 @@ DEFINE_FIELD_X(ReplaceEvent, FReplaceEvent, Replacee)
DEFINE_FIELD_X(ReplaceEvent, FReplaceEvent, Replacement)
DEFINE_FIELD_X(ReplaceEvent, FReplaceEvent, IsFinal)
DEFINE_FIELD_X(ReplacedEvent, FReplacedEvent, Replacee)
DEFINE_FIELD_X(ReplacedEvent, FReplacedEvent, Replacement)
DEFINE_FIELD_X(ReplacedEvent, FReplacedEvent, IsFinal)
DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder)
{
PARAM_SELF_PROLOGUE(DStaticEventHandler);
@ -1192,6 +1204,21 @@ void DStaticEventHandler::CheckReplacement( PClassActor *replacee, PClassActor *
}
}
void DStaticEventHandler::CheckReplacee(PClassActor **replacee, PClassActor *replacement, bool *final)
{
IFVIRTUAL(DStaticEventHandler, CheckReplacee)
{
// don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return;
FReplacedEvent e = { *replacee, replacement, *final };
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
if (e.Replacee != replacement) // prevent infinite recursion
*replacee = e.Replacee;
*final = e.IsFinal;
}
}
void DStaticEventHandler::NewGame()
{
IFVIRTUAL(DStaticEventHandler, NewGame)

View file

@ -81,6 +81,8 @@ void E_Console(int player, FString name, int arg1, int arg2, int arg3, bool manu
// called when looking up the replacement for an actor class
bool E_CheckReplacement(PClassActor* replacee, PClassActor** replacement);
// called when looking up the replaced for an actor class
bool E_CheckReplacee(PClassActor** replacee, PClassActor* replacement);
// called on new game
void E_NewGame(EventHandlerType handlerType);
@ -187,6 +189,7 @@ public:
//
void CheckReplacement(PClassActor* replacee, PClassActor** replacement, bool* final);
void CheckReplacee(PClassActor** replacee, PClassActor* replacement, bool* final);
//
void NewGame();
@ -301,4 +304,11 @@ struct FReplaceEvent
bool IsFinal;
};
struct FReplacedEvent
{
PClassActor* Replacee;
PClassActor* Replacement;
bool IsFinal;
};
#endif

View file

@ -593,6 +593,16 @@ PClassActor *PClassActor::GetReplacee(bool lookskill)
}
}
PClassActor *savedrep = ActorInfo()->Replacee;
// [MC] Same code as CheckReplacement but turned around so modders can indicate
// what monsters spawn from which entity. I.e. instead of a randomspawner
// showing up, one can assign an Arachnotron as the one being replaced
// so functions like CheckReplacee and A_BossDeath can actually work, given
// modders set it up that way.
if (E_CheckReplacee(&savedrep, this))
{
// [MK] the replacement is final, so don't continue with the chain
return savedrep ? savedrep : this;
}
if (savedrep == nullptr && (!lookskill || skillrepname == NAME_None))
{
return this;

View file

@ -300,6 +300,13 @@ struct ReplaceEvent native version("2.4")
native bool IsFinal;
}
struct ReplacedEvent native version("3.7")
{
native Class<Actor> Replacee;
native readonly Class<Actor> Replacement;
native bool IsFinal;
}
class StaticEventHandler : Object native play version("2.4")
{
// static event handlers CAN register other static event handlers.
@ -312,7 +319,7 @@ class StaticEventHandler : Object native play version("2.4")
virtual void OnUnregister() {}
// actual handlers are here
virtual void WorldLoaded(WorldEvent e) {}
virtual void WorldLoaded(WorldEvent e) {}
virtual void WorldUnloaded(WorldEvent e) {}
virtual void WorldThingSpawned(WorldEvent e) {}
virtual void WorldThingDied(WorldEvent e) {}
@ -348,6 +355,7 @@ virtual void WorldLoaded(WorldEvent e) {}
//
virtual void CheckReplacement(ReplaceEvent e) {}
virtual void CheckReplacee(ReplacedEvent e) {}
//
virtual void NewGame() {}