]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_race.qc
Merge branch 'master' into terencehill/tooltips_cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_race.qc
index 20f3d4ffb189902e0b96a0bcf855df323ba4e487..271456986d393461bbd21f00030bff8092abda33 100644 (file)
@@ -1,7 +1,13 @@
+#include "gamemode_race.qh"
+
+#include "gamemode.qh"
+
+#include "../race.qh"
+
 // legacy bot roles
 .float race_checkpoint;
 void havocbot_role_race()
-{
+{SELFPARAM();
        if(self.deadflag != DEAD_NO)
                return;
 
@@ -29,7 +35,7 @@ void havocbot_role_race()
 
 void race_ScoreRules()
 {
-       ScoreRules_basics(race_teams, 0, 0, FALSE);
+       ScoreRules_basics(race_teams, 0, 0, false);
        if(race_teams)
        {
                ScoreInfo_SetLabel_TeamScore(  ST_RACE_LAPS,    "laps",      SFL_SORT_PRIO_PRIMARY);
@@ -50,8 +56,14 @@ void race_ScoreRules()
        ScoreRules_basics_end();
 }
 
-MUTATOR_HOOKFUNCTION(race_PlayerPhysics)
+void race_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
 {
+       if(autocvar_sv_eventlog)
+               GameLogEcho(strcat(":race:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
+}
+
+MUTATOR_HOOKFUNCTION(race_PlayerPhysics)
+{SELFPARAM();
        // force kbd movement for fairness
        float wishspeed;
        vector wishvel;
@@ -60,26 +72,26 @@ MUTATOR_HOOKFUNCTION(race_PlayerPhysics)
        // ensure nothing EVIL is being done (i.e. div0_evade)
        // this hinders joystick users though
        // but it still gives SOME analog control
-       wishvel_x = fabs(self.movement_x);
-       wishvel_y = fabs(self.movement_y);
-       if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
+       wishvel.x = fabs(self.movement.x);
+       wishvel.y = fabs(self.movement.y);
+       if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
        {
-               wishvel_z = 0;
+               wishvel.z = 0;
                wishspeed = vlen(wishvel);
-               if(wishvel_x >= 2 * wishvel_y)
+               if(wishvel.x >= 2 * wishvel.y)
                {
                        // pure X motion
-                       if(self.movement_x > 0)
+                       if(self.movement.x > 0)
                                self.movement_x = wishspeed;
                        else
                                self.movement_x = -wishspeed;
                        self.movement_y = 0;
                }
-               else if(wishvel_y >= 2 * wishvel_x)
+               else if(wishvel.y >= 2 * wishvel.x)
                {
                        // pure Y motion
                        self.movement_x = 0;
-                       if(self.movement_y > 0)
+                       if(self.movement.y > 0)
                                self.movement_y = wishspeed;
                        else
                                self.movement_y = -wishspeed;
@@ -87,18 +99,18 @@ MUTATOR_HOOKFUNCTION(race_PlayerPhysics)
                else
                {
                        // diagonal
-                       if(self.movement_x > 0)
+                       if(self.movement.x > 0)
                                self.movement_x = M_SQRT1_2 * wishspeed;
                        else
                                self.movement_x = -M_SQRT1_2 * wishspeed;
-                       if(self.movement_y > 0)
+                       if(self.movement.y > 0)
                                self.movement_y = M_SQRT1_2 * wishspeed;
                        else
                                self.movement_y = -M_SQRT1_2 * wishspeed;
                }
        }
-       
-       return FALSE;
+
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_ResetMap)
@@ -119,7 +131,7 @@ MUTATOR_HOOKFUNCTION(race_ResetMap)
                        if(!s)
                                e.race_place = 0;
                }
-               print(e.netname, " = ", ftos(e.race_place), "\n");
+               race_EventLog(ftos(e.race_place), e);
        }
 
        if(g_race_qualifying == 2)
@@ -131,22 +143,22 @@ MUTATOR_HOOKFUNCTION(race_ResetMap)
                cvar_set("timelimit", ftos(race_timelimit));
                race_ScoreRules();
        }
-       
-       return FALSE;
+
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_PlayerPreThink)
-{
+{SELFPARAM();
        if(IS_SPEC(self) || IS_OBSERVER(self))
        if(g_race_qualifying)
        if(msg_entity.enemy.race_laptime)
                race_SendNextCheckpoint(msg_entity.enemy, 1);
 
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_ClientConnect)
-{
+{SELFPARAM();
        race_PreparePlayer();
        self.race_checkpoint = -1;
 
@@ -169,11 +181,11 @@ MUTATOR_HOOKFUNCTION(race_ClientConnect)
                }
        }
 
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_MakePlayerObserver)
-{
+{SELFPARAM();
        if(g_race_qualifying)
        if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
                self.frags = FRAGS_LMS_LOSER;
@@ -183,11 +195,11 @@ MUTATOR_HOOKFUNCTION(race_MakePlayerObserver)
        race_PreparePlayer();
        self.race_checkpoint = -1;
 
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_PlayerSpawn)
-{
+{SELFPARAM();
        if(spawn_spot.target == "")
                // Emergency: this wasn't a real spawnpoint. Can this ever happen?
                race_PreparePlayer();
@@ -197,12 +209,12 @@ MUTATOR_HOOKFUNCTION(race_PlayerSpawn)
        self.race_respawn_spotref = spawn_spot;
 
        self.race_place = 0;
-       
-       return FALSE;
+
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_PutClientInServer)
-{
+{SELFPARAM();
        if(IS_PLAYER(self))
        if(!gameover)
        {
@@ -213,24 +225,24 @@ MUTATOR_HOOKFUNCTION(race_PutClientInServer)
 
                race_AbandonRaceCheck(self);
        }
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_PlayerDies)
-{
+{SELFPARAM();
        self.respawn_flags |= RESPAWN_FORCE;
        race_AbandonRaceCheck(self);
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_BotRoles)
-{
+{SELFPARAM();
        self.havocbot_role = havocbot_role_race;
-       return TRUE;
+       return true;
 }
 
 MUTATOR_HOOKFUNCTION(race_PlayerPostThink)
-{
+{SELFPARAM();
        if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
        {
                if (!self.stored_netname)
@@ -243,21 +255,30 @@ MUTATOR_HOOKFUNCTION(race_PlayerPostThink)
                }
        }
 
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_ForbidClearPlayerScore)
 {
        if(g_race_qualifying)
-               return TRUE; // in qualifying, you don't lose score by observing
+               return true; // in qualifying, you don't lose score by observing
 
-       return FALSE;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(race_GetTeamCount)
 {
        ret_float = race_teams;
-       return FALSE;
+       return false;
+}
+
+MUTATOR_HOOKFUNCTION(race_CountFrags)
+{
+       // announce remaining frags if not in qualifying mode
+       if(!g_race_qualifying)
+               return true;
+
+       return false;
 }
 
 void race_Initialize()
@@ -277,10 +298,11 @@ MUTATOR_DEFINITION(gamemode_race)
        MUTATOR_HOOK(PlayerSpawn, race_PlayerSpawn, CBC_ORDER_ANY);
        MUTATOR_HOOK(PutClientInServer, race_PutClientInServer, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerDies, race_PlayerDies, CBC_ORDER_ANY);
-       MUTATOR_HOOK(HavocBot_ChooseRule, race_BotRoles, CBC_ORDER_ANY);
+       MUTATOR_HOOK(HavocBot_ChooseRole, race_BotRoles, CBC_ORDER_ANY);
        MUTATOR_HOOK(GetPressedKeys, race_PlayerPostThink, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidPlayerScore_Clear, race_ForbidClearPlayerScore, CBC_ORDER_ANY);
        MUTATOR_HOOK(GetTeamCount, race_GetTeamCount, CBC_ORDER_ANY);
+       MUTATOR_HOOK(Scores_CountFragsRemaining, race_CountFrags, CBC_ORDER_ANY);
 
        MUTATOR_ONADD
        {
@@ -298,7 +320,7 @@ MUTATOR_DEFINITION(gamemode_race)
 
        MUTATOR_ONREMOVE
        {
-               print("This is a game type and it cannot be removed at runtime.");
+               LOG_INFO("This is a game type and it cannot be removed at runtime.");
                return -1;
        }