]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
add game/demo intermission hooks
authordrjaska <drjaska83@gmail.com>
Thu, 7 Dec 2023 22:04:36 +0000 (00:04 +0200)
committerdrjaska <drjaska83@gmail.com>
Thu, 7 Dec 2023 22:04:36 +0000 (00:04 +0200)
breaking change: gameend hook is no longer fired at the start of an
intermission.

gamemodes-client.cfg
qcsrc/client/main.qc
qcsrc/client/main.qh
qcsrc/client/view.qc

index 431a6cdb51ceb24296aa4db579ea5cfc308798c3..a1979e5117f4eebf004011c4f47aab732cc79d7a 100644 (file)
@@ -36,8 +36,10 @@ alias cl_hook_gamestart_mayhem
 alias cl_hook_gamestart_tmayhem
 alias cl_hook_gamestart_tka
 alias cl_hook_gamestart_surv
+alias cl_hook_intermission
 alias cl_hook_gameend
 alias cl_hook_shutdown
 alias cl_hook_activeweapon
 alias cl_hook_demostart
+alias cl_hook_demointermission
 alias cl_hook_demoend
index 17f872d0e2914030323bc3617e20e7b1c9b121d7..f0dd1a88e51fd4332f9147145bf617a059d80671 100644 (file)
@@ -187,10 +187,11 @@ void Shutdown()
                // call gameend hook if it hasn't somehow yet fired by intermission starting
                if (!(calledhooks & HOOK_END))
                {
-                       int gamecount = cvar("cl_matchcount");
                        localcmd("\ncl_hook_gameend\n");
+
                        // NOTE: using localcmd here to ensure it's executed AFTER cl_hook_gameend
                        // earlier versions of the game abuse the hook to set this cvar
+                       int gamecount = cvar("cl_matchcount");
                        localcmd(strcat("cl_matchcount ", itos(gamecount + 1), "\n"));
                        //cvar_set("cl_matchcount", itos(gamecount + 1));
                        calledhooks |= HOOK_END;
index 7929a450e078d0a9bc339b3f583858e7aae3ab6d..c8632918886723fdbed33ae19424ec65de1c71a8 100644 (file)
@@ -146,8 +146,9 @@ float damagepush_speedfactor;
 
 //hooks
 int calledhooks;
-const int HOOK_START =    1;
-const int HOOK_END =      2;
+const int HOOK_START        = 1; // VM init
+const int HOOK_END          = 2; // VM shutdown
+const int HOOK_INTERMISSION = 4; // intermission start
 
 .float ping, ping_packetloss, ping_movementloss;
 
index 17927c78d13154bc3244a9279d12ada2fe617543..86d8bc7acbe1dbde4b2b43285f92ecb2ec973a26 100644 (file)
@@ -1641,20 +1641,30 @@ void CSQC_UpdateView(entity this, float w, float h)
        else if(game_stopped_time && !STAT(GAME_STOPPED))
                game_stopped_time = 0;
 
-       // fire game end hooks here once intermission starts
-       // do not fire demo end hooks here as we are
-       // still running a demo until the CSQC VM is shutdown
-       if(intermission && !isdemo() && !(calledhooks & HOOK_END))
+       // fire intermission hooks here once intermission starts
+       // do not fire game/demo end hooks here as we are
+       // still running something until the CSQC VM is shutdown
+       if(intermission && !(calledhooks & HOOK_INTERMISSION))
        {
-               if(calledhooks & HOOK_START)
+               if(!isdemo())
                {
-                       int gamecount = cvar("cl_matchcount");
-                       localcmd("\ncl_hook_gameend\n");
-                       // NOTE: using localcmd here to ensure it's executed AFTER cl_hook_gameend
-                       // earlier versions of the game abuse the hook to set this cvar
-                       localcmd(strcat("cl_matchcount ", itos(gamecount + 1), "\n"));
-                       //cvar_set("cl_matchcount", itos(gamecount + 1));
-                       calledhooks |= HOOK_END;
+                       // ensure that we have properly initiated a gamemode
+                       // before firing this hook. gamestart -> intermission
+                       if(calledhooks & HOOK_START)
+                       {
+                               localcmd("\ncl_hook_intermission\n");
+                               calledhooks |= HOOK_INTERMISSION;
+                       }
+               }
+               else
+               {
+                       // ensure that we have properly initiated a gamemode
+                       // before firing this hook. demostart -> intermission
+                       if(calledhooks & HOOK_START)
+                       {
+                               localcmd("\ncl_hook_demointermission\n");
+                               calledhooks |= HOOK_INTERMISSION;
+                       }
                }
        }