experimental change: sort impulse weapon order by weapon priority too
authorRudolf Polzer <divverent@alientrap.org>
Wed, 27 Oct 2010 15:40:36 +0000 (17:40 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Wed, 27 Oct 2010 15:40:36 +0000 (17:40 +0200)
qcsrc/client/Defs.qc
qcsrc/client/Main.qc
qcsrc/common/items.qc
qcsrc/common/items.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_weapons.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc

index e816fe221a13bc4994deb8aaf2f90318b1364e38..0fcd337732e18cb319fcdca03de2a29e48b1f05f 100644 (file)
@@ -265,3 +265,4 @@ float cr_maxbullets;
 
 float bgmtime;
 
+string weaponorder_byimpulse;
index 9c50d7a3442d7fd36585ad836d26ced8ea07f6e6..897626a4e89024cdc64cdacface730c9b6a7cf47 100644 (file)
@@ -338,6 +338,8 @@ void PostInit(void)
        Porto_Init();
        TrueAim_Init();
 
+       weaponorder_byimpulse = W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(cvar_string("cl_weaponpriority"))));
+
        postinit = true;
 }
 
index 33b48371502aaa00f1cdb922fe53cd6f3662a789..37ffb25e7c3cff3b49e3581dc69a179048483212 100644 (file)
@@ -26,8 +26,6 @@ float w_null(float dummy)
 }
 void register_weapons_done()
 {
-       entity wi;
-
        dummy_weapon_info = spawn();
        dummy_weapon_info.classname = "weapon_info";
        dummy_weapon_info.weapon = 0; // you can recognize dummies by this
@@ -48,25 +46,7 @@ void register_weapons_done()
        for(i = 24; i >= 1; --i)
                if(weapon_info[i-1])
                        weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
-
-       float imp;
-       weaponorder_byimpulse = "";
-       for(i = 1; i <= 24; ++i)
-       {
-               wi = weapon_info[i-1];
-               if(wi && wi.impulse == 0)
-                       weaponorder_byimpulse = strcat(weaponorder_byimpulse, " ", ftos(i));
-       }
-       for(imp = 9; imp > 0; --imp)
-               for(i = 1; i <= 24; ++i)
-               {
-                       wi = weapon_info[i-1];
-                       if(wi && wi.impulse == imp)
-                               weaponorder_byimpulse = strcat(weaponorder_byimpulse, " ", ftos(i));
-               }
-
        weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
-       weaponorder_byimpulse = strzone(substring(weaponorder_byimpulse, 1, strlen(weaponorder_byimpulse) - 1));
 }
 entity get_weaponinfo(float id)
 {
@@ -111,3 +91,54 @@ string W_NumberWeaponOrder(string order)
 {
        return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
 }
+
+float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
+string W_FixWeaponOrder_BuildImpulseList_order;
+void W_FixWeaponOrder_BuildImpulseList_swap(float i, float j, entity pass)
+{
+       float h;
+       h = W_FixWeaponOrder_BuildImpulseList_buf[i];
+       W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
+       W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
+}
+float W_FixWeaponOrder_BuildImpulseList_cmp(float i, float j, entity pass)
+{
+       entity e1, e2;
+       float d;
+       e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
+       e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
+       d = mod(e1.impulse + 9, 10) - mod(e2.impulse + 9, 10);
+       if(d != 0)
+               return -d; // high impulse first!
+       return
+               strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
+               -
+               strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
+               ; // low char index first!
+}
+string W_FixWeaponOrder_BuildImpulseList(string o)
+{
+       float i;
+       W_FixWeaponOrder_BuildImpulseList_order = o;
+       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+               W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
+       heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
+       o = "";
+       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+               o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
+       W_FixWeaponOrder_BuildImpulseList_order = string_null;
+       return substring(o, 1, -1);
+}
+
+string W_FixWeaponOrder_AllowIncomplete(string order)
+{
+       return W_FixWeaponOrder(order, 0);
+}
+
+string W_FixWeaponOrder_ForceComplete(string order)
+{
+       if(order == "")
+               order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
+       return W_FixWeaponOrder(order, 1);
+}
+
index 62f2d8551e7c58716280895cd8c7bbc0ce531745..64d7abd644b5f9de2240e4d1779596c19ccd15e0 100644 (file)
@@ -53,7 +53,6 @@ float AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel
 
 // variables:
 string weaponorder_byid;
-string weaponorder_byimpulse;
 
 // functions:
 entity get_weaponinfo(float id);
@@ -111,3 +110,11 @@ float WEPBIT_ALL;
 
 #undef REGISTER_WEAPON
 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done)
