Skip to content

Commit

Permalink
vehicle position -> absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed Feb 3, 2025
1 parent e655016 commit d861e9a
Show file tree
Hide file tree
Showing 29 changed files with 288 additions and 200 deletions.
11 changes: 7 additions & 4 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,9 @@ bikerack_racking_activity_actor::bikerack_racking_activity_actor( const vehicle
const vehicle &racked_vehicle, const std::vector<int> &racks )
: racks( racks )
{
parent_vehicle_pos = parent_vehicle.bub_part_pos( 0 );
racked_vehicle_pos = racked_vehicle.bub_part_pos( 0 );
map &here = get_map();
parent_vehicle_pos = parent_vehicle.bub_part_pos( &here, 0 );
racked_vehicle_pos = racked_vehicle.bub_part_pos( &here, 0 );
}

void bikerack_racking_activity_actor::start( player_activity &act, Character & )
Expand Down Expand Up @@ -1582,7 +1583,8 @@ bikerack_unracking_activity_actor::bikerack_unracking_activity_actor( const vehi
const std::vector<int> &parts, const std::vector<int> &racks )
: parts( parts ), racks( racks )
{
parent_vehicle_pos = parent_vehicle.bub_part_pos( 0 );
map &here = get_map();
parent_vehicle_pos = parent_vehicle.bub_part_pos( &here, 0 );
}

void bikerack_unracking_activity_actor::start( player_activity &act, Character & )
Expand Down Expand Up @@ -8008,8 +8010,9 @@ bool vehicle_folding_activity_actor::fold_vehicle( Character &p, bool check_only

vehicle_folding_activity_actor::vehicle_folding_activity_actor( const vehicle &target )
{
map &here = get_map();
folding_time = target.folding_time();
target_pos = target.bub_part_pos( 0 );
target_pos = target.bub_part_pos( &here, 0 );
}

void vehicle_folding_activity_actor::start( player_activity &act, Character &p )
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 @@ -219,14 +219,14 @@ static bool handle_spillable_contents( Character &c, item &it, map &m )
static void put_into_vehicle( Character &c, item_drop_reason reason, const std::list<item> &items,
const vpart_reference &vpr )
{
map &here = get_map();
if( items.empty() ) {
return;
}
c.invalidate_weight_carried_cache();
vehicle_part &vp = vpr.part();
vehicle &veh = vpr.vehicle();
const tripoint_bub_ms where = veh.bub_part_pos( vp );
map &here = get_map();
const tripoint_bub_ms where = veh.bub_part_pos( &here, vp );
int items_did_not_fit_count = 0;
int into_vehicle_count = 0;
const std::string part_name = vp.info().name();
Expand Down
4 changes: 3 additions & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3731,6 +3731,8 @@ static void vehicle_battery_charge()

static void vehicle_export()
{
map &here = get_map();

if( optional_vpart_position ovp = get_map().veh_at( get_avatar().pos_bub() ) ) {
cata_path export_dir{ cata_path::root_path::user, "export_dir" };
assure_dir_exist( export_dir );
Expand All @@ -3742,7 +3744,7 @@ static void vehicle_export()
try {
write_to_file( veh_path, [&]( std::ostream & fout ) {
JsonOut jsout( fout );
ovp->vehicle().refresh();
ovp->vehicle().refresh( &here );
vehicle_prototype::save_vehicle_as_prototype( ovp->vehicle(), jsout );
} );
} catch( const std::exception &err ) {
Expand Down
25 changes: 13 additions & 12 deletions src/grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
{
const optional_vpart_position grabbed_vehicle_vp = m.veh_at( u.pos_bub() + u.grab_point );
map &here = get_map();
const optional_vpart_position grabbed_vehicle_vp = m.veh_at( u.pos_bub( &here ) + u.grab_point );
if( !grabbed_vehicle_vp ) {
add_msg( m_info, _( "No vehicle at grabbed point." ) );
u.grab( object_type::NONE );
Expand All @@ -37,7 +38,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
u.grab( object_type::NONE );
return false;
}
const vehicle *veh_under_player = veh_pointer_or_null( m.veh_at( u.pos_bub() ) );
const vehicle *veh_under_player = veh_pointer_or_null( m.veh_at( u.pos_bub( &here ) ) );
if( grabbed_vehicle == veh_under_player ) {
u.grab_point = - dp;
return false;
Expand Down Expand Up @@ -106,7 +107,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
units::angle face_delta = angle_delta( grabbed_vehicle->face.dir(), my_dir.dir() );

tileray my_pos_dir;
tripoint_rel_ms my_angle = u.pos_bub() - grabbed_vehicle->pos_bub();
tripoint_rel_ms my_angle = u.pos_bub( &here ) - grabbed_vehicle->pos_bub( &here );
my_pos_dir.init( my_angle.xy() );
back_of_vehicle = ( angle_delta( grabbed_vehicle->face.dir(), my_pos_dir.dir() ) > 90_degrees );
invalid_veh_face = ( face_delta > vehicles::steer_increment * 2 - 1_degrees &&
Expand All @@ -120,7 +121,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
} else {
str_req = max_str_req / 10;
//determine movecost for terrain touching wheels
const tripoint_bub_ms vehpos = grabbed_vehicle->pos_bub();
const tripoint_bub_ms vehpos = grabbed_vehicle->pos_bub( &here );
for( int p : wheel_indices ) {
const tripoint_bub_ms wheel_pos = vehpos + grabbed_vehicle->part( p ).precalc[0];
const int mapcost = m.move_cost( wheel_pos, grabbed_vehicle );
Expand All @@ -147,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->pos_bub(), str_req * 2, sounds::sound_t::movement,
sounds::sound( grabbed_vehicle->pos_bub( &here ), str_req * 2, sounds::sound_t::movement,
_( "a scraping noise." ), true, "misc", "scraping" );
}
//calculate exertion factor and movement penalty
Expand Down Expand Up @@ -220,9 +221,9 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )

// Grabbed part has to stay at distance 1 to the player
// and in roughly the same direction.
const tripoint_bub_ms new_part_pos = grabbed_vehicle->pos_bub() +
const tripoint_bub_ms new_part_pos = grabbed_vehicle->pos_bub( &here ) +
grabbed_vehicle->part( grabbed_part ).precalc[1];
const tripoint_bub_ms expected_pos = u.pos_bub() + dp + md_next_grab;
const tripoint_bub_ms expected_pos = u.pos_bub( &here ) + dp + md_next_grab;
tripoint_rel_ms actual_dir = tripoint_rel_ms( ( expected_pos - new_part_pos ).xy(), 0 );

bool failed = false;
Expand All @@ -234,8 +235,8 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
while( !no_player_collision ) {
no_player_collision = true;
for( const vpart_reference &vp : grabbed_vehicle->get_all_parts() ) {
if( grabbed_vehicle->pos_bub() +
vp.part().precalc[1] + actual_dir == u.pos_bub() + skip ) {
if( grabbed_vehicle->pos_bub( &here ) +
vp.part().precalc[1] + actual_dir == u.pos_bub( &here ) + skip ) {
no_player_collision = false;
break;
}
Expand All @@ -253,7 +254,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
}
}
// Set player location to illegal value so it can't collide with vehicle.
const tripoint_bub_ms player_prev = u.pos_bub();
const tripoint_bub_ms player_prev = u.pos_bub( &here );
u.setpos( tripoint_bub_ms::zero, false );
std::vector<veh_collision> colls;
failed = grabbed_vehicle->collision( colls, actual_dir, true );
Expand Down Expand Up @@ -296,7 +297,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp )
add_msg( _( "You let go of the %1$s as it starts to fall." ), grabbed_vehicle->disp_name() );
u.grab( object_type::NONE );
u.grab_point = tripoint_rel_ms::zero;
m.set_seen_cache_dirty( grabbed_vehicle->pos_bub() );
m.set_seen_cache_dirty( grabbed_vehicle->pos_bub( &here ) );
return true;
}
} else {
Expand All @@ -307,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_bub_ms wheel_p = grabbed_vehicle->bub_part_pos( vp_wheel );
tripoint_bub_ms wheel_p = grabbed_vehicle->bub_part_pos( &here, vp_wheel );
grabbed_vehicle->handle_trap( wheel_p, vp_wheel );
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/handle_liquid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ static const flag_id json_flag_FROM_FROZEN_LIQUID( "FROM_FROZEN_LIQUID" );
static void serialize_liquid_source( player_activity &act, const vehicle &veh, const int part_num,
const item &liquid )
{
map &here = get_map();
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( get_map().get_abs( veh.bub_part_pos( part_num ) ) );
act.coords.push_back( here.get_abs( veh.bub_part_pos( &here, part_num ) ) );
} else {
act.coords.push_back( veh.pos_abs() );
}
Expand Down Expand Up @@ -84,9 +85,10 @@ static void serialize_liquid_source( player_activity &act, const tripoint_bub_ms

static void serialize_liquid_target( player_activity &act, const vpart_reference &vp )
{
map &here = get_map();
act.values.push_back( static_cast<int>( liquid_target_type::VEHICLE ) );
act.values.push_back( 0 ); // dummy
act.coords.push_back( get_map().get_abs( vp.vehicle().bub_part_pos( 0 ) ) );
act.coords.push_back( here.get_abs( vp.vehicle().bub_part_pos( &here, 0 ) ) );
act.values.push_back( vp.part_index() ); // tank part index
}

Expand Down
6 changes: 4 additions & 2 deletions src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ class item_location::impl::item_on_vehicle : public item_location::impl
}

tripoint_bub_ms pos_bub() const override {
return cur.veh.bub_part_pos( cur.part );
map &here = get_map();
return cur.veh.bub_part_pos( &here, cur.part );
}

Character *carrier() const override {
Expand Down Expand Up @@ -532,9 +533,10 @@ class item_location::impl::item_on_vehicle : public item_location::impl
return 0;
}

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

// TODO: handle unpacking costs

Expand Down
2 changes: 1 addition & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5056,7 +5056,7 @@ std::optional<int> link_up_actor::link_tow_cable( Character *p, item &it,

const auto can_link = [&here]( const tripoint_bub_ms & point ) {
const optional_vpart_position ovp = here.veh_at( point );
return ovp && ovp->vehicle().is_external_part(&here, point );
return ovp && ovp->vehicle().is_external_part( &here, point );
};

const std::optional<tripoint_bub_ms> pnt_ = choose_adjacent_highlight(
Expand Down
4 changes: 2 additions & 2 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void map::generate_lightmap( const int zlev )

for( const vehicle_part *pt : lights ) {
const vpart_info &vp = pt->info();
tripoint_bub_ms src = v->bub_part_pos( *pt );
tripoint_bub_ms src = v->bub_part_pos( this, *pt );

if( !inbounds( src ) ) {
continue;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void map::build_seen_cache( const tripoint_bub_ms &origin, const int target_z, i
continue; // Player not at camera control, so cameras don't work
}

const tripoint_bub_ms mirror_pos = veh->bub_part_pos( vp_mirror );
const tripoint_bub_ms mirror_pos = veh->bub_part_pos( this, vp_mirror );

// Determine how far the light has already traveled so mirrors
// don't cheat the light distance falloff.
Expand Down
26 changes: 15 additions & 11 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void map::add_vehicle_to_cache( vehicle *veh )
if( vpr.part().removed ) {
continue;
}
const tripoint_bub_ms p = veh->bub_part_pos( vpr.part() );
const tripoint_bub_ms p = veh->bub_part_pos( this, vpr.part() );
level_cache &ch = get_cache( p.z() );
ch.set_veh_cached_parts( p, *veh, static_cast<int>( vpr.part_index() ) );
if( inbounds( p ) ) {
Expand Down Expand Up @@ -957,7 +957,7 @@ vehicle *map::move_vehicle( vehicle &veh, const tripoint_rel_ms &dp, const tiler
for( const int vp_wheel_idx : wheel_indices ) {
vehicle_part &vp_wheel = veh.part( vp_wheel_idx );
const vpart_info &vpi_wheel = vp_wheel.info();
const tripoint_bub_ms wheel_p = veh.bub_part_pos( vp_wheel );
const tripoint_bub_ms wheel_p = veh.bub_part_pos( this, vp_wheel );
if( one_in( 2 ) && displace_water( wheel_p ) ) {
sounds::sound( wheel_p, 4, sounds::sound_t::movement, _( "splash!" ), false,
"environment", "splash" );
Expand Down Expand Up @@ -1026,8 +1026,8 @@ float map::vehicle_vehicle_collision( vehicle &veh, vehicle &veh2,

// Check whether avatar sees the collision, and log a message if so
const avatar &you = get_avatar();
const tripoint_bub_ms part1_pos = veh.bub_part_pos( vp1 );
const tripoint_bub_ms part2_pos = veh2.bub_part_pos( vp2 );
const tripoint_bub_ms part1_pos = veh.bub_part_pos( this, vp1 );
const tripoint_bub_ms part2_pos = veh2.bub_part_pos( this, vp2 );
if( you.sees( part1_pos ) || you.sees( part2_pos ) ) {
//~ %1$s: first vehicle name (without "the")
//~ %2$s: first part name
Expand Down Expand Up @@ -1304,7 +1304,7 @@ VehicleList map::get_vehicles( const tripoint_bub_ms &start, const tripoint_bub_
elem->sm_pos.z() = cz;
wrapped_vehicle w;
w.v = elem.get();
w.pos = w.v->pos_bub();
w.pos = w.v->pos_bub( this );
vehs.push_back( w );
}
}
Expand Down Expand Up @@ -1529,7 +1529,7 @@ bool map::displace_vehicle( vehicle &veh, const tripoint_rel_ms &dp, const bool
continue;
}
Creature *psg = r.psg;
const tripoint_bub_ms part_pos = veh.bub_part_pos( prt );
const tripoint_bub_ms part_pos = veh.bub_part_pos( this, prt );
if( psg == nullptr ) {
debugmsg( "Empty passenger for part #%d at %d,%d,%d player at %d,%d,%d?",
prt, part_pos.x(), part_pos.y(), part_pos.z(),
Expand Down Expand Up @@ -8171,7 +8171,7 @@ void map::loadn( const point_bub_sm &grid, bool update_vehicles )
vehicle *veh = iter->get();
if( veh->part_count() > 0 ) {
// Always fix submap coordinates for easier Z-level-related operations
veh->sm_pos = abs_sub.xy() + tripoint_rel_sm{ rebase_rel(grid), z};
veh->sm_pos = abs_sub.xy() + tripoint_rel_sm{ rebase_rel( grid ), z};
iter++;
if( main_inbounds ) {
_main_requires_cleanup = true;
Expand Down Expand Up @@ -8593,7 +8593,7 @@ void map::actualize( const tripoint_rel_sm &grid )
const item &base_const = vp.part().get_base();
const_cast<item &>( base_const ).overflow( vp.pos_bub() );
}
veh->refresh();
veh->refresh( this );
}

const time_duration time_since_last_actualize = calendar::turn - tmpsub->last_touched;
Expand Down Expand Up @@ -9428,12 +9428,14 @@ void map::build_floor_caches()

static void vehicle_caching_internal( level_cache &zch, const vpart_reference &vp, vehicle *v )
{
map &here =
get_map(); // TODO: Check is this is actually reasonable. Probably need to feed the map in.
auto &outside_cache = zch.outside_cache;
auto &transparency_cache = zch.transparency_cache;
auto &floor_cache = zch.floor_cache;

const size_t part = vp.part_index();
const tripoint_bub_ms part_pos = v->bub_part_pos( vp.part() );
const tripoint_bub_ms part_pos = v->bub_part_pos( &here, vp.part() );

bool vehicle_is_opaque = vp.has_feature( VPFLAG_OPAQUE ) && !vp.part().is_broken();

Expand All @@ -9458,8 +9460,10 @@ static void vehicle_caching_internal( level_cache &zch, const vpart_reference &v
static void vehicle_caching_internal_above( level_cache &zch_above, const vpart_reference &vp,
vehicle *v )
{
map &here =
get_map(); // TODO: Check is this is actually reasonable. Probably need to feed the map in.
if( vp.has_feature( VPFLAG_ROOF ) || vp.has_feature( VPFLAG_OPAQUE ) ) {
const tripoint_bub_ms part_pos = v->bub_part_pos( vp.part() );
const tripoint_bub_ms part_pos = v->bub_part_pos( &here, vp.part() );
zch_above.floor_cache[part_pos.x()][part_pos.y()] = true;
}
}
Expand All @@ -9472,7 +9476,7 @@ void map::do_vehicle_caching( int z )
}
for( vehicle *v : ch->vehicle_list ) {
for( const vpart_reference &vp : v->get_all_parts_with_fakes() ) {
const tripoint_bub_ms part_pos = v->bub_part_pos( vp.part() );
const tripoint_bub_ms part_pos = v->bub_part_pos( this, vp.part() );
if( !inbounds( part_pos.xy() ) ) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ class map
// Returns the wheel area of the vehicle multiplied by traction of the surface
// When ignore_movement_modifiers is set to true, it returns the area of the wheels touching the ground
// TODO: Remove the ugly sinking vehicle hack
float vehicle_wheel_traction( const vehicle &veh, bool ignore_movement_modifiers = false ) const;
float vehicle_wheel_traction( const vehicle &veh, bool ignore_movement_modifiers = false );

// Executes vehicle-vehicle collision based on vehicle::collision results
// Returns impulse of the executed collision
Expand Down
Loading

0 comments on commit d861e9a

Please sign in to comment.