From dd32e65af7a14956ccce1617a73126aa4b0f62dc Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 22 Jan 2010 19:46:23 +0000 Subject: [PATCH] make weapons named, not numbered, everywhere git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8523 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/defaultNexuiz.cfg | 20 ++++++------- data/qcsrc/client/Main.qc | 9 ++++++ data/qcsrc/common/items.qc | 29 +++++++++++++++++++ data/qcsrc/common/items.qh | 2 ++ data/qcsrc/common/util.qc | 14 +++++++++ .../nexuiz/dialog_multiplayer_playersetup.c | 2 +- data/qcsrc/menu/nexuiz/weaponslist.c | 6 ++-- data/qcsrc/server/bot/bot.qc | 6 ++-- data/qcsrc/server/cl_weapons.qc | 2 +- 9 files changed, 72 insertions(+), 18 deletions(-) diff --git a/data/defaultNexuiz.cfg b/data/defaultNexuiz.cfg index b3525551a..5ffe14c0b 100644 --- a/data/defaultNexuiz.cfg +++ b/data/defaultNexuiz.cfg @@ -406,9 +406,9 @@ set bot_ai_keyboard_treshold 0.57 set bot_ai_aimskill_offset 0.3 "Amount of error induced to the bots aim" set bot_ai_aimskill_think 1 "Aiming velocity. Use values below 1 for slower aiming" set bot_ai_custom_weapon_priority_distances "300 850" "Define close and far distances in any order. Based on the distance to the enemy bots will choose different weapons" -set bot_ai_custom_weapon_priority_far "11 7 15 14 9 4 5 8 13 6 1 3 16 2" "Desired weapons for far distances ordered by priority" -set bot_ai_custom_weapon_priority_mid "11 9 7 16 4 5 3 15 14 6 13 8 2 1" "Desired weapons for middle distances ordered by priority" -set bot_ai_custom_weapon_priority_close "11 7 3 13 14 8 6 4 2 5 15 1 16" "Desired weapons for close distances ordered by priority" +set bot_ai_custom_weapon_priority_far "minstanex nex campingrifle rocketlauncher grenadelauncher electro hagar hlac crylink laser uzi fireball shotgun tuba" "Desired weapons for far distances ordered by priority" +set bot_ai_custom_weapon_priority_mid "minstanex rocketlauncher nex fireball grenadelauncher electro uzi campingrifle crylink hlac hagar shotgun laser tuba" "Desired weapons for middle distances ordered by priority" +set bot_ai_custom_weapon_priority_close "minstanex nex uzi hlac tuba hagar crylink grenadelauncher shotgun electro campingrifle rocketlauncher laser fireball" "Desired weapons for close distances ordered by priority" set bot_ai_weapon_combo 1 "Enable bots to do weapon combos" set bot_ai_weapon_combo_threshold 0.3 "Try to make a combo N seconds after the last attack" set bot_ai_friends_aware_pickup_radius "500" "Bots will not pickup items if a team mate is this distance near the item" @@ -1452,14 +1452,14 @@ set g_jump_grunt 0 "Do you make a grunting noise every time you jump? Is it the alias allready "sv_cmd allready" // note: these cvars use weapon NUMBERS. Use the menu to edit this cvar, or look the numbers up in qcsrc/common/constants.qh. -seta cl_weaponpriority "11 9 7 4 13 8 6 15 3 5 14 2 1 12 10" "weapon priority list (edit it using the menu, numbers see constants.qh)" +seta cl_weaponpriority "minstanex rocketlauncher nex grenadelauncher fireball hlac hagar crylink campingrifle uzi electro tuba shotgun laser hook porto" "weapon priority list" seta cl_weaponpriority_useforcycling 0 "when set, weapon cycling by the mouse wheel makes use of the weapon priority list" -seta cl_weaponpriority0 "9 4 13 8 14" "use impulse 200 for prev gun from this list, 210 for best gun, 220 for next gun. Default value: explosives" -seta cl_weaponpriority1 "11 7 6 5 1" "use impulse 201 for prev gun from this list, 211 for best gun, 221 for next gun. Default value: energy" -seta cl_weaponpriority2 "11 7 15 3" "use impulse 202 for prev gun from this list, 212 for best gun, 222 for next gun. Default value: hitscan exact" -seta cl_weaponpriority3 "11 7 15 3 2" "use impulse 203 for prev gun from this list, 213 for best gun, 223 for next gun. Default value: hitscan all" -seta cl_weaponpriority4 "4 13 8 6 2" "use impulse 204 for prev gun from this list, 214 for best gun, 224 for next gun. Default value: spam weapons" -seta cl_weaponpriority5 "1 12 10" "use impulse 205 for prev gun from this list, 215 for best gun, 225 for next gun. Default value: weapons for moving" +seta cl_weaponpriority0 "rocketlauncher grenadelauncher hagar fireball" "use impulse 200 for prev gun from this list, 210 for best gun, 220 for next gun. Default value: explosives" +seta cl_weaponpriority1 "minstanex nex crylink hlac electro laser" "use impulse 201 for prev gun from this list, 211 for best gun, 221 for next gun. Default value: energy" +seta cl_weaponpriority2 "minstanex nex campingrifle" "use impulse 202 for prev gun from this list, 212 for best gun, 222 for next gun. Default value: hitscan exact" +seta cl_weaponpriority3 "minstanex nex campingrifle uzi shotgun" "use impulse 203 for prev gun from this list, 213 for best gun, 223 for next gun. Default value: hitscan all" +seta cl_weaponpriority4 "grenadelauncher hlac hagar crylink shotgun" "use impulse 204 for prev gun from this list, 214 for best gun, 224 for next gun. Default value: spam weapons" +seta cl_weaponpriority5 "laser hook porto" "use impulse 205 for prev gun from this list, 215 for best gun, 225 for next gun. Default value: weapons for moving" seta cl_weaponpriority6 "" "use impulse 206 for prev gun from this list, 216 for best gun, 226 for next gun" seta cl_weaponpriority7 "" "use impulse 207 for prev gun from this list, 217 for best gun, 227 for next gun" seta cl_weaponpriority8 "" "use impulse 208 for prev gun from this list, 218 for best gun, 228 for next gun" diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index fd96c605a..06225050f 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -472,6 +472,7 @@ void ShotOrg_Spawn() void GameCommand(string msg) { + string s; float argc; argc = tokenize_console(msg); @@ -557,6 +558,14 @@ void GameCommand(string msg) } localcmd("sv_cmd debug_shotorg\n"); } + else if(cmd == "sendcvar") { + s = cvar_string(argv(1)); + if(argv(1) == "cl_weaponpriority") + s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1); + else if(substring(argv(1), 0, 17) == "cl_weaponpriority" && strlen(argv(1)) == 18) + s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0); + localcmd("cmd sentcvar ", argv(1), " \"", s, "\"\n"); + } else { print("Invalid command. For a list of supported commands, try cl_cmd help.\n"); diff --git a/data/qcsrc/common/items.qc b/data/qcsrc/common/items.qc index d1714c9c4..de32afd3e 100644 --- a/data/qcsrc/common/items.qc +++ b/data/qcsrc/common/items.qc @@ -89,3 +89,32 @@ string W_FixWeaponOrder(string order, float complete) { return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete); } +string W_NameWeaponOrder_MapFunc(string s) +{ + entity wi; + if(s == "0" || stof(s)) + { + wi = get_weaponinfo(stof(s)); + if(wi != dummy_weapon_info) + return wi.netname; + } + return s; +} +string W_NameWeaponOrder(string order) +{ + return mapPriorityList(order, W_NameWeaponOrder_MapFunc); +} +string W_NumberWeaponOrder_MapFunc(string s) +{ + float i; + if(s == "0" || stof(s)) + return s; + for(i = WEP_FIRST; i <= WEP_LAST; ++i) + if(s == get_weaponinfo(i).netname) + return ftos(i); + return s; +} +string W_NumberWeaponOrder(string order) +{ + return mapPriorityList(order, W_NumberWeaponOrder_MapFunc); +} diff --git a/data/qcsrc/common/items.qh b/data/qcsrc/common/items.qh index 2bb10d40c..262f43c6a 100644 --- a/data/qcsrc/common/items.qh +++ b/data/qcsrc/common/items.qh @@ -52,6 +52,8 @@ string weaponpriority_hudselector_1; // functions: entity get_weaponinfo(float id); string W_FixWeaponOrder(string order, float complete); +string W_NameWeaponOrder(string order); +string W_NumberWeaponOrder(string order); #define WEPSPAWNFLAG_NORMAL 1 #define WEPSPAWNFLAG_CANCLIMB 2 diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index 49b321cd8..6f2c4485a 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -701,6 +701,7 @@ string fixPriorityList(string order, float from, float to, float subtract, float float i, n, w; n = tokenize_console(order); + neworder = ""; for(i = 0; i < n; ++i) { w = stof(argv(i)); @@ -733,6 +734,19 @@ string fixPriorityList(string order, float from, float to, float subtract, float return substring(neworder, 0, strlen(neworder) - 1); } +string mapPriorityList(string order, string(string) mapfunc) +{ + string neworder; + float i, n, w; + + n = tokenize_console(order); + neworder = ""; + for(i = 0; i < n; ++i) + neworder = strcat(neworder, mapfunc(argv(i)), " "); + + return substring(neworder, 0, strlen(neworder) - 1); +} + string swapInPriorityList(string order, float i, float j) { string s; diff --git a/data/qcsrc/menu/nexuiz/dialog_multiplayer_playersetup.c b/data/qcsrc/menu/nexuiz/dialog_multiplayer_playersetup.c index ee6995b5e..53e2682c9 100644 --- a/data/qcsrc/menu/nexuiz/dialog_multiplayer_playersetup.c +++ b/data/qcsrc/menu/nexuiz/dialog_multiplayer_playersetup.c @@ -173,6 +173,6 @@ void fillNexuizPlayerSettingsTab(entity me) me.TR(me); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, makeNexuizCommandButton("Apply immediately", '0 0 0', "color -1 -1;name \"$_cl_name\";sendcvar cl_weaponpriority;sendcvar cl_zoomfactor;sendcvar cl_zoomspeed;sendcvar cl_autoswitch;sendcvar cl_shownames;sendcvar cl_forceplayermodelsfromnexuiz;sendcvar cl_forceplayermodels", COMMANDBUTTON_APPLY)); + me.TD(me, 1, me.columns, makeNexuizCommandButton("Apply immediately", '0 0 0', "color -1 -1;name \"$_cl_name\";cl_cmd sendcvar cl_weaponpriority;sendcvar cl_zoomfactor;sendcvar cl_zoomspeed;sendcvar cl_autoswitch;sendcvar cl_shownames;sendcvar cl_forceplayermodelsfromnexuiz;sendcvar cl_forceplayermodels", COMMANDBUTTON_APPLY)); } #endif diff --git a/data/qcsrc/menu/nexuiz/weaponslist.c b/data/qcsrc/menu/nexuiz/weaponslist.c index 4aa01befe..a8b1e91a4 100644 --- a/data/qcsrc/menu/nexuiz/weaponslist.c +++ b/data/qcsrc/menu/nexuiz/weaponslist.c @@ -33,12 +33,12 @@ void drawNexuizWeaponsList(entity me) { // read in cvar? string s, t; - s = cvar_string("cl_weaponpriority"); + s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority")); t = W_FixWeaponOrder(s, 1); if(t != s) { print("AUTOFIXED\n"); - cvar_set("cl_weaponpriority", t); + cvar_set("cl_weaponpriority", W_NameWeaponOrder(t)); } me.nItems = tokenize_console(t); drawListBox(me); @@ -81,7 +81,7 @@ string toStringNexuizWeaponsList(entity me) float n, i; string s; entity e; - n = tokenize_console(cvar_string("cl_weaponpriority")); + n = tokenize_console(cvar_string(W_NumberWeaponOrder("cl_weaponpriority"))); s = ""; for(i = 0; i < n; ++i) { diff --git a/data/qcsrc/server/bot/bot.qc b/data/qcsrc/server/bot/bot.qc index 55e2125eb..2401c746f 100644 --- a/data/qcsrc/server/bot/bot.qc +++ b/data/qcsrc/server/bot/bot.qc @@ -245,7 +245,7 @@ void bot_custom_weapon_priority_setup() bot_weapons_close[0] = -1; // Parse far distance weapon priorities - tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_far")," "); + tokens = tokenizebyseparator(W_NumberWeaponOrder(cvar_string("bot_ai_custom_weapon_priority_far"))," "); c = 0; for(i=0; i < tokens && c < WEP_COUNT; ++i){ @@ -259,7 +259,7 @@ void bot_custom_weapon_priority_setup() bot_weapons_far[c] = -1; // Parse mid distance weapon priorities - tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_mid")," "); + tokens = tokenizebyseparator(W_NumberWeaponOrder(cvar_string("bot_ai_custom_weapon_priority_mid"))," "); c = 0; for(i=0; i < tokens && c < WEP_COUNT; ++i){ @@ -273,7 +273,7 @@ void bot_custom_weapon_priority_setup() bot_weapons_mid[c] = -1; // Parse close distance weapon priorities - tokens = tokenizebyseparator(cvar_string("bot_ai_custom_weapon_priority_close")," "); + tokens = tokenizebyseparator(W_NumberWeaponOrder(cvar_string("bot_ai_custom_weapon_priority_close"))," "); c = 0; for(i=0; i < tokens && i < WEP_COUNT; ++i){ diff --git a/data/qcsrc/server/cl_weapons.qc b/data/qcsrc/server/cl_weapons.qc index 5c2e08e24..da9d7156f 100644 --- a/data/qcsrc/server/cl_weapons.qc +++ b/data/qcsrc/server/cl_weapons.qc @@ -135,7 +135,7 @@ string W_FixWeaponOrder_AllowIncomplete(string order) string W_FixWeaponOrder_ForceComplete(string order) { if(order == "") - order = cvar_string("cl_weaponpriority"); + order = W_NumberWeaponOrder(cvar_string("cl_weaponpriority")); return W_FixWeaponOrder(order, 1); } -- 2.39.2