]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_cts.qc
Merged master
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_cts.qc
index e54e1801f4bfb67c2a53c09b354a73db4feac172..8e7512eb6965d42a7e7e4b88bea02bfcd690189d 100644 (file)
@@ -1,50 +1,6 @@
 #include "gamemode_cts.qh"
 #include <server/race.qh>
 
-#ifndef GAMEMODE_CTS_H
-#define GAMEMODE_CTS_H
-
-void cts_Initialize();
-
-REGISTER_MUTATOR(cts, false)
-{
-       MUTATOR_ONADD
-       {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
-
-               g_race_qualifying = true;
-               independent_players = 1;
-               SetLimits(0, 0, autocvar_timelimit_override, -1);
-
-               cts_Initialize();
-       }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back cts_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
-       return 0;
-}
-
-// scores
-const float ST_CTS_LAPS = 1;
-const float SP_CTS_LAPS = 4;
-const float SP_CTS_TIME = 5;
-const float SP_CTS_FASTEST = 6;
-#endif
-
-#ifdef IMPLEMENTATION
-
 #include <server/race.qh>
 
 float autocvar_g_cts_finish_kill_delay;
@@ -62,7 +18,7 @@ void havocbot_role_cts(entity this)
                this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
-               FOREACH_ENTITY_CLASS("trigger_race_checkpoint", true,
+               IL_EACH(g_racecheckpoints, true,
                {
                        if(it.cnt == this.race_checkpoint)
                                navigation_routerating(this, it, 1000000, 5000);
@@ -79,13 +35,13 @@ void cts_ScoreRules()
        ScoreRules_basics(0, 0, 0, false);
        if(g_race_qualifying)
        {
-               ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest",   SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
+               ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest",   SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
        }
        else
        {
-               ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS,    "laps",      SFL_SORT_PRIO_PRIMARY);
-               ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME,    "time",      SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
-               ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest",   SFL_LOWER_IS_BETTER | SFL_TIME);
+               ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS,    "laps",      SFL_SORT_PRIO_PRIMARY);
+               ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME,    "time",      SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
+               ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest",   SFL_LOWER_IS_BETTER | SFL_TIME);
        }
        ScoreRules_basics_end();
 }
@@ -93,7 +49,7 @@ void cts_ScoreRules()
 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
 {
        if(autocvar_sv_eventlog)
-               GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
+               GameLogEcho(strcat(":cts:", mode, ":", ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : "")));
 }
 
 void KillIndicator_Think(entity this);
@@ -111,8 +67,9 @@ void CTS_ClientKill(entity e) // silent version of ClientKill, used when player
 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
 {
        entity player = M_ARGV(0, entity);
+       float dt = M_ARGV(1, float);
 
-       player.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
+       player.race_movetime_frac += dt;
        float f = floor(player.race_movetime_frac);
        player.race_movetime_frac -= f;
        player.race_movetime_count += f;
@@ -127,7 +84,7 @@ MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
                if(player.race_penalty)
                {
                        player.velocity = '0 0 0';
-                       player.movetype = MOVETYPE_NONE;
+                       set_movetype(player, MOVETYPE_NONE);
                        player.disableclientprediction = 2;
                }
        }
@@ -141,8 +98,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(player.movement.x);
-       wishvel.y = fabs(player.movement.y);
+       wishvel.x = fabs(CS(player).movement.x);
+       wishvel.y = fabs(CS(player).movement.y);
        if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
        {
                wishvel.z = 0;
@@ -150,32 +107,32 @@ MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
                if(wishvel.x >= 2 * wishvel.y)
                {
                        // pure X motion
-                       if(player.movement.x > 0)
-                               player.movement_x = wishspeed;
+                       if(CS(player).movement.x > 0)
+                               CS(player).movement_x = wishspeed;
                        else
-                               player.movement_x = -wishspeed;
-                       player.movement_y = 0;
+                               CS(player).movement_x = -wishspeed;
+                       CS(player).movement_y = 0;
                }
                else if(wishvel.y >= 2 * wishvel.x)
                {
                        // pure Y motion
-                       player.movement_x = 0;
-                       if(player.movement.y > 0)
-                               player.movement_y = wishspeed;
+                       CS(player).movement_x = 0;
+                       if(CS(player).movement.y > 0)
+                               CS(player).movement_y = wishspeed;
                        else
-                               player.movement_y = -wishspeed;
+                               CS(player).movement_y = -wishspeed;
                }
                else
                {
                        // diagonal
-                       if(player.movement.x > 0)
-                               player.movement_x = M_SQRT1_2 * wishspeed;
+                       if(CS(player).movement.x > 0)
+                               CS(player).movement_x = M_SQRT1_2 * wishspeed;
                        else
-                               player.movement_x = -M_SQRT1_2 * wishspeed;
-                       if(player.movement.y > 0)
-                               player.movement_y = M_SQRT1_2 * wishspeed;
+                               CS(player).movement_x = -M_SQRT1_2 * wishspeed;
+                       if(CS(player).movement.y > 0)
+                               CS(player).movement_y = M_SQRT1_2 * wishspeed;
                        else
-                               player.movement_y = -M_SQRT1_2 * wishspeed;
+                               CS(player).movement_y = -M_SQRT1_2 * wishspeed;
                }
        }
 }
@@ -184,7 +141,7 @@ MUTATOR_HOOKFUNCTION(cts, reset_map_global)
 {
        float s;
 
-       Score_NicePrint(world);
+       Score_NicePrint(NULL);
 
        race_ClearRecords();
        PlayerScore_Sort(race_place, 0, 1, 0);
@@ -208,8 +165,6 @@ MUTATOR_HOOKFUNCTION(cts, reset_map_global)
                cvar_set("timelimit", ftos(race_timelimit));
                cts_ScoreRules();
        }
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
@@ -237,8 +192,14 @@ MUTATOR_HOOKFUNCTION(cts, ClientConnect)
                        race_SendRankings(i, 0, 0, MSG_ONE);
                }
        }
+}
+
+MUTATOR_HOOKFUNCTION(cts, AbortSpeedrun)
+{
+       entity player = M_ARGV(0, entity);
 
-       return false;
+       if(autocvar_g_allow_checkpoints)
+               race_PreparePlayer(player); // nice try
 }
 
 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
@@ -252,8 +213,6 @@ MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
 
        race_PreparePlayer(player);
        player.race_checkpoint = -1;
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
@@ -270,8 +229,6 @@ MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
        player.race_respawn_spotref = spawn_spot;
 
        player.race_place = 0;
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
@@ -279,25 +236,23 @@ MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
        entity player = M_ARGV(0, entity);
 
        if(IS_PLAYER(player))
-       if(!gameover)
+       if(!game_stopped)
        {
-               if(player.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
+               if(CS(player).killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
                        race_PreparePlayer(player);
                else // respawn
                        race_RetractPlayer(player);
 
                race_AbandonRaceCheck(player);
        }
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
 {
        entity frag_target = M_ARGV(2, entity);
-       
+
        frag_target.respawn_flags |= RESPAWN_FORCE;
        race_AbandonRaceCheck(frag_target);
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
@@ -363,11 +318,9 @@ MUTATOR_HOOKFUNCTION(cts, FilterItem)
 
        if(item.classname == "droppedweapon")
                return true;
-
-       return false;
 }
 
-MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
+MUTATOR_HOOKFUNCTION(cts, Damage_Calculate)
 {
        entity frag_attacker = M_ARGV(1, entity);
        entity frag_target = M_ARGV(2, entity);
@@ -380,8 +333,6 @@ MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
                frag_damage = 0;
                M_ARGV(4, float) = frag_damage;
        }
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
@@ -411,7 +362,7 @@ MUTATOR_HOOKFUNCTION(cts, GetRecords)
        M_ARGV(1, string) = ret_string;
 }
 
-void ClientKill_Now();
+void ClientKill_Now(entity this);
 MUTATOR_HOOKFUNCTION(cts, ClientKill)
 {
     entity player = M_ARGV(0, entity);
@@ -420,10 +371,10 @@ MUTATOR_HOOKFUNCTION(cts, ClientKill)
 
        if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
        {
-               remove(player.killindicator);
-               player.killindicator = world;
+               delete(player.killindicator);
+               player.killindicator = NULL;
 
-               WITHSELF(player, ClientKill_Now()); // allow instant kill in this case
+               ClientKill_Now(player); // allow instant kill in this case
                return;
        }
 }
@@ -436,6 +387,11 @@ MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
                CTS_ClientKill(player);
 }
 
+MUTATOR_HOOKFUNCTION(cts, HideTeamNagger)
+{
+       return true; // doesn't work so well (but isn't cts a teamless mode?)
+}
+
 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
 {
        entity player = M_ARGV(0, entity);
@@ -450,9 +406,12 @@ MUTATOR_HOOKFUNCTION(cts, WantWeapon)
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(cts, ForbidDropCurrentWeapon)
+{
+       return true;
+}
+
 void cts_Initialize()
 {
        cts_ScoreRules();
 }
-
-#endif