Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adds new options to allow auto ignoring sounds and hostile creatures based on safe mode #35983

Closed
wants to merge 15 commits into from
27 changes: 22 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ bool game::do_turn()
if( hostile_critter != nullptr ) {
cancel_activity_or_ignore_query( distraction_type::hostile_spotted,
string_format( _( "The %s is dangerously close!" ),
hostile_critter->get_name() ) );
hostile_critter->get_name() ), -1 );
}
}

Expand Down Expand Up @@ -1687,8 +1687,17 @@ static bool cancel_auto_move( player &p, const std::string &text )
return false;
}

bool game::cancel_activity_or_ignore_query( const distraction_type type, const std::string &text )
bool game::cancel_activity_or_ignore_query( const distraction_type type, const std::string &text,
int distance /*=0*/ )
{
if( ( type == distraction_type::noise || type == distraction_type::hostile_spotted ) &&
( distance >= get_option<int>( "AUTOIGNOREDISTANCE" ) )
&& ( get_option<std::string>( "AUTOIGNOREMODE" ) == "ALWAYS" ||
( get_option<std::string>( "AUTOIGNOREMODE" ) == "SAFEON" && g->safe_mode ) ||
( get_option<std::string>( "AUTOIGNOREMODE" ) == "SAFEOFF" && !g->safe_mode )
) ) {
return false;
}
if( u.has_distant_destination() ) {
if( cancel_auto_move( u, text ) ) {
return true;
Expand Down Expand Up @@ -3844,6 +3853,7 @@ void game::mon_info( const catacurses::window &w, int hor_padding )
// @todo change current_turn to time_point
const int current_turn = to_turns<int>( calendar::turn - calendar::turn_zero );
const int sm_ignored_turns = get_option<int>( "SAFEMODEIGNORETURNS" );
int distance = -1;

for( auto &c : u.get_visible_creatures( MAPSIZE_X ) ) {
const auto m = dynamic_cast<monster *>( c );
Expand Down Expand Up @@ -3913,6 +3923,9 @@ void game::mon_info( const catacurses::window &w, int hor_padding )

const monster_attitude matt = critter.attitude( &u );
const int mon_dist = rl_dist( u.pos(), critter.pos() );
if( mon_dist < distance || distance == -1 ) {
distance = mon_dist;
}
safemode_state = get_safemode().check_monster( critter.name(), critter.attitude_to( u ), mon_dist );

if( ( !safemode_empty && safemode_state == RULE_BLACKLISTED ) || ( safemode_empty &&
Expand Down Expand Up @@ -3949,6 +3962,9 @@ void game::mon_info( const catacurses::window &w, int hor_padding )
//Safe mode NPC check

const int npc_dist = rl_dist( u.pos(), p->pos() );
if( npc_dist < distance || distance == -1 ) {
distance = npc_dist;
}
safemode_state = get_safemode().check_monster( get_safemode().npc_type_name(), p->attitude_to( u ),
npc_dist );

Expand All @@ -3967,7 +3983,7 @@ void game::mon_info( const catacurses::window &w, int hor_padding )
if( !new_seen_mon.empty() ) {
monster &critter = *new_seen_mon.back();
cancel_activity_or_ignore_query( distraction_type::hostile_spotted,
string_format( _( "%s spotted!" ), critter.name() ) );
string_format( _( "%s spotted!" ), critter.name() ), distance );
if( u.has_trait( trait_id( "M_DEFENDER" ) ) && critter.type->in_species( PLANT ) ) {
add_msg( m_warning, _( "We have detected a %s - an enemy of the Mycus!" ), critter.name() );
if( !u.has_effect( effect_adrenaline_mycus ) ) {
Expand All @@ -3982,10 +3998,11 @@ void game::mon_info( const catacurses::window &w, int hor_padding )
} else {
//Hostile NPC
cancel_activity_or_ignore_query( distraction_type::hostile_spotted,
_( "Hostile survivor spotted!" ) );
_( "Hostile survivor spotted!" ), distance );
}
} else {
cancel_activity_or_ignore_query( distraction_type::hostile_spotted, _( "Monsters spotted!" ) );
cancel_activity_or_ignore_query( distraction_type::hostile_spotted, _( "Monsters spotted!" ),
distance );
}
turnssincelastmon = 0;
if( safe_mode == SAFE_MODE_ON ) {
Expand Down
3 changes: 2 additions & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ class game
bool cancel_activity_query( const std::string &text );
/** Asks if the player wants to cancel their activity and if so cancels it. Additionally checks
* if the player wants to ignore further distractions. */
bool cancel_activity_or_ignore_query( distraction_type type, const std::string &text );
bool cancel_activity_or_ignore_query( distraction_type type, const std::string &text,
int distance = 0 );
/** Handles players exiting from moving vehicles. */
void moving_vehicle_dismount( const tripoint &dest_loc );

Expand Down
15 changes: 15 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,21 @@ void options_manager::add_options_general()

mOptionsSort["general"]++;

add( "AUTOIGNOREMODE", "general", translate_marker( "Auto ignore sounds/hostiles mode" ),
translate_marker( "While auto ignore is active you will not be interrupted by sounds or spotted hostiles. Always: Auto ignore will always be active. SafeOn: Auto ignore will be active while safe mode is on. SafeOff: Auto ignore will be active while safe mode is off. Never: Auto ignore will never be active." ),
Ramza13 marked this conversation as resolved.
Show resolved Hide resolved
{ { "ALWAYS", translate_marker( "Always" ) }, { "SAFEON", translate_marker( "SafeOn" ) }, { "SAFEOFF", translate_marker( "SafeOff" ) }, { "NEVER", translate_marker( "Never" ) } },
"NEVER"
);

add( "AUTOIGNOREDISTANCE", "general", translate_marker( "Auto ignore starting distance" ),
translate_marker( "Only sounds/hostiles this distance and further away will be auto ignored. Each Z Level counts as 10 horizontal distance." ),
Ramza13 marked this conversation as resolved.
Show resolved Hide resolved
0, 30, 5
);

get_option( "AUTOIGNOREDISTANCE" ).setPrerequisites( "AUTOIGNOREMODE", { "ALWAYS", "SAFEON", "SAFEOFF" } );

mOptionsSort["general"]++;

add( "TURN_DURATION", "general", translate_marker( "Realtime turn progression" ),
translate_marker( "If enabled, monsters will take periodic gameplay turns. This value is the delay between each turn, in seconds. Works best with Safe Mode disabled. 0 = disabled." ),
0.0, 10.0, 0.0, 0.05
Expand Down
4 changes: 2 additions & 2 deletions src/player_hardcoded_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void player::hardcoded_effects( effect &it )
g->place_critter_at( spawn_details.name, dest );
if( g->u.sees( dest ) ) {
g->cancel_activity_or_ignore_query( distraction_type::hostile_spotted,
_( "A monster appears nearby!" ) );
_( "A monster appears nearby!" ), -1 );
add_msg_if_player( m_warning, _( "A portal opens nearby, and a monster crawls through!" ) );
}
it.mult_duration( .25 );
Expand Down Expand Up @@ -671,7 +671,7 @@ void player::hardcoded_effects( effect &it )
g->place_critter_at( spawn_details.name, dest );
if( g->u.sees( dest ) ) {
g->cancel_activity_or_ignore_query( distraction_type::hostile_spotted,
_( "A monster appears nearby!" ) );
_( "A monster appears nearby!" ), -1 );
add_msg( m_warning, _( "A portal opens nearby, and a monster crawls through!" ) );
}
if( one_in( 2 ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/sounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void sounds::process_sound_markers( player *p )
if( !sound.ambient && ( pos != p->pos() ) && !g->m.pl_sees( pos, distance_to_sound ) ) {
if( !p->activity.is_distraction_ignored( distraction_type::noise ) ) {
const std::string query = string_format( _( "Heard %s!" ), description );
g->cancel_activity_or_ignore_query( distraction_type::noise, query );
g->cancel_activity_or_ignore_query( distraction_type::noise, query, distance_to_sound );
}
}

Expand Down