]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/main.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / main.qc
index 53cf24b534b50f8001ece3b6b6a93eebc618e575..f48c0c530a40cf631c10c1e54c696d80db6dc741 100644 (file)
@@ -1,20 +1,21 @@
 #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/triggers/include.qh>
 #include <common/vehicles/all.qh>
@@ -108,7 +109,6 @@ void CSQC_Init()
        binddb = db_create();
        tempdb = db_create();
        ClientProgsDB = db_load("client.db");
-       compressShortVector_init();
 
        draw_endBoldFont();
 
@@ -131,13 +131,7 @@ void CSQC_Init()
 
        registercvar("cl_spawn_near_teammate", "1");
 
-       gametype = 0;
-
-       // hud_fields uses strunzone on the titles!
-       for(int i = 0; i < MAX_HUD_FIELDS; ++i)
-               hud_title[i] = strzone("(null)");
-
-       Cmd_HUD_SetFields(0);
+       gametype = NULL;
 
        postinit = false;
 
@@ -185,8 +179,8 @@ void Shutdown()
 {
        WarpZone_Shutdown();
 
-       remove(teams);
-       remove(players);
+       delete(teams);
+       delete(players);
        db_close(binddb);
        db_close(tempdb);
        if(autocvar_cl_db_saveasdump)
@@ -235,7 +229,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;
@@ -251,7 +245,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;
@@ -323,9 +317,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);
                        }
                }
        }
@@ -385,23 +379,21 @@ void Ent_RemovePlayerScore(entity this)
        if(this.owner) {
                SetTeam(this.owner, -1);
                this.owner.gotscores = 0;
-               for(int i = 0; i < MAX_SCORE; ++i) {
-                       this.owner.(scores[i]) = 0; // clear all scores
-               }
+               FOREACH(Scores, true, {
+                       this.owner.(scores(it)) = 0; // clear all scores
+               });
        }
 }
 
 NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
 {
        make_pure(this);
-       int i, n;
-       bool isNew;
        entity o;
 
        // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
        // (no I've never heard of M-x replace-string, sed, or anything like that)
-       isNew = !this.owner; // workaround for DP bug
-       n = ReadByte()-1;
+       bool isNew = !this.owner; // workaround for DP bug
+       int n = ReadByte()-1;
 
 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
        if(!isNew && n != this.sv_entnum)
@@ -429,27 +421,23 @@ NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
        //playerchecker will do this for us later, if it has not already done so
 
     int sf, lf;
-#if MAX_SCORE <= 8
-       sf = ReadByte();
-       lf = ReadByte();
-#else
        sf = ReadShort();
        lf = ReadShort();
-#endif
-    int p;
-       for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
-               if(sf & p)
+       FOREACH(Scores, true, {
+        int p = 1 << (i % 16);
+               if (sf & p)
                {
-                       if(lf & p)
-                               o.(scores[i]) = ReadInt24_t();
+                       if (lf & p)
+                               o.(scores(it)) = ReadInt24_t();
                        else
-                               o.(scores[i]) = ReadChar();
+                               o.(scores(it)) = ReadChar();
                }
+    });
 
        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,14 +464,14 @@ NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
                if(sf & p)
                {
                        if(lf & p)
-                               o.(teamscores[i]) = ReadInt24_t();
+                               o.(teamscores(i)) = ReadInt24_t();
                        else
-                               o.(teamscores[i]) = ReadChar();
+                               o.(teamscores(i)) = ReadChar();
                }
 
        return = true;
 
-       HUD_UpdateTeamPos(o);
+       Scoreboard_UpdateTeamPos(o);
 }
 
 NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
@@ -506,15 +494,21 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
 
        spectatorbutton_zoom = (f & 4);
 
-       if(f & 8)
+       if(f & 16)
        {
-               angles_held_status = 1;
-               angles_held.x = ReadAngle();
-               angles_held.y = ReadAngle();
-               angles_held.z = 0;
+               num_spectators = ReadByte();
+
+               float i, slot;
+
+               for(i = 0; i < MAX_SPECTATORS; ++i)
+                       spectatorlist[i] = 0; // reset list first
+
+               for(i = 0; i < num_spectators; ++i)
+               {
+                       slot = ReadByte();
+                       spectatorlist[i] = slot - 1;
+               }
        }
