mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 06:53:58 +00:00
Implemented player scripts.
This commit is contained in:
parent
19d2f6a4db
commit
39355cf45d
6 changed files with 45 additions and 11 deletions
|
@ -61,6 +61,7 @@ Everything that is changed is marked (maybe commented) with "Added by MC"
|
|||
#include "d_netinf.h"
|
||||
#include "d_player.h"
|
||||
#include "doomerrors.h"
|
||||
#include "events.h"
|
||||
|
||||
static FRandom pr_botspawn ("BotSpawn");
|
||||
|
||||
|
@ -418,6 +419,9 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
|
|||
}
|
||||
}
|
||||
}
|
||||
// [ZZ] run event hook
|
||||
E_PlayerDisconnected(i);
|
||||
//
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, players[i].mo, true, i, true);
|
||||
ClearPlayer (i, !fromlist);
|
||||
}
|
||||
|
|
|
@ -337,10 +337,15 @@ void E_WorldThingDestroyed(AActor* actor)
|
|||
handler->WorldThingDestroyed(actor);
|
||||
}
|
||||
|
||||
void E_PlayerEntered(int num)
|
||||
void E_PlayerEntered(int num, bool fromhub)
|
||||
{
|
||||
// this event can happen during savegamerestore. make sure that local handlers don't receive it.
|
||||
// actually, global handlers don't want it too.
|
||||
if (savegamerestore && !fromhub)
|
||||
return;
|
||||
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerEntered(num);
|
||||
handler->PlayerEntered(num, fromhub);
|
||||
}
|
||||
|
||||
void E_PlayerRespawned(int num)
|
||||
|
@ -540,7 +545,7 @@ static DWorldEvent* E_SetupWorldEvent()
|
|||
static DWorldEvent* e = nullptr;
|
||||
if (!e) e = (DWorldEvent*)RUNTIME_CLASS(DWorldEvent)->CreateNew();
|
||||
e->IsSaveGame = savegamerestore;
|
||||
e->IsReopen = level.FromSnapshot;
|
||||
e->IsReopen = level.FromSnapshot && !savegamerestore; // each one by itself isnt helpful, but with hub load we have savegamerestore==0 and level.FromSnapshot==1.
|
||||
e->Thing = nullptr;
|
||||
e->Inflictor = nullptr;
|
||||
e->Damage = 0;
|
||||
|
@ -710,11 +715,11 @@ static DPlayerEvent* E_SetupPlayerEvent()
|
|||
static DPlayerEvent* e = nullptr;
|
||||
if (!e) e = (DPlayerEvent*)RUNTIME_CLASS(DPlayerEvent)->CreateNew();
|
||||
e->PlayerNumber = -1;
|
||||
e->IsReturn = level.FromSnapshot;
|
||||
e->IsReturn = false;
|
||||
return e;
|
||||
}
|
||||
|
||||
void DStaticEventHandler::PlayerEntered(int num)
|
||||
void DStaticEventHandler::PlayerEntered(int num, bool fromhub)
|
||||
{
|
||||
IFVIRTUAL(DStaticEventHandler, PlayerEntered)
|
||||
{
|
||||
|
@ -722,6 +727,7 @@ void DStaticEventHandler::PlayerEntered(int num)
|
|||
if (func == DStaticEventHandler_PlayerEntered_VMPtr)
|
||||
return;
|
||||
DPlayerEvent* e = E_SetupPlayerEvent();
|
||||
e->IsReturn = fromhub;
|
||||
e->PlayerNumber = num;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, e };
|
||||
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
|
||||
|
|
|
@ -42,7 +42,7 @@ void E_WorldTick();
|
|||
// called on each render frame once.
|
||||
void E_RenderFrame();
|
||||
// this executes when a player enters the level (once). PlayerEnter+inhub = RETURN
|
||||
void E_PlayerEntered(int num);
|
||||
void E_PlayerEntered(int num, bool fromhub);
|
||||
// this executes when a player respawns. includes resurrect cheat.
|
||||
void E_PlayerRespawned(int num);
|
||||
// this executes when a player dies (partially duplicating worldthingdied, but whatever)
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
virtual void RenderFrame();
|
||||
|
||||
//
|
||||
virtual void PlayerEntered(int num);
|
||||
virtual void PlayerEntered(int num, bool fromhub);
|
||||
virtual void PlayerRespawned(int num);
|
||||
virtual void PlayerDied(int num);
|
||||
virtual void PlayerDisconnected(int num);
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
|
||||
#include "g_hub.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "events.h"
|
||||
|
||||
|
||||
static FRandom pr_dmspawn ("DMSpawn");
|
||||
|
@ -1791,6 +1792,8 @@ void G_DoPlayerPop(int playernum)
|
|||
|
||||
// [RH] Make the player disappear
|
||||
FBehavior::StaticStopMyScripts(players[playernum].mo);
|
||||
// [ZZ] fire player disconnect hook
|
||||
E_PlayerDisconnected(playernum);
|
||||
// [RH] Let the scripts know the player left
|
||||
FBehavior::StaticStartTypedScripts(SCRIPT_Disconnect, players[playernum].mo, true, playernum, true);
|
||||
if (players[playernum].mo != NULL)
|
||||
|
|
|
@ -1256,6 +1256,10 @@ void G_FinishTravel ()
|
|||
FPlayerStart *start;
|
||||
int pnum;
|
||||
|
||||
//
|
||||
APlayerPawn* pawns[MAXPLAYERS];
|
||||
int pawnsnum = 0;
|
||||
|
||||
next = it.Next ();
|
||||
while ( (pawn = next) != NULL)
|
||||
{
|
||||
|
@ -1347,16 +1351,30 @@ void G_FinishTravel ()
|
|||
{
|
||||
pawn->Speed = pawn->GetDefault()->Speed;
|
||||
}
|
||||
if (level.FromSnapshot)
|
||||
{
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Return, pawn, true);
|
||||
}
|
||||
// [ZZ] we probably don't want to fire any scripts before all players are in, especially with runNow = true.
|
||||
pawns[pawnsnum++] = pawn;
|
||||
}
|
||||
|
||||
// [ZZ] fire the reopen hook.
|
||||
if (level.FromSnapshot)
|
||||
{
|
||||
// [Nash] run REOPEN scripts upon map re-entry
|
||||
FBehavior::StaticStartTypedScripts(SCRIPT_Reopen, NULL, false);
|
||||
|
||||
for (int i = 0; i < pawnsnum; i++)
|
||||
{
|
||||
// [ZZ] fire the enter hook.
|
||||
E_PlayerEntered(pawns[i]->player - players, true);
|
||||
//
|
||||
FBehavior::StaticStartTypedScripts(SCRIPT_Return, pawns[i], true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < pawnsnum; i++)
|
||||
{
|
||||
E_PlayerEntered(pawns[i]->player - players, false);
|
||||
}
|
||||
}
|
||||
|
||||
bglobal.FinishTravel ();
|
||||
|
|
|
@ -610,6 +610,9 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags)
|
|||
// [RH] Death messages
|
||||
ClientObituary (this, inflictor, source, dmgflags);
|
||||
|
||||
// [ZZ] fire player death hook
|
||||
E_PlayerDied(player - players);
|
||||
|
||||
// Death script execution, care of Skull Tag
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Death, this, true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue