]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/main.qc
Make g_balance_damagepush_speedfactor a networked variable rather than relying on...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / main.qc
index 4021161732b422ad9fc88c719d25ffbaf16d9d44..13b63652bb5e8e4c6d470b4d8a040f4f202d35b1 100644 (file)
@@ -1,21 +1,23 @@
 #include "main.qh"
 
 #include <common/effects/qc/all.qh>
-#include "hud/all.qh"
+#include "hud/_mod.qh"
 #include "mapvoting.qh"
 #include "mutators/events.qh"
+#include "hud/panel/scoreboard.qh"
 #include "hud/panel/quickmenu.qh"
-#include "scoreboard.qh"
 #include "shownames.qh"
 #include <common/t_items.qh>
 #include "wall.qh"
 #include "weapons/projectile.qh"
 #include <common/deathtypes/all.qh>
-#include <common/items/all.qh>
+#include <common/items/_mod.qh>
 #include <common/mapinfo.qh>
 #include <common/minigames/cl_minigames.qh>
 #include <common/minigames/cl_minigames_hud.qh>
+#include <common/net_linked.qh>
 #include <common/net_notice.qh>
+#include <common/scores.qh>
 #include <common/triggers/include.qh>
 #include <common/vehicles/all.qh>
 #include <lib/csqcmodel/cl_model.qh>
@@ -30,7 +32,7 @@
 
 void draw_cursor(vector pos, vector ofs, string img, vector col, float a)
 {
-       ofs = eX * (ofs.x * SIZE_CURSOR.x) + eY * (ofs.y * SIZE_CURSOR.y);
+       ofs = vec2(ofs.x * SIZE_CURSOR.x, ofs.y * SIZE_CURSOR.y);
        drawpic(pos - ofs, strcat(draw_currentSkin, img), SIZE_CURSOR, col, a, DRAWFLAG_NORMAL);
 }
 
@@ -130,13 +132,10 @@ void CSQC_Init()
 
        registercvar("cl_spawn_near_teammate", "1");
 
-       gametype = NULL;
-
-       // hud_fields uses strunzone on the titles!
-       for(int i = 0; i < MAX_HUD_FIELDS; ++i)
-               hud_title[i] = strzone("(null)");
+       if(autocvar_cl_lockview)
+               cvar_set("cl_lockview", "0");
 
-       Cmd_HUD_SetFields(0);
+       gametype = NULL;
 
        postinit = false;
 
@@ -211,6 +210,8 @@ void Shutdown()
                        localcmd("\ncl_hook_gameend\n");
        }
 
+       localcmd("\ncl_hook_shutdown\n");
+
        deactivate_minigame();
        HUD_MinigameMenu_Close(NULL, NULL, NULL);
 }
@@ -234,7 +235,7 @@ float SetTeam(entity o, int Team)
                        default:
                                if(GetTeam(Team, false) == NULL)
                                {
-                                       LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
+                                       LOG_TRACEF("trying to switch to unsupported team %d", Team);
                                        Team = NUM_SPECTATOR;
                                }
                                break;
@@ -250,7 +251,7 @@ float SetTeam(entity o, int Team)
                        default:
                                if(GetTeam(Team, false) == NULL)
                                {
-                                       LOG_TRACEF("trying to switch to unsupported team %d\n", Team);
+                                       LOG_TRACEF("trying to switch to unsupported team %d", Team);
                                        Team = NUM_SPECTATOR;
                                }
                                break;
@@ -322,9 +323,9 @@ void Playerchecker_Think(entity this)
                                e.ping_movementloss = 0;
                                //e.gotscores = 0; // we might already have the scores...
                                int t = entcs_GetScoreTeam(i);
-                               if (t) SetTeam(e, t); // will not hurt; later updates come with HUD_UpdatePlayerTeams
+                               if (t) SetTeam(e, t); // will not hurt; later updates come with Scoreboard_UpdatePlayerTeams
                                RegisterPlayer(e);
-                               HUD_UpdatePlayerPos(e);
+                               Scoreboard_UpdatePlayerPos(e);
                        }
                }
        }
@@ -442,7 +443,7 @@ NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
        return = true;
 
        if(o.sort_prev)
-               HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
+               Scoreboard_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
 
        this.entremove = Ent_RemovePlayerScore;
 }
@@ -476,7 +477,7 @@ NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
 
        return = true;
 
-       HUD_UpdateTeamPos(o);
+       Scoreboard_UpdateTeamPos(o);
 }
 
 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
@@ -499,16 +500,6 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
 
        spectatorbutton_zoom = (f & 4);
 
-       if(f & 8)
-       {
-               angles_held_status = 1;
-               angles_held.x = ReadAngle();
-               angles_held.y = ReadAngle();
-               angles_held.z = 0;
-       }
-       else
-               angles_held_status = 0;
-
        if(f & 16)
        {
                num_spectators = ReadByte();
@@ -579,7 +570,7 @@ NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
        {
                if(vote_called_vote)
                        strunzone(vote_called_vote);
-               vote_called_vote = strzone(ColorTranslateRGB(ReadString()));
+               vote_called_vote = strzone(ReadString());
        }
 
        if(nags & 1)
@@ -714,7 +705,7 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
                }*/
                if(autocvar_cl_spawn_point_particles)
                {
-                       if((serverflags & SERVERFLAG_TEAMPLAY))
+                       if(teamplay)
                        {
                                switch(teamnum)
                                {
@@ -786,8 +777,8 @@ NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new)
                        localcmd("-zoom\n");
                        button_zoom = false;
                }
+               HUD_Radar_Hide_Maximized();
        }
