From 8dbf8b04abc3b3b4456554fbb1e22778939f9191 Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Sat, 16 May 2015 16:10:09 -0700 Subject: [PATCH 1/4] Add automatic shield equalization Automatic shield equalization is an optional feature that is toggled by pressing Alt-Q (this key combination is remappable). When enabled, damage to shields triggers shield equalization. Automatic shield equalization can be temporarily overriden by manually adjusting shield distribution; to re-enable automatic shield equalization, manually equalize your shields. Automatic shield equalization is subject to the same 2% power penalty per equalization (max 1/second) as manual shield equalization; it is therefore functionally equivalent to mashing Q as fast as possible. --- code/controlconfig/controlsconfig.h | 5 +++ code/controlconfig/controlsconfigcommon.cpp | 1 + code/io/keycontrol.cpp | 38 +++++++++++++++++---- code/io/keycontrol.h | 1 + code/localization/localize.cpp | 2 +- code/mission/missiontraining.cpp | 5 ++- code/playerman/player.h | 2 ++ code/playerman/playercontrol.cpp | 4 +++ code/scripting/lua.cpp | 1 + code/ship/shiphit.cpp | 5 +++ 10 files changed, 55 insertions(+), 9 deletions(-) diff --git a/code/controlconfig/controlsconfig.h b/code/controlconfig/controlsconfig.h index 74a4107c527..14d055f4834 100644 --- a/code/controlconfig/controlsconfig.h +++ b/code/controlconfig/controlsconfig.h @@ -270,6 +270,11 @@ enum IoActionId { //!< ---------------------------- CYCLE_PRIMARY_WEAPON_SEQUENCE =118, //!< cycle num primaries to fire at once + //!< @n + //!< Auto-balance shields + //!< ---------------------- + TOGGLE_AUTO_SHIELD_EQUALIZE =119, //!< toggle automatic shield equalization + /*! * This must always be below the last defined item */ diff --git a/code/controlconfig/controlsconfigcommon.cpp b/code/controlconfig/controlsconfigcommon.cpp index 89dc92c0e74..88496f925c3 100644 --- a/code/controlconfig/controlsconfigcommon.cpp +++ b/code/controlconfig/controlsconfigcommon.cpp @@ -196,6 +196,7 @@ config_item Control_config[CCFG_MAX + 1] = { { KEY_ALTED | KEY_N, -1, COMPUTER_TAB, false, "Cycle Nav Points", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, { KEY_ALTED | KEY_G, -1, SHIP_TAB, false, "Toggle Gliding", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, { KEY_O, -1, WEAPON_TAB, false, "Cycle Primary Weapon Firing Rate", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, + { KEY_ALTED | KEY_Q, -1, COMPUTER_TAB, false, "Toggle Auto Equalize Shields", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, { -1, -1, -1, false, "", CC_TYPE_TRIGGER, -1, -1, 0, false, false } }; diff --git a/code/io/keycontrol.cpp b/code/io/keycontrol.cpp index cd17cf9d665..e77fd82e74f 100644 --- a/code/io/keycontrol.cpp +++ b/code/io/keycontrol.cpp @@ -330,7 +330,9 @@ int Normal_key_set[] = { NAV_CYCLE, TOGGLE_GLIDING, - CYCLE_PRIMARY_WEAPON_SEQUENCE + CYCLE_PRIMARY_WEAPON_SEQUENCE, + + TOGGLE_AUTO_SHIELD_EQUALIZE, }; int Dead_key_set[] = { @@ -394,6 +396,7 @@ int Critical_key_set[] = { SHIELD_XFER_RIGHT, XFER_SHIELD, XFER_LASER, + TOGGLE_AUTO_SHIELD_EQUALIZE, }; int Non_critical_key_set[] = { @@ -465,7 +468,9 @@ int Non_critical_key_set[] = { AUTO_PILOT_TOGGLE, NAV_CYCLE, TOGGLE_GLIDING, - CYCLE_PRIMARY_WEAPON_SEQUENCE + CYCLE_PRIMARY_WEAPON_SEQUENCE, + + TOGGLE_AUTO_SHIELD_EQUALIZE, }; int Ignored_keys[CCFG_MAX]; @@ -2304,11 +2309,6 @@ int button_function(int n) case CYCLE_PREV_PRIMARY: // cycle to previous primary weapon case CYCLE_SECONDARY: // cycle to next secondary weapon case CYCLE_NUM_MISSLES: // cycle number of missiles fired from secondary bank - case SHIELD_EQUALIZE: // equalize shield energy to all quadrants - case SHIELD_XFER_TOP: // transfer shield energy to front - case SHIELD_XFER_BOTTOM: // transfer shield energy to rear - case SHIELD_XFER_LEFT: // transfer shield energy to left - case SHIELD_XFER_RIGHT: // transfer shield energy to right case XFER_SHIELD: // transfer energy to shield from weapons case XFER_LASER: // transfer energy to weapons from shield return button_function_critical(n); @@ -2327,6 +2327,18 @@ int button_function(int n) } return 1; break; + + case SHIELD_EQUALIZE: // equalize shield energy to all quadrants + Player->flags &= ~PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE; + return button_function_critical(n); + + case SHIELD_XFER_TOP: // transfer shield energy to front + case SHIELD_XFER_BOTTOM: // transfer shield energy to rear + case SHIELD_XFER_LEFT: // transfer shield energy to left + case SHIELD_XFER_RIGHT: // transfer shield energy to right + Player->flags |= PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE; + return button_function_critical(n); + } /** @@ -2514,6 +2526,7 @@ int button_function(int n) if (!Sel_NextNav()) gamesnd_play_iface(SND_GENERAL_FAIL); break; + default: keyHasBeenUsed = FALSE; break; @@ -2805,6 +2818,17 @@ int button_function(int n) hud_escort_target_next(); break; + case TOGGLE_AUTO_SHIELD_EQUALIZE: + Players[Player_num].flags ^= PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE; + if (Players[Player_num].flags & PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE) { + Players[Player_num].flags &= ~PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE; + button_function(SHIELD_EQUALIZE); + HUD_printf(XSTR("Auto shield equalization activated", 1638)); + } else { + HUD_printf(XSTR("Auto shield equalization deactivated", 1639)); + } + break; + default: keyHasBeenUsed = FALSE; break; diff --git a/code/io/keycontrol.h b/code/io/keycontrol.h index 618880099b5..701a721595e 100644 --- a/code/io/keycontrol.h +++ b/code/io/keycontrol.h @@ -39,5 +39,6 @@ void process_set_of_keys(int key, int count, int *list); void game_process_pause_key(); void button_strip_noncritical_keys(button_info *bi); +extern int button_function(int n); #endif diff --git a/code/localization/localize.cpp b/code/localization/localize.cpp index 935c3a0a658..a8b0b4906a0 100644 --- a/code/localization/localize.cpp +++ b/code/localization/localize.cpp @@ -57,7 +57,7 @@ int Lcl_english = 1; // the english version (in the code) to a foreign version (in the table). Thus, if you // add a new string to the code, you must assign it a new index. Use the number below for // that index and increase the number below by one. -#define XSTR_SIZE 1638 +#define XSTR_SIZE 1640 // struct to allow for strings.tbl-determined x offset diff --git a/code/mission/missiontraining.cpp b/code/mission/missiontraining.cpp index a70fba4e24e..bad9505c0d9 100644 --- a/code/mission/missiontraining.cpp +++ b/code/mission/missiontraining.cpp @@ -362,8 +362,11 @@ void training_mission_init() // only clear player flags if this is actually a training mission if ( The_mission.game_type & MISSION_TYPE_TRAINING ) { - Player->flags &= ~(PLAYER_FLAGS_MATCH_TARGET | PLAYER_FLAGS_MSG_MODE | PLAYER_FLAGS_AUTO_TARGETING | PLAYER_FLAGS_AUTO_MATCH_SPEED | PLAYER_FLAGS_LINK_PRIMARY | PLAYER_FLAGS_LINK_SECONDARY ); + Player->flags &= ~(PLAYER_FLAGS_MATCH_TARGET | PLAYER_FLAGS_MSG_MODE | PLAYER_FLAGS_AUTO_TARGETING | PLAYER_FLAGS_AUTO_MATCH_SPEED | PLAYER_FLAGS_LINK_PRIMARY | PLAYER_FLAGS_LINK_SECONDARY | PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE ); } + + // never start with auto shield equalization on but overridden + Player->flags &= ~PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE; } void training_mission_page_in() diff --git a/code/playerman/player.h b/code/playerman/player.h index ba4306526a8..59d631bda43 100644 --- a/code/playerman/player.h +++ b/code/playerman/player.h @@ -52,6 +52,8 @@ struct campaign_info; #define PLAYER_FLAGS_KILLED_SELF_UNKNOWN (1<<16) // player died by his own hand #define PLAYER_FLAGS_KILLED_SELF_MISSILES (1<<17) // player died by his own missile #define PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE (1<<18) // player died by his own shockwave +#define PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE (1<<19) // is auto shield equalization on? +#define PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE (1<<20) // is auto shield equalization overridden by manual control? #define PLAYER_KILLED_SELF ( PLAYER_FLAGS_KILLED_SELF_MISSILES | PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE ) diff --git a/code/playerman/playercontrol.cpp b/code/playerman/playercontrol.cpp index 8b8d8d00a64..817ec91807a 100644 --- a/code/playerman/playercontrol.cpp +++ b/code/playerman/playercontrol.cpp @@ -1293,6 +1293,10 @@ void player_save_target_and_weapon_link_prefs() Player->flags &= ~PLAYER_FLAGS_LINK_SECONDARY; } } + + if ( Player->flags & PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE ) { + Player->save_flags |= PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE; + } } /** diff --git a/code/scripting/lua.cpp b/code/scripting/lua.cpp index cdc8b6dcf09..4618f4b21b5 100644 --- a/code/scripting/lua.cpp +++ b/code/scripting/lua.cpp @@ -230,6 +230,7 @@ flag_def_list plr_commands[] = { { "AUTO_PILOT_TOGGLE", AUTO_PILOT_TOGGLE, 3 }, { "NAV_CYCLE", NAV_CYCLE, 3 }, { "TOGGLE_GLIDING", TOGGLE_GLIDING, 3 }, + { "TOGGLE_AUTO_SHIELD_EQUALIZE", TOGGLE_AUTO_SHIELD_EQUALIZE, 3 }, }; int num_plr_commands = sizeof(plr_commands)/sizeof(flag_def_list); diff --git a/code/ship/shiphit.cpp b/code/ship/shiphit.cpp index e17d4204579..fc27fd96e92 100755 --- a/code/ship/shiphit.cpp +++ b/code/ship/shiphit.cpp @@ -25,6 +25,7 @@ #include "hud/hudtarget.h" #include "iff_defs/iff_defs.h" #include "io/joy_ff.h" +#include "io/keycontrol.h" #include "io/timer.h" #include "mission/missionlog.h" #include "mod_table/mod_table.h" @@ -2103,6 +2104,10 @@ static void ship_do_damage(object *ship_objp, object *other_obj, vec3d *hitpos, damage += (piercing_pct * pre_shield); subsystem_damage += (piercing_pct * pre_shield_ss); } + + if (((Player->flags & (PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE | PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE)) == PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE) && (ship_objp == Player_obj)) { + button_function(SHIELD_EQUALIZE); + } } // if shield damage was increased, don't carry over leftover damage at scaled level From 913bb55c7e90a3d84e745465c4b76f701a157312 Mon Sep 17 00:00:00 2001 From: z64555 Date: Thu, 10 Sep 2015 11:26:03 -0500 Subject: [PATCH 2/4] auto-equalize shield toggle, like other energy controls, is a critical control --- code/io/keycontrol.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/io/keycontrol.cpp b/code/io/keycontrol.cpp index e77fd82e74f..815731aab56 100644 --- a/code/io/keycontrol.cpp +++ b/code/io/keycontrol.cpp @@ -469,8 +469,6 @@ int Non_critical_key_set[] = { NAV_CYCLE, TOGGLE_GLIDING, CYCLE_PRIMARY_WEAPON_SEQUENCE, - - TOGGLE_AUTO_SHIELD_EQUALIZE, }; int Ignored_keys[CCFG_MAX]; From eb5edf69a77ac8f90361be7bc11ef8fd458e95d4 Mon Sep 17 00:00:00 2001 From: z64555 Date: Thu, 10 Sep 2015 14:33:15 -0500 Subject: [PATCH 3/4] Disables auto-equalize by default. Allows control_config items to be default disabled inside the hardcode. --- code/controlconfig/controlsconfigcommon.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/controlconfig/controlsconfigcommon.cpp b/code/controlconfig/controlsconfigcommon.cpp index 88496f925c3..d3c42a552fb 100644 --- a/code/controlconfig/controlsconfigcommon.cpp +++ b/code/controlconfig/controlsconfigcommon.cpp @@ -196,7 +196,7 @@ config_item Control_config[CCFG_MAX + 1] = { { KEY_ALTED | KEY_N, -1, COMPUTER_TAB, false, "Cycle Nav Points", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, { KEY_ALTED | KEY_G, -1, SHIP_TAB, false, "Toggle Gliding", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, { KEY_O, -1, WEAPON_TAB, false, "Cycle Primary Weapon Firing Rate", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, - { KEY_ALTED | KEY_Q, -1, COMPUTER_TAB, false, "Toggle Auto Equalize Shields", CC_TYPE_TRIGGER, -1, -1, 0, false, false }, + { KEY_ALTED | KEY_Q, -1, COMPUTER_TAB, false, "Toggle Auto Equalize Shields", CC_TYPE_TRIGGER, -1, -1, 0, true, false }, { -1, -1, -1, false, "", CC_TYPE_TRIGGER, -1, -1, 0, false, false } }; @@ -595,7 +595,6 @@ void control_config_common_load_overrides(); void control_config_common_init() { for (int i=0; i Date: Mon, 14 Sep 2015 10:06:31 -0500 Subject: [PATCH 4/4] adds a few mprintf's to write controlconfigdefaults.tbl debug messages --- code/controlconfig/controlsconfigcommon.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code/controlconfig/controlsconfigcommon.cpp b/code/controlconfig/controlsconfigcommon.cpp index d3c42a552fb..bd4ef5fc75e 100644 --- a/code/controlconfig/controlsconfigcommon.cpp +++ b/code/controlconfig/controlsconfigcommon.cpp @@ -812,8 +812,10 @@ void control_config_common_load_overrides() LoadEnumsIntoMaps(); if (cf_exists_full("controlconfigdefaults.tbl", CF_TYPE_TABLES)) { + mprintf(("Found controlconfigdefaults.tbl\n")); read_file_text("controlconfigdefaults.tbl", CF_TYPE_TABLES); } else { + mprintf(("Didn't find controlconfigdefaults.tbl, using hardcoded values\n")); read_file_text_from_default(defaults_get_file("controlconfigdefaults.tbl")); } @@ -829,8 +831,10 @@ void control_config_common_load_overrides() SCP_string preset_name; if (optional_string("$Name:")) { stuff_string_line(preset_name); + mprintf((" Found preset %s\n", preset_name.c_str())); } else { preset_name = ""; + mprintf((" Found unnamed preset\n")); } Control_config_preset_names.push_back(preset_name); @@ -902,9 +906,13 @@ void control_config_common_load_overrides() if (optional_string("+Disable")) { r_ccConfig.disabled = true; + mprintf((" Deprecated option '+Disable' found. Please use '$Disable: true' instead\n")); + mprintf((" Bind '%s' was disabled\n", r_ccConfig.text)); } + if (optional_string("$Disable:")) { stuff_boolean(&r_ccConfig.disabled); + mprintf((" Bind '%s' was %s\n", r_ccConfig.text, (r_ccConfig.disabled == true) ? "disabled" : "enabled")); } // Nerf the buffer now.