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

mapified a lot of vehicle stuff #79611

Merged
merged 2 commits into from
Feb 10, 2025
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
20 changes: 11 additions & 9 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,15 @@ void autodrive_activity_actor::start( player_activity &, Character &who )

void autodrive_activity_actor::do_turn( player_activity &act, Character &who )
{
map &here = get_map();

if( who.in_vehicle && who.controlling_vehicle && player_vehicle ) {
if( who.get_moves() <= 0 ) {
// out of moves? the driver's not doing anything this turn
// (but the vehicle will continue moving)
return;
}
switch( player_vehicle->do_autodrive( who ) ) {
switch( player_vehicle->do_autodrive( here, who ) ) {
case autodrive_result::ok:
if( who.get_moves() > 0 ) {
// if do_autodrive() didn't eat up all our moves, end the turn
Expand Down Expand Up @@ -1357,8 +1359,8 @@ bikerack_racking_activity_actor::bikerack_racking_activity_actor( const vehicle
: racks( racks )
{
map &here = get_map();
parent_vehicle_pos = parent_vehicle.bub_part_pos( &here, 0 );
racked_vehicle_pos = racked_vehicle.bub_part_pos( &here, 0 );
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 @@ -1584,7 +1586,7 @@ bikerack_unracking_activity_actor::bikerack_unracking_activity_actor( const vehi
: parts( parts ), racks( racks )
{
map &here = get_map();
parent_vehicle_pos = parent_vehicle.bub_part_pos( &here, 0 );
parent_vehicle_pos = parent_vehicle.bub_part_pos( here, 0 );
}

void bikerack_unracking_activity_actor::start( player_activity &act, Character & )
Expand Down Expand Up @@ -8031,14 +8033,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( &here ), elem );
here.add_item_or_charges( veh.pos_bub( here ), elem );
}
cargo.clear();
}

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

return true;
Expand All @@ -8048,7 +8050,7 @@ vehicle_folding_activity_actor::vehicle_folding_activity_actor( const vehicle &t
{
map &here = get_map();
folding_time = target.folding_time();
target_pos = target.bub_part_pos( &here, 0 );
target_pos = target.bub_part_pos( here, 0 );
}

void vehicle_folding_activity_actor::start( player_activity &act, Character &p )
Expand Down Expand Up @@ -8121,7 +8123,7 @@ bool vehicle_unfolding_activity_actor::unfold_vehicle( Character &p, bool check_
here.destroy_vehicle( veh );
return false;
}
const bool cant_float = !veh->can_float();
const bool cant_float = !veh->can_float( here );
const auto invalid_pos = [&here, &cant_float]( const tripoint_bub_ms & p ) {
return ( cant_float && here.has_flag_ter( ter_furn_flag::TFLAG_DEEP_WATER, p ) )
|| here.veh_at( p )
Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ void activity_handlers::vehicle_finish( player_activity *act, Character *you )
const optional_vpart_position vp = here.veh_at( here.get_bub( tripoint_abs_ms( act->values[0],
act->values[1],
you->posz() ) ) );
veh_interact::complete_vehicle( *you );
veh_interact::complete_vehicle( here, *you );
// complete_vehicle set activity type to NULL if the vehicle
// was completely dismantled, otherwise the vehicle still exist and
// is to be examined again.
Expand Down
2 changes: 1 addition & 1 deletion src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void put_into_vehicle( Character &c, item_drop_reason reason, const std::
c.invalidate_weight_carried_cache();
vehicle_part &vp = vpr.part();
vehicle &veh = vpr.vehicle();
const tripoint_bub_ms where = veh.bub_part_pos( &here, vp );
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
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( &here ).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
36 changes: 24 additions & 12 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3072,6 +3072,7 @@ int Character::get_standard_stamina_cost( const item *thrown_item ) const
std::vector<item_location> Character::nearby( const
std::function<bool( const item *, const item * )> &func, int radius ) const
{
map &here = get_map();
std::vector<item_location> res;

visit_items( [&]( const item * e, const item * parent ) {
Expand All @@ -3081,7 +3082,7 @@ std::vector<item_location> Character::nearby( const
return VisitResponse::NEXT;
} );

for( const map_cursor &cur : map_selector( pos_bub(), radius ) ) {
for( const map_cursor &cur : map_selector( pos_bub( &here ), radius ) ) {
cur.visit_items( [&]( const item * e, const item * parent ) {
if( func( e, parent ) ) {
res.emplace_back( cur, const_cast<item *>( e ) );
Expand All @@ -3090,7 +3091,7 @@ std::vector<item_location> Character::nearby( const
} );
}

for( const vehicle_cursor &cur : vehicle_selector( pos_bub(), radius ) ) {
for( const vehicle_cursor &cur : vehicle_selector( here, pos_bub( &here ), 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 @@ -3210,6 +3211,7 @@ units::mass Character::best_nearby_lifting_assist() const

units::mass Character::best_nearby_lifting_assist( const tripoint_bub_ms &world_pos ) const
{
map &here = get_map();
int mech_lift = 0;
if( is_mounted() ) {
auto *mons = mounted_creature.get();
Expand All @@ -3219,7 +3221,7 @@ units::mass Character::best_nearby_lifting_assist( const tripoint_bub_ms &world_
}
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( here, world_pos, 4, true, true ).max_quality( qual_LIFT )
} );
return lifting_quality_to_mass( lift_quality );
}
Expand Down Expand Up @@ -6925,6 +6927,7 @@ void Character::mod_stamina( int mod )

void Character::burn_move_stamina( int moves )
{
map &here = get_map();
int overburden_percentage = 0;
//add half the difference between current stored kcal weight and healthy stored kcal weight to weight of carried gear
units::mass fat_penalty = units::from_kilogram( 0.5f * std::max( 0.0f,
Expand All @@ -6946,12 +6949,12 @@ void Character::burn_move_stamina( int moves )

///\EFFECT_SWIMMING decreases stamina burn when swimming
//Appropriate traits let you walk along the bottom without getting as tired
if( get_map().has_flag( ter_furn_flag::TFLAG_DEEP_WATER, pos_bub() ) &&
if( here.has_flag( ter_furn_flag::TFLAG_DEEP_WATER, pos_bub( &here ) ) &&
!has_flag( json_flag_WATERWALKING ) &&
( !has_flag( json_flag_WALK_UNDERWATER ) ||
get_map().has_flag( ter_furn_flag::TFLAG_GOES_DOWN, pos_bub() ) ) &&
!get_map().has_flag_furn( "BRIDGE", pos_bub() ) &&
!( in_vehicle && get_map().veh_at( pos_bub() )->vehicle().can_float() ) ) {
here.has_flag( ter_furn_flag::TFLAG_GOES_DOWN, pos_bub( &here ) ) ) &&
!here.has_flag_furn( "BRIDGE", pos_bub( &here ) ) &&
!( in_vehicle && here.veh_at( pos_bub( &here ) )->vehicle().can_float( here ) ) ) {
burn_ratio += 100 / std::pow( 1.1, get_skill_level( skill_swimming ) );
}

Expand Down Expand Up @@ -13351,7 +13354,7 @@ void Character::pause()
for( wrapped_vehicle &v : vehs ) {
veh = v.v;
if( veh && veh->is_moving() && veh->player_in_control( here, *this ) ) {
double exp_temp = 1 + veh->total_mass() / 400.0_kilogram +
double exp_temp = 1 + veh->total_mass( here ) / 400.0_kilogram +
std::abs( veh->velocity / 3200.0 );
int experience = static_cast<int>( exp_temp );
if( exp_temp - experience > 0 && x_in_y( exp_temp - experience, 1.0 ) ) {
Expand All @@ -13367,8 +13370,7 @@ void Character::pause()
wait_effects();
}

template <typename T>
bool Character::can_lift( const T &obj ) const
bool Character::can_lift( item &obj ) const
{
// avoid comparing by weight as different objects use differing scales (grams vs kilograms etc)
int str = get_lift_str();
Expand All @@ -13379,8 +13381,18 @@ bool Character::can_lift( const T &obj ) const
const int npc_str = get_lift_assist();
return str + npc_str >= obj.lift_strength();
}
template bool Character::can_lift<item>( const item &obj ) const;
template bool Character::can_lift<vehicle>( const vehicle &obj ) const;

bool Character::can_lift( vehicle &veh, map &here ) const
{
// avoid comparing by weight as different objects use differing scales (grams vs kilograms etc)
int str = get_lift_str();
if( mounted_creature ) {
auto *const mons = mounted_creature.get();
str = mons->mech_str_addition() == 0 ? str : mons->mech_str_addition();
}
const int npc_str = get_lift_assist();
return str + npc_str >= veh.lift_strength( here );
}

static std::string wrap60( const std::string &text )
{
Expand Down
6 changes: 2 additions & 4 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,8 @@ class Character : public Creature, public visitable
void pause(); // '.' command; pauses & resets recoil

/** Check player strong enough to lift an object unaided by equipment (jacks, levers etc) */
template <typename T> bool can_lift( const T &obj ) const;
bool can_lift( item &obj ) const;
bool can_lift( vehicle &veh, map &here ) const;
// --------------- Values ---------------
std::string name; // Pre-cataclysm name, invariable
// In-game name which you give to npcs or whoever asks, variable
Expand Down Expand Up @@ -4206,7 +4207,4 @@ struct enum_traits<character_stat> {
};
/// Get translated name of a stat
std::string get_stat_name( character_stat Stat );

extern template bool Character::can_lift<item>( const item &obj ) const;
extern template bool Character::can_lift<vehicle>( const vehicle &obj ) const;
#endif // CATA_SRC_CHARACTER_H
4 changes: 3 additions & 1 deletion src/character_guns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ std::vector<const item *> Character::get_ammo( const ammotype &at ) const

std::vector<item_location> Character::find_ammo( const item &obj, bool empty, int radius ) const
{
map &here = get_map();

std::vector<item_location> res;

find_ammo_helper( const_cast<Character &>( *this ), obj, empty, std::back_inserter( res ), true );
Expand All @@ -118,7 +120,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_bub(), radius ) ) {
for( vehicle_cursor &cursor : vehicle_selector( here, pos_bub( &here ), radius ) ) {
find_ammo_helper( cursor, obj, empty, std::back_inserter( res ), false );
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ 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_rel_ms::zero, vpart_from_item( base.typeId() ),
const int partnum = veh->install_part( here, point_rel_ms::zero, vpart_from_item( base.typeId() ),
item( base ) );
veh->part( partnum ).set_flag( vp_flag::unsalvageable_flag );

Expand All @@ -1730,9 +1730,10 @@ void construct::done_vehicle( const tripoint_bub_ms &p, Character & )

void construct::done_wiring( const tripoint_bub_ms &p, Character &who )
{
get_map().partial_con_remove( p );
map &here = get_map();
here.partial_con_remove( p );

place_appliance( p, vpart_from_item( itype_wall_wiring ), who );
place_appliance( here, p, vpart_from_item( itype_wall_wiring ), who );
}

void construct::done_appliance( const tripoint_bub_ms &p, Character &who )
Expand All @@ -1756,7 +1757,7 @@ void construct::done_appliance( const tripoint_bub_ms &p, Character &who )
const item &base = components.front();
const vpart_id &vpart = vpart_appliance_from_item( base.typeId() );

place_appliance( p, vpart, who, base );
place_appliance( here, p, vpart, who, base );
}

void construct::done_deconstruct( const tripoint_bub_ms &p, Character &player_character )
Expand Down
17 changes: 11 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ vehicle *game::place_vehicle_nearby(
std::vector<std::string> search_types = omt_search_types;
if( search_types.empty() ) {
const vehicle &veh = *id->blueprint;
if( veh.max_ground_velocity( here ) == 0 && veh.can_float() ) {
if( veh.max_ground_velocity( here ) == 0 && veh.can_float( here ) ) {
search_types.emplace_back( "river" );
search_types.emplace_back( "lake" );
search_types.emplace_back( "ocean" );
Expand Down Expand Up @@ -2853,7 +2853,7 @@ void game::setremoteveh( vehicle *veh )
}

std::stringstream remote_veh_string;
const tripoint_bub_ms vehpos = veh->pos_bub( &here );
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 @@ -5772,7 +5772,9 @@ void game::save_cyborg( item *cyborg, const tripoint_bub_ms &couch_pos, Characte

void game::exam_appliance( vehicle &veh, const point_rel_ms &c )
{
player_activity act = veh_app_interact::run( veh, c );
map &here = get_map();

player_activity act = veh_app_interact::run( here, veh, c );
if( act ) {
u.set_moves( 0 );
u.assign_activity( act );
Expand All @@ -5781,11 +5783,13 @@ void game::exam_appliance( vehicle &veh, const point_rel_ms &c )

void game::exam_vehicle( vehicle &veh, const point_rel_ms &c )
{
map &here = get_map();

if( veh.magic ) {
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( here, veh, c );
if( act ) {
u.set_moves( 0 );
u.assign_activity( act );
Expand Down Expand Up @@ -5846,7 +5850,7 @@ void game::control_vehicle()
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 )
&& veh->get_harnessed_animal();
&& veh->get_harnessed_animal( here );
if( veh->player_in_control( here, u ) ) {
// player already "driving" - offer ways to leave
if( controls_ok ) {
Expand Down Expand Up @@ -11202,6 +11206,7 @@ bool game::walk_move( const tripoint_bub_ms &dest_loc, const bool via_ramp,

point_rel_sm game::place_player( const tripoint_bub_ms &dest_loc, bool quick )
{
map &here = get_map();
const optional_vpart_position vp1 = m.veh_at( dest_loc );
if( const std::optional<std::string> label = vp1.get_label() ) {
add_msg( m_info, _( "Label here: %s" ), *label );
Expand Down Expand Up @@ -11485,7 +11490,7 @@ point_rel_sm game::place_player( const tripoint_bub_ms &dest_loc, bool quick )
// Drench the player if swimmable
if( m.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, u.pos_bub() ) &&
!m.has_flag_furn( "BRIDGE", u.pos_bub() ) &&
!( u.is_mounted() || ( u.in_vehicle && vp1->vehicle().can_float() ) ) &&
!( u.is_mounted() || ( u.in_vehicle && vp1->vehicle().can_float( here ) ) ) &&
!u.has_flag( json_flag_WATERWALKING ) ) {
u.drench( 80, u.get_drenching_body_parts( false, false ),
false );
Expand Down
Loading
Loading