Skip to content

Commit

Permalink
made more vehicle stuff map aware
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed Feb 5, 2025
1 parent 6882f8b commit 8bc13fb
Show file tree
Hide file tree
Showing 43 changed files with 386 additions and 364 deletions.
10 changes: 5 additions & 5 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ void hacksaw_activity_actor::do_turn( player_activity &/*act*/, Character &who )
return;
}
vehicle &veh = vp->vehicle();
if( vehicle::use_vehicle_tool( veh, veh_pos.value(), type.value(), true ) ) {
if( vehicle::use_vehicle_tool( veh, &here, 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!
Expand Down Expand Up @@ -2597,7 +2597,7 @@ void lockpick_activity_actor::finish( player_activity &act, Character &who )

if( veh ) {
std::vector<vehicle_part *> parts_at_target = veh->vehicle().get_parts_at(
target, "LOCKABLE_DOOR", part_status_flag::available );
&here, target, "LOCKABLE_DOOR", part_status_flag::available );
if( !parts_at_target.empty() ) {
locked_part = veh->vehicle().next_part_to_unlock(
veh->vehicle().index_of_part( parts_at_target.front() ) );
Expand Down Expand Up @@ -8025,14 +8025,14 @@ bool vehicle_folding_activity_actor::fold_vehicle( Character &p, bool check_only
for( const vpart_reference &vpr : veh.get_any_parts( VPFLAG_CARGO ) ) {
vehicle_stack cargo = vpr.items();
for( const item &elem : cargo ) {
here.add_item_or_charges( veh.pos_bub(), elem );
here.add_item_or_charges( veh.pos_bub( &here ), elem );
}
cargo.clear();
}

veh.unboard_all();
p.add_msg_if_player( _( "You fold the %s." ), veh.name );
here.add_item_or_charges( veh.pos_bub(), veh.get_folded_item() );
here.add_item_or_charges( veh.pos_bub( &here ), veh.get_folded_item() );
here.destroy_vehicle( &veh );

return true;
Expand Down Expand Up @@ -8127,7 +8127,7 @@ bool vehicle_unfolding_activity_actor::unfold_vehicle( Character &p, bool check_
if( vp.info().location != "structure" ) {
continue;
}
if( invalid_pos( vp.pos_bub() ) ) {
if( invalid_pos( vp.pos_bub( &here ) ) ) {
p.add_msg_if_player( m_info, _( "There's no room to unfold the %s." ), it.tname() );
here.destroy_vehicle( veh );
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
if( act == ACT_VEHICLE_DECONSTRUCTION ) {
// find out if there is a vehicle part here we can remove.
std::vector<vehicle_part *> parts =
veh->get_parts_at( src_loc, "", part_status_flag::any );
veh->get_parts_at( &here, 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.
std::vector<vehicle_part *> parts = veh->get_parts_at( src_loc, "", part_status_flag::any );
std::vector<vehicle_part *> parts = veh->get_parts_at( &here, 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/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms &center, int wid
if( g->display_overlay_state( ACTION_DISPLAY_VEHICLE_AI ) ) {
for( const wrapped_vehicle &elem : here.get_vehicles() ) {
const vehicle &veh = *elem.v;
const point_bub_ms veh_pos = veh.pos_bub().xy();
const point_bub_ms veh_pos = veh.pos_bub( &here ).xy();
for( const auto &overlay_data : veh.get_debug_overlay_data() ) {
const point_bub_ms pt = veh_pos + std::get<0>( overlay_data );
const int color = std::get<1>( overlay_data );
Expand Down
2 changes: 1 addition & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ bool Creature::will_be_cramped_in_vehicle_tile( const tripoint_abs_ms &loc ) con
vehicle &veh = vp_there->vehicle();

std::vector<vehicle_part *> cargo_parts;
cargo_parts = veh.get_parts_at( here.get_bub( loc ), "CARGO", part_status_flag::any );
cargo_parts = veh.get_parts_at( loc, "CARGO", part_status_flag::any );

units::volume capacity = 0_ml;
units::volume free_cargo = 0_ml;
Expand Down
4 changes: 2 additions & 2 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3733,7 +3733,7 @@ static void vehicle_export()
{
map &here = get_map();

if( optional_vpart_position ovp = get_map().veh_at( get_avatar().pos_bub() ) ) {
if( optional_vpart_position ovp = here.veh_at( get_avatar().pos_abs() ) ) {
cata_path export_dir{ cata_path::root_path::user, "export_dir" };
assure_dir_exist( export_dir );
const std::string text = string_input_popup()
Expand All @@ -3744,7 +3744,7 @@ static void vehicle_export()
try {
write_to_file( veh_path, [&]( std::ostream & fout ) {
JsonOut jsout( fout );
ovp->vehicle().refresh( &here );
ovp->vehicle().refresh( );
vehicle_prototype::save_vehicle_as_prototype( ovp->vehicle(), jsout );
} );
} catch( const std::exception &err ) {
Expand Down
18 changes: 12 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ bool game::start_game()
std::string search = std::string( "helicopter" );
if( name.find( search ) != std::string::npos ) {
for( const vpart_reference &vp : v.v->get_any_parts( VPFLAG_CONTROLS ) ) {
const tripoint_bub_ms pos = vp.pos_bub();
const tripoint_abs_ms pos = vp.pos_abs();
u.setpos( pos );

// Delete the items that would have spawned here from a "corpse"
Expand Down Expand Up @@ -2831,6 +2831,8 @@ vehicle *game::remoteveh()

void game::setremoteveh( vehicle *veh )
{
map &here = get_map();

remoteveh_cache_time = calendar::turn;
remoteveh_cache = veh;
if( veh != nullptr && !u.has_active_bionic( bio_remote ) &&
Expand All @@ -2845,7 +2847,7 @@ void game::setremoteveh( vehicle *veh )
}

std::stringstream remote_veh_string;
const tripoint_bub_ms vehpos = veh->pos_bub();
const tripoint_bub_ms vehpos = veh->pos_bub( &here );
remote_veh_string << vehpos.x() << ' ' << vehpos.y() << ' ' << vehpos.z();
u.set_value( "remote_controlling_vehicle", remote_veh_string.str() );
}
Expand Down Expand Up @@ -5822,9 +5824,11 @@ void game::moving_vehicle_dismount( const tripoint_bub_ms &dest_loc )

void game::control_vehicle()
{
map &here = get_map();

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_bub() );
remote_veh->interact_with( vpr.pos_bub( &here ) );
return;
}
}
Expand Down Expand Up @@ -10314,6 +10318,8 @@ void game::reload_wielded( bool prompt )

void game::reload_weapon( bool try_everything )
{
map &here = get_map();

// As a special streamlined activity, hitting reload repeatedly should:
// Reload wielded gun
// First reload a magazine if necessary.
Expand Down Expand Up @@ -10368,9 +10374,9 @@ void game::reload_weapon( bool try_everything )
return;
}
// 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() );
const optional_vpart_position ovp = m.veh_at( u.pos_abs() );
if( ovp ) {
const turret_data turret = ovp->vehicle().turret_query( ovp->pos_bub() );
const turret_data turret = ovp->vehicle().turret_query( ovp->pos_bub( &here ) );
if( turret.can_reload() ) {
item::reload_option opt = u.select_ammo( turret.base(), true );
if( opt ) {
Expand Down Expand Up @@ -11154,7 +11160,7 @@ bool game::walk_move( const tripoint_bub_ms &dest_loc, const bool via_ramp,

if( grabbed_vehicle ) {
// Vehicle might be at different z level than the grabbed part.
u.grab_point.z() = vp_grab->pos_bub().z() - u.posz();
u.grab_point.z() = vp_grab->pos_abs().z() - u.posz();
}

if( pulling ) {
Expand Down
2 changes: 1 addition & 1 deletion src/grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
if( one_in( 2 ) ) {
vehicle_part &vp_wheel = grabbed_vehicle->part( p );
tripoint_bub_ms wheel_p = grabbed_vehicle->bub_part_pos( &here, vp_wheel );
grabbed_vehicle->handle_trap( wheel_p, vp_wheel );
grabbed_vehicle->handle_trap( &m, wheel_p, vp_wheel );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,10 +1565,10 @@ void iexamine::elevator( Character &you, const tripoint_bub_ms &examp )
}

for( vehicle *v : vehs.v ) {
tripoint_bub_ms const p = _rotate_point_sm( { v->pos_bub().xy(), movez},
tripoint_bub_ms const p = _rotate_point_sm( { v->pos_bub( &here ).xy(), movez},
erot,
sm_orig );
here.displace_vehicle( *v, p - v->pos_bub() );
here.displace_vehicle( *v, p - v->pos_bub( &here ) );
v->turn( erot * 90_degrees );
v->face = tileray( v->turn_dir );
v->precalc_mounts( 0, v->turn_dir, v->pivot_anchor[0] );
Expand Down Expand Up @@ -2064,7 +2064,7 @@ void iexamine::locked_object( Character &you, const tripoint_bub_ms &examp )
// Check if the locked thing is a lockable door part.
if( veh ) {
std::vector<vehicle_part *> parts_at_target = veh->vehicle().get_parts_at(
examp, "LOCKABLE_DOOR", part_status_flag::available );
&here, examp, "LOCKABLE_DOOR", part_status_flag::available );
if( !parts_at_target.empty() ) {
locked_part = veh->vehicle().next_part_to_unlock(
veh->vehicle().index_of_part( parts_at_target.front() ) );
Expand Down Expand Up @@ -2133,7 +2133,7 @@ void iexamine::locked_object_pickable( Character &you, const tripoint_bub_ms &ex

if( veh ) {
const std::vector<vehicle_part *> parts_at_target = veh->vehicle().get_parts_at(
examp, "LOCKABLE_DOOR", part_status_flag::available );
&here, examp, "LOCKABLE_DOOR", part_status_flag::available );
if( !parts_at_target.empty() ) {
locked_part = veh->vehicle().next_part_to_unlock(
veh->vehicle().index_of_part( parts_at_target.front() ) );
Expand Down
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14426,8 +14426,8 @@ bool item::process_link( map &here, Character *carrier, const tripoint_bub_ms &p
link().last_processed = calendar::turn;

// Set the new absolute position to the vehicle's origin.
tripoint_bub_ms t_veh_bub_pos = t_veh->pos_bub();
tripoint_abs_ms new_t_abs_pos = here.get_abs( t_veh_bub_pos );
tripoint_abs_ms new_t_abs_pos = t_veh->pos_abs();;
tripoint_bub_ms t_veh_bub_pos = here.get_bub( new_t_abs_pos );;
if( link().t_abs_pos != new_t_abs_pos ) {
link().t_abs_pos = new_t_abs_pos;
length_check_needed = true;
Expand Down
2 changes: 1 addition & 1 deletion src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class item_location::impl::item_on_vehicle : public item_location::impl
debugmsg( "item in vehicle part without cargo storage" );
}
if( ch ) {
res += " " + direction_suffix( ch->pos_bub(), part_pos.pos_bub() );
res += " " + direction_suffix( ch->pos_abs(), part_pos.pos_abs() );
}
return res;
}
Expand Down
13 changes: 8 additions & 5 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7306,15 +7306,16 @@ static bool hackveh( Character &p, item &it, vehicle &veh )

static vehicle *pickveh( const tripoint_bub_ms &center, bool advanced )
{
map &here = get_map();
static const std::string ctrl = "CTRL_ELECTRONIC";
static const std::string advctrl = "REMOTE_CONTROLS";
uilist pmenu;
pmenu.title = _( "Select vehicle to access" );
std::vector< vehicle * > vehs;

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

Expand Down Expand Up @@ -7371,6 +7372,8 @@ std::optional<int> iuse::remoteveh_tick( Character *p, item *it, const tripoint_

std::optional<int> iuse::remoteveh( Character *p, item *it, const tripoint_bub_ms &pos )
{
map &here = get_map();

vehicle *remote = g->remoteveh();

bool controlling = it->active && remote != nullptr;
Expand Down Expand Up @@ -7419,9 +7422,9 @@ std::optional<int> iuse::remoteveh( Character *p, item *it, const tripoint_bub_m
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_bub() );
veh->interact_with( electronics_parts.begin()->pos_bub( &here ) );
} else {
veh->interact_with( rctrl_parts.begin()->pos_bub() );
veh->interact_with( rctrl_parts.begin()->pos_bub( &here ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void map::generate_lightmap( const int zlev )
}

for( const vpart_reference &vpr : v->get_any_parts( VPFLAG_CARGO ) ) {
const tripoint_bub_ms pos = vpr.pos_bub();
const tripoint_bub_ms pos = vpr.pos_bub( this );
if( !inbounds( pos ) || vpr.info().has_flag( "COVERED" ) ) {
continue;
}
Expand Down Expand Up @@ -1097,8 +1097,8 @@ void map::build_seen_cache( const tripoint_bub_ms &origin, const int target_z, i
if( vp.part().removed || vp.part().is_broken() || !vp.info().has_flag( VPFLAG_EXTENDS_VISION ) ) {
continue;
}
const tripoint_bub_ms mirror_pos = vp.pos_bub();
if( rl_dist( origin, vp.pos_bub() ) > extension_range ) {
const tripoint_bub_ms mirror_pos = vp.pos_bub( this );
if( rl_dist( origin, vp.pos_bub( this ) ) > extension_range ) {
continue;
}
// We can utilize the current state of the seen cache to determine
Expand Down
9 changes: 9 additions & 0 deletions src/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,15 @@ std::string direction_suffix( const tripoint_bub_ms &p, const tripoint_bub_ms &q
return string_format( "%d%s", dist, trim( direction_name_short( direction_from( p, q ) ) ) );
}

std::string direction_suffix( const tripoint_abs_ms &p, const tripoint_abs_ms &q )
{
int dist = square_dist( p, q );
if( dist <= 0 ) {
return std::string();
}
return string_format( "%d%s", dist, trim( direction_name_short( direction_from( p, q ) ) ) );
}

// Cardinals are cardinals. Result is cardinal and adjacent sub-cardinals.
// Sub-Cardinals are sub-cardinals && abs(x) == abs(y). Result is sub-cardinal and adjacent cardinals.
// Sub-sub-cardinals are direction && abs(x) > abs(y) or vice versa.
Expand Down
1 change: 1 addition & 0 deletions src/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ std::string direction_arrow( direction dir );

/* Get suffix describing vector from p to q (e.g. 1NW, 2SE) or empty string if p == q */
std::string direction_suffix( const tripoint_bub_ms &p, const tripoint_bub_ms &q );
std::string direction_suffix( const tripoint_abs_ms &p, const tripoint_abs_ms &q );

/**
* The actual Bresenham algorithm in 2D and 3D, everything else should call these
Expand Down
Loading

0 comments on commit 8bc13fb

Please sign in to comment.