]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/Main.qc
Merge branch 'master' into mirceakitsune/sandbox
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / Main.qc
index 0b0faa31084dd773ae2336727e5dd21a5fa833ec..90f1fcb334cf55c8813b9e89570e27321f588335 100644 (file)
@@ -25,24 +25,23 @@ void cvar_clientsettemp_restore()
                        cvar_set(e.netname, e.message);
 }
 
-void() menu_show_error =
+void menu_show_error()
 {
        drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
-};
+}
 
 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
 // Useful for precaching things
 
-void() menu_sub_null =
+void menu_sub_null()
 {
-};
+}
 
 #ifdef USE_FTE
 float __engine_check;
 #endif
 
 string forcefog;
-string cl_announcer_prev;
 void WaypointSprite_Load();
 void CSQC_Init(void)
 {
@@ -79,38 +78,34 @@ void CSQC_Init(void)
        menu_action = menu_sub_null;
 
        for(i = 0; i < 255; ++i)
-               if(getplayerkey(i, "viewentity") == "")
+               if(getplayerkeyvalue(i, "viewentity") == "")
                        break;
        maxclients = i;
 
-       //ctf_temp_1 = "";
-       // localcmd("alias order \"cmd order $*\""); enable if ctf-command thingy is used
-       //registercmd("ctf_menu");
-       registercmd("ons_map");
-       registercmd("hud_configure");
-       registercmd("hud_save");
-       //registercmd("menu_action");
+       registercommand("hud_configure");
+       registercommand("hud_save");
+       //registercommand("menu_action");
 
-       registercmd("+showscores");registercmd("-showscores");
-       registercmd("+showaccuracy");registercmd("-showaccuracy");
+       registercommand("+showscores");registercommand("-showscores");
+       registercommand("+showaccuracy");registercommand("-showaccuracy");
 
 #ifndef CAMERATEST
        if(isdemo())
        {
 #endif
-               registercmd("+forward");registercmd("-forward");
-               registercmd("+back");registercmd("-back");
-               registercmd("+moveup");registercmd("-moveup");
-               registercmd("+movedown");registercmd("-movedown");
-               registercmd("+moveright");registercmd("-moveright");
-               registercmd("+moveleft");registercmd("-moveleft");
-               registercmd("+roll_right");registercmd("-roll_right");
-               registercmd("+roll_left");registercmd("-roll_left");
+               registercommand("+forward");registercommand("-forward");
+               registercommand("+back");registercommand("-back");
+               registercommand("+moveup");registercommand("-moveup");
+               registercommand("+movedown");registercommand("-movedown");
+               registercommand("+moveright");registercommand("-moveright");
+               registercommand("+moveleft");registercommand("-moveleft");
+               registercommand("+roll_right");registercommand("-roll_right");
+               registercommand("+roll_left");registercommand("-roll_left");
 #ifndef CAMERATEST
        }
 #endif
        registercvar("hud_usecsqc", "1");
-       registercvar("scoreboard_columns", "default", CVAR_SAVE);
+       registercvar("scoreboard_columns", "default");
 
        gametype = 0;
 
@@ -132,6 +127,7 @@ void CSQC_Init(void)
        WaypointSprite_Load();
 
        // precaches
+       precache_model("null");
        precache_sound("misc/hit.wav");
        precache_sound("misc/typehit.wav");
        Projectile_Precache();
@@ -141,18 +137,15 @@ void CSQC_Init(void)
        DamageInfo_Precache();
        Vehicles_Precache();
        turrets_precache();
-
-       if(autocvar_cl_announcer != cl_announcer_prev) {
-               Announcer_Precache();
-               if(cl_announcer_prev)
-                       strunzone(cl_announcer_prev);
-               cl_announcer_prev = strzone(autocvar_cl_announcer);
-       }
+  Announcer_Precache();
        Tuba_Precache();
-
-       if(autocvar_cl_reticle_item_normal) precache_pic("gfx/reticle_normal");
-       if(autocvar_cl_reticle_item_nex) precache_pic("gfx/reticle_nex");
-
+       
+       if(autocvar_cl_reticle)
+       {
+               if(autocvar_cl_reticle_item_normal) { precache_pic("gfx/reticle_normal"); }
+               if(autocvar_cl_reticle_item_nex) { precache_pic("gfx/reticle_nex"); }
+       }
+       
        get_mi_min_max_texcoords(1); // try the CLEVER way first
        minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
        shortmapname = mi_shortname;
@@ -232,7 +225,7 @@ float SetTeam(entity o, float Team)
                        case COLOR_TEAM4:
                                break;
                        default:
-                               if(GetTeam(Team, false) == NULL)
+                               if(GetTeam(Team, false) == world)
                                {
                                        print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
                                        Team = COLOR_SPECTATOR;
@@ -248,7 +241,7 @@ float SetTeam(entity o, float Team)
                        case 0:
                                break;
                        default:
-                               if(GetTeam(Team, false) == NULL)
+                               if(GetTeam(Team, false) == world)
                                {
                                        print(sprintf(_("trying to switch to unsupported team %d\n"), Team));
                                        Team = COLOR_SPECTATOR;
@@ -345,7 +338,7 @@ void PostInit(void)
        postinit = true;
 }
 
-// CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
+// CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercommand" function
 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
 float button_zoom;
 void Cmd_HUD_SetFields(float);
@@ -354,11 +347,10 @@ float CSQC_ConsoleCommand(string strMessage)
 {
        float argc;
        // Tokenize String
-       //argc = tokenize(strMessage);
        argc = tokenize_console(strMessage);
 
        // Acquire Command
-       local string strCmd;
+       string strCmd;
        strCmd = argv(0);
 
        if(strCmd == "hud_configure") { // config hud
@@ -507,6 +499,13 @@ void GameCommand(string msg)
        if(cmd == "mv_download") {
                Cmd_MapVote_MapDownload(argc);
        }
+       else if(cmd == "hud_panel_radar_maximized")
+       {
+               if(argc == 1)
+                       hud_panel_radar_maximized = !hud_panel_radar_maximized;
+               else
+                       hud_panel_radar_maximized = (stof(argv(1)) != 0);
+       }
        else if(cmd == "settemp") {
                cvar_clientsettemp(argv(1), argv(2));
        }
@@ -595,7 +594,7 @@ void GameCommand(string msg)
         {
             vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
             vote_prev = 0;
-            cvar_set("cl_allow_uid2name", "1");
+            localcmd("setreport cl_allow_uid2name 1\n");
             vote_change = -9999;
                        uid2name_dialog = 0;
         }
@@ -610,7 +609,7 @@ void GameCommand(string msg)
         {
             vote_active = 0;
             vote_prev = 0;
-            cvar_set("cl_allow_uid2name", "0");
+            localcmd("setreport cl_allow_uid2name 0\n");
             vote_change = -9999;
                        uid2name_dialog = 0;
         }
@@ -636,7 +635,7 @@ void GameCommand(string msg)
 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
 {
-       local float bSkipKey;
+       float bSkipKey;
        bSkipKey = false;
 
        if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
@@ -937,7 +936,7 @@ void Ent_ReadAccuracy(void)
 void Ent_RadarLink();
 void Ent_Init();
 void Ent_ScoresInfo();
-void(float bIsNewEntity) CSQC_Ent_Update =
+void CSQC_Ent_Update(float bIsNewEntity)
 {
        float t;
        float savetime;
@@ -958,13 +957,23 @@ void(float bIsNewEntity) CSQC_Ent_Update =
 
 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
        if(self.enttype)
-               if(t != self.enttype)
+       {
+               if(t != self.enttype || bIsNewEntity)
                {
                        //print(_("A CSQC entity changed its type!\n"));
-                       print(sprintf(_("A CSQC entity changed its type! (edict: %d, classname: %s)\n"), num_for_edict(self), self.classname));
+                       print(sprintf(_("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n"), num_for_edict(self), self.entnum, self.enttype, t));
                        Ent_Remove();
                        bIsNewEntity = 1;
                }
+       }
+       else
+       {
+               if(!bIsNewEntity)
+               {
+                       print(sprintf(_("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n"), num_for_edict(self), self.entnum, t));
+                       bIsNewEntity = 1;
+               }
+       }
 #endif
        self.enttype = t;
        switch(t)
@@ -1007,7 +1016,7 @@ void(float bIsNewEntity) CSQC_Ent_Update =
        }
 
        time = savetime;
-};
+}
 // Destructor, but does NOT deallocate the entity by calling remove(). Also
 // used when an entity changes its type. For an entity that someone interacts
 // with others, make sure it can no longer do so.
@@ -1049,10 +1058,10 @@ void CSQC_Parse_Print(string strMessage)
        print(ColorTranslateRGB(strMessage));
 }
 
-// CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided.
+// CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
 void CSQC_Parse_CenterPrint(string strMessage)
 {
-       centerprint(strMessage);
+       centerprint_hud(strMessage);
 }
 
 string notranslate_fogcmd1 = "\nfog ";
@@ -1313,20 +1322,6 @@ void Net_ReadPingPLReport()
        playerslots[e].ping_movementloss = ml / 255.0;
 }
 
-void Net_Notify() {
-       float type;
-       type = ReadByte();
-
-       if(type == CSQC_KILLNOTIFY)
-       {
-               HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
-       }
-       else if(type == CSQC_CENTERPRINT)
-       {
-               HUD_Centerprint(ReadString(), ReadString(), ReadShort(), ReadByte());
-       }
-}
-
 void Net_WeaponComplain() {
        complain_weapon = ReadByte();
 
@@ -1345,10 +1340,10 @@ void Net_WeaponComplain() {
 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
 float CSQC_Parse_TempEntity()
 {
-       local float bHandled;
+       float bHandled;
                bHandled  = true;
        // Acquire TE ID
-       local float nTEID;
+       float nTEID;
                nTEID = ReadByte();
 
                // NOTE: Could just do return instead of break...
@@ -1391,21 +1386,36 @@ float CSQC_Parse_TempEntity()
                        bHandled = true;
                        break;
                case TE_CSQC_ANNOUNCE:
-                       announce_snd = strzone(ReadString());
+                       Announcer_Play(ReadString());
+                       bHandled = true;
+                       break;
+               case TE_CSQC_KILLNOTIFY:
+                       HUD_KillNotify(ReadString(), ReadString(), ReadString(), ReadShort(), ReadByte());
+                       bHandled = true;
+                       break;
+               case TE_CSQC_KILLCENTERPRINT:
+                       HUD_KillCenterprint(ReadString(), ReadString(), ReadShort(), ReadByte());
                        bHandled = true;
                        break;
-               case TE_CSQC_NOTIFY:
-                       Net_Notify();
+               case TE_CSQC_CENTERPRINT_GENERIC:
+                       float id;
+                       string s;
+                       id = ReadByte();
+                       s = ReadString();
+                       if (id != 0 && s != "")
+                               centerprint_generic(id, s, ReadByte(), ReadByte());
+                       else
+                               centerprint_generic(id, s, 0, 0);
                        bHandled = true;
                        break;
                case TE_CSQC_WEAPONCOMPLAIN:
                        Net_WeaponComplain();
                        bHandled = true;
                        break;
-        case TE_CSQC_VEHICLESETUP:
-            Net_VehicleSetup();
-            bHandled = true;
-            break;
+               case TE_CSQC_VEHICLESETUP:
+                       Net_VehicleSetup();
+                       bHandled = true;
+                       break;
                default:
                        // No special logic for this temporary entity; return 0 so the engine can handle it
                        bHandled = false;
@@ -1426,7 +1436,7 @@ string getcommandkey(string text, string command)
        keys = db_get(binddb, command);
        if (!keys)
        {
-               n = tokenize(findkeysforcommand(command)); // uses '...' strings
+               n = tokenize(findkeysforcommand(command, 0)); // uses '...' strings
                for(j = 0; j < n; ++j)
                {
                        k = stof(argv(j));