From 9139838b67e2e60e8b0ff09ac96cab616883803b Mon Sep 17 00:00:00 2001 From: Ramza13 <52087122+Ramza13@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:49:55 -0500 Subject: [PATCH 1/3] Fix --- src/activity_actor.cpp | 79 ++++++++++++++++++++++++-------- src/activity_actor_definitions.h | 7 ++- src/iuse.cpp | 10 ++-- src/iuse.h | 2 +- src/vehicle.h | 2 + src/vehicle_use.cpp | 9 ++-- 6 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index f32046cf283df..472e34fa111c5 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -1244,7 +1244,22 @@ void hacksaw_activity_actor::start( player_activity &act, Character &/*who*/ ) return; } - const int qual = tool->get_quality( qual_SAW_M ); + int qual; + if( type.has_value() ) { + item veh_tool = item( type.value(), calendar::turn ); + for( const std::pair &quality : type.value()->qualities ) { + if( quality.first == qual_SAW_M ) { + qual = quality.second; + } + } + for( const std::pair &quality : type.value()->charged_qualities ) { + if( quality.first == qual_SAW_M ) { + qual = std::max( qual, quality.second ); + } + } + } else { + qual = tool->get_quality( qual_SAW_M ); + } if( qual < 2 ) { if( !testing ) { debugmsg( "Item %s with 'HACKSAW' use action requires SAW_M quality of at least 2.", @@ -1266,27 +1281,52 @@ void hacksaw_activity_actor::do_turn( player_activity &/*act*/, Character &who ) { std::string method = "HACKSAW"; - if( tool->ammo_sufficient( &who, method ) ) { - int ammo_consumed = tool->ammo_required(); - std::map::const_iterator iter = tool->type->ammo_scale.find( method ); - if( iter != tool->type->ammo_scale.end() ) { - ammo_consumed *= iter->second; - } + if( !veh_pos.has_value() ) { + if( tool->ammo_sufficient( &who, method ) ) { + int ammo_consumed = tool->ammo_required(); + std::map::const_iterator iter = tool->type->ammo_scale.find( method ); + if( iter != tool->type->ammo_scale.end() ) { + ammo_consumed *= iter->second; + } - tool->ammo_consume( ammo_consumed, tool.position(), &who ); - sfx::play_activity_sound( "tool", "hacksaw", sfx::get_heard_volume( target ) ); - if( calendar::once_every( 1_minutes ) ) { - //~ Sound of a metal sawing tool at work! - sounds::sound( target, 15, sounds::sound_t::destructive_activity, _( "grnd grnd grnd" ) ); + tool->ammo_consume( ammo_consumed, tool.position(), &who ); + sfx::play_activity_sound( "tool", "hacksaw", sfx::get_heard_volume( target ) ); + if( calendar::once_every( 1_minutes ) ) { + //~ Sound of a metal sawing tool at work! + sounds::sound( target, 15, sounds::sound_t::destructive_activity, _( "grnd grnd grnd" ) ); + } + } else { + if( who.is_avatar() ) { + who.add_msg_if_player( m_bad, _( "Your %1$s ran out of charges." ), tool->tname() ); + } else { // who.is_npc() + add_msg_if_player_sees( who.pos(), _( "%1$s %2$s ran out of charges." ), who.disp_name( false, + true ), tool->tname() ); + } + who.cancel_activity(); } } else { - if( who.is_avatar() ) { - who.add_msg_if_player( m_bad, _( "Your %1$s ran out of charges." ), tool->tname() ); - } else { // who.is_npc() - add_msg_if_player_sees( who.pos(), _( "%1$s %2$s ran out of charges." ), who.disp_name( false, - true ), tool->tname() ); + map &here = get_map(); + const optional_vpart_position vp = here.veh_at( veh_pos.value() ); + if( !vp ) { + debugmsg( "Lost ACT_HACKSAW vehicle tool" ); + return; + } + vehicle &veh = vp->vehicle(); + if( vehicle::use_vehicle_tool( veh, veh_pos.value(), type.value(), true ) ) { + sfx::play_activity_sound( "tool", "hacksaw", sfx::get_heard_volume( target ) ); + if( calendar::once_every( 1_minutes ) ) { + //~ Sound of a metal sawing tool at work! + sounds::sound( target, 15, sounds::sound_t::destructive_activity, _( "grnd grnd grnd" ) ); + } + } else { + if( who.is_avatar() ) { + who.add_msg_if_player( m_bad, _( "Your %1$s ran out of charges." ), type.value()->nname( 1 ) ); + } else { // who.is_npc() + add_msg_if_player_sees( who.pos(), _( "%1$s %2$s ran out of charges." ), who.disp_name( false, + true ), type.value()->nname( 1 ) ); + } + who.cancel_activity(); } - who.cancel_activity(); } } @@ -1374,7 +1414,8 @@ bool hacksaw_activity_actor::can_resume_with_internal( const activity_actor &oth { const hacksaw_activity_actor &actor = static_cast ( other ); - return actor.target == target && actor.tool.operator == ( tool ); + return actor.target == target && ( ( veh_pos.has_value() && + veh_pos.value() == actor.veh_pos.value_or( tripoint_max ) ) || actor.tool.operator == ( tool ) ); } void hacksaw_activity_actor::serialize( JsonOut &jsout ) const diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index 23e6d04ce4288..b033ec7e88331 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -27,6 +27,7 @@ #include "units.h" #include "units_fwd.h" #include "vehicle.h" +#include "vehicle_selector.h" #include "activity_actor.h" @@ -176,7 +177,8 @@ class hacksaw_activity_actor : public activity_actor public: explicit hacksaw_activity_actor( const tripoint &target, const item_location &tool ) : target( target ), tool( tool ) {}; - + explicit hacksaw_activity_actor( const tripoint &target, const itype_id &type, + const tripoint &veh_pos ) : target( target ), type( type ), veh_pos( veh_pos ) {}; activity_id get_type() const override { return activity_id( "ACT_HACKSAW" ); } @@ -197,7 +199,8 @@ class hacksaw_activity_actor : public activity_actor private: tripoint target; item_location tool; - + std::optional veh_pos; + std::optional type; bool can_resume_with_internal( const activity_actor &other, const Character &/*who*/ ) const override; }; diff --git a/src/iuse.cpp b/src/iuse.cpp index 86d2adbb58e2a..3bce94824fb9f 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -116,6 +116,7 @@ #include "veh_interact.h" #include "veh_type.h" #include "vehicle.h" +#include "vehicle_selector.h" #include "viewer.h" #include "vitamin.h" #include "vpart_position.h" @@ -4913,7 +4914,7 @@ std::optional iuse::oxytorch( Character *p, item *it, const tripoint & ) return std::nullopt; } -std::optional iuse::hacksaw( Character *p, item *it, const tripoint & ) +std::optional iuse::hacksaw( Character *p, item *it, const tripoint &it_pnt ) { if( !p ) { debugmsg( "%s called action hacksaw that requires character but no character is present", @@ -4952,8 +4953,11 @@ std::optional iuse::hacksaw( Character *p, item *it, const tripoint & ) } return std::nullopt; } - - p->assign_activity( hacksaw_activity_actor( pnt, item_location{*p, it} ) ); + if( p->pos() == it_pnt ) { + p->assign_activity( hacksaw_activity_actor( pnt, item_location{ *p, it } ) ); + } else { + p->assign_activity( hacksaw_activity_actor( pnt, it->typeId(), it_pnt ) ); + } return std::nullopt; } diff --git a/src/iuse.h b/src/iuse.h index db040d5a4d204..b049e01881006 100644 --- a/src/iuse.h +++ b/src/iuse.h @@ -134,7 +134,7 @@ std::optional granade_act( Character *, item *, const tripoint & ); std::optional grenade_inc_act( Character *, item *, const tripoint & ); std::optional gun_repair( Character *, item *, const tripoint & ); std::optional gunmod_attach( Character *, item *, const tripoint & ); -std::optional hacksaw( Character *, item *, const tripoint & ); +std::optional hacksaw( Character *, item *, const tripoint &it_pnt ); std::optional hairkit( Character *, item *, const tripoint & ); std::optional hammer( Character *, item *, const tripoint & ); std::optional hand_crank( Character *, item *, const tripoint & ); diff --git a/src/vehicle.h b/src/vehicle.h index 188e0edfd6b73..372181a01e1d7 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -1774,6 +1774,8 @@ class vehicle * @return amount of ammo in the `pseudo_magazine` or 0 */ int prepare_tool( item &tool ) const; + static bool use_vehicle_tool( vehicle &veh, const tripoint &vp_pos, const itype_id &tool_type, + bool no_invoke = false ); /** * if \p tool is not an itype with tool != nullptr this returns { itype::NULL_ID(), 0 } pair * @param tool the item to examine diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index eea4f9b8aad25..adb7d21c85844 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -1774,7 +1774,8 @@ int vehicle::prepare_tool( item &tool ) const return ammo_count; } -static bool use_vehicle_tool( vehicle &veh, const tripoint &vp_pos, const itype_id &tool_type ) +bool vehicle::use_vehicle_tool( vehicle &veh, const tripoint &vp_pos, const itype_id &tool_type, + bool no_invoke ) { item tool( tool_type, calendar::turn ); const auto &[ammo_type_id, avail_ammo_amount] = veh.tool_ammo_available( tool_type ); @@ -1783,7 +1784,9 @@ static bool use_vehicle_tool( vehicle &veh, const tripoint &vp_pos, const itype_ if( tool.ammo_required() > avail_ammo_amount ) { return false; } - get_player_character().invoke_item( &tool ); + if( !no_invoke ) { + get_player_character().invoke_item( &tool, vp_pos ); + } // HACK: Evil hack incoming player_activity &act = get_player_character().activity; @@ -2415,4 +2418,4 @@ void vehicle::interact_with( const tripoint &p, bool with_pickup ) menu.reset(); build_interact_menu( menu, p, with_pickup ); } while( menu.query() ); -} \ No newline at end of file +} From 9d1f584b03f51f515145c86b3749db1bc17f392d Mon Sep 17 00:00:00 2001 From: Ramza13 <52087122+Ramza13@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:53:48 -0500 Subject: [PATCH 2/3] fix --- src/activity_actor_definitions.h | 1 - src/iuse.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index b033ec7e88331..cc6e164cbee29 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -27,7 +27,6 @@ #include "units.h" #include "units_fwd.h" #include "vehicle.h" -#include "vehicle_selector.h" #include "activity_actor.h" diff --git a/src/iuse.cpp b/src/iuse.cpp index 3bce94824fb9f..f6e3a0a02905f 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -116,7 +116,6 @@ #include "veh_interact.h" #include "veh_type.h" #include "vehicle.h" -#include "vehicle_selector.h" #include "viewer.h" #include "vitamin.h" #include "vpart_position.h" From 4ac79e1b347a1c3d10b1646d1ab3ab7533af46dd Mon Sep 17 00:00:00 2001 From: Ramza13 <52087122+Ramza13@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:27:32 -0500 Subject: [PATCH 3/3] Update activity_actor_definitions.h --- src/activity_actor_definitions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/activity_actor_definitions.h b/src/activity_actor_definitions.h index cc6e164cbee29..d164e45a10f5f 100644 --- a/src/activity_actor_definitions.h +++ b/src/activity_actor_definitions.h @@ -198,8 +198,8 @@ class hacksaw_activity_actor : public activity_actor private: tripoint target; item_location tool; - std::optional veh_pos; std::optional type; + std::optional veh_pos; bool can_resume_with_internal( const activity_actor &other, const Character &/*who*/ ) const override; };