From d7c2ccad885769e40816cf54752dd8b414225aeb Mon Sep 17 00:00:00 2001 From: danij Date: Mon, 18 Sep 2006 23:23:03 +0000 Subject: [PATCH] Added cvar "player-autoswitch-ammo" autoswitch weapon when after collecting ammo for a weapon which had previously ran out of ammo; 0= never 1= if better 2= always. --- doomsday/plugins/common/src/mn_menu.c | 49 +++++++++++++------- doomsday/plugins/common/src/p_player.c | 29 ++++++++---- doomsday/plugins/doom64tc/data/conhelp.txt | 3 ++ doomsday/plugins/doom64tc/include/d_config.h | 1 + doomsday/plugins/doom64tc/src/d_console.c | 1 + doomsday/plugins/doom64tc/src/d_main.c | 3 +- doomsday/plugins/jdoom/data/conhelp.txt | 3 ++ doomsday/plugins/jdoom/include/d_config.h | 1 + doomsday/plugins/jdoom/src/d_console.c | 1 + doomsday/plugins/jdoom/src/d_main.c | 3 +- doomsday/plugins/jheretic/data/conhelp.txt | 3 ++ doomsday/plugins/jheretic/include/h_config.h | 2 +- doomsday/plugins/jheretic/src/h_console.c | 1 + doomsday/plugins/jheretic/src/h_main.c | 3 +- doomsday/plugins/jhexen/data/conhelp.txt | 3 ++ doomsday/plugins/jhexen/include/x_config.h | 3 +- doomsday/plugins/jhexen/src/h2_main.c | 2 + doomsday/plugins/jhexen/src/hconsole.c | 3 +- doomsday/plugins/wolftc/data/conhelp.txt | 3 ++ doomsday/plugins/wolftc/include/d_config.h | 1 + doomsday/plugins/wolftc/src/d_console.c | 1 + doomsday/plugins/wolftc/src/d_main.c | 3 +- 22 files changed, 89 insertions(+), 33 deletions(-) diff --git a/doomsday/plugins/common/src/mn_menu.c b/doomsday/plugins/common/src/mn_menu.c index c2f114085e..fb23b1832d 100644 --- a/doomsday/plugins/common/src/mn_menu.c +++ b/doomsday/plugins/common/src/mn_menu.c @@ -109,7 +109,8 @@ void M_ToggleVar(int option, void *data); void M_OpenDCP(int option, void *data); void M_ChangeMessages(int option, void *data); -void M_AutoSwitch(int option, void *data); +void M_WeaponAutoSwitch(int option, void *data); +void M_AmmoAutoSwitch(int option, void *data); void M_HUDInfo(int option, void *data); void M_HUDScale(int option, void *data); void M_SfxVol(int option, void *data); @@ -987,40 +988,41 @@ static MenuItem_t WeaponItems[] = { #endif {ITT_EFUNC, 0, "Use with Next/Previous :", M_ToggleVar, 0, NULL, "player-weapon-nextmode"}, {ITT_EMPTY, 0, NULL, NULL, 0}, - {ITT_LRFUNC, 0, "AUTOSWITCH :", M_AutoSwitch, 0}, + {ITT_LRFUNC, 0, "WEAPON AUTO SWITCH :", M_WeaponAutoSwitch, 0}, + {ITT_LRFUNC, 0, "AMMO AUTO SWITCH :", M_AmmoAutoSwitch, 0}, #if __JDOOM__ - {ITT_EFUNC, 0, "BERSERK AUTOSWITCH :", M_ToggleVar, 0, NULL, "player-autoswitch-berserk"} + {ITT_EFUNC, 0, "BERSERK AUTO SWITCH :", M_ToggleVar, 0, NULL, "player-autoswitch-berserk"} #endif }; static Menu_t WeaponDef = { #if !__JDOOM__ - 60, 30, + 50, 30, #else - 78, 44, + 68, 44, #endif M_DrawWeaponMenu, #if __DOOM64TC__ - 18, WeaponItems, + 19, WeaponItems, #elif __JDOOM__ - 17, WeaponItems, + 18, WeaponItems, #elif __JHERETIC__ - 15, WeaponItems, + 16, WeaponItems, #elif __JHEXEN__ - 11, WeaponItems, + 12, WeaponItems, #endif 0, MENU_OPTIONS, 1, hu_font_a, cfg.menuColor2, LINEHEIGHT_A, #ifdef __DOOM64TC__ - 0, 18 + 0, 19 #elif __JDOOM__ - 0, 17 + 0, 18 #elif __JHERETIC__ - 0, 15 + 0, 16 #elif __JHEXEN__ - 0, 11 + 0, 12 #endif }; @@ -2972,17 +2974,21 @@ void M_DrawWeaponMenu(void) #if __JHEXEN__ M_WriteMenuText(menu, 8, yesno[cfg.weaponNextMode]); M_WriteMenuText(menu, 10, autoswitch[cfg.weaponAutoSwitch]); + M_WriteMenuText(menu, 11, autoswitch[cfg.ammoAutoSwitch]); #elif __JHERETIC__ M_WriteMenuText(menu, 12, yesno[cfg.weaponNextMode]); M_WriteMenuText(menu, 14, autoswitch[cfg.weaponAutoSwitch]); + M_WriteMenuText(menu, 15, autoswitch[cfg.ammoAutoSwitch]); #elif __DOOM64TC__ M_WriteMenuText(menu, 14, yesno[cfg.weaponNextMode]); M_WriteMenuText(menu, 16, autoswitch[cfg.weaponAutoSwitch]); - M_WriteMenuText(menu, 17, yesno[berserkAutoSwitch != 0]); + M_WriteMenuText(menu, 17, autoswitch[cfg.ammoAutoSwitch]); + M_WriteMenuText(menu, 18, yesno[berserkAutoSwitch != 0]); #elif __JDOOM__ M_WriteMenuText(menu, 13, yesno[cfg.weaponNextMode]); M_WriteMenuText(menu, 15, autoswitch[cfg.weaponAutoSwitch]); - M_WriteMenuText(menu, 16, yesno[berserkAutoSwitch != 0]); + M_WriteMenuText(menu, 16, autoswitch[cfg.ammoAutoSwitch]); + M_WriteMenuText(menu, 17, yesno[berserkAutoSwitch != 0]); #endif } @@ -3016,7 +3022,7 @@ void M_WeaponOrder(int option, void *data) } } -void M_AutoSwitch(int option, void *data) +void M_WeaponAutoSwitch(int option, void *data) { if(option == RIGHT_DIR) { @@ -3027,6 +3033,17 @@ void M_AutoSwitch(int option, void *data) cfg.weaponAutoSwitch--; } +void M_AmmoAutoSwitch(int option, void *data) +{ + if(option == RIGHT_DIR) + { + if(cfg.ammoAutoSwitch < 2) + cfg.ammoAutoSwitch++; + } + else if(cfg.ammoAutoSwitch > 0) + cfg.ammoAutoSwitch--; +} + void M_DrawHUDMenu(void) { Menu_t *menu = &HUDDef; diff --git a/doomsday/plugins/common/src/p_player.c b/doomsday/plugins/common/src/p_player.c index 98eb314926..673c2bc49a 100644 --- a/doomsday/plugins/common/src/p_player.c +++ b/doomsday/plugins/common/src/p_player.c @@ -245,7 +245,7 @@ weapontype_t P_MaybeChangeWeapon(player_t *player, weapontype_t weapon, } else if(ammo != AM_NOAMMO) // Player is about to be given some ammo. { - if(!player->ammo[ammo] || force) + if((!player->ammo[ammo] && cfg.ammoAutoSwitch != 0) || force) { // We were down to zero, so select a new weapon. // Iterate the weapon order array and see if the player owns a @@ -265,18 +265,27 @@ weapontype_t P_MaybeChangeWeapon(player_t *player, weapontype_t weapon, continue; // Does the weapon use this type of ammo? - if(winf->mode[lvl].ammotype[ammo]) - { - // FIXME: Have we got enough of ALL used ammo types? - // Problem, since the ammo has not been given yet (could - // be an object that gives several ammo types eg backpack) - // we can't test for this with what we know! - - // This routine should be called AFTER the new ammo has - // been given. Somewhat complex logic to decipher first... + if(!(winf->mode[lvl].ammotype[ammo])) + continue; + + // FIXME: Have we got enough of ALL used ammo types? + // Problem, since the ammo has not been given yet (could + // be an object that gives several ammo types eg backpack) + // we can't test for this with what we know! + + // This routine should be called AFTER the new ammo has + // been given. Somewhat complex logic to decipher first... + + if(cfg.ammoAutoSwitch == 2) + { // Always change weapon mode returnval = candidate; break; } + else if(cfg.ammoAutoSwitch == 1 && + player->readyweapon == candidate) + { // readyweapon has a higher priority so don't change. + break; + } } } } diff --git a/doomsday/plugins/doom64tc/data/conhelp.txt b/doomsday/plugins/doom64tc/data/conhelp.txt index db94d90275..a8990a8db5 100644 --- a/doomsday/plugins/doom64tc/data/conhelp.txt +++ b/doomsday/plugins/doom64tc/data/conhelp.txt @@ -795,6 +795,9 @@ desc = Player movement speed while airborne. [player-autoswitch] desc = Change weapon automatically when picking one up. 1=If better 2=Always +[player-autoswitch-ammo] +desc = Change weapon automatically when picking up ammo. 1=If better 2=Always + [player-autoswitch-berserk] desc = Change to fist automatically when picking up berserk pack diff --git a/doomsday/plugins/doom64tc/include/d_config.h b/doomsday/plugins/doom64tc/include/d_config.h index 28eb7d7774..8c715fef60 100644 --- a/doomsday/plugins/doom64tc/include/d_config.h +++ b/doomsday/plugins/doom64tc/include/d_config.h @@ -108,6 +108,7 @@ typedef struct jdoom_config_s { byte usePatchReplacement; byte moveCheckZ; // if true, mobjs can move over/under each other. byte weaponAutoSwitch; + byte ammoAutoSwitch; byte berserkAutoSwitch; int weaponOrder[NUMWEAPONS]; byte weaponNextMode; // if true use the weaponOrder for next/previous. diff --git a/doomsday/plugins/doom64tc/src/d_console.c b/doomsday/plugins/doom64tc/src/d_console.c index 6cfedd1883..7c05846163 100644 --- a/doomsday/plugins/doom64tc/src/d_console.c +++ b/doomsday/plugins/doom64tc/src/d_console.c @@ -152,6 +152,7 @@ cvar_t gameCVars[] = { // Weapon switch preferences {"player-autoswitch", 0, CVT_BYTE, &cfg.weaponAutoSwitch, 0, 2}, + {"player-autoswitch-ammo", 0, CVT_BYTE, &cfg.ammoAutoSwitch, 0, 2}, {"player-autoswitch-berserk", 0, CVT_BYTE, &cfg.berserkAutoSwitch, 0, 1}, // Weapon Order preferences diff --git a/doomsday/plugins/doom64tc/src/d_main.c b/doomsday/plugins/doom64tc/src/d_main.c index 95573d53fb..d83e081dd5 100644 --- a/doomsday/plugins/doom64tc/src/d_main.c +++ b/doomsday/plugins/doom64tc/src/d_main.c @@ -286,7 +286,8 @@ void D_PreInit(void) cfg.moveCheckZ = true; cfg.jumpPower = 9; cfg.airborneMovement = 1; - cfg.weaponAutoSwitch = true; + cfg.weaponAutoSwitch = 1; // IF BETTER + cfg.ammoAutoSwitch = 0; // never cfg.secretMsg = true; cfg.netJumping = true; cfg.netEpisode = 1; diff --git a/doomsday/plugins/jdoom/data/conhelp.txt b/doomsday/plugins/jdoom/data/conhelp.txt index 8371fc800a..3f3f588efd 100644 --- a/doomsday/plugins/jdoom/data/conhelp.txt +++ b/doomsday/plugins/jdoom/data/conhelp.txt @@ -789,6 +789,9 @@ desc = Player movement speed while airborne. [player-autoswitch] desc = Change weapon automatically when picking one up. 1=If better 2=Always +[player-autoswitch-ammo] +desc = Change weapon automatically when picking up ammo. 1=If better 2=Always + [player-autoswitch-berserk] desc = Change to fist automatically when picking up berserk pack diff --git a/doomsday/plugins/jdoom/include/d_config.h b/doomsday/plugins/jdoom/include/d_config.h index 9b6090c83d..eada96e552 100644 --- a/doomsday/plugins/jdoom/include/d_config.h +++ b/doomsday/plugins/jdoom/include/d_config.h @@ -109,6 +109,7 @@ typedef struct jdoom_config_s { byte usePatchReplacement; byte moveCheckZ; // if true, mobjs can move over/under each other. byte weaponAutoSwitch; + byte ammoAutoSwitch; byte berserkAutoSwitch; int weaponOrder[NUMWEAPONS]; byte weaponNextMode; // if true use the weaponOrder for next/previous. diff --git a/doomsday/plugins/jdoom/src/d_console.c b/doomsday/plugins/jdoom/src/d_console.c index 5734297d28..04091d813f 100644 --- a/doomsday/plugins/jdoom/src/d_console.c +++ b/doomsday/plugins/jdoom/src/d_console.c @@ -150,6 +150,7 @@ cvar_t gameCVars[] = { // Weapon switch preferences {"player-autoswitch", 0, CVT_BYTE, &cfg.weaponAutoSwitch, 0, 2}, + {"player-autoswitch-ammo", 0, CVT_BYTE, &cfg.ammoAutoSwitch, 0, 2}, {"player-autoswitch-berserk", 0, CVT_BYTE, &cfg.berserkAutoSwitch, 0, 1}, // Weapon Order preferences diff --git a/doomsday/plugins/jdoom/src/d_main.c b/doomsday/plugins/jdoom/src/d_main.c index cd13d19468..d0e5a824ab 100644 --- a/doomsday/plugins/jdoom/src/d_main.c +++ b/doomsday/plugins/jdoom/src/d_main.c @@ -409,7 +409,8 @@ void D_PreInit(void) cfg.moveCheckZ = true; cfg.jumpPower = 9; cfg.airborneMovement = 1; - cfg.weaponAutoSwitch = true; + cfg.weaponAutoSwitch = 1; // if better + cfg.ammoAutoSwitch = 0; // never cfg.secretMsg = true; cfg.netJumping = true; cfg.netEpisode = 1; diff --git a/doomsday/plugins/jheretic/data/conhelp.txt b/doomsday/plugins/jheretic/data/conhelp.txt index f79c1066ae..ca1370acf8 100644 --- a/doomsday/plugins/jheretic/data/conhelp.txt +++ b/doomsday/plugins/jheretic/data/conhelp.txt @@ -726,6 +726,9 @@ desc = Player movement speed while airborne. [player-autoswitch] desc = Change weapon automatically when picking one up. 1=If better 2=Always +[player-autoswitch-ammo] +desc = Change weapon automatically when picking up ammo. 1=If better 2=Always + [player-weapon-order0] desc = Weapon change order, slot 0. diff --git a/doomsday/plugins/jheretic/include/h_config.h b/doomsday/plugins/jheretic/include/h_config.h index eef17b4d8b..79174f2135 100644 --- a/doomsday/plugins/jheretic/include/h_config.h +++ b/doomsday/plugins/jheretic/include/h_config.h @@ -102,7 +102,7 @@ typedef struct jheretic_config_s { byte usePatchReplacement; byte moveCheckZ; // if true, mobjs can move over/under each other. byte weaponAutoSwitch; - + byte ammoAutoSwitch; int weaponOrder[NUMWEAPONS]; byte weaponNextMode; // if true use the weaponOrder for next/previous. byte secretMsg; diff --git a/doomsday/plugins/jheretic/src/h_console.c b/doomsday/plugins/jheretic/src/h_console.c index fa66896737..2d647de617 100644 --- a/doomsday/plugins/jheretic/src/h_console.c +++ b/doomsday/plugins/jheretic/src/h_console.c @@ -147,6 +147,7 @@ cvar_t gameCVars[] = { // Weapon switch preferences {"player-autoswitch", 0, CVT_BYTE, &cfg.weaponAutoSwitch, 0, 2}, + {"player-autoswitch-ammo", 0, CVT_BYTE, &cfg.ammoAutoSwitch, 0, 2}, // Weapon Order preferences {"player-weapon-order0", 0, CVT_INT, &cfg.weaponOrder[0], 0, NUMWEAPONS}, diff --git a/doomsday/plugins/jheretic/src/h_main.c b/doomsday/plugins/jheretic/src/h_main.c index 4ccb98983e..9052676005 100644 --- a/doomsday/plugins/jheretic/src/h_main.c +++ b/doomsday/plugins/jheretic/src/h_main.c @@ -305,7 +305,8 @@ void H_PreInit(void) cfg.moveCheckZ = true; cfg.jumpPower = 9; cfg.airborneMovement = 1; - cfg.weaponAutoSwitch = true; + cfg.weaponAutoSwitch = 1; // IF BETTER + cfg.ammoAutoSwitch = 0; // never cfg.secretMsg = true; cfg.netJumping = true; cfg.netEpisode = 1; diff --git a/doomsday/plugins/jhexen/data/conhelp.txt b/doomsday/plugins/jhexen/data/conhelp.txt index b6c0988d12..128b7d210e 100644 --- a/doomsday/plugins/jhexen/data/conhelp.txt +++ b/doomsday/plugins/jhexen/data/conhelp.txt @@ -786,6 +786,9 @@ desc = Player movement speed while airborne and NOT flying. [player-autoswitch] desc = Change weapon automatically when picking one up. 1=If better 2=Always +[player-autoswitch-ammo] +desc = Change weapon automatically when picking up ammo. 1=If better 2=Always + [player-weapon-order0] desc = Weapon change order, slot 0. diff --git a/doomsday/plugins/jhexen/include/x_config.h b/doomsday/plugins/jhexen/include/x_config.h index eddf94eb99..639fac51b7 100644 --- a/doomsday/plugins/jhexen/include/x_config.h +++ b/doomsday/plugins/jhexen/include/x_config.h @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA * * In addition, as a special exception, we, the authors of deng @@ -112,6 +112,7 @@ typedef struct { byte msgShow; float msgColor[3]; byte weaponAutoSwitch; + byte ammoAutoSwitch; int weaponOrder[NUMWEAPONS]; byte weaponNextMode; // if true use the weaponOrder for next/previous. float inventoryTimer; // Number of seconds until the invetory auto-hides. diff --git a/doomsday/plugins/jhexen/src/h2_main.c b/doomsday/plugins/jhexen/src/h2_main.c index bd4f671e56..80d3ebe07a 100644 --- a/doomsday/plugins/jhexen/src/h2_main.c +++ b/doomsday/plugins/jhexen/src/h2_main.c @@ -291,6 +291,8 @@ void H2_PreInit(void) cfg.jumpEnabled = cfg.netJumping = true; // true by default in Hexen cfg.jumpPower = 9; cfg.airborneMovement = 1; + cfg.weaponAutoSwitch = 1; // IF BETTER + cfg.ammoAutoSwitch = 0; // never cfg.netMap = 1; cfg.netSkill = sk_medium; cfg.netColor = 8; // Use the default color by default. diff --git a/doomsday/plugins/jhexen/src/hconsole.c b/doomsday/plugins/jhexen/src/hconsole.c index 44c13a1c9e..c5a11a4e10 100644 --- a/doomsday/plugins/jhexen/src/hconsole.c +++ b/doomsday/plugins/jhexen/src/hconsole.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA * * In addition, as a special exception, we, the authors of deng @@ -153,6 +153,7 @@ cvar_t gameCVars[] = { // Weapon switch preferences {"player-autoswitch", 0, CVT_BYTE, &cfg.weaponAutoSwitch, 0, 2}, + {"player-autoswitch-ammo", 0, CVT_BYTE, &cfg.ammoAutoSwitch, 0, 2}, // Weapon Order preferences {"player-weapon-order0", 0, CVT_INT, &cfg.weaponOrder[0], 0, NUMWEAPONS}, diff --git a/doomsday/plugins/wolftc/data/conhelp.txt b/doomsday/plugins/wolftc/data/conhelp.txt index 8ce183aa14..f25fada520 100644 --- a/doomsday/plugins/wolftc/data/conhelp.txt +++ b/doomsday/plugins/wolftc/data/conhelp.txt @@ -789,6 +789,9 @@ desc = Player movement speed while airborne. [player-autoswitch] desc = Change weapon automatically when picking one up. 1=If better 2=Always +[player-autoswitch-ammo] +desc = Change weapon automatically when picking up ammo. 1=If better 2=Always + [player-autoswitch-berserk] desc = Change to fist automatically when picking up berserk pack diff --git a/doomsday/plugins/wolftc/include/d_config.h b/doomsday/plugins/wolftc/include/d_config.h index 7fd3c00ea1..dae4d940b9 100644 --- a/doomsday/plugins/wolftc/include/d_config.h +++ b/doomsday/plugins/wolftc/include/d_config.h @@ -106,6 +106,7 @@ typedef struct jdoom_config_s { byte usePatchReplacement; byte moveCheckZ; // if true, mobjs can move over/under each other. byte weaponAutoSwitch; + byte ammoAutoSwitch; byte berserkAutoSwitch; int weaponOrder[NUMWEAPONS]; byte weaponNextMode; // if true use the weaponOrder for next/previous. diff --git a/doomsday/plugins/wolftc/src/d_console.c b/doomsday/plugins/wolftc/src/d_console.c index 078b58b788..64f45b4ada 100644 --- a/doomsday/plugins/wolftc/src/d_console.c +++ b/doomsday/plugins/wolftc/src/d_console.c @@ -153,6 +153,7 @@ cvar_t gameCVars[] = { // Weapon switch preferences {"player-autoswitch", 0, CVT_BYTE, &cfg.weaponAutoSwitch, 0, 2}, + {"player-autoswitch-ammo", 0, CVT_BYTE, &cfg.ammoAutoSwitch, 0, 2}, {"player-autoswitch-berserk", 0, CVT_BYTE, &cfg.berserkAutoSwitch, 0, 1}, // Weapon Order preferences diff --git a/doomsday/plugins/wolftc/src/d_main.c b/doomsday/plugins/wolftc/src/d_main.c index 6d3543e949..b032707bdc 100644 --- a/doomsday/plugins/wolftc/src/d_main.c +++ b/doomsday/plugins/wolftc/src/d_main.c @@ -409,7 +409,8 @@ void D_PreInit(void) cfg.moveCheckZ = true; cfg.jumpPower = 9; cfg.airborneMovement = 1; - cfg.weaponAutoSwitch = true; + cfg.weaponAutoSwitch = 1; // IF BETTER + cfg.ammoAutoSwitch = 0; // never cfg.secretMsg = true; cfg.netJumping = true; cfg.netEpisode = 1;