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

typified a bit of vehicle.h and dependents #77554

Merged
merged 5 commits into from
Nov 10, 2024
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
6 changes: 3 additions & 3 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ static bool vehicle_activity( Character &you, const tripoint_bub_ms &src_loc, in
// so , NPCs can remove the last part on a position, then there is no vehicle there anymore,
// for someone else who stored that position at the start of their activity.
// so we may need to go looking a bit further afield to find it , at activities end.
for( const tripoint &pt : veh->get_points( true ) ) {
for( const tripoint_bub_ms &pt : veh->get_points( true ) ) {
you.activity.coord_set.insert( here.getglobal( pt ).raw() );
}
// values[0]
Expand Down Expand Up @@ -1056,7 +1056,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
// find out if there is a vehicle part here we can remove.
// TODO: fix point types
std::vector<vehicle_part *> parts =
veh->get_parts_at( src_loc.raw(), "", part_status_flag::any );
veh->get_parts_at( src_loc, "", part_status_flag::any );
for( vehicle_part *part_elem : parts ) {
const int vpindex = veh->index_of_part( part_elem, true );
// if part is not on this vehicle, or if its attached to another part that needs to be removed first.
Expand Down Expand Up @@ -1101,7 +1101,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
} else if( act == ACT_VEHICLE_REPAIR ) {
// find out if there is a vehicle part here we can repair.
// TODO: fix point types
std::vector<vehicle_part *> parts = veh->get_parts_at( src_loc.raw(), "", part_status_flag::any );
std::vector<vehicle_part *> parts = veh->get_parts_at( src_loc, "", part_status_flag::any );
for( vehicle_part *part_elem : parts ) {
const vpart_info &vpinfo = part_elem->info();
int vpindex = veh->index_of_part( part_elem, true );
Expand Down
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void avatar::grab( object_type grab_type_new, const tripoint_rel_ms &grab_point_
map &m = get_map();
if( gtype == object_type::VEHICLE ) {
if( const optional_vpart_position ovp = m.veh_at( pos_bub() + gpoint ) ) {
for( const tripoint &target : ovp->vehicle().get_points() ) {
for( const tripoint_bub_ms &target : ovp->vehicle().get_points() ) {
if( erase ) {
memorize_clear_decoration( m.getglobal( target ), /* prefix = */ "vp_" );
}
Expand Down
8 changes: 4 additions & 4 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,12 +1429,12 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
if( g->display_overlay_state( ACTION_DISPLAY_VEHICLE_AI ) ) {
for( const wrapped_vehicle &elem : here.get_vehicles() ) {
const vehicle &veh = *elem.v;
const point veh_pos = veh.global_pos3().xy();
const point_bub_ms veh_pos = veh.pos_bub().xy();
for( const auto &overlay_data : veh.get_debug_overlay_data() ) {
const point pt = veh_pos + std::get<0>( overlay_data );
const point_bub_ms pt = veh_pos + std::get<0>( overlay_data );
const int color = std::get<1>( overlay_data );
const std::string &text = std::get<2>( overlay_data );
overlay_strings.emplace( player_to_screen( pt ),
overlay_strings.emplace( player_to_screen( pt.raw() ),
formatted_text( text, color,
text_alignment::left ) );
}
Expand Down Expand Up @@ -3940,7 +3940,7 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
avatar &you = get_avatar();
if( !veh.forward_velocity() && !veh.player_in_control( you )
&& !( you.get_grab_type() == object_type::VEHICLE
&& veh.get_points().count( ( you.pos_bub() + you.grab_point ).raw() ) )
&& veh.get_points().count( ( you.pos_bub() + you.grab_point ) ) )
&& here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), vd.get_tileset_id(), subtile, rotation );
}
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11106,7 +11106,7 @@ void Character::stagger()
const optional_vpart_position vp_there = here.veh_at( dest );
if( vp_there ) {
vehicle &veh = vp_there->vehicle();
if( veh.enclosed_at( dest.raw() ) ) {
if( veh.enclosed_at( dest ) ) {
blocked = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,8 @@ void construct::done_vehicle( const tripoint_bub_ms &p, Character & )
const item &base = components.front();

veh->name = name;
const int partnum = veh->install_part( point_zero, vpart_from_item( base.typeId() ), item( base ) );
const int partnum = veh->install_part( point_rel_ms_zero, vpart_from_item( base.typeId() ),
item( base ) );
veh->part( partnum ).set_flag( vp_flag::unsalvageable_flag );

// Update the vehicle cache immediately,
Expand Down
8 changes: 4 additions & 4 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ bool Creature::will_be_cramped_in_vehicle_tile( const tripoint_abs_ms &loc ) con
}
if( capacity > 0_ml ) {
// First, we'll try to squeeze in. Open-topped vehicle parts have more room to step over cargo.
if( !veh.enclosed_at( here.bub_from_abs( loc ).raw() ) ) {
if( !veh.enclosed_at( here.bub_from_abs( loc ) ) ) {
free_cargo *= 1.2;
}
const creature_size size = get_size();
Expand Down Expand Up @@ -630,10 +630,10 @@ bool Creature::sees( const tripoint_bub_ms &t, bool is_avatar, int range_mod ) c

// Helper function to check if potential area of effect of a weapon overlaps vehicle
// Maybe TODO: If this is too slow, precalculate a bounding box and clip the tested area to it
static bool overlaps_vehicle( const std::set<tripoint> &veh_area, const tripoint &pos,
static bool overlaps_vehicle( const std::set<tripoint_bub_ms> &veh_area, const tripoint_bub_ms &pos,
const int area )
{
for( const tripoint &tmp : tripoint_range<tripoint>( pos - tripoint( area, area, 0 ),
for( const tripoint_bub_ms &tmp : tripoint_range<tripoint_bub_ms>( pos - tripoint( area, area, 0 ),
pos + tripoint( area - 1, area - 1, 0 ) ) ) {
if( veh_area.count( tmp ) > 0 ) {
return true;
Expand Down Expand Up @@ -775,7 +775,7 @@ Creature *Creature::auto_find_hostile_target( int range, int &boo_hoo, int area
continue; // Handle this late so that boo_hoo++ can happen
}
// Expensive check for proximity to vehicle
if( self_area_iff && overlaps_vehicle( in_veh->get_points(), m->pos(), area ) ) {
if( self_area_iff && overlaps_vehicle( in_veh->get_points(), tripoint_bub_ms( m->pos() ), area ) ) {
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,8 +2716,8 @@ void game::setremoteveh( vehicle *veh )
}

std::stringstream remote_veh_string;
const tripoint vehpos = veh->global_pos3();
remote_veh_string << vehpos.x << ' ' << vehpos.y << ' ' << vehpos.z;
const tripoint_bub_ms vehpos = veh->pos_bub();
remote_veh_string << vehpos.x() << ' ' << vehpos.y() << ' ' << vehpos.z();
u.set_value( "remote_controlling_vehicle", remote_veh_string.str() );
}

Expand Down Expand Up @@ -5576,7 +5576,7 @@ void game::control_vehicle()
{
if( vehicle *remote_veh = remoteveh() ) { // remote controls have priority
for( const vpart_reference &vpr : remote_veh->get_avail_parts( "REMOTE_CONTROLS" ) ) {
remote_veh->interact_with( vpr.pos() );
remote_veh->interact_with( vpr.pos_bub() );
return;
}
}
Expand Down Expand Up @@ -5690,7 +5690,7 @@ void game::control_vehicle()
if( veh ) {
// If we reached here, we gained control of a vehicle.
// Clear the map memory for the area covered by the vehicle to eliminate ghost vehicles.
for( const tripoint &target : veh->get_points() ) {
for( const tripoint_bub_ms &target : veh->get_points() ) {
u.memorize_clear_decoration( m.getglobal( target ), "vp_" );
m.memory_cache_dec_set_dirty( target, true );
}
Expand Down Expand Up @@ -10025,7 +10025,7 @@ void game::reload_weapon( bool try_everything )
// If we make it here and haven't found anything to reload, start looking elsewhere.
const optional_vpart_position ovp = m.veh_at( u.pos_bub() );
if( ovp ) {
const turret_data turret = ovp->vehicle().turret_query( ovp->pos() );
const turret_data turret = ovp->vehicle().turret_query( ovp->pos_bub() );
if( turret.can_reload() ) {
item::reload_option opt = u.select_ammo( turret.base(), true );
if( opt ) {
Expand Down
8 changes: 4 additions & 4 deletions src/grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
if( str_req <= str ) {
if( str_req == max_str_req ) {
//if vehicle has no wheels, make a noise.
sounds::sound( grabbed_vehicle->global_pos3(), str_req * 2, sounds::sound_t::movement,
sounds::sound( grabbed_vehicle->pos_bub(), str_req * 2, sounds::sound_t::movement,
_( "a scraping noise." ), true, "misc", "scraping" );
}
//calculate exertion factor and movement penalty
Expand Down Expand Up @@ -217,7 +217,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
precalc_dir = mdir.dir();
}
grabbed_vehicle->precalc_mounts( 1, precalc_dir, grabbed_vehicle->pivot_point() );
grabbed_vehicle->pos -= grabbed_vehicle->pivot_displacement();
grabbed_vehicle->pos -= grabbed_vehicle->pivot_displacement().raw();

// Grabbed part has to stay at distance 1 to the player
// and in roughly the same direction.
Expand Down Expand Up @@ -257,7 +257,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
const tripoint player_prev = u.pos();
u.setpos( tripoint_zero );
std::vector<veh_collision> colls;
failed = grabbed_vehicle->collision( colls, actual_dir.raw(), true );
failed = grabbed_vehicle->collision( colls, actual_dir, true );
u.setpos( player_prev );
if( !colls.empty() ) {
blocker_name = colls.front().target_name;
Expand Down Expand Up @@ -308,7 +308,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
for( int p : wheel_indices ) {
if( one_in( 2 ) ) {
vehicle_part &vp_wheel = grabbed_vehicle->part( p );
tripoint wheel_p = grabbed_vehicle->global_part_pos3( vp_wheel );
tripoint_bub_ms wheel_p = grabbed_vehicle->bub_part_pos( vp_wheel );
grabbed_vehicle->handle_trap( wheel_p, vp_wheel );
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ static void pldrive( const tripoint &p )
return;
}
}
veh->pldrive( get_avatar(), p.xy(), p.z );
veh->pldrive( get_avatar(), p.x, p.y, p.z );
}

static void pldrive( point d )
Expand Down Expand Up @@ -762,7 +762,7 @@ static void grab()
//solid vehicles can't be grabbed while boarded
const optional_vpart_position vp_boarded = here.veh_at( you.pos_bub() );
if( vp_boarded ) {
const std::set<tripoint> grabbed_veh_points = vp->vehicle().get_points();
const std::set<tripoint_bub_ms> grabbed_veh_points = vp->vehicle().get_points();
if( &vp_boarded->vehicle() == &vp->vehicle() &&
!empty( vp->vehicle().get_avail_parts( VPFLAG_OBSTACLE ) ) ) {
add_msg( m_info, _( "You can't move the %s while you're boarding it." ), veh_name );
Expand Down Expand Up @@ -1767,7 +1767,7 @@ static void fire()
}
// try firing turrets
if( const optional_vpart_position ovp = here.veh_at( you.pos_bub() ) ) {
if( turret_data turret_here = ovp->vehicle().turret_query( you.pos() ) ) {
if( turret_data turret_here = ovp->vehicle().turret_query( you.pos_bub() ) ) {
if( avatar_action::fire_turret_manual( you, here, turret_here ) ) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/handle_liquid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ static void serialize_liquid_source( player_activity &act, const vehicle &veh, c
act.values.push_back( static_cast<int>( liquid_source_type::VEHICLE ) );
act.values.push_back( part_num );
if( part_num != -1 ) {
act.coords.push_back( veh.global_part_pos3( part_num ) );
act.coords.push_back( veh.bub_part_pos( part_num ).raw() );
} else {
act.coords.push_back( veh.global_pos3() );
act.coords.push_back( veh.pos_bub().raw() );
}
act.str_values.push_back( serialize( liquid ) );
}
Expand Down Expand Up @@ -84,7 +84,7 @@ static void serialize_liquid_target( player_activity &act, const vpart_reference
{
act.values.push_back( static_cast<int>( liquid_target_type::VEHICLE ) );
act.values.push_back( 0 ); // dummy
act.coords.push_back( vp.vehicle().global_part_pos3( 0 ) );
act.coords.push_back( vp.vehicle().bub_part_pos( 0 ).raw() );
act.values.push_back( vp.part_index() ); // tank part index
}

Expand Down
3 changes: 2 additions & 1 deletion src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,8 @@ void iexamine::elevator( Character &you, const tripoint_bub_ms &examp )
}

for( vehicle *v : vehs.v ) {
tripoint_bub_ms const p = tripoint_bub_ms( _rotate_point_sm( { v->global_pos3().xy(), movez }, erot,
tripoint_bub_ms const p = tripoint_bub_ms( _rotate_point_sm( { v->pos_bub().xy().raw(), movez},
erot,
sm_orig.raw() ) );
here.displace_vehicle( *v, p - v->pos_bub() );
v->turn( erot * 90_degrees );
Expand Down
12 changes: 6 additions & 6 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13681,12 +13681,12 @@ ret_val<void> item::link_to( vehicle &veh, const point_rel_ms &mount, link_state
}

// Prepare target tripoints for the cable parts that'll be added to the selected/previous vehicles
const std::pair<tripoint, tripoint> prev_part_target = std::make_pair(
( veh.global_square_location() + veh.coord_translate( mount ) ).raw(),
veh.global_square_location().raw() );
const std::pair<tripoint, tripoint> sel_part_target = std::make_pair(
( link().t_abs_pos + prev_veh->coord_translate( link().t_mount ) ).raw(),
link().t_abs_pos.raw() );
const std::pair<tripoint_abs_ms, tripoint_abs_ms> prev_part_target = std::make_pair(
veh.global_square_location() + veh.coord_translate( mount ),
veh.global_square_location() );
const std::pair<tripoint_abs_ms, tripoint_abs_ms> sel_part_target = std::make_pair(
link().t_abs_pos + prev_veh->coord_translate( link().t_mount ),
link().t_abs_pos );

for( const vpart_reference &vpr : prev_veh->get_any_parts( VPFLAG_POWER_TRANSFER ) ) {
if( vpr.part().target.first == prev_part_target.first &&
Expand Down
4 changes: 2 additions & 2 deletions src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class item_location::impl::item_on_vehicle : public item_location::impl
}

tripoint position() const override {
return cur.veh.global_part_pos3( cur.part );
return cur.veh.bub_part_pos( cur.part ).raw();
}

Character *carrier() const override {
Expand Down Expand Up @@ -534,7 +534,7 @@ class item_location::impl::item_on_vehicle : public item_location::impl

item *obj = target();
int mv = ch.item_handling_cost( *obj, true, VEHICLE_HANDLING_PENALTY, qty );
mv += 100 * rl_dist( ch.pos(), cur.veh.global_part_pos3( cur.part ) );
mv += 100 * rl_dist( ch.pos_bub(), cur.veh.bub_part_pos( cur.part ) );

// TODO: handle unpacking costs

Expand Down
8 changes: 4 additions & 4 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7356,7 +7356,7 @@ static vehicle *pickveh( const tripoint &center, bool advanced )

for( wrapped_vehicle &veh : get_map().get_vehicles() ) {
vehicle *&v = veh.v;
if( rl_dist( center, v->global_pos3() ) < 40 &&
if( rl_dist( center, v->pos_bub().raw() ) < 40 &&
v->fuel_left( itype_battery ) > 0 &&
( !empty( v->get_avail_parts( advctrl ) ) ||
( !advanced && !empty( v->get_avail_parts( ctrl ) ) ) ) ) {
Expand All @@ -7366,7 +7366,7 @@ static vehicle *pickveh( const tripoint &center, bool advanced )
std::vector<tripoint> locations;
for( int i = 0; i < static_cast<int>( vehs.size() ); i++ ) {
vehicle *veh = vehs[i];
locations.push_back( veh->global_pos3() );
locations.push_back( veh->pos_bub().raw() );
pmenu.addentry( i, true, MENU_AUTOASSIGN, veh->name );
}

Expand Down Expand Up @@ -7461,9 +7461,9 @@ std::optional<int> iuse::remoteveh( Character *p, item *it, const tripoint &pos
const auto electronics_parts = veh->get_avail_parts( "CTRL_ELECTRONIC" );
// Revert to original behavior if we can't find remote controls.
if( empty( rctrl_parts ) ) {
veh->interact_with( electronics_parts.begin()->pos() );
veh->interact_with( electronics_parts.begin()->pos_bub() );
} else {
veh->interact_with( rctrl_parts.begin()->pos() );
veh->interact_with( rctrl_parts.begin()->pos_bub() );
}
}

Expand Down
Loading
Loading