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

feat: auto ladder climbing and ledge prompts #3141

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static const std::string flag_DIG_TOOL( "DIG_TOOL" );
static const std::string flag_NO_UNWIELD( "NO_UNWIELD" );
static const std::string flag_RAMP_END( "RAMP_END" );
static const std::string flag_SWIMMABLE( "SWIMMABLE" );
static const std::string flag_LADDER( "LADDER" );

#define dbg(x) DebugLog((x), DC::SDL)

Expand All @@ -108,27 +109,29 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
dest_loc.y = rng( you.posy() - 1, you.posy() + 1 );
dest_loc.z = you.posz();
} else {
dest_loc.x = you.posx() + d.x;
dest_loc.y = you.posy() + d.y;
dest_loc.z = you.posz() + d.z;
dest_loc = you.pos() + d;
}

if( dest_loc == you.pos() ) {
// Well that sure was easy
return true;
}

const bool auto_features = get_option<bool>( "AUTO_FEATURES" );
const bool auto_mine = auto_features && get_option<bool>( "AUTO_MINING" );

bool via_ramp = false;
if( m.has_flag( TFLAG_RAMP_UP, dest_loc ) ) {
dest_loc.z += 1;
via_ramp = true;
} else if( m.has_flag( TFLAG_RAMP_DOWN, dest_loc ) ) {
} else if( m.has_flag( TFLAG_RAMP_DOWN, dest_loc ) ||
( !is_riding && m.has_flag( flag_LADDER, dest_loc + tripoint_below ) ) ) {
dest_loc.z -= 1;
via_ramp = true;
}

if( m.has_flag( TFLAG_MINEABLE, dest_loc ) && g->mostseen == 0 &&
get_option<bool>( "AUTO_FEATURES" ) && get_option<bool>( "AUTO_MINING" ) &&
!m.veh_at( dest_loc ) && !you.is_underwater() && !you.has_effect( effect_stunned ) &&
auto_mine && !m.veh_at( dest_loc ) && !you.is_underwater() && !you.has_effect( effect_stunned ) &&
!is_riding ) {
item &digging_tool = you.primary_weapon();
if( digging_tool.has_flag( flag_DIG_TOOL ) ) {
Expand Down Expand Up @@ -396,6 +399,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
if( g->walk_move( dest_loc, via_ramp ) ) {
return true;
}

if( veh_closed_door ) {
if( !veh1->handle_potential_theft( you ) ) {
return true;
Expand Down Expand Up @@ -434,6 +438,11 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
return true;
}

if( !is_riding && m.has_flag( flag_LADDER, you.pos() ) &&
g->walk_move( dest_loc + tripoint_above ) ) {
return true;
}

// Invalid move
const bool waste_moves = you.is_blind() || you.has_effect( effect_stunned );
if( waste_moves || dest_loc.z != you.posz() ) {
Expand Down
36 changes: 22 additions & 14 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8723,19 +8723,25 @@ bool game::is_dangerous_tile( const tripoint &dest_loc ) const

bool game::prompt_dangerous_tile( const tripoint &dest_loc ) const
{
static const iexamine_function ledge_examine = iexamine_function_from_string( "ledge" );
std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );

if( !harmful_stuff.empty() &&
!query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ) {
return false;
if( harmful_stuff.empty() ) {
return true;
}
if( !harmful_stuff.empty() && u.is_mounted() &&
m.tr_at( dest_loc ).loadid == tr_ledge ) {
add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ),
u.mounted_creature->get_name() );

if( !( harmful_stuff.size() == 1 && m.tr_at( dest_loc ).loadid == tr_ledge ) ) {
return query_yn( _( "Really step into %s?" ), enumerate_as_string( harmful_stuff ) ) ;
}

if( !u.is_mounted() ) {
ledge_examine( u, dest_loc );
return false;
}
return true;

add_msg( m_warning, _( "Your %s refuses to move over that ledge!" ),
u.mounted_creature->get_name() );
return false;
}

std::vector<std::string> game::get_dangerous_tile( const tripoint &dest_loc ) const
Expand Down Expand Up @@ -8896,24 +8902,26 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp )
std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
const auto dangerous_terrain_opt = get_option<std::string>( "DANGEROUS_TERRAIN_WARNING_PROMPT" );
const auto harmful_text = enumerate_as_string( harmful_stuff );
const auto warn_msg = [&]( const char *const msg ) {
add_msg( m_warning, msg, harmful_text );
const auto looks_risky = _( "Stepping into that %1$s looks risky. %2$s" );

const auto warn_msg = [&]( std::string_view action ) {
add_msg( m_warning, looks_risky, harmful_text, action.data() );
};

if( dangerous_terrain_opt == "IGNORE" ) {
warn_msg( _( "Stepping into that %1$s looks risky, but you enter anyway." ) );
warn_msg( _( "But you enter anyway." ) );
} else if( dangerous_terrain_opt == "ALWAYS" && !prompt_dangerous_tile( dest_loc ) ) {
return true;
} else if( dangerous_terrain_opt == "RUNNING" &&
( !u.movement_mode_is( CMM_RUN ) || !prompt_dangerous_tile( dest_loc ) ) ) {
warn_msg( _( "Stepping into that %1$s looks risky. Run into it if you wish to enter anyway." ) );
warn_msg( _( "Run into it if you wish to enter anyway." ) );
return true;
} else if( dangerous_terrain_opt == "CROUCHING" &&
( !u.movement_mode_is( CMM_CROUCH ) || !prompt_dangerous_tile( dest_loc ) ) ) {
warn_msg( _( "Stepping into that %1$s looks risky. Crouch and move into it if you wish to enter anyway." ) );
warn_msg( _( "Crouch and move into it if you wish to enter anyway." ) );
return true;
} else if( dangerous_terrain_opt == "NEVER" && !u.movement_mode_is( CMM_RUN ) ) {
warn_msg( _( "Stepping into that %1$s looks risky. Run into it if you wish to enter anyway." ) );
warn_msg( _( "Run into it if you wish to enter anyway." ) );
return true;
}
}
Expand Down
Loading