From 011a5500a0255b8073d3bee1233292720e0e1f87 Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 2 Sep 2008 11:49:14 +0000 Subject: [PATCH] document weapon impulse order; load weapon priority from client git-svn-id: svn://svn.icculus.org/nexuiz/trunk@4285 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/cl_impulse.qc | 28 +++ data/qcsrc/server/cl_weapons.qc | 272 ++++++++++++--------------- data/qcsrc/server/cl_weaponsystem.qc | 27 --- data/qcsrc/server/defs.qh | 13 +- data/qcsrc/server/miscfunctions.qc | 30 ++- 5 files changed, 188 insertions(+), 182 deletions(-) diff --git a/data/qcsrc/server/cl_impulse.qc b/data/qcsrc/server/cl_impulse.qc index e0febc51b..18e1001eb 100644 --- a/data/qcsrc/server/cl_impulse.qc +++ b/data/qcsrc/server/cl_impulse.qc @@ -56,6 +56,34 @@ void printsurfaceinfo(entity e, vector v) } }; +/* + * 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; diff --git a/data/qcsrc/server/cl_weapons.qc b/data/qcsrc/server/cl_weapons.qc index 19eaa7c62..d5eaab708 100644 --- a/data/qcsrc/server/cl_weapons.qc +++ b/data/qcsrc/server/cl_weapons.qc @@ -1,3 +1,124 @@ +// 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 @@ -150,157 +271,6 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce) 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() { diff --git a/data/qcsrc/server/cl_weaponsystem.qc b/data/qcsrc/server/cl_weaponsystem.qc index c421dbfeb..fbb79eb25 100644 --- a/data/qcsrc/server/cl_weaponsystem.qc +++ b/data/qcsrc/server/cl_weaponsystem.qc @@ -384,33 +384,6 @@ void w_ready() 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) { diff --git a/data/qcsrc/server/defs.qh b/data/qcsrc/server/defs.qh index 4bb7695fa..d1bbe1726 100644 --- a/data/qcsrc/server/defs.qh +++ b/data/qcsrc/server/defs.qh @@ -340,14 +340,23 @@ float default_weapon_alpha; .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; diff --git a/data/qcsrc/server/miscfunctions.qc b/data/qcsrc/server/miscfunctions.qc index e91ee26f6..133b7bc2f 100644 --- a/data/qcsrc/server/miscfunctions.qc +++ b/data/qcsrc/server/miscfunctions.qc @@ -486,6 +486,21 @@ void GetCvars_handleString(float f, .string field, string name) 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 @@ void GetCvars_handleFloat(float f, .float field, string name) 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) -- 2.39.2