]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/Main.qc
Merge remote-tracking branch 'origin/master' into samual/spawn_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / Main.qc
index 95ff68f52fb2455c1ba8f52d5c0157445207126f..fe9fd6dd38a5b4aa8e736136864f40c0416e8d8e 100644 (file)
@@ -2,8 +2,20 @@
 // BEGIN REQUIRED CSQC FUNCTIONS
 //include "main.qh"
 
-#define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
+entity clearentity_ent;
+void clearentity(entity e)
+{
+       if not(clearentity_ent)
+       {
+               clearentity_ent = spawn();
+               clearentity_ent.classname = "clearentity";
+       }
+       float n = e.entnum;
+       copyentity(clearentity_ent, e);
+       e.entnum = n;
+}
 
+#define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
 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);
@@ -71,6 +83,7 @@ void precache_all_playermodels(string pattern)
 
 string forcefog;
 void WaypointSprite_Load();
+void ConsoleCommand_macro_init();
 void CSQC_Init(void)
 {
        prvm_language = cvar_string("prvm_language");
@@ -115,28 +128,12 @@ void CSQC_Init(void)
                        break;
        maxclients = i;
 
-       registercommand("hud_configure");
-       registercommand("hud_save");
+       //registercommand("hud_configure");
+       //registercommand("hud_save");
        //registercommand("menu_action");
+       
+       ConsoleCommand_macro_init();
 
-       registercommand("+showscores");registercommand("-showscores");
-       registercommand("+showaccuracy");registercommand("-showaccuracy");
-
-#ifndef CAMERATEST
-       if(isdemo())
-       {
-#endif
-               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");
 
@@ -181,7 +178,7 @@ void CSQC_Init(void)
        DamageInfo_Precache();
        Vehicles_Precache();
        turrets_precache();
-  Announcer_Precache();
+    Announcer_Precache();
        Tuba_Precache();
        
        if(autocvar_cl_reticle)
@@ -382,290 +379,7 @@ void PostInit(void)
        postinit = true;
 }
 
-// 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);
-void Cmd_HUD_Help(float);
-float CSQC_ConsoleCommand(string strMessage)
-{
-       float argc;
-       // Tokenize String
-       argc = tokenize_console(strMessage);
-
-       // Acquire Command
-       string strCmd;
-       strCmd = argv(0);
-
-       if(strCmd == "hud_configure") { // config hud
-               cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
-               return true;
-       } else if(strCmd == "hud_save") { // save hud config
-               if(argv(1) == "" || argv(2)) {
-                       print(_("Usage:\n"));
-                       print(_("hud_save configname   (saves to hud_skinname_configname.cfg)\n"));
-               }
-               else
-                       HUD_Panel_ExportCfg(argv(1));
-               return true;
-       } else if(strCmd == "+showscores") {
-               scoreboard_showscores = true;
-               return true;
-       } else if(strCmd == "-showscores") {
-               scoreboard_showscores = false;
-               return true;
-       } else if(strCmd == "+showaccuracy") {
-               scoreboard_showaccuracy = true;
-               return true;
-       } else if(strCmd == "-showaccuracy") {
-               scoreboard_showaccuracy = false;
-               return true;
-       }
-
-       if(camera_active)
-       if(strCmd == "+forward" || strCmd == "-back") {
-               ++camera_direction_x;
-               return true;
-       } else if(strCmd == "-forward" || strCmd == "+back") {
-               --camera_direction_x;
-               return true;
-       } else if(strCmd == "+moveright" || strCmd == "-moveleft") {
-               --camera_direction_y;
-               return true;
-       } else if(strCmd == "-moveright" || strCmd == "+moveleft") {
-               ++camera_direction_y;
-               return true;
-       } else if(strCmd == "+moveup" || strCmd == "-movedown") {
-               ++camera_direction_z;
-               return true;
-       } else if(strCmd == "-moveup" || strCmd == "+movedown") {
-               --camera_direction_z;
-               return true;
-       } else if(strCmd == "+roll_right" || strCmd == "-roll_left") {
-               ++camera_roll;
-               return true;
-       } else if(strCmd == "+roll_left" || strCmd == "-roll_right") {
-               --camera_roll;
-               return true;
-       }
-
-       return false;
-}
-
-.vector view_ofs;
-entity debug_shotorg;
-void ShotOrg_Draw()
-{
-       self.origin = view_origin + view_forward * self.view_ofs_x + view_right * self.view_ofs_y + view_up * self.view_ofs_z;
-       self.angles = view_angles;
-       self.angles_x = -self.angles_x;
-       if not(self.cnt)
-               self.drawmask = MASK_NORMAL;
-       else
-               self.drawmask = 0;
-}
-void ShotOrg_Draw2D()
-{
-       vector coord2d_topleft, coord2d_topright, coord2d;
-       string s;
-       vector fs;
-
-       s = vtos(self.view_ofs);
-       s = substring(s, 1, strlen(s) - 2);
-       if(tokenize_console(s) == 3)
-               s = strcat(argv(0), " ", argv(1), " ", argv(2));
-
-       coord2d_topleft = project_3d_to_2d(self.origin + view_up * 4 - view_right * 4);
-       coord2d_topright = project_3d_to_2d(self.origin + view_up * 4 + view_right * 4);
-
-       fs = '1 1 0' * ((coord2d_topright_x - coord2d_topleft_x) / stringwidth(s, FALSE, '8 8 0'));
-
-       coord2d = coord2d_topleft;
-       if(fs_x < 8)
-       {
-               coord2d_x += (coord2d_topright_x - coord2d_topleft_x) * (1 - 8 / fs_x) * 0.5;
-               fs = '8 8 0';
-       }
-       coord2d_y -= fs_y;
-       coord2d_z = 0;
-       drawstring(coord2d, s, fs, '1 1 1', 1, 0);
-}
-
-void ShotOrg_Spawn()
-{
-       debug_shotorg = spawn();
-       debug_shotorg.draw = ShotOrg_Draw;
-       debug_shotorg.draw2d = ShotOrg_Draw2D;
-       debug_shotorg.renderflags = RF_VIEWMODEL;
-       debug_shotorg.effects = EF_FULLBRIGHT;
-       precache_model("models/shotorg_adjuster.md3");
-       setmodel(debug_shotorg, "models/shotorg_adjuster.md3");
-       debug_shotorg.scale = 2;
-       debug_shotorg.view_ofs = '25 8 -8';
-}
-
-void DrawDebugModel()
-{
-       if(time - floor(time) > 0.5)
-       {
-               PolyDrawModel(self);
-               self.drawmask = 0;
-       }
-       else
-       {
-               self.renderflags = 0;
-               self.drawmask = MASK_NORMAL;
-       }
-}
-
-void GameCommand(string msg)
-{
-       string s;
-       float argc;
-       entity e;
-       argc = tokenize_console(msg);
-
-       if(argv(0) == "help" || argc == 0)
-       {
-               print(_("Usage: cl_cmd COMMAND..., where possible commands are:\n"));
-               print(_("  scoreboard_columns_set ...\n"));
-               print(_("  scoreboard_columns_help\n"));
-               GameCommand_Generic("help");
-               return;
-       }
-
-       if(GameCommand_Generic(msg))
-               return;
-
-       string cmd;
-       cmd = argv(0);
-       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 == "scoreboard_columns_set") {
-               Cmd_HUD_SetFields(argc);
-       }
-       else if(cmd == "scoreboard_columns_help") {
-               Cmd_HUD_Help(argc);
-       }
-#ifdef BLURTEST
-       else if(cmd == "blurtest") {
-               blurtest_time0 = time;
-               blurtest_time1 = time + stof(argv(1));
-               blurtest_radius = stof(argv(2));
-               blurtest_power = stof(argv(3));
-       }
-#endif
-       else if(cmd == "shotorg_move") {
-               if(!debug_shotorg)
-                       ShotOrg_Spawn();
-               else
-                       debug_shotorg.view_ofs = debug_shotorg.view_ofs + stov(argv(1));
-               localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
-       }
-       else if(cmd == "shotorg_movez") {
-               if(!debug_shotorg)
-                       ShotOrg_Spawn();
-               else
-                       debug_shotorg.view_ofs = debug_shotorg.view_ofs + stof(argv(1)) * (debug_shotorg.view_ofs * (1 / debug_shotorg.view_ofs_x)); // closer/farther, same xy pos
-               localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
-       }
-       else if(cmd == "shotorg_set") {
-               if(!debug_shotorg)
-                       ShotOrg_Spawn();
-               else
-                       debug_shotorg.view_ofs = stov(argv(1));
-               localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
-       }
-       else if(cmd == "shotorg_setz") {
-               if(!debug_shotorg)
-                       ShotOrg_Spawn();
-               else
-                       debug_shotorg.view_ofs = debug_shotorg.view_ofs * (stof(argv(1)) / debug_shotorg.view_ofs_x); // closer/farther, same xy pos
-               localcmd("sv_cmd debug_shotorg \"", vtos(debug_shotorg.view_ofs), "\"\n");
-       }
-       else if(cmd == "shotorg_toggle_hide") {
-               if(debug_shotorg)
-               {
-                       debug_shotorg.cnt = !debug_shotorg.cnt;
-               }
-       }
-       else if(cmd == "shotorg_end") {
-               if(debug_shotorg)
-               {
-                       print(vtos(debug_shotorg.view_ofs), "\n");
-                       remove(debug_shotorg);
-                       debug_shotorg = world;
-               }
-               localcmd("sv_cmd debug_shotorg\n");
-       }
-       else if(cmd == "sendcvar") {
-               // W_FixWeaponOrder will trash argv, so save what we need.
-               string thiscvar;
-               thiscvar = strzone(argv(1));
-               s = cvar_string(thiscvar);
-               if(thiscvar == "cl_weaponpriority")
-                       s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
-               else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
-                       s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
-               localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
-               strunzone(thiscvar);
-       }
-       else if(cmd == "spawn") {
-               s = argv(1);
-               e = spawn();
-               precache_model(s);
-               setmodel(e, s);
-               setorigin(e, view_origin);
-               e.angles = view_angles;
-               e.draw = DrawDebugModel;
-               e.classname = "debugmodel";
-       }
-    else if(cmd == "vyes")
-    {
-        if(uid2name_dialog)
-        {
-            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;
-            localcmd("setreport cl_allow_uid2name 1\n");
-            vote_change = -9999;
-                       uid2name_dialog = 0;
-        }
-        else
-        {
-            localcmd("cmd vote yes\n");
-        }
-    }
-    else if(cmd == "vno")
-    {
-        if(uid2name_dialog)
-        {
-            vote_active = 0;
-            vote_prev = 0;
-            localcmd("setreport cl_allow_uid2name 0\n");
-            vote_change = -9999;
-                       uid2name_dialog = 0;
-        }
-        else
-        {
-            localcmd("cmd vote no\n");
-        }
-    }
-
-       else
-       {
-               print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
-       }
-
-       return;
-}
 
 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
