Skip to content

Commit

Permalink
Merge pull request #77764 from PatrikLundell/typify
Browse files Browse the repository at this point in the history
typified vehicle stuff
  • Loading branch information
Night-Pryanik authored Nov 22, 2024
2 parents d42cfd9 + 9592445 commit b1266d1
Show file tree
Hide file tree
Showing 42 changed files with 369 additions and 501 deletions.
17 changes: 9 additions & 8 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ pixel_minimap_mode pixel_minimap_mode_from_string( const std::string &mode )
return pixel_minimap_mode::solid;
}

auto simple_point_hash = []( const auto &p )
// Generic function for hashing points. Untype them to use them.
auto simple_point_hash = []( const point &p )
{
return p.x + p.y * 65536;
};
Expand Down Expand Up @@ -2804,7 +2805,7 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
case TILE_CATEGORY::FIELD:
case TILE_CATEGORY::LIGHTING:
// stationary map tiles, seed based on map coordinates
seed = simple_point_hash( here.getglobal( pos ).raw() );
seed = simple_point_hash( here.getglobal( pos ).raw().xy() );
break;
case TILE_CATEGORY::VEHICLE_PART:
// vehicle parts, seed based on coordinates within the vehicle
Expand All @@ -2822,7 +2823,7 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
} else {
const optional_vpart_position vp = here.veh_at( pos );
if( vp ) {
seed = simple_point_hash( vp->mount() );
seed = simple_point_hash( vp->mount_pos().raw() );
}
}
}
Expand All @@ -2836,7 +2837,7 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
if( fid.is_valid() ) {
const furn_t &f = fid.obj();
if( !f.is_movable() ) {
seed = simple_point_hash( here.getglobal( pos ).raw() );
seed = simple_point_hash( here.getglobal( pos ).raw().xy() );
}
}
}
Expand All @@ -2845,14 +2846,14 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
case TILE_CATEGORY::OVERMAP_TERRAIN:
case TILE_CATEGORY::OVERMAP_VISION_LEVEL:
case TILE_CATEGORY::MAP_EXTRA:
seed = simple_point_hash( pos );
seed = simple_point_hash( pos.xy() );
break;
case TILE_CATEGORY::NONE:
// graffiti
if( found_id == "graffiti" ) {
seed = std::hash<std::string> {}( here.graffiti_at( pos ) );
} else if( string_starts_with( found_id, "graffiti" ) ) {
seed = simple_point_hash( here.getglobal( pos ).raw() );
seed = simple_point_hash( here.getglobal( pos ).raw().xy() );
}
break;
case TILE_CATEGORY::ITEM:
Expand Down Expand Up @@ -3631,7 +3632,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int

