Skip to content

Commit

Permalink
Set cable traits and cable part mounts immediately to avoid inaccuracies
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamayana committed Jul 14, 2023
1 parent 7590ca4 commit 73ee5a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/mods/TEST_DATA/appliance.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"epower": "0 W",
"//": "Epower for POWER_TRANSFER stuff is how much percentage-wise loss there is in transmission",
"durability": 120,
"description": "A power cord sticking out of an appliance. You need to plug it in a powered grid for the appliance to work properly.",
"description": "A power cord sticking out of an appliance. You need to plug it into a powered grid for the appliance to work properly.",
"item": "test_power_cord",
"flags": [ "NO_INSTALL_HIDDEN", "NO_UNINSTALL", "UNMOUNT_ON_DAMAGE", "POWER_TRANSFER" ],
"variants": [ { "symbols": "{", "symbols_broken": "s" } ]
Expand Down
4 changes: 4 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4822,11 +4822,13 @@ std::optional<int> link_up_actor::link_to_veh_app( Character *p, item &it,
prev_part.target.first = here.getabs( pnt );
prev_part.target.second = target_veh->global_square_location().raw();
prev_veh->install_part( vcoords1, std::move( prev_part ) );
prev_veh->precalc_mounts( 1, prev_veh->pivot_rotation[1], prev_veh->pivot_anchor[1] );

vehicle_part target_part( vpid, item( it ) );
target_part.target.first = here.getabs( prev_veh->mount_to_tripoint( it.link->t_mount ) );
target_part.target.second = prev_veh->global_square_location().raw();
target_veh->install_part( vcoords2, std::move( target_part ) );
target_veh->precalc_mounts( 1, target_veh->pivot_rotation[1], target_veh->pivot_anchor[1] );

if( p->has_item( it ) ) {
//~ %1$s - first vehicle name, %2$s - second vehicle name - %3$s - cable name,
Expand Down Expand Up @@ -4953,11 +4955,13 @@ std::optional<int> link_up_actor::link_tow_cable( Character *p, item &it,
prev_part.target.first = here.getabs( pnt );
prev_part.target.second = target_veh->global_square_location().raw();
prev_veh->install_part( vcoords1, std::move( prev_part ) );
prev_veh->precalc_mounts( 1, prev_veh->pivot_rotation[1], prev_veh->pivot_anchor[1] );

vehicle_part target_part( vpid, item( it ) );
target_part.target.first = here.getabs( prev_veh->mount_to_tripoint( it.link->t_mount ) );
target_part.target.second = prev_veh->global_square_location().raw();
target_veh->install_part( vcoords2, std::move( target_part ) );
target_veh->precalc_mounts( 1, target_veh->pivot_rotation[1], target_veh->pivot_anchor[1] );

if( p->has_item( it ) ) {
//~ %1$s - first vehicle name, %2$s - second vehicle name - %3$s - tow cable name,
Expand Down
3 changes: 3 additions & 0 deletions src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ item vehicle::init_cord( const tripoint &pos )
cord.link->t_state = link_state::vehicle_port;
cord.link->t_veh_safe = get_safe_reference();
cord.link->t_abs_pos = get_map().getglobal( pos );
cord.set_link_traits();

return cord;
}
Expand Down Expand Up @@ -587,12 +588,14 @@ void vehicle::connect( const tripoint &source_pos, const tripoint &target_pos )
source_part.target.first = target_global;
source_part.target.second = target_veh->global_square_location().raw();
source_veh->install_part( vcoords, std::move( source_part ) );
source_veh->precalc_mounts( 1, source_veh->pivot_rotation[1], source_veh->pivot_anchor[1] );

vcoords = target_vp->mount();
vehicle_part target_part( vpid, item( cord ) );
target_part.target.first = cord.link->t_abs_pos.raw();
target_part.target.second = source_veh->global_square_location().raw();
target_veh->install_part( vcoords, std::move( target_part ) );
target_veh->precalc_mounts( 1, target_veh->pivot_rotation[1], target_veh->pivot_anchor[1] );
}

double vehicle::engine_cold_factor( const vehicle_part &vp ) const
Expand Down
6 changes: 5 additions & 1 deletion tests/vehicle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static void connect_power_line( const tripoint &src_pos, const tripoint &dst_pos
cord.link = cata::make_value<item::link_data>();
cord.link->t_state = link_state::vehicle_port;
cord.link->t_abs_pos = here.getglobal( src_pos );
cord.active = true;
cord.set_link_traits();

const optional_vpart_position target_vp = here.veh_at( dst_pos );
const optional_vpart_position source_vp = here.veh_at( src_pos );
Expand All @@ -454,12 +454,14 @@ static void connect_power_line( const tripoint &src_pos, const tripoint &dst_pos
source_part.target.first = target_global;
source_part.target.second = target_veh->global_square_location().raw();
source_veh->install_part( vcoords, std::move( source_part ) );
source_veh->precalc_mounts( 1, source_veh->pivot_rotation[1], source_veh->pivot_anchor[1] );

vcoords = target_vp->mount();
vehicle_part target_part( vpid, item( cord ) );
target_part.target.first = cord.link->t_abs_pos.raw();
target_part.target.second = source_veh->global_square_location().raw();
target_veh->install_part( vcoords, std::move( target_part ) );
target_veh->precalc_mounts( 1, target_veh->pivot_rotation[1], target_veh->pivot_anchor[1] );
}

TEST_CASE( "power_cable_stretch_disconnect" )
Expand Down Expand Up @@ -492,6 +494,7 @@ TEST_CASE( "power_cable_stretch_disconnect" )
REQUIRE( app2.part_count() == 2 );

REQUIRE( app1.part( 1 ).get_base().type->maximum_charges() == 3 );
REQUIRE( app1.part( 1 ).get_base().max_link_length() == 3 );

const int max_dist = app1.part( 1 ).get_base().type->maximum_charges();

Expand Down Expand Up @@ -532,6 +535,7 @@ TEST_CASE( "power_cable_stretch_disconnect" )
REQUIRE( app2.part_count() == 2 );

REQUIRE( app1.part( 1 ).get_base().type->maximum_charges() == 10 );
REQUIRE( app1.part( 1 ).get_base().max_link_length() == 10 );

const int max_dist = app1.part( 1 ).get_base().type->maximum_charges();

Expand Down

0 comments on commit 73ee5a9

Please sign in to comment.