@@ -1005,6 +719,7 @@ void CSQC_Ent_Update(float bIsNewEntity)
                        //print(_("A CSQC entity changed its type!\n"));
                        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();
+                       clearentity(self);
                        bIsNewEntity = 1;
                }
        }
@@ -1077,6 +792,11 @@ void Ent_Remove()
 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
 void CSQC_Ent_Remove()
 {
+       if(wasfreed(self))
+       {
+               print("WARNING: CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
+               return;
+       }
        if(self.enttype)
                Ent_Remove();
        remove(self);
@@ -1086,7 +806,8 @@ void Gamemode_Init()
 {
        if not(isdemo())
        {
-               localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
+               if(!(calledhooks & HOOK_START))
+                       localcmd("\n_cl_hook_gamestart ", MapInfo_Type_ToString(gametype), "\n");
                calledhooks |= HOOK_START;
        }
 }
@@ -1179,6 +900,7 @@ void Ent_Init()
        hagar_maxrockets = ReadByte();
 
        g_trueaim_minrange = ReadCoord();
+       g_balance_porto_secondary = ReadByte();
 
        if(!postinit)
                PostInit();
@@ -1459,6 +1181,14 @@ float CSQC_Parse_TempEntity()
                        Net_VehicleSetup();
                        bHandled = true;
                        break;
+               case TE_CSQC_SVNOTICE:
+                       cl_notice_read();
+                       bHandled = true;
+                       break;
+               case TE_CSQC_SHOCKWAVEPARTICLE:
+                       Net_ReadShockwaveParticle();
+                       bHandled = true;
+                       break;
                default:
                        // No special logic for this temporary entity; return 0 so the engine can handle it
                        bHandled = false;