]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_cts.qc
Cleanse the physics hooks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_cts.qc
index 1ce78a1f74b60e27a233bb4210d1cf458c5f2062..5f2a7eeedc9e5e448913289b544665a737bdf934 100644 (file)
@@ -1,3 +1,4 @@
+#include "gamemode_cts.qh"
 #include <server/race.qh>
 
 #ifndef GAMEMODE_CTS_H
@@ -14,7 +15,7 @@ REGISTER_MUTATOR(cts, false)
 
                g_race_qualifying = true;
                independent_players = 1;
-               SetLimits(0, 0, -1, -1);
+               SetLimits(0, 0, autocvar_timelimit_override, -1);
 
                cts_Initialize();
        }
@@ -51,25 +52,25 @@ bool autocvar_g_cts_selfdamage;
 
 // legacy bot roles
 .float race_checkpoint;
-void havocbot_role_cts()
-{SELFPARAM();
-       if(IS_DEAD(self))
+void havocbot_role_cts(entity this)
+{
+       if(IS_DEAD(this))
                return;
 
-       if (self.bot_strategytime < time)
+       if (this.bot_strategytime < time)
        {
-               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-               navigation_goalrating_start();
+               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+               navigation_goalrating_start(this);
 
                FOREACH_ENTITY_CLASS("trigger_race_checkpoint", true,
                {
-                       if(it.cnt == self.race_checkpoint)
-                               navigation_routerating(it, 1000000, 5000);
-                       else if(self.race_checkpoint == -1)
-                               navigation_routerating(it, 1000000, 5000);
+                       if(it.cnt == this.race_checkpoint)
+                               navigation_routerating(this, it, 1000000, 5000);
+                       else if(this.race_checkpoint == -1)
+                               navigation_routerating(this, it, 1000000, 5000);
                });
 
-               navigation_goalrating_end();
+               navigation_goalrating_end(this);
        }
 }
 
@@ -95,11 +96,12 @@ void cts_EventLog(string mode, entity actor) // use an alias for easy changing a
                GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
 }
 
+void KillIndicator_Think(entity this);
 void CTS_ClientKill(entity e) // silent version of ClientKill, used when player finishes a CTS run. Useful to prevent cheating by running back to the start line and starting out with more speed
 {
     e.killindicator = spawn();
     e.killindicator.owner = e;
-    e.killindicator.think = KillIndicator_Think;
+    setthink(e.killindicator, KillIndicator_Think);
     e.killindicator.nextthink = time + (e.lip) * 0.05;
     e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
     e.killindicator.health = 1; // this is used to indicate that it should be silent
@@ -107,24 +109,26 @@ void CTS_ClientKill(entity e) // silent version of ClientKill, used when player
 }
 
 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
