Skip to content

Commit 38acf9a

Browse files
authored
Allow mods to easily tune 'Target Hostile Bomb or Bomber' control (#7048)
* Allow mods to easily tune 'Target Hostile Bomb or Bomber' control The `Target Hostile Bomb or Bomber` control targets bombs or bombers, though in mods may want a way to easily set exactly what this control does while still leveraging the utility of the 'bomb' flag for weapons and/or 'bomber' flag for ships (both of which affect AI behavior in various ways). For example, in Solaris, Darius wants a way a way to allow players to only target bombs, while still allowing ships to be classified as as 'bomber'. In this case, the 'only bombs' option can be used. This PR adds a `$Behavior for pressing 'Target Hostile Bomb or Bomber' control:` to allow mods to set the behavior to `default` `only bombs` or `only bombers`. For example, in FotG we want to allow players to target just bombers, as bombs themselves are hard to shoot down (critically though we still want the player to be able to manually target a bomb via 'target object in reticle'. This allows players to prioritize and easily target bombers while allowing skilled pilots to retain the option of manually shooting down bombs if they want an extra challenge. In this case the 'only bomber' option can be used. Tested and works as expected in all cases. * update using cleaned up function * extra alt option for default case * warning cleanup * update default message * whitespace clang * appease clang with brackets
1 parent a0b4ae1 commit 38acf9a

File tree

6 files changed

+113
-60
lines changed

6 files changed

+113
-60
lines changed

code/hud/hudconfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ void hud_config_handle_keypresses(int k)
10261026
{
10271027
switch(k) {
10281028
case KEY_ESC:
1029-
if (escape_key_behavior_in_options == EscapeKeyBehaviorInOptions::SAVE) {
1029+
if (Escape_key_behavior_in_options == EscapeKeyBehaviorInOptions::SAVE) {
10301030
hud_config_commit();
10311031
} else {
10321032
hud_config_cancel();

code/hud/hudtarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,11 +1570,11 @@ void hud_target_hostile_bomb_or_bomber(object* source_obj, int next_flag, bool t
15701570
} else {
15711571
// cycle with wraparound
15721572
int next_index;
1573-
int num_candiates = static_cast<int>(candidates.size());
1573+
int num_candidates = static_cast<int>(candidates.size());
15741574
if (next_flag > 0) {
1575-
next_index = (current_target_index + 1) % num_candiates;
1575+
next_index = (current_target_index + 1) % num_candidates;
15761576
} else {
1577-
next_index = (current_target_index - 1 + num_candiates) % num_candiates;
1577+
next_index = (current_target_index - 1 + num_candidates) % num_candidates;
15781578
}
15791579
target_to_set = candidates[next_index];
15801580
}

code/io/keycontrol.cpp

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,62 +2718,74 @@ int button_function(int n)
27182718
}
27192719

27202720
keyHasBeenUsed = TRUE;
2721-
switch(n) {
2722-
// undefined in multiplayer for clients right now
2723-
// match target speed
2724-
case MATCH_TARGET_SPEED:
2725-
// If player is auto-matching, break auto-match speed
2726-
if ( Player->flags & PLAYER_FLAGS_AUTO_MATCH_SPEED ) {
2727-
Player->flags &= ~PLAYER_FLAGS_AUTO_MATCH_SPEED;
2728-
}
2729-
player_match_target_speed();
2730-
break;
2731-
2732-
// toggle auto-targeting
2733-
case TOGGLE_AUTO_TARGETING:
2734-
hud_gauge_popup_start(HUD_AUTO_TARGET);
2735-
Players[Player_num].flags ^= PLAYER_FLAGS_AUTO_TARGETING;
2736-
if ( Players[Player_num].flags & PLAYER_FLAGS_AUTO_TARGETING ) {
2737-
if (hud_sensors_ok(Player_ship)) {
2738-
hud_target_closest(iff_get_attackee_mask(Player_ship->team), -1, FALSE, TRUE );
2739-
snd_play(gamesnd_get_game_sound(GameSounds::SHIELD_XFER_OK), 1.0f);
2740-
//HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Auto targeting activated", -1));
2741-
} else {
2742-
Players[Player_num].flags ^= PLAYER_FLAGS_AUTO_TARGETING;
2743-
}
2744-
} else {
2721+
switch (n) {
2722+
// undefined in multiplayer for clients right now
2723+
// match target speed
2724+
case MATCH_TARGET_SPEED:
2725+
// If player is auto-matching, break auto-match speed
2726+
if (Player->flags & PLAYER_FLAGS_AUTO_MATCH_SPEED) {
2727+
Player->flags &= ~PLAYER_FLAGS_AUTO_MATCH_SPEED;
2728+
}
2729+
player_match_target_speed();
2730+
break;
2731+
2732+
// toggle auto-targeting
2733+
case TOGGLE_AUTO_TARGETING:
2734+
hud_gauge_popup_start(HUD_AUTO_TARGET);
2735+
Players[Player_num].flags ^= PLAYER_FLAGS_AUTO_TARGETING;
2736+
if (Players[Player_num].flags & PLAYER_FLAGS_AUTO_TARGETING) {
2737+
if (hud_sensors_ok(Player_ship)) {
2738+
hud_target_closest(iff_get_attackee_mask(Player_ship->team), -1, FALSE, TRUE);
27452739
snd_play(gamesnd_get_game_sound(GameSounds::SHIELD_XFER_OK), 1.0f);
2746-
//HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Auto targeting deactivated", -1));
2740+
// HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Auto targeting activated", -1));
2741+
} else {
2742+
Players[Player_num].flags ^= PLAYER_FLAGS_AUTO_TARGETING;
27472743
}
2748-
break;
2744+
} else {
2745+
snd_play(gamesnd_get_game_sound(GameSounds::SHIELD_XFER_OK), 1.0f);
2746+
// HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Auto targeting deactivated", -1));
2747+
}
2748+
break;
27492749

2750-
// target the closest repair ship
2751-
case TARGET_CLOSEST_REPAIR_SHIP:
2752-
// AL: Try to find the closest repair ship coming to repair the player... if no support
2753-
// ships are coming to rearm the player, just try for the closest repair ship
2754-
if ( hud_target_closest_repair_ship(OBJ_INDEX(Player_obj)) == 0 ) {
2755-
if ( hud_target_closest_repair_ship() == 0 ) {
2756-
snd_play(gamesnd_get_game_sound(GameSounds::TARGET_FAIL));
2757-
}
2750+
// target the closest repair ship
2751+
case TARGET_CLOSEST_REPAIR_SHIP:
2752+
// AL: Try to find the closest repair ship coming to repair the player... if no support
2753+
// ships are coming to rearm the player, just try for the closest repair ship
2754+
if (hud_target_closest_repair_ship(OBJ_INDEX(Player_obj)) == 0) {
2755+
if (hud_target_closest_repair_ship() == 0) {
2756+
snd_play(gamesnd_get_game_sound(GameSounds::TARGET_FAIL));
27582757
}
2759-
break;
2758+
}
2759+
break;
27602760

2761-
// stop targeting ship
2762-
case STOP_TARGETING_SHIP:
2763-
hud_cease_targeting(true);
2764-
break;
2761+
// stop targeting ship
2762+
case STOP_TARGETING_SHIP:
2763+
hud_cease_targeting(true);
2764+
break;
27652765

2766-
// stop targeting subsystems on ship
2767-
case STOP_TARGETING_SUBSYSTEM:
2768-
hud_cease_subsystem_targeting();
2769-
break;
2770-
2771-
case TARGET_NEXT_BOMB:
2772-
hud_target_hostile_bomb_or_bomber(Player_obj, 1, true, true, false);
2773-
break;
2766+
// stop targeting subsystems on ship
2767+
case STOP_TARGETING_SUBSYSTEM:
2768+
hud_cease_subsystem_targeting();
2769+
break;
27742770

2775-
case TARGET_PREV_BOMB:
2776-
hud_target_hostile_bomb_or_bomber(Player_obj, 0, true, true, false);
2771+
case TARGET_NEXT_BOMB:
2772+
{
2773+
bool target_bomb = ((Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS) ||
2774+
(Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::ONLY_BOMBS));
2775+
bool target_bomber = ((Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS) ||
2776+
(Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::ONLY_BOMBERS));
2777+
hud_target_hostile_bomb_or_bomber(Player_obj, 1, target_bomb, target_bomber, Target_bomb_or_bomber_use_distance);
2778+
}
2779+
break;
2780+
2781+
case TARGET_PREV_BOMB:
2782+
{
2783+
bool target_bomb = ((Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS) ||
2784+
(Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::ONLY_BOMBS));
2785+
bool target_bomber = ((Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS) ||
2786+
(Target_bomb_or_bomber_behavior == TargetBomborBomberBehaviorOptions::ONLY_BOMBERS));
2787+
hud_target_hostile_bomb_or_bomber(Player_obj, 0, target_bomb, target_bomber, Target_bomb_or_bomber_use_distance);
2788+
}
27772789
break;
27782790

27792791
// wingman message: attack current target

code/menuui/optionsmenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ void options_menu_do_frame(float /*frametime*/)
12811281
break;
12821282

12831283
case KEY_ESC:
1284-
if (escape_key_behavior_in_options == EscapeKeyBehaviorInOptions::SAVE) {
1284+
if (Escape_key_behavior_in_options == EscapeKeyBehaviorInOptions::SAVE) {
12851285
options_accept();
12861286
gamesnd_play_iface(InterfaceSounds::COMMIT_PRESSED);
12871287
gameseq_post_event(GS_EVENT_PREVIOUS_STATE);

code/mod_table/mod_table.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ bool Hide_main_rearm_items_in_comms_gauge;
173173
bool Fix_scripted_velocity;
174174
color Overhead_line_colors[MAX_SHIP_SECONDARY_BANKS];
175175
bool Preload_briefing_icon_models;
176-
EscapeKeyBehaviorInOptions escape_key_behavior_in_options;
176+
EscapeKeyBehaviorInOptions Escape_key_behavior_in_options;
177+
bool Target_bomb_or_bomber_use_distance;
178+
TargetBomborBomberBehaviorOptions Target_bomb_or_bomber_behavior;
177179
bool Fix_asteroid_bounding_box_check;
178180
bool Disable_intro_movie;
179181
bool Show_locked_status_scramble_missions;
@@ -1564,16 +1566,44 @@ void parse_mod_table(const char *filename)
15641566

15651567
if (temp == "default")
15661568
{
1567-
escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::DEFAULT;
1569+
Escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::DEFAULT;
15681570
}
15691571
else if (temp == "save")
15701572
{
1571-
escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::SAVE;
1573+
Escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::SAVE;
15721574
}
15731575
else
15741576
{
15751577
Warning(LOCATION, "$Behavior for pressing Escape key in options menu: Invalid selection. Must be value of 'default' or 'save'. Reverting to 'default' value.");
1576-
escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::DEFAULT;
1578+
Escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::DEFAULT;
1579+
}
1580+
}
1581+
1582+
if (optional_string("$Use closest distance method for 'Target Hostile Bomb or Bomber' control:")) {
1583+
stuff_boolean(&Target_bomb_or_bomber_use_distance);
1584+
}
1585+
1586+
if (optional_string("$Objects targeted with 'Target Hostile Bomb or Bomber' control:")) {
1587+
SCP_string temp;
1588+
stuff_string(temp, F_RAW);
1589+
SCP_tolower(temp);
1590+
1591+
if (temp == "default" || temp == "bombs and bombers")
1592+
{
1593+
Target_bomb_or_bomber_behavior = TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS;
1594+
}
1595+
else if (temp == "only bombs")
1596+
{
1597+
Target_bomb_or_bomber_behavior = TargetBomborBomberBehaviorOptions::ONLY_BOMBS;
1598+
}
1599+
else if (temp == "only bombers")
1600+
{
1601+
Target_bomb_or_bomber_behavior = TargetBomborBomberBehaviorOptions::ONLY_BOMBERS;
1602+
}
1603+
else
1604+
{
1605+
Warning(LOCATION, "$Objects targeted with 'Target Hostile Bomb or Bomber' control: Invalid selection. Must be value of 'default' or 'bombs and bombers' or 'only bombs' or 'only bombers'. Reverting to 'bombs and bombers' value.");
1606+
Target_bomb_or_bomber_behavior = TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS;
15771607
}
15781608
}
15791609

@@ -1845,7 +1875,9 @@ void mod_table_reset()
18451875
gr_init_alphacolor(&Overhead_line_colors[2], 175, 175, 175, 255);
18461876
gr_init_alphacolor(&Overhead_line_colors[3], 100, 100, 100, 255);
18471877
Preload_briefing_icon_models = false;
1848-
escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::DEFAULT;
1878+
Escape_key_behavior_in_options = EscapeKeyBehaviorInOptions::DEFAULT;
1879+
Target_bomb_or_bomber_use_distance = false;
1880+
Target_bomb_or_bomber_behavior = TargetBomborBomberBehaviorOptions::BOMBS_AND_BOMBERS;
18491881
Fix_asteroid_bounding_box_check = false;
18501882
Disable_intro_movie = false;
18511883
Show_locked_status_scramble_missions = false;

code/mod_table/mod_table.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ typedef enum {
2626
SAVE
2727
} EscapeKeyBehaviorInOptions;
2828

29+
// Typedef for 'Target Hostile Bomb or Bomber' control behavior --wookieejedi
30+
typedef enum {
31+
BOMBS_AND_BOMBERS,
32+
ONLY_BOMBS,
33+
ONLY_BOMBERS
34+
} TargetBomborBomberBehaviorOptions;
35+
2936
// And one for splash screens
3037
struct splash_screen {
3138
SCP_string filename;
@@ -188,7 +195,9 @@ extern bool Hide_main_rearm_items_in_comms_gauge;
188195
extern bool Fix_scripted_velocity;
189196
extern color Overhead_line_colors[MAX_SHIP_SECONDARY_BANKS];
190197
extern bool Preload_briefing_icon_models;
191-
extern EscapeKeyBehaviorInOptions escape_key_behavior_in_options;
198+
extern EscapeKeyBehaviorInOptions Escape_key_behavior_in_options;
199+
extern bool Target_bomb_or_bomber_use_distance;
200+
extern TargetBomborBomberBehaviorOptions Target_bomb_or_bomber_behavior;
192201
extern bool Fix_asteroid_bounding_box_check;
193202
extern bool Disable_intro_movie;
194203
extern bool Show_locked_status_scramble_missions;

0 commit comments

Comments
 (0)