-       HUD_Radar_Hide_Maximized();
        //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum);
 }
 
@@ -844,7 +835,7 @@ void CSQC_Ent_Update(entity this, bool isnew)
        time = savetime;
        if (!done)
        {
-               LOG_FATALF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
+               LOG_FATALF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
        }
 }
 
@@ -879,7 +870,7 @@ void CSQC_Ent_Remove(entity this)
        if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Ent_Remove() with this=%i {.entnum=%d, .enttype=%d}\n", this, this.entnum, this.enttype);
        if (wasfreed(this))
        {
-               LOG_WARN("CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
+               LOG_WARN("CSQC_Ent_Remove called for already removed entity. Packet loss?");
                return;
        }
        if (this.enttype) Ent_Remove(this);
@@ -950,6 +941,7 @@ NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
 {
        make_pure(this);
        gametype = ReadRegistered(Gametypes);
+       teamplay = _MapInfo_GetTeamPlayBool(gametype);
        HUD_ModIcons_SetFunc();
        FOREACH(Scores, true, {
                if (scores_label(it)) strunzone(scores_label(it));
@@ -963,7 +955,7 @@ NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
                teamscores_flags(i) = ReadByte();
        }
        return = true;
-       HUD_InitScores();
+       Scoreboard_InitScores();
        Gamemode_Init();
 }
 
@@ -984,6 +976,7 @@ NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
        forcefog = strzone(ReadString());
 
        armorblockpercent = ReadByte() / 255.0;
+       damagepush_speedfactor = ReadByte() / 255.0;
 
        serverflags = ReadByte();
 
@@ -1042,9 +1035,18 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                        race_checkpoint = ReadByte();
                        race_time = ReadInt24_t();
                        race_previousbesttime = ReadInt24_t();
+                       race_mypreviousbesttime = ReadInt24_t();
                        if(race_previousbestname)
                                strunzone(race_previousbestname);
-                       race_previousbestname = strzone(ColorTranslateRGB(ReadString()));
+                       string pbestname = ReadString();
+                       if(autocvar_cl_race_cptimes_onlyself)
+                       {
+                               race_previousbesttime = race_mypreviousbesttime;
+                               race_mypreviousbesttime = 0;
+                               race_previousbestname = strzone("");
+                       }
+                       else
+                               race_previousbestname = strzone(pbestname);
 
                        race_checkpointtime = time;
 
@@ -1053,7 +1055,6 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_penaltyaccumulator = 0;
                                race_laptime = time; // valid
                        }
-
                        break;
 
                case RACE_NET_CHECKPOINT_CLEAR:
@@ -1069,9 +1070,18 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                        race_nextcheckpoint = ReadByte();
 
                        race_nextbesttime = ReadInt24_t();
+                       race_mybesttime = ReadInt24_t();
                        if(race_nextbestname)
                                strunzone(race_nextbestname);
-                       race_nextbestname = strzone(ColorTranslateRGB(ReadString()));
+                       string newname = ReadString();
+                       if(autocvar_cl_race_cptimes_onlyself)
+                       {
+                               race_nextbesttime = race_mybesttime;
+                               race_mybesttime = 0;
+                               race_nextbestname = strzone("");
+                       }
+                       else
+                               race_nextbestname = strzone(newname);
                        break;
 
                case RACE_NET_CHECKPOINT_HIT_RACE:
@@ -1083,7 +1093,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_mycheckpointlapsdelta -= 256;
                        if(race_mycheckpointenemy)
                                strunzone(race_mycheckpointenemy);
-                       race_mycheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
+                       int who = ReadByte();
+                       if(who)
+                               race_mycheckpointenemy = strzone(entcs_GetName(who - 1));
+                       else
+                               race_mycheckpointenemy = strzone(""); // TODO: maybe string_null works fine here?
                        break;
 
                case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
@@ -1095,7 +1109,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_othercheckpointlapsdelta -= 256;
                        if(race_othercheckpointenemy)
                                strunzone(race_othercheckpointenemy);
-                       race_othercheckpointenemy = strzone(ColorTranslateRGB(ReadString()));
+                       int what = ReadByte();
+                       if(what)
+                               race_othercheckpointenemy = strzone(entcs_GetName(what - 1));
+                       else
+                               race_othercheckpointenemy = strzone(""); // TODO: maybe string_null works fine here?
                        break;
 
                case RACE_NET_PENALTY_RACE:
@@ -1181,7 +1199,7 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                strunzone(grecordholder[pos-1]);
                        grecordholder[pos-1] = strzone(ReadString());
                        grecordtime[pos-1] = ReadInt24_t();
-                       if(grecordholder[pos-1] == entcs_GetName(player_localnum))
+                       if(strdecolorize(grecordholder[pos-1]) == strdecolorize(entcs_GetName(player_localnum)))
                                race_myrank = pos;
                        break;
                case RACE_NET_SERVER_STATUS:
@@ -1241,7 +1259,7 @@ string _getcommandkey(string cmd_name, string command, bool forcename)
        keys = db_get(binddb, command);
        if (keys == "")
        {
-               bool joy_detected = cvar("joy_detected");
+               bool joy_active = cvar("joy_active");
                n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
                for(j = 0; j < n; ++j)
                {
@@ -1249,7 +1267,7 @@ string _getcommandkey(string cmd_name, string command, bool forcename)
                        if(k != -1)
                        {
                                string key = keynumtostring(k);
-                               if(!joy_detected && substring(key, 0, 3) == "JOY")
+                               if(!joy_active && substring(key, 0, 3) == "JOY")
                                        continue;
 
                                if (keys == "")