r4285 - trunk/data/qcsrc/server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Tue Sep 2 07:49:14 EDT 2008
Author: div0
Date: 2008-09-02 07:49:14 -0400 (Tue, 02 Sep 2008)
New Revision: 4285
Modified:
trunk/data/qcsrc/server/cl_impulse.qc
trunk/data/qcsrc/server/cl_weapons.qc
trunk/data/qcsrc/server/cl_weaponsystem.qc
trunk/data/qcsrc/server/defs.qh
trunk/data/qcsrc/server/miscfunctions.qc
Log:
document weapon impulse order; load weapon priority from client
Modified: trunk/data/qcsrc/server/cl_impulse.qc
===================================================================
--- trunk/data/qcsrc/server/cl_impulse.qc 2008-09-02 11:19:52 UTC (rev 4284)
+++ trunk/data/qcsrc/server/cl_impulse.qc 2008-09-02 11:49:14 UTC (rev 4285)
@@ -56,6 +56,34 @@
}
};
+/*
+ * Impulse map:
+ *
+ * 0 reserved (no input)
+ * 1 to 9: weapon shortcuts
+ * 10: next weapon
+ * 11: most recently used weapon
+ * 12: previous weapon
+ * 13: moving clone
+ * 14: fixed clone
+ * 17: throw weapon
+ * 19: printsurfaceinfo
+ * 20: distance
+ * 30 to 39: create waypoints
+ * 47: clear personal waypoints
+ * 48: clear team waypoints
+ * 49: turn base waypoints on/off
+ * 77: ctf speedrun
+ * 99: loaded
+ * 143: emergency teleport
+ *
+ * TODO:
+ * 200 to 219: individual weapons
+ * 220 to 229: next weapon shortcuts
+ * 230 to 239: prev weapon shortcuts
+ * 240 to 249: best weapon shortcuts
+ */
+
void ImpulseCommands (void)
{
local float imp;
Modified: trunk/data/qcsrc/server/cl_weapons.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weapons.qc 2008-09-02 11:19:52 UTC (rev 4284)
+++ trunk/data/qcsrc/server/cl_weapons.qc 2008-09-02 11:49:14 UTC (rev 4285)
@@ -1,4 +1,125 @@
+// switch between weapons
+void W_SwitchWeapon(float imp)
+{
+ if (self.weapon != imp)
+ if (client_hasweapon(self, imp, TRUE, TRUE))
+ {
+ self.cnt = self.weapon ? self.weapon : self.switchweapon;
+ self.switchweapon = imp;
+ }
+};
+float W_GetCycleWeapon(entity pl, string weaponorder, float dir)
+{
+ float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
+ n = tokenize(weaponorder);
+ switchtonext = switchtolast = 0;
+ first_valid = prev_valid = -1;
+
+ if(dir == 0)
+ switchtonext = 1;
+
+ for(i = 0; i < n; ++i)
+ {
+ weaponwant = stof(argv(i));
+ if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
+ {
+ if(switchtonext)
+ return weaponwant;
+ if(first_valid < 0)
+ first_valid = weaponwant;
+ prev_valid = weaponwant;
+ if(weaponwant == pl.switchweapon)
+ {
+ if(dir >= 0)
+ switchtonext = 1;
+ else if(prev_valid >= 0)
+ return prev_valid;
+ else
+ {
+ switchtolast = 1;
+ break;
+ }
+ }
+ }
+ }
+ if(first_valid >= 0)
+ {
+ if(switchtolast)
+ return prev_valid;
+ else
+ return first_valid;
+ }
+ return -1;
+}
+
+void W_CycleWeapon(string weaponorder, float dir)
+{
+ float w;
+ w = W_GetCycleWeapon(self, weaponorder, dir);
+ if(w >= 0)
+ W_SwitchWeapon(w);
+ else
+ // none available
+ sprint(self, "You do not have any of the specified weapons.\n");
+}
+
+// next weapon
+void W_NextWeapon()
+{
+ W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
+}
+
+// prev weapon
+void W_PreviousWeapon()
+{
+ W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
+}
+
+string W_FixWeaponOrder(string order, float complete)
+{
+ string neworder;
+ float i, n, w;
+
+ n = tokenize(order);
+ for(i = 0; i < n; ++i)
+ {
+ w = stof(argv(i));
+ if(w >= WEP_FIRST && w <= WEP_LAST && w == floor(w))
+ neworder = strcat(neworder, ftos(w), " ");
+ }
+
+ if(complete)
+ {
+ n = tokenize(neworder);
+ for(w = WEP_FIRST; w <= WEP_LAST; ++w)
+ {
+ for(i = 0; i < n; ++i)
+ if(stof(argv(i)) == w)
+ break;
+ if(i == n) // not found
+ neworder = strcat(neworder, ftos(w), " ");
+ }
+ }
+
+ return substring(neworder, 0, strlen(neworder) - 1);
+}
+
+string W_FixWeaponOrder_AllowIncomplete(string order)
+{
+ return W_FixWeaponOrder(order, 0);
+}
+
+string W_FixWeaponOrder_ForceComplete(string order)
+{
+ return W_FixWeaponOrder(order, 1);
+}
+
+float w_getbestweapon(entity e)
+{
+ return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0);
+};
+
// generic weapons table
// add new weapons here
float weapon_action(float wpn, float wrequest)
@@ -150,157 +271,6 @@
self = e;
};
-// switch between weapons
-void W_SwitchWeapon(float imp)
-{
- if (self.weapon != imp)
- if (client_hasweapon(self, imp, TRUE, TRUE))
- {
- self.cnt = self.weapon ? self.weapon : self.switchweapon;
- self.switchweapon = imp;
- }
-};
-
-// next weapon
-void W_NextWeapon()
-{
- local float weaponwant, maxtries;
-
- maxtries = WEP_LAST;
-
- weaponwant = self.switchweapon + 1;
- if (weaponwant < WEP_FIRST)
- weaponwant = WEP_LAST;
- if (weaponwant > WEP_LAST)
- weaponwant = WEP_FIRST;
- while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
- {
- if(!maxtries)
- return;
-
- maxtries -= 1;
- weaponwant = weaponwant + 1;
- if (weaponwant < WEP_FIRST)
- weaponwant = WEP_LAST;
- if (weaponwant > WEP_LAST)
- weaponwant = WEP_FIRST;
- }
- self.cnt = self.weapon ? self.weapon : self.switchweapon;
- self.switchweapon = weaponwant;
-};
-
-// prev weapon
-void W_PreviousWeapon()
-{
- local float weaponwant, maxtries;
-
- maxtries = WEP_LAST;
-
- weaponwant = self.switchweapon - 1;
- if (weaponwant < WEP_FIRST)
- weaponwant = WEP_LAST;
- if (weaponwant > WEP_LAST)
- weaponwant = WEP_FIRST;
- while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
- {
- if(!maxtries)
- return;
-
- maxtries -= 1;
- weaponwant = weaponwant - 1;
- if (weaponwant < WEP_FIRST)
- weaponwant = WEP_LAST;
- if (weaponwant > WEP_LAST)
- weaponwant = WEP_FIRST;
- }
- self.cnt = self.weapon ? self.weapon : self.switchweapon;
- self.switchweapon = weaponwant;
-};
-
-float W_GetCycleWeapon(string weaponorder, float dir)
-{
- float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
- n = tokenize(weaponorder);
- switchtonext = switchtolast = 0;
- first_valid = prev_valid = -1;
-
- if(dir == 0)
- switchtonext = 1;
-
- for(i = 0; i < n; ++i)
- {
- weaponwant = stof(argv(i));
- if(client_hasweapon(self, weaponwant, TRUE, FALSE))
- {
- if(switchtonext)
- return weaponwant;
- if(first_valid < 0)
- first_valid = weaponwant;
- prev_valid = weaponwant;
- if(weaponwant == self.switchweapon)
- {
- if(dir >= 0)
- switchtonext = 1;
- else if(prev_valid >= 0)
- return prev_valid;
- else
- {
- switchtolast = 1;
- break;
- }
- }
- }
- }
- if(first_valid >= 0)
- {
- if(switchtolast)
- return prev_valid;
- else
- return first_valid;
- }
- return -1;
-}
-
-void W_CycleWeapon(string weaponorder, float dir)
-{
- float w;
- w = W_GetCycleWeapon(weaponorder, dir);
- if(w >= 0)
- W_SwitchWeapon(w);
- else
- // none available
- sprint(self, "You do not have any of the specified weapons.\n");
-}
-
-string W_FixWeaponOrder(string order, float complete)
-{
- string neworder;
- float i, n, w;
-
- n = tokenize(order);
- for(i = 0; i < n; ++i)
- {
- w = stof(argv(i));
- if(w >= WEP_FIRST && w <= WEP_LAST && w == floor(w))
- neworder = strcat(neworder, ftos(w), " ");
- }
-
- if(complete)
- {
- n = tokenize(neworder);
- for(w = WEP_FIRST; w <= WEP_LAST; ++w)
- {
- for(i = 0; i < n; ++i)
- if(stof(argv(i)) == w)
- break;
- if(i == n) // not found
- neworder = strcat(neworder, ftos(w), " ");
- }
- }
-
- return substring(neworder, 0, strlen(neworder) - 1);
-}
-
// Bringed back weapon frame
void W_WeaponFrame()
{
Modified: trunk/data/qcsrc/server/cl_weaponsystem.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weaponsystem.qc 2008-09-02 11:19:52 UTC (rev 4284)
+++ trunk/data/qcsrc/server/cl_weaponsystem.qc 2008-09-02 11:49:14 UTC (rev 4285)
@@ -384,33 +384,6 @@
weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
};
-// FIXME: add qw-style client-custom weaponrating (cl_weaponrating)?
-// by using W_GetCycleWeapon
-float w_getbestweapon(entity e)
-{
-// add new weapons here
- if (client_hasweapon(e, WEP_ROCKET_LAUNCHER, TRUE, FALSE))
- return WEP_ROCKET_LAUNCHER;
- else if (client_hasweapon(e, WEP_NEX, TRUE, FALSE))
- return WEP_NEX;
- else if (client_hasweapon(e, WEP_HAGAR, TRUE, FALSE))
- return WEP_HAGAR;
- else if (client_hasweapon(e, WEP_GRENADE_LAUNCHER, TRUE, FALSE))
- return WEP_GRENADE_LAUNCHER;
- else if (client_hasweapon(e, WEP_ELECTRO, TRUE, FALSE))
- return WEP_ELECTRO;
- else if (client_hasweapon(e, WEP_CRYLINK, TRUE, FALSE))
- return WEP_CRYLINK;
- else if (client_hasweapon(e, WEP_UZI, TRUE, FALSE))
- return WEP_UZI;
- else if (client_hasweapon(e, WEP_SHOTGUN, TRUE, FALSE))
- return WEP_SHOTGUN;
- else if (client_hasweapon(e, WEP_LASER, FALSE, FALSE))
- return WEP_LASER;
- else
- return 0;
-};
-
// Setup weapon for client (after this raise frame will be launched)
void weapon_setup(float windex, string wname, float hudammo)
{
Modified: trunk/data/qcsrc/server/defs.qh
===================================================================
--- trunk/data/qcsrc/server/defs.qh 2008-09-02 11:19:52 UTC (rev 4284)
+++ trunk/data/qcsrc/server/defs.qh 2008-09-02 11:49:14 UTC (rev 4285)
@@ -340,14 +340,23 @@
.float() customizeentityforclient;
.float cvar_cl_handicap;
-.float cvar_cl_zoomfactor;
-.float cvar_cl_zoomspeed;
.float cvar_cl_playerdetailreduction;
.float cvar_cl_nogibs;
.float cvar_scr_centertime;
.float cvar_cl_shownames;
.float cvar_cl_hidewaypoints;
.string cvar_g_nexuizversion;
+.string cvar_cl_weaponpriority;
+.string cvar_cl_weaponpriority0;
+.string cvar_cl_weaponpriority1;
+.string cvar_cl_weaponpriority2;
+.string cvar_cl_weaponpriority3;
+.string cvar_cl_weaponpriority4;
+.string cvar_cl_weaponpriority5;
+.string cvar_cl_weaponpriority6;
+.string cvar_cl_weaponpriority7;
+.string cvar_cl_weaponpriority8;
+.string cvar_cl_weaponpriority9;
.float version_nagtime;
Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc 2008-09-02 11:19:52 UTC (rev 4284)
+++ trunk/data/qcsrc/server/miscfunctions.qc 2008-09-02 11:49:14 UTC (rev 4285)
@@ -486,6 +486,21 @@
else
stuffcmd(self, strcat("sendcvar ", name, "\n"));
}
+void GetCvars_handleString_Fixup(float f, .string field, string name, string(string) func)
+{
+ GetCvars_handleString(f, field, name);
+ if(f >= 0) // also initialize to the fitting value for "" when sending cvars out
+ if(argv(f) == name)
+ {
+ string s;
+ s = func(strcat1(self.field));
+ if(s != self.field)
+ {
+ strunzone(self.field);
+ self.field = strzone(s);
+ }
+ }
+}
void GetCvars_handleFloat(float f, .float field, string name)
{
if(f < 0)
@@ -499,18 +514,29 @@
else
stuffcmd(self, strcat("sendcvar ", name, "\n"));
}
+string W_FixWeaponOrder_ForceComplete(string s);
+string W_FixWeaponOrder_AllowIncomplete(string s);
void GetCvars(float f)
{
GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
- GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
- GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
GetCvars_handleFloat(f, cvar_cl_handicap, "cl_handicap");
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority0, "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority1, "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority2, "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority3, "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority4, "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority5, "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority6, "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority7, "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority8, "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
+ GetCvars_handleString_Fixup(f, cvar_cl_weaponpriority9, "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
}
float fexists(string f)
More information about the nexuiz-commits
mailing list