]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make respawn code cleaner by adding respawn flags and the new mutator hook GetRespawn...
authorterencehill <piuntn@gmail.com>
Mon, 11 Mar 2013 15:35:41 +0000 (16:35 +0100)
committerterencehill <piuntn@gmail.com>
Mon, 11 Mar 2013 15:35:41 +0000 (16:35 +0100)
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/constants.qh
qcsrc/server/mutators/base.qh
qcsrc/server/mutators/gamemode_arena.qc
qcsrc/server/mutators/gamemode_ca.qc

index 67190df2d91488b5beff48e89989ab174892613f..574df368d2df71479c55a2d0555683c5c96745c1 100644 (file)
@@ -479,6 +479,7 @@ void PutObserverInServer (void)
        self.damageforcescale = 0;
        self.death_time = 0;
        self.respawn_time = 0;
+       self.stat_respawn_time = 0;
        self.alpha = 0;
        self.scale = 0;
        self.fade_time = 0;
@@ -765,6 +766,7 @@ void PutClientInServer (void)
                self.damageforcescale = 2;
                self.death_time = 0;
                self.respawn_time = 0;
+               self.stat_respawn_time = 0;
                self.scale = 0;
                self.fade_time = 0;
                self.pain_frame = 0;
@@ -2495,8 +2497,6 @@ void PlayerPreThink (void)
        self.stat_allow_oldnexbeam = autocvar_g_allow_oldnexbeam;
        self.stat_leadlimit = autocvar_leadlimit;
 
-       self.stat_respawn_time = self.respawn_time;
-
        if(frametime)
        {
                // physics frames: update anticheat stuff
@@ -2622,25 +2622,30 @@ void PlayerPreThink (void)
 
                if (self.deadflag != DEAD_NO)
                {
-                       float button_pressed, force_respawn;
                        if(self.personal && g_race_qualifying)
                        {
                                if(time > self.respawn_time)
                                {
                                        self.respawn_time = time + 1; // only retry once a second
+                                       self.stat_respawn_time = self.respawn_time;
                                        respawn();
                                        self.impulse = 141;
                                }
                        }
                        else
                        {
+                               float button_pressed, respawn_flags;
                                if(frametime)
                                        player_anim();
                                button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
-                               force_respawn = (g_lms || g_ca || g_cts || autocvar_g_forced_respawn);
+
+                               respawn_flags = MUTATOR_CALLHOOK(GetRespawnFlags);
+                               if(g_lms || g_cts || autocvar_g_forced_respawn)
+                                       respawn_flags = respawn_flags | RESPAWN_FORCE;
+
                                if (self.deadflag == DEAD_DYING)
                                {
-                                       if(force_respawn)
+                                       if(respawn_flags & RESPAWN_FORCE)
                                                self.deadflag = DEAD_RESPAWNING;
                                        else if(!button_pressed)
                                                self.deadflag = DEAD_DEAD;
@@ -2663,7 +2668,13 @@ void PlayerPreThink (void)
                                                respawn();
                                        }
                                }
+
                                ShowRespawnCountdown();
+
+                               if(respawn_flags & RESPAWN_SILENT)
+                                       self.stat_respawn_time = 0;
+                               else
+                                       self.stat_respawn_time = self.respawn_time;
                        }
 
                        // if respawning, invert stat_respawn_time to indicate this, the client translates it
index 23014b857bed9596d4031c1a04deb683f97c9f05..2c9a823a88634a86a64caf20e68d477496e3ccc2 100644 (file)
@@ -661,6 +661,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        self.respawn_time = ceil((time + sdelay) / waves) * waves;
                else
                        self.respawn_time = time + sdelay;
+               self.stat_respawn_time = self.respawn_time;
                if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
                        self.respawn_countdown = 10; // first number to count down from is 10
                else
index 522bb2ffca0dc94174ef97e50321431a9c113e62..cb3c34fdc4de8a5fd6e4ef2f8c716a7d650381ad 100644 (file)
@@ -47,6 +47,9 @@ float DEAD_DEAD                               = 2;
 float  DEAD_RESPAWNABLE                        = 3;
 float  DEAD_RESPAWNING                 = 4;
 
+float  RESPAWN_FORCE                   = 1;
+float  RESPAWN_SILENT                  = 2;
+
 float  DAMAGE_NO                               = 0;
 float  DAMAGE_YES                              = 1;
 float  DAMAGE_AIM                              = 2;
index d3d91232cf94c30fdacb9003eddea5167a816da4..06b5c0892bef1f23634f2815c151dc1fed180d98 100644 (file)
@@ -65,6 +65,9 @@ MUTATOR_HOOKABLE(ForbidPlayerScore_Clear);
 MUTATOR_HOOKABLE(ClientDisconnect);
        // called when a player disconnects
 
+MUTATOR_HOOKABLE(GetRespawnFlags);
+       // returns respawn flags
+
 MUTATOR_HOOKABLE(PlayerDies);
        // called when a player dies to e.g. remove stuff he was carrying.
        // INPUT:
index 92c5fd6142944e7368008271cb0077550d867930..c561815ad0cbc9941b89541e57f755909059b9ba 100644 (file)
@@ -204,16 +204,12 @@ MUTATOR_HOOKFUNCTION(arena_PlayerSpawn)
        return 1;
 }
 
