From 0fcb6a8b6414847988eef3f8bf654fc3d5270e81 Mon Sep 17 00:00:00 2001 From: Valiant Date: Mon, 28 Oct 2024 13:28:02 +0400 Subject: [PATCH] Allowed throwing items while piloting mechs --- src/avatar_action.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index a06375d090a43..993983bffb3b5 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -952,6 +952,8 @@ void avatar_action::plthrow( avatar &you, item_location loc, add_msg( m_info, _( "You lack the substance to affect anything." ) ); return; } + + bool in_mech = false; if( you.is_mounted() ) { monster *mons = get_player_character().mounted_creature.get(); if( mons->has_flag( mon_flag_RIDEABLE_MECH ) ) { @@ -960,6 +962,7 @@ void avatar_action::plthrow( avatar &you, item_location loc, mons->get_name() ); return; } + in_mech = true; } } @@ -973,10 +976,13 @@ void avatar_action::plthrow( avatar &you, item_location loc, return; } - const ret_val ret = you.can_wield( *loc ); - if( !ret.success() ) { - add_msg( m_info, "%s", ret.c_str() ); - return; + // Bypass check for whether we can wield an item if we're inside a mech + if( !in_mech ) { + const ret_val ret = you.can_wield( *loc ); + if( !ret.success() ) { + add_msg( m_info, "%s", ret.c_str() ); + return; + } } // make a copy and get the original. @@ -1012,9 +1018,12 @@ void avatar_action::plthrow( avatar &you, item_location loc, } } // you must wield the item to throw it - if( !you.is_wielding( *orig ) ) { - if( !you.wield( *orig ) ) { - return; + // if we're in the mech, let's assume the mech wields the item + if( !in_mech ) { + if( !you.is_wielding( *orig ) ) { + if( !you.wield( *orig ) ) { + return; + } } } @@ -1028,7 +1037,7 @@ void avatar_action::plthrow( avatar &you, item_location loc, g->temp_exit_fullscreen(); - item_location weapon = you.get_wielded_item(); + item_location weapon = in_mech ? loc : you.get_wielded_item(); target_handler::trajectory trajectory = target_handler::mode_throw( you, *weapon, blind_throw_from_pos.has_value() ); @@ -1045,7 +1054,11 @@ void avatar_action::plthrow( avatar &you, item_location loc, weapon->mod_charges( -1 ); thrown.charges = 1; } else { - you.remove_weapon(); + if( in_mech ) { + loc.remove_item(); + } else { + you.remove_weapon(); + } } you.throw_item( trajectory.back(), thrown, blind_throw_from_pos ); g->reenter_fullscreen();