Skip to content

Commit 52eaba2

Browse files
committed
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.
1 parent 1784e88 commit 52eaba2

10 files changed

Lines changed: 55 additions & 9 deletions

File tree

code/controlconfig/controlsconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ enum IoActionId {
270270
//!< ----------------------------
271271
CYCLE_PRIMARY_WEAPON_SEQUENCE =118, //!< cycle num primaries to fire at once
272272

273+
//!< @n
274+
//!< Auto-balance shields
275+
//!< ----------------------
276+
TOGGLE_AUTO_SHIELD_EQUALIZE =119, //!< toggle automatic shield equalization
277+
273278
/*!
274279
* This must always be below the last defined item
275280
*/

code/controlconfig/controlsconfigcommon.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ config_item Control_config[CCFG_MAX + 1] = {
192192
{ KEY_ALTED | KEY_N, -1, COMPUTER_TAB, false, "Cycle Nav Points", CC_TYPE_TRIGGER, -1, -1, 0, false, false },
193193
{ KEY_ALTED | KEY_G, -1, SHIP_TAB, false, "Toggle Gliding", CC_TYPE_TRIGGER, -1, -1, 0, false, false },
194194
{ KEY_O, -1, WEAPON_TAB, false, "Cycle Primary Weapon Firing Rate", CC_TYPE_TRIGGER, -1, -1, 0, false, false },
195+
{ KEY_ALTED | KEY_Q, -1, COMPUTER_TAB, false, "Toggle Auto Equalize Shields", CC_TYPE_TRIGGER, -1, -1, 0, false, false },
195196
{ -1, -1, -1, false, "", CC_TYPE_TRIGGER, -1, -1, 0, false, false }
196197
};
197198

code/io/keycontrol.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ int Normal_key_set[] = {
330330
NAV_CYCLE,
331331

332332
TOGGLE_GLIDING,
333-
CYCLE_PRIMARY_WEAPON_SEQUENCE
333+
CYCLE_PRIMARY_WEAPON_SEQUENCE,
334+
335+
TOGGLE_AUTO_SHIELD_EQUALIZE,
334336
};
335337

336338
int Dead_key_set[] = {
@@ -394,6 +396,7 @@ int Critical_key_set[] = {
394396
SHIELD_XFER_RIGHT,
395397
XFER_SHIELD,
396398
XFER_LASER,
399+
TOGGLE_AUTO_SHIELD_EQUALIZE,
397400
};
398401

399402
int Non_critical_key_set[] = {
@@ -465,7 +468,9 @@ int Non_critical_key_set[] = {
465468
AUTO_PILOT_TOGGLE,
466469
NAV_CYCLE,
467470
TOGGLE_GLIDING,
468-
CYCLE_PRIMARY_WEAPON_SEQUENCE
471+
CYCLE_PRIMARY_WEAPON_SEQUENCE,
472+
473+
TOGGLE_AUTO_SHIELD_EQUALIZE,
469474
};
470475

471476
int Ignored_keys[CCFG_MAX];
@@ -2311,11 +2316,6 @@ int button_function(int n)
23112316
case CYCLE_PREV_PRIMARY: // cycle to previous primary weapon
23122317
case CYCLE_SECONDARY: // cycle to next secondary weapon
23132318
case CYCLE_NUM_MISSLES: // cycle number of missiles fired from secondary bank
2314-
case SHIELD_EQUALIZE: // equalize shield energy to all quadrants
2315-
case SHIELD_XFER_TOP: // transfer shield energy to front
2316-
case SHIELD_XFER_BOTTOM: // transfer shield energy to rear
2317-
case SHIELD_XFER_LEFT: // transfer shield energy to left
2318-
case SHIELD_XFER_RIGHT: // transfer shield energy to right
23192319
case XFER_SHIELD: // transfer energy to shield from weapons
23202320
case XFER_LASER: // transfer energy to weapons from shield
23212321
return button_function_critical(n);
@@ -2334,6 +2334,18 @@ int button_function(int n)
23342334
}
23352335
return 1;
23362336
break;
2337+
2338+
case SHIELD_EQUALIZE: // equalize shield energy to all quadrants
2339+
Player->flags &= ~PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE;
2340+
return button_function_critical(n);
2341+
2342+
case SHIELD_XFER_TOP: // transfer shield energy to front
2343+
case SHIELD_XFER_BOTTOM: // transfer shield energy to rear
2344+
case SHIELD_XFER_LEFT: // transfer shield energy to left
2345+
case SHIELD_XFER_RIGHT: // transfer shield energy to right
2346+
Player->flags |= PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE;
2347+
return button_function_critical(n);
2348+
23372349
}
23382350

23392351
/**
@@ -2521,6 +2533,7 @@ int button_function(int n)
25212533
if (!Sel_NextNav())
25222534
gamesnd_play_iface(SND_GENERAL_FAIL);
25232535
break;
2536+
25242537
default:
25252538
keyHasBeenUsed = FALSE;
25262539
break;
@@ -2812,6 +2825,17 @@ int button_function(int n)
28122825
hud_escort_target_next();
28132826
break;
28142827

2828+
case TOGGLE_AUTO_SHIELD_EQUALIZE:
2829+
Players[Player_num].flags ^= PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE;
2830+
if (Players[Player_num].flags & PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE) {
2831+
Players[Player_num].flags &= ~PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE;
2832+
button_function(SHIELD_EQUALIZE);
2833+
HUD_printf(XSTR("Auto shield equalization activated", 1638));
2834+
} else {
2835+
HUD_printf(XSTR("Auto shield equalization deactivated", 1639));
2836+
}
2837+
break;
2838+
28152839
default:
28162840
keyHasBeenUsed = FALSE;
28172841
break;

code/io/keycontrol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ void process_set_of_keys(int key, int count, int *list);
3939
void game_process_pause_key();
4040
void button_strip_noncritical_keys(button_info *bi);
4141

42+
extern int button_function(int n);
4243

4344
#endif

code/localization/localize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int Lcl_english = 1;
5858
// the english version (in the code) to a foreign version (in the table). Thus, if you
5959
// add a new string to the code, you must assign it a new index. Use the number below for
6060
// that index and increase the number below by one.
61-
#define XSTR_SIZE 1638
61+
#define XSTR_SIZE 1640
6262

6363

6464
// struct to allow for strings.tbl-determined x offset

code/mission/missiontraining.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,11 @@ void training_mission_init()
363363

364364
// only clear player flags if this is actually a training mission
365365
if ( The_mission.game_type & MISSION_TYPE_TRAINING ) {
366-
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 );
366+
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 );
367367
}
368+
369+
// never start with auto shield equalization on but overridden
370+
Player->flags &= ~PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE;
368371
}
369372

370373
void training_mission_page_in()

code/parse/lua.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ flag_def_list plr_commands[] = {
873873
{ "AUTO_PILOT_TOGGLE", AUTO_PILOT_TOGGLE, 3 },
874874
{ "NAV_CYCLE", NAV_CYCLE, 3 },
875875
{ "TOGGLE_GLIDING", TOGGLE_GLIDING, 3 },
876+
{ "TOGGLE_AUTO_SHIELD_EQUALIZE", TOGGLE_AUTO_SHIELD_EQUALIZE, 3 },
876877
};
877878

878879
int num_plr_commands = sizeof(plr_commands)/sizeof(flag_def_list);

code/playerman/player.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ struct campaign_info;
5252
#define PLAYER_FLAGS_KILLED_SELF_UNKNOWN (1<<16) // player died by his own hand
5353
#define PLAYER_FLAGS_KILLED_SELF_MISSILES (1<<17) // player died by his own missile
5454
#define PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE (1<<18) // player died by his own shockwave
55+
#define PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE (1<<19) // is auto shield equalization on?
56+
#define PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE (1<<20) // is auto shield equalization overridden by manual control?
5557

5658
#define PLAYER_KILLED_SELF ( PLAYER_FLAGS_KILLED_SELF_MISSILES | PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE )
5759

code/playerman/playercontrol.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ void player_save_target_and_weapon_link_prefs()
11631163
Player->flags &= ~PLAYER_FLAGS_LINK_SECONDARY;
11641164
}
11651165
}
1166+
1167+
if ( Player->flags & PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE ) {
1168+
Player->save_flags |= PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE;
1169+
}
11661170
}
11671171

11681172
/**

code/ship/shiphit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "parse/parselo.h"
4747
#include "object/objectsnd.h"
4848
#include "mod_table/mod_table.h"
49+
#include "io/keycontrol.h"
4950

5051
//#pragma optimize("", off)
5152
//#pragma auto_inline(off)
@@ -2115,6 +2116,10 @@ static void ship_do_damage(object *ship_objp, object *other_obj, vec3d *hitpos,
21152116
damage += (piercing_pct * pre_shield);
21162117
subsystem_damage += (piercing_pct * pre_shield_ss);
21172118
}
2119+
2120+
if (((Player->flags & (PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE | PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE_OVERRIDE)) == PLAYER_FLAGS_AUTO_SHIELD_EQUALIZE) && (ship_objp == Player_obj)) {
2121+
button_function(SHIELD_EQUALIZE);
2122+
}
21182123
}
21192124

21202125
// if shield damage was increased, don't carry over leftover damage at scaled level

0 commit comments

Comments
 (0)