+
+
+string W_FixWeaponOrder(string order, float complete);
+string W_NumberWeaponOrder(string order);
+string W_NameWeaponOrder(string order);
+string W_FixWeaponOrder_BuildImpulseList(string o);
+string W_FixWeaponOrder_AllowIncomplete(string order);
+string W_FixWeaponOrder_ForceComplete(string order);
index bb2b753b84369a3d87907d307885b0e44b94bcbf..955c0a45d2e0660d002343905515cf34f67b6647 100644 (file)
@@ -1695,6 +1695,8 @@ void ClientDisconnect (void)
                strunzone(self.netname_previous);
        if(self.clientstatus)
                strunzone(self.clientstatus);
+       if(self.weaponorder_byimpulse)
+               strunzone(self.weaponorder_byimpulse);
 
        ClearPlayerSounds();
 
index 540e3f84acbba076156d31ddbe8cb20f54a6339f..477b641ba7e61d21ba7d28989827ccbe20a5ef8a 100644 (file)
@@ -123,7 +123,7 @@ void W_NextWeapon(float list)
        if(list == 0)
                W_CycleWeapon(weaponorder_byid, -1);
        else if(list == 1)
-               W_CycleWeapon(weaponorder_byimpulse, -1);
+               W_CycleWeapon(self.weaponorder_byimpulse, -1);
        else if(list == 2)
                W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
 }
@@ -134,23 +134,11 @@ void W_PreviousWeapon(float list)
        if(list == 0)
                W_CycleWeapon(weaponorder_byid, +1);
        else if(list == 1)
-               W_CycleWeapon(weaponorder_byimpulse, +1);
+               W_CycleWeapon(self.weaponorder_byimpulse, +1);
        else if(list == 2)
                W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
 }
 
-string W_FixWeaponOrder_AllowIncomplete(string order)
-{
-       return W_FixWeaponOrder(order, 0);
-}
-
-string W_FixWeaponOrder_ForceComplete(string order)
-{
-       if(order == "")
-               order = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
-       return W_FixWeaponOrder(order, 1);
-}
-
 float w_getbestweapon(entity e)
 {
        return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, FALSE, TRUE);
index 745a6e0b2a5e148be15ba87a3e3da7079d4d2f86..f327ac30dbce30b881cefb56f151bdf27add3d51 100644 (file)
@@ -329,6 +329,8 @@ float sv_loddistance2;
 .float cvar_cl_gunalign;
 .float cvar_cl_noantilag;
 
+.string weaponorder_byimpulse;
+
 void Announce(string snd);
 void AnnounceTo(entity e, string snd);
 
index 05f297746c5243812b1a0e61d811002c8aa422c9..d774958ade3916cf98ee96f55c1613f9bb07e24b 100644 (file)
@@ -583,7 +583,19 @@ void GetCvars_handleFloatOnce(string thisname, float f, .float field, string nam
 }
 string W_FixWeaponOrder_ForceComplete(string s);
 string W_FixWeaponOrder_AllowIncomplete(string s);
-float w_getbestweapon(entity e);
+string W_FixWeaponOrder_BuildImpulseList(string s);
+string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(string wo)
+{
+       string o, s;
+       o = W_FixWeaponOrder_ForceComplete(wo);
+       if(self.weaponorder_byimpulse)
+       {
+               strunzone(self.weaponorder_byimpulse);
+               self.weaponorder_byimpulse = string_null;
+       }
+       self.weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(o));
+       return o;
+}
 void GetCvars(float f)
 {
        string s;
@@ -600,7 +612,7 @@ void GetCvars(float f)
        GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames");
        GetCvars_handleString(s, f, cvar_g_xonoticversion, "g_xonoticversion");
        GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap");
-       GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
+       GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
        GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
        GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
        GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);