-       else
-               angles_held_status = 0;
 
        return = true;
 
@@ -684,6 +678,8 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
        spn_origin.y = ReadCoord();
        spn_origin.z = ReadCoord();
 
+       this.team = (teamnum + 1);
+
        //if(is_new)
        //{
                this.origin = spn_origin;
@@ -697,12 +693,13 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
                        precache_model(this.mdl);
                        setmodel(this, this.mdl);
                        this.drawmask = MASK_NORMAL;
-                       //this.movetype = MOVETYPE_NOCLIP;
+                       //this.move_movetype = MOVETYPE_NOCLIP;
                        //this.draw = Spawn_Draw;
+                       IL_PUSH(g_drawables, this);
                }*/
                if(autocvar_cl_spawn_point_particles)
                {
-                       if((serverflags & SERVERFLAG_TEAMPLAY))
+                       if(teamplay)
                        {
                                switch(teamnum)
                                {
@@ -716,6 +713,7 @@ NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
                        else { this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
 
                        this.draw = Spawn_Draw;
+                       if (is_new) IL_PUSH(g_drawables, this);
                        setpredraw(this, Spawn_PreDraw);
                        this.fade_start = autocvar_cl_spawn_point_dist_min;
                        this.fade_end = autocvar_cl_spawn_point_dist_max;
@@ -825,12 +823,13 @@ void CSQC_Ent_Update(entity this, bool isnew)
                if (autocvar_developer_csqcentities)
             LOG_INFOF("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);
                done = it.m_read(this, NULL, isnew);
+               MUTATOR_CALLHOOK(Ent_Update, this, isnew);
                break;
        });
        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);
        }
 }
 
@@ -865,11 +864,11 @@ 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_WARNING("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);
-       remove(this);
+       delete(this);
 }
 
 void Gamemode_Init()
@@ -935,22 +934,22 @@ void Gamemode_Init();
 NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
 {
        make_pure(this);
-       gametype = ReadInt24_t();
+       gametype = ReadRegistered(Gametypes);
+       teamplay = _MapInfo_GetTeamPlayBool(gametype);
        HUD_ModIcons_SetFunc();
-       for (int i = 0; i < MAX_SCORE; ++i)
-       {
-               if (scores_label[i]) strunzone(scores_label[i]);
-               scores_label[i] = strzone(ReadString());
-               scores_flags[i] = ReadByte();
-       }
+       FOREACH(Scores, true, {
+               if (scores_label(it)) strunzone(scores_label(it));
+               scores_label(it) = strzone(ReadString());
+               scores_flags(it) = ReadByte();
+       });
        for (int i = 0; i < MAX_TEAMSCORE; ++i)
        {
-               if (teamscores_label[i]) strunzone(teamscores_label[i]);
-               teamscores_label[i] = strzone(ReadString());
-               teamscores_flags[i] = ReadByte();
+               if (teamscores_label(i)) strunzone(teamscores_label(i));
+               teamscores_label(i) = strzone(ReadString());
+               teamscores_flags(i) = ReadByte();
        }
        return = true;
-       HUD_InitScores();
+       Scoreboard_InitScores();
        Gamemode_Init();
 }
 
@@ -1217,13 +1216,13 @@ NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
        }
 }
 
-string getcommandkey(string text, string command)
+string _getcommandkey(string cmd_name, string command, bool forcename)
 {
        string keys;
        float n, j, k, l = 0;
 
        if (!autocvar_hud_showbinds)
-               return text;
+               return cmd_name;
 
        keys = db_get(binddb, command);
        if (keys == "")
@@ -1257,12 +1256,12 @@ string getcommandkey(string text, string command)
 
        if (keys == "NO_KEY") {
                if (autocvar_hud_showbinds > 1)
-                       return sprintf(_("%s (not bound)"), text);
+                       return sprintf(_("%s (not bound)"), cmd_name);
                else
-                       return text;
+                       return cmd_name;
        }
-       else if (autocvar_hud_showbinds > 1)
-               return sprintf("%s (%s)", text, keys);
+       else if (autocvar_hud_showbinds > 1 || forcename)
+               return sprintf("%s (%s)", cmd_name, keys);
        else
                return keys;
 }