-MUTATOR_HOOKFUNCTION(arena_PlayerPreThink)
+MUTATOR_HOOKFUNCTION(arena_GetRespawnFlags)
 {
-       self.stat_respawn_time = 0;
-
        // put dead players in the spawn queue
        if(arena_roundbased)
-       if(self.deadflag && time - self.death_time >= 1.5)
-               PutClientInServer();
-
-       return 1;
+               return (RESPAWN_FORCE | RESPAWN_SILENT);
+       return RESPAWN_SILENT;
 }
 
 MUTATOR_HOOKFUNCTION(arena_ForbidPlayerScore_Clear)
@@ -261,7 +257,7 @@ MUTATOR_DEFINITION(gamemode_arena)
        MUTATOR_HOOK(PutClientInServer, arena_PutClientInServer, CBC_ORDER_ANY);
        MUTATOR_HOOK(ClientConnect, arena_ClientConnect, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerSpawn, arena_PlayerSpawn, CBC_ORDER_ANY);
-       MUTATOR_HOOK(PlayerPreThink, arena_PlayerPreThink, CBC_ORDER_ANY);
+       MUTATOR_HOOK(GetRespawnFlags, arena_GetRespawnFlags, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidPlayerScore_Clear, arena_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
        MUTATOR_HOOK(GiveFragsForKill, arena_GiveFragsForKill, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerDies, arena_PlayerDies, CBC_ORDER_ANY);
index 3e8d1b747306f23fe4a5727782cf9fe2fdb77697..c86aa6d9e7d7565e4976017677858589f60e9f0c 100644 (file)
@@ -190,11 +190,11 @@ MUTATOR_HOOKFUNCTION(ca_GetTeamCount)
        return 1;
 }
 
-MUTATOR_HOOKFUNCTION(ca_PlayerPreThink)
+MUTATOR_HOOKFUNCTION(ca_GetRespawnFlags)
 {
        if(!allowed_to_spawn)
-               self.stat_respawn_time = 0;
-       return 1;
+               return RESPAWN_SILENT;
+       return 0;
 }
 
 MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
@@ -244,7 +244,7 @@ MUTATOR_DEFINITION(gamemode_ca)
        MUTATOR_HOOK(reset_map_global, ca_reset_map_global, CBC_ORDER_ANY);
        MUTATOR_HOOK(reset_map_players, ca_reset_map_players, CBC_ORDER_ANY);
        MUTATOR_HOOK(GetTeamCount, ca_GetTeamCount, CBC_ORDER_EXCLUSIVE);
-       MUTATOR_HOOK(PlayerPreThink, ca_PlayerPreThink, CBC_ORDER_ANY);
+       MUTATOR_HOOK(GetRespawnFlags, ca_GetRespawnFlags, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidPlayerScore_Clear, ca_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidThrowCurrentWeapon, ca_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
        MUTATOR_HOOK(GiveFragsForKill, ca_GiveFragsForKill, CBC_ORDER_FIRST);