-{SELFPARAM();
-       self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
-       float f = floor(self.race_movetime_frac);
-       self.race_movetime_frac -= f;
-       self.race_movetime_count += f;
-       self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
+{
+       entity player = M_ARGV(0, entity);
+
+       player.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
+       float f = floor(player.race_movetime_frac);
+       player.race_movetime_frac -= f;
+       player.race_movetime_count += f;
+       player.race_movetime = player.race_movetime_frac + player.race_movetime_count;
 
 #ifdef SVQC
-       if(IS_PLAYER(self))
+       if(IS_PLAYER(player))
        {
-               if (self.race_penalty)
-                       if (time > self.race_penalty)
-                               self.race_penalty = 0;
-               if(self.race_penalty)
+               if (player.race_penalty)
+                       if (time > player.race_penalty)
+                               player.race_penalty = 0;
+               if(player.race_penalty)
                {
-                       self.velocity = '0 0 0';
-                       self.movetype = MOVETYPE_NONE;
-                       self.disableclientprediction = 2;
+                       player.velocity = '0 0 0';
+                       player.movetype = MOVETYPE_NONE;
+                       player.disableclientprediction = 2;
                }
        }
 #endif
@@ -137,8 +141,8 @@ MUTATOR_HOOKFUNCTION(cts, 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);
+       wishvel.x = fabs(player.movement.x);
+       wishvel.y = fabs(player.movement.y);
        if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
        {
                wishvel.z = 0;
@@ -146,36 +150,34 @@ MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
                if(wishvel.x >= 2 * wishvel.y)
                {
                        // pure X motion
-                       if(self.movement.x > 0)
-                               self.movement_x = wishspeed;
+                       if(player.movement.x > 0)
+                               player.movement_x = wishspeed;
                        else
-                               self.movement_x = -wishspeed;
-                       self.movement_y = 0;
+                               player.movement_x = -wishspeed;
+                       player.movement_y = 0;
                }
                else if(wishvel.y >= 2 * wishvel.x)
                {
                        // pure Y motion
-                       self.movement_x = 0;
-                       if(self.movement.y > 0)
-                               self.movement_y = wishspeed;
+                       player.movement_x = 0;
+                       if(player.movement.y > 0)
+                               player.movement_y = wishspeed;
                        else
-                               self.movement_y = -wishspeed;
+                               player.movement_y = -wishspeed;
                }
                else
                {
                        // diagonal
-                       if(self.movement.x > 0)
-                               self.movement_x = M_SQRT1_2 * wishspeed;
+                       if(player.movement.x > 0)
+                               player.movement_x = M_SQRT1_2 * wishspeed;
                        else
-                               self.movement_x = -M_SQRT1_2 * wishspeed;
-                       if(self.movement.y > 0)
-                               self.movement_y = M_SQRT1_2 * wishspeed;
+                               player.movement_x = -M_SQRT1_2 * wishspeed;
+                       if(player.movement.y > 0)
+                               player.movement_y = M_SQRT1_2 * wishspeed;
                        else
-                               self.movement_y = -M_SQRT1_2 * wishspeed;
+                               player.movement_y = -M_SQRT1_2 * wishspeed;
                }
        }
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
@@ -211,15 +213,17 @@ MUTATOR_HOOKFUNCTION(cts, reset_map_global)
 }
 
 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
-{SELFPARAM();
-       race_PreparePlayer();
-       self.race_checkpoint = -1;
+{
+       entity player = M_ARGV(0, entity);
+
+       race_PreparePlayer(player);
+       player.race_checkpoint = -1;
 
-       if(IS_REAL_CLIENT(self))
+       if(IS_REAL_CLIENT(player))
        {
                string rr = CTS_RECORD;
 
-               msg_entity = self;
+               msg_entity = player;
                race_send_recordtime(MSG_ONE);
                race_send_speedaward(MSG_ONE);
 
@@ -238,58 +242,69 @@ MUTATOR_HOOKFUNCTION(cts, ClientConnect)
 }
 
 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
-{SELFPARAM();
-       if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
-               self.frags = FRAGS_LMS_LOSER;
+{
+       entity player = M_ARGV(0, entity);
+
+       if(PlayerScore_Add(player, SP_RACE_FASTEST, 0))
+               player.frags = FRAGS_LMS_LOSER;
        else
-               self.frags = FRAGS_SPECTATOR;
+               player.frags = FRAGS_SPECTATOR;
 
-       race_PreparePlayer();
-       self.race_checkpoint = -1;
+       race_PreparePlayer(player);
+       player.race_checkpoint = -1;
 
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
-{SELFPARAM();
+{
+       entity player = M_ARGV(0, entity);
+       entity spawn_spot = M_ARGV(1, entity);
+
        if(spawn_spot.target == "")
                // Emergency: this wasn't a real spawnpoint. Can this ever happen?
-               race_PreparePlayer();
+               race_PreparePlayer(player);
 
        // if we need to respawn, do it right
-       self.race_respawn_checkpoint = self.race_checkpoint;
-       self.race_respawn_spotref = spawn_spot;
+       player.race_respawn_checkpoint = player.race_checkpoint;
+       player.race_respawn_spotref = spawn_spot;
 
-       self.race_place = 0;
+       player.race_place = 0;
 
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
-{SELFPARAM();
-       if(IS_PLAYER(self))
+{
+       entity player = M_ARGV(0, entity);
+
+       if(IS_PLAYER(player))
        if(!gameover)
        {
-               if(self.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
-                       race_PreparePlayer();
+               if(player.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
+                       race_PreparePlayer(player);
                else // respawn
-                       race_RetractPlayer();
+                       race_RetractPlayer(player);
 
-               race_AbandonRaceCheck(self);
+               race_AbandonRaceCheck(player);
        }
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
-{SELFPARAM();
-       self.respawn_flags |= RESPAWN_FORCE;
-       race_AbandonRaceCheck(self);
+{
+       entity frag_target = M_ARGV(2, entity);
+       
+       frag_target.respawn_flags |= RESPAWN_FORCE;
+       race_AbandonRaceCheck(frag_target);
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
-{SELFPARAM();
-       self.havocbot_role = havocbot_role_cts;
+{
+       entity bot = M_ARGV(0, entity);
+
+       bot.havocbot_role = havocbot_role_cts;
        return true;
 }
 
@@ -343,8 +358,10 @@ MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
 }
 
 MUTATOR_HOOKFUNCTION(cts, FilterItem)
-{SELFPARAM();
-       if(self.classname == "droppedweapon")
+{
+       entity item = M_ARGV(0, entity);
+
+       if(item.classname == "droppedweapon")
                return true;
 
        return false;
@@ -352,9 +369,17 @@ MUTATOR_HOOKFUNCTION(cts, FilterItem)
 
 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
 {
+       entity frag_attacker = M_ARGV(1, entity);
+       entity frag_target = M_ARGV(2, entity);
+       float frag_deathtype = M_ARGV(3, float);
+       float frag_damage = M_ARGV(4, float);
+
        if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
        if(!autocvar_g_cts_selfdamage)
+       {
                frag_damage = 0;
+               M_ARGV(4, float) = frag_damage;
+       }
 
        return false;
 }
@@ -366,6 +391,9 @@ MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
 
 MUTATOR_HOOKFUNCTION(cts, GetRecords)
 {
+       int record_page = M_ARGV(0, int);
+       string ret_string = M_ARGV(1, string);
+
        for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
        {
                if(MapInfo_Get_ByID(i))
@@ -380,42 +408,45 @@ MUTATOR_HOOKFUNCTION(cts, GetRecords)
                }
        }
 
-       return false;
+       M_ARGV(1, string) = ret_string;
 }
 
+void ClientKill_Now();
 MUTATOR_HOOKFUNCTION(cts, ClientKill)
 {
-       ret_float = 0;
+    entity player = M_ARGV(0, entity);
+
+       M_ARGV(1, float) = 0; // kill delay
 
-       if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
+       if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
        {
-               remove(self.killindicator);
-               self.killindicator = world;
+               remove(player.killindicator);
+               player.killindicator = world;
 
-               ClientKill_Now(); // allow instant kill in this case
+               WITHSELF(player, ClientKill_Now()); // allow instant kill in this case
                return;
        }
-
 }
 
 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
 {
-       if(autocvar_g_cts_finish_kill_delay)
-               CTS_ClientKill(race_player);
+       entity player = M_ARGV(0, entity);
 
-       return false;
+       if(autocvar_g_cts_finish_kill_delay)
+               CTS_ClientKill(player);
 }
 
 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
 {
-       stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
-       return false;
+       entity player = M_ARGV(0, entity);
+
+       stuffcmd(player, "cl_cmd settemp cl_movecliptokeyboard 2\n");
 }
 
 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
 {
-       ret_float = (want_weaponinfo == WEP_SHOTGUN);
-       want_mutatorblocked = true;
+       M_ARGV(1, float) = (M_ARGV(0, entity) == WEP_SHOTGUN); // want weapon = weapon info
+       M_ARGV(3, bool) = true; // want mutator blocked
        return true;
 }