Skip to content

Commit

Permalink
typified vehicle stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed Nov 11, 2024
1 parent 053284c commit eee3684
Show file tree
Hide file tree
Showing 45 changed files with 373 additions and 513 deletions.
7 changes: 2 additions & 5 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,13 +1693,10 @@ void Character::process_bionic( bionic &bio )
mod_power_level( -trigger_cost );
}
} else if( bio.id == bio_gills ) {
const units::energy trigger_cost = bio.info().power_trigger / 8;
if( has_effect( effect_asthma ) && get_power_level() >= trigger_cost ) {
if( has_effect( effect_asthma ) ) {
add_msg_if_player( m_good,
_( "Your %s activates and you feel your throat open up and air filling your lungs!" ),
bio.info().name );
_( "You feel your throat open up and air filling your lungs!" ) );
remove_effect( effect_asthma );
mod_power_level( -trigger_cost );
}
} else if( bio.id == bio_evap ) {
if( is_underwater() ) {
Expand Down
2 changes: 0 additions & 2 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ static void AddGlyphRangesFromCLDR( ImFontGlyphRangesBuilder *b, const std::stri
AddGlyphRangesFromCLDRForPL( b );
} else if( lang == "pt_BR" ) {
AddGlyphRangesFromCLDRForPT( b );
} else if( lang == "pt_PT" ) {
AddGlyphRangesFromCLDRForPT( b );
} else if( lang == "ru" ) {
AddGlyphRangesFromCLDRForRU( b );
} else if( lang == "sr" ) {
Expand Down
19 changes: 10 additions & 9 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 @@ -2790,7 +2791,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 @@ -2808,7 +2809,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 @@ -2822,7 +2823,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 @@ -2831,14 +2832,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 @@ -3654,7 +3655,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 @@ -3682,7 +3683,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 @@ -3934,7 +3935,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 @@ -3085,7 +3085,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 @@ -3214,7 +3214,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 @@ -652,15 +652,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 @@ -1034,11 +1034,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 @@ -1200,7 +1200,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 @@ -5511,7 +5511,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 @@ -5524,7 +5524,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 @@ -5583,8 +5583,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 @@ -6011,7 +6011,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 @@ -10807,7 +10807,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 @@ -13583,7 +13583,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 @@ -13594,11 +13594,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 @@ -4880,7 +4880,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 @@ -4923,7 +4923,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
Loading

0 comments on commit eee3684

Please sign in to comment.