// get the sprite to draw
// roll is based on the maptile seed to keep visuals consistent
int roll = simple_point_hash( p ) % layer_var.total_weight;
int roll = simple_point_hash( p.xy() ) % layer_var.total_weight;
std::string sprite_to_draw;
for( const auto &sprite_list : layer_var.sprite ) {
roll = roll - sprite_list.second;
Expand Down Expand Up @@ -3897,7 +3898,7 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
const optional_vpart_position ovp = here.veh_at( p );
if( ovp && !invisible[0] ) {
const vehicle &veh = ovp->vehicle();
const vpart_display vd = veh.get_display_of_tile( ovp->mount() );
const vpart_display vd = veh.get_display_of_tile( ovp->mount_pos() );
if( !vd.id.is_null() ) {
const int subtile = vd.is_open ? open_ : vd.is_broken ? broken : 0;
const int rotation = angle_to_dir4( 270_degrees - veh.face.dir() );
Expand Down
4 changes: 2 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ std::vector<item_location> Character::nearby( const
} );
}

for( const vehicle_cursor &cur : vehicle_selector( pos(), radius ) ) {
for( const vehicle_cursor &cur : vehicle_selector( pos_bub(), radius ) ) {
cur.visit_items( [&]( const item * e, const item * parent ) {
if( func( e, parent ) ) {
res.emplace_back( cur, const_cast<item *>( e ) );
Expand Down Expand Up @@ -3213,7 +3213,7 @@ units::mass Character::best_nearby_lifting_assist( const tripoint &world_pos ) c
}
int lift_quality = std::max( { this->max_quality( qual_LIFT ), mech_lift,
map_selector( this->pos_bub(), PICKUP_RANGE ).max_quality( qual_LIFT ),
vehicle_selector( world_pos, 4, true, true ).max_quality( qual_LIFT )
vehicle_selector( tripoint_bub_ms( world_pos ), 4, true, true ).max_quality( qual_LIFT )
} );
return lifting_quality_to_mass( lift_quality );
}
Expand Down
2 changes: 1 addition & 1 deletion src/character_guns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ std::vector<item_location> Character::find_ammo( const item &obj, bool empty, in
for( map_cursor &cursor : map_selector( pos_bub(), radius ) ) {
find_ammo_helper( cursor, obj, empty, std::back_inserter( res ), false );
}
for( vehicle_cursor &cursor : vehicle_selector( pos(), radius ) ) {
for( vehicle_cursor &cursor : vehicle_selector( pos_bub(), radius ) ) {
find_ammo_helper( cursor, obj, empty, std::back_inserter( res ), false );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ void zone_manager::add( const std::string &name, const zone_type_id &type, const
return;
}

create_vehicle_loot_zone( vp->vehicle(), vp->mount(), new_zone, pmap );
create_vehicle_loot_zone( vp->vehicle(), vp->mount_pos().raw(), new_zone, pmap );
return;
}
}
Expand Down Expand Up @@ -1791,7 +1791,7 @@ void zone_manager::revert_vzones()
const tripoint_bub_ms pos = here.bub_from_abs( zone.get_start_point() );
if( const std::optional<vpart_reference> vp = here.veh_at( pos ).cargo() ) {
zone.set_is_vehicle( true );
vp->vehicle().loot_zones.emplace( vp->mount(), zone );
vp->vehicle().loot_zones.emplace( vp->mount_pos(), zone );
here.register_vehicle_zone( &vp->vehicle(), here.get_abs_sub().z() );
cache_vzones();
}
Expand Down
5 changes: 3 additions & 2 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,15 +654,16 @@ void editmap::draw_main_ui_overlay()
false );
}
if( const optional_vpart_position ovp = tmpmap.veh_at( tmp_p ) ) {
const vpart_display vd = ovp->vehicle().get_display_of_tile( ovp->mount() );
const vpart_display vd = ovp->vehicle().get_display_of_tile( ovp->mount_pos() );
char part_mod = 0;
if( vd.is_open ) {
part_mod = 1;
} else if( vd.is_broken ) {
part_mod = 2;
}
const units::angle veh_dir = ovp->vehicle().face.dir();
g->draw_vpart_override( map_p, vpart_id( vd.id ), part_mod, veh_dir, vd.has_cargo, ovp->mount() );
g->draw_vpart_override( map_p, vpart_id( vd.id ), part_mod, veh_dir, vd.has_cargo,
ovp->mount_pos().raw() );
} else {
g->draw_vpart_override( map_p, vpart_id::NULL_ID(), 0, 0_degrees, false, point_zero );
}
Expand Down
18 changes: 9 additions & 9 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,11 @@ 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 pos = vp.pos();
const tripoint_bub_ms pos = vp.pos_bub();
u.setpos( pos );

// Delete the items that would have spawned here from a "corpse"
for( const int sp : v.v->parts_at_relative( vp.mount(), true ) ) {
for( const int sp : v.v->parts_at_relative( vp.mount_pos(), true ) ) {
vpart_reference( *v.v, sp ).items().clear();
}

Expand Down Expand Up @@ -1225,7 +1225,7 @@ vehicle *game::place_vehicle_nearby(
point_sm_ms remainder;
std::tie( quotient, remainder ) = coords::project_remain<coords::sm>( abs_local );
veh->sm_pos = quotient.raw();
veh->pos = remainder.raw();
veh->pos = remainder;

veh->unlock(); // always spawn unlocked
veh->toggle_tracking(); // always spawn tracked
Expand Down Expand Up @@ -5555,7 +5555,7 @@ void game::save_cyborg( item *cyborg, const tripoint &couch_pos, Character &inst

void game::exam_appliance( vehicle &veh, const point &c )
{
player_activity act = veh_app_interact::run( veh, c );
player_activity act = veh_app_interact::run( veh, point_rel_ms( c ) );
if( act ) {
u.set_moves( 0 );
u.assign_activity( act );
Expand All @@ -5568,7 +5568,7 @@ void game::exam_vehicle( vehicle &veh, const point &c )
add_msg( m_info, _( "This is your %s" ), veh.name );
return;
}
player_activity act = veh_interact::run( veh, c );
player_activity act = veh_interact::run( veh, point_rel_ms( c ) );
if( act ) {
u.set_moves( 0 );
u.assign_activity( act );
Expand Down Expand Up @@ -5627,8 +5627,8 @@ void game::control_vehicle()
vehicle *veh = nullptr;
if( const optional_vpart_position vp = m.veh_at( u.pos_bub() ) ) {
veh = &vp->vehicle();
const int controls_idx = veh->avail_part_with_feature( vp->mount(), "CONTROLS" );
const int reins_idx = veh->avail_part_with_feature( vp->mount(), "CONTROL_ANIMAL" );
const int controls_idx = veh->avail_part_with_feature( vp->mount_pos(), "CONTROLS" );
const int reins_idx = veh->avail_part_with_feature( vp->mount_pos(), "CONTROL_ANIMAL" );
const bool controls_ok = controls_idx >= 0; // controls available to "drive"
const bool reins_ok = reins_idx >= 0 // reins + animal available to "drive"
&& veh->has_engine_type( fuel_type_animal, false )
Expand Down Expand Up @@ -6055,7 +6055,7 @@ void game::examine( const tripoint_bub_ms &examp, bool with_pickup )
if( !vp->vehicle().is_appliance() ) {
vp->vehicle().interact_with( examp, with_pickup );
} else {
g->exam_appliance( vp->vehicle(), vp->mount() );
g->exam_appliance( vp->vehicle(), vp->mount_pos().raw() );
}
return;
} else {
Expand Down Expand Up @@ -10856,7 +10856,7 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool

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

if( pulling ) {
Expand Down
2 changes: 1 addition & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ static void grab()
return;
}
get_player_character().pause();
vp->vehicle().separate_from_grid( vp.value().mount() );
vp->vehicle().separate_from_grid( vp.value().mount_pos() );
if( const optional_vpart_position &split_vp = here.veh_at( grabp ) ) {
veh_name = split_vp->vehicle().name;
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13654,7 +13654,7 @@ std::string item::link_name() const

ret_val<void> item::link_to( const optional_vpart_position &linked_vp, link_state link_type )
{
return linked_vp ? link_to( linked_vp->vehicle(), linked_vp->mount(), link_type ) :
return linked_vp ? link_to( linked_vp->vehicle(), linked_vp->mount_pos(), link_type ) :
ret_val<void>::make_failure();
}

Expand All @@ -13665,11 +13665,12 @@ ret_val<void> item::link_to( const optional_vpart_position &first_linked_vp,
return ret_val<void>::make_failure();
}
// Link up the second vehicle first so, if it's a tow cable, the first vehicle will tow the second.
ret_val<void> result = link_to( second_linked_vp->vehicle(), second_linked_vp->mount(), link_type );
ret_val<void> result = link_to( second_linked_vp->vehicle(), second_linked_vp->mount_pos(),
link_type );
if( !result.success() ) {
return result;
}
return link_to( first_linked_vp->vehicle(), first_linked_vp->mount(), link_type );
return link_to( first_linked_vp->vehicle(), first_linked_vp->mount_pos(), link_type );
}

ret_val<void> item::link_to( vehicle &veh, const point &mount, link_state link_type )
Expand Down
2 changes: 1 addition & 1 deletion src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,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(), part_pos.pos() );
res += " " + direction_suffix( ch->pos_bub().raw(), part_pos.pos_bub().raw() );
}
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4896,7 +4896,7 @@ std::optional<int> link_up_actor::link_to_veh_app( Character *p, item &it,

const auto can_link = [&here, &to_ports]( const tripoint & point ) {
const optional_vpart_position ovp = here.veh_at( point );
return ovp && ovp->vehicle().avail_linkable_part( ovp->mount(), to_ports ) != -1;
return ovp && ovp->vehicle().avail_linkable_part( ovp->mount_pos(), to_ports ) != -1;
};
const std::optional<tripoint> pnt_ = choose_adjacent_highlight( _( "Attach the cable where?" ),
"", can_link, false, false );
Expand Down Expand Up @@ -4939,7 +4939,7 @@ std::optional<int> link_up_actor::link_to_veh_app( Character *p, item &it,
}

// Get the part name for the connection message, using the vehicle name as a fallback.
const int part_index = sel_vp->vehicle().avail_linkable_part( sel_vp->mount(), to_ports );
const int part_index = sel_vp->vehicle().avail_linkable_part( sel_vp->mount_pos(), to_ports );
const std::string sel_vp_name = part_index == -1 ? sel_vp->vehicle().name :
sel_vp->vehicle().part( part_index ).name( false );

Expand Down
18 changes: 9 additions & 9 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ bool map::deregister_vehicle_zone( zone_data &zone ) const
const tripoint_bub_ms pos = bub_from_abs( zone.get_start_point() );
if( const std::optional<vpart_reference> vp = veh_at( pos ).cargo() ) {
vehicle &veh = vp->vehicle();
auto bounds = veh.loot_zones.equal_range( vp->mount() );
auto bounds = veh.loot_zones.equal_range( vp->mount_pos() );
for( auto it = bounds.first; it != bounds.second; it++ ) {
if( &zone == &( it->second ) ) {
veh.loot_zones.erase( it );
Expand All @@ -1280,7 +1280,7 @@ std::set<tripoint_bub_ms> map::get_moving_vehicle_targets( const Creature &z, in
continue; // coarse distance filter, 40 = ~24 * sqrt(2) - rough max diameter of a vehicle
}
for( const vpart_reference &vpr : v.v->get_all_parts() ) {
const tripoint_bub_ms vppos = static_cast<tripoint_bub_ms>( vpr.pos() );
const tripoint_bub_ms vppos = vpr.pos_bub();
if( rl_dist( zpos, vppos ) > max_range ) {
continue;
}
Expand Down Expand Up @@ -1602,7 +1602,7 @@ bool map::displace_vehicle( vehicle &veh, const tripoint_rel_ms &dp, const bool
}

veh.shed_loose_parts( trinary::SOME, &dst );
smzs = veh.advance_precalc_mounts( dst_offset.raw(), src.raw(), dp.raw(), ramp_offset,
smzs = veh.advance_precalc_mounts( dst_offset, src, dp, ramp_offset,
adjust_pos, parts_to_move );
veh.update_active_fakes();

Expand Down Expand Up @@ -3854,7 +3854,7 @@ bool map::terrain_moppable( const tripoint_bub_ms &p )
// Moppable vehicles ( blood splatter )
if( const optional_vpart_position ovp = veh_at( p ) ) {
vehicle *const veh = &ovp->vehicle();
for( const int elem : veh->parts_at_relative( ovp->mount(), true ) ) {
for( const int elem : veh->parts_at_relative( ovp->mount_pos(), true ) ) {
const vehicle_part &vp = veh->part( elem );
if( vp.blood > 0 ) {
return true;
Expand Down Expand Up @@ -3899,7 +3899,7 @@ bool map::mop_spills( const tripoint_bub_ms &p )

if( const optional_vpart_position ovp = veh_at( p ) ) {
vehicle *const veh = &ovp->vehicle();
for( const int elem : veh->parts_at_relative( ovp->mount(), true ) ) {
for( const int elem : veh->parts_at_relative( ovp->mount_pos(), true ) ) {
vehicle_part &vp = veh->part( elem );
if( vp.blood > 0 ) {
vp.blood = 0;
Expand Down Expand Up @@ -6025,7 +6025,7 @@ void map::process_items_in_vehicle( vehicle &cur_veh, submap &current_submap )
}
const auto it = std::find_if( begin( cargo_parts ),
end( cargo_parts ), [&]( const vpart_reference & part ) {
return active_item_ref.location.raw() == part.mount();
return active_item_ref.location == part.mount_pos();
} );

if( it == end( cargo_parts ) ) {
Expand Down Expand Up @@ -6996,7 +6996,7 @@ void map::add_splatter( const field_type_id &type, const tripoint_bub_ms &where,
if( const optional_vpart_position vp = veh_at( where ) ) {
vehicle *const veh = &vp->vehicle();
// Might be -1 if all the vehicle's parts at where are marked for removal
const int part = veh->part_displayed_at( vp->mount(), true );
const int part = veh->part_displayed_at( vp->mount_pos(), true );
if( part != -1 ) {
veh->part( part ).blood += 200 * std::min( intensity, 3 ) / 3;
return;
Expand Down Expand Up @@ -7628,7 +7628,7 @@ void map::draw_from_above( const catacurses::window &w, const tripoint_bub_ms &p
tercol = curr_furn.color();
} else if( ( veh = veh_at_internal( p, part_below ) ) != nullptr ) {
const vpart_position vpp( const_cast<vehicle &>( *veh ), part_below );
const vpart_display vd = veh->get_display_of_tile( vpp.mount(), true, true, true );
const vpart_display vd = veh->get_display_of_tile( vpp.mount_pos(), true, true, true );
const int roof = veh->roof_at_part( part_below );
sym = vd.symbol_curses;
tercol = roof >= 0 || vpp.obstacle_at_part() ? c_light_gray : c_light_gray_cyan;
Expand Down Expand Up @@ -9046,7 +9046,7 @@ void map::actualize( const tripoint_rel_sm &grid )
// spill out items too large, MIGRATION pockets etc from vehicle parts
for( const vpart_reference &vp : veh->get_all_parts() ) {
const item &base_const = vp.part().get_base();
const_cast<item &>( base_const ).overflow( vp.pos() );
const_cast<item &>( base_const ).overflow( vp.pos_bub().raw() );
}
veh->refresh();
}
Expand Down
Loading

0 comments on commit b1266d1

Please sign in to comment.