Skip to content

Commit

Permalink
Allow getting in vehicles anyway (#74981)
Browse files Browse the repository at this point in the history
* Allow to get in the vehicle just be cramped

* NPCs just get in there too

* rename test

* Silence warnings about unused cramped var

---------

Co-authored-by: Fris0uman <[email protected]>
Co-authored-by: Kevin Granade <[email protected]>
  • Loading branch information
3 people authored Jul 13, 2024
1 parent 6d80609 commit 17b6b9c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 79 deletions.
5 changes: 1 addition & 4 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11126,10 +11126,7 @@ void Character::process_effects()
}

// Being stuck in tight spaces sucks. TODO: could be expanded to apply to non-vehicle conditions.
bool cramped = false;
// return is intentionally discarded, sets cramped if appropriate
can_move_to_vehicle_tile( get_map().getglobal( pos() ), cramped );
if( cramped ) {
if( will_be_cramped_in_vehicle_tile( get_map().getglobal( pos() ) ) ) {
if( is_npc() && !has_effect( effect_narcosis ) ) {
npc &as_npc = dynamic_cast<npc &>( *this );
as_npc.complain_about( "cramped_vehicle", 30_minutes, "<cramped_vehicle>", false );
Expand Down
20 changes: 7 additions & 13 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ void Creature::setpos( const tripoint_bub_ms &p )
Creature::setpos( p.raw() );
}

bool Creature::can_move_to_vehicle_tile( const tripoint_abs_ms &loc, bool &cramped ) const
bool Creature::will_be_cramped_in_vehicle_tile( const tripoint_abs_ms &loc ) const
{
map &here = get_map();
const optional_vpart_position vp_there = here.veh_at( loc );
if( !vp_there ) {
return true;
return false;
}

const monster *mon = as_monster();
Expand Down Expand Up @@ -257,36 +257,30 @@ bool Creature::can_move_to_vehicle_tile( const tripoint_abs_ms &loc, bool &cramp
}

if( critter_volume > free_cargo ) {
return false;
return true;
}

if( size == creature_size::huge &&
!vp_there.part_with_feature( "HUGE_OK", false ) ) {
return false;
return true;
}

// free_cargo * 0.75 < critter_volume && critter_volume <= free_cargo
if( free_cargo * 0.75 < critter_volume ) {
if( !mon || !( mon->type->bodytype == "snake" || mon->type->bodytype == "blob" ||
mon->type->bodytype == "fish" ||
has_flag( mon_flag_PLASTIC ) || has_flag( mon_flag_SMALL_HIDER ) ) ) {
cramped = true;
return true;
}
}

if( size == creature_size::huge && !vp_there.part_with_feature( "AISLE", false ) &&
!vp_there.part_with_feature( "HUGE_OK", false ) ) {
cramped = true;
return true;
}
}

return true;
}

bool Creature::can_move_to_vehicle_tile( const tripoint_abs_ms &loc ) const
{
bool dummy = false;
return can_move_to_vehicle_tile( loc, dummy );
return false;
}

void Creature::move_to( const tripoint_abs_ms &loc )
Expand Down
6 changes: 2 additions & 4 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,8 @@ class Creature : public viewer
void setpos( const tripoint &p );
void setpos( const tripoint_bub_ms &p );

/** Checks if the creature fits into a given tile. Set the boolean argument to true if the creature would barely fit. */
bool can_move_to_vehicle_tile( const tripoint_abs_ms &loc, bool &cramped ) const;
/** Helper overload for when the boolean is discardable */
bool can_move_to_vehicle_tile( const tripoint_abs_ms &loc ) const;
/** Checks if the creature fits confortably into a given tile. */
bool will_be_cramped_in_vehicle_tile( const tripoint_abs_ms &loc ) const;
/** Moves the creature to the given location and calls the on_move() handler. */
void move_to( const tripoint_abs_ms &loc );

Expand Down
8 changes: 1 addition & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10502,12 +10502,6 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool
}
u.set_underwater( false );

bool cramped = false;
if( vp_there && !u.can_move_to_vehicle_tile( get_map().getglobal( dest_loc ), cramped ) ) {
add_msg( m_warning, _( "There's not enough room for you to fit there." ) );
return false;
}

if( !shifting_furniture && !pushing && is_dangerous_tile( dest_loc ) ) {
std::vector<std::string> harmful_stuff = get_dangerous_tile( dest_loc );
if( harmful_stuff.size() == 1 && harmful_stuff[0] == "ledge" ) {
Expand Down Expand Up @@ -10722,7 +10716,7 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool
start_hauling( oldpos );
}

if( cramped ) { // passed by reference, can_move_to_vehicle_tile sets to true if actually cramped
if( u.will_be_cramped_in_vehicle_tile( get_map().getglobal( dest_loc ) ) ) {
if( u.get_size() == creature_size::huge ) {
add_msg( m_warning, _( "You barely fit in this tiny human vehicle." ) );
} else if( u.get_total_volume() > u.get_base_volume() ) {
Expand Down
13 changes: 4 additions & 9 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,8 +1624,8 @@ bool monster::bash_at( const tripoint &p )
return false;
}

const bool too_cramped = !can_move_to_vehicle_tile( get_map().getglobal( p ) );
bool try_bash = !can_move_to( p ) || one_in( 3 ) || too_cramped;
const bool cramped = will_be_cramped_in_vehicle_tile( get_map().getglobal( p ) );
bool try_bash = !can_move_to( p ) || one_in( 3 ) || cramped;
if( !try_bash ) {
return false;
}
Expand All @@ -1635,7 +1635,7 @@ bool monster::bash_at( const tripoint &p )
}

map &here = get_map();
if( !( here.is_bashable_furn( p ) || here.veh_at( p ).obstacle_at_part() || too_cramped ) ) {
if( !( here.is_bashable_furn( p ) || here.veh_at( p ).obstacle_at_part() || cramped ) ) {
// if the only thing here is road or flat, rarely bash it
bool flat_ground = here.has_flag( ter_furn_flag::TFLAG_ROAD, p ) ||
here.has_flag( ter_furn_flag::TFLAG_FLAT, p );
Expand Down Expand Up @@ -1806,11 +1806,6 @@ bool monster::move_to( const tripoint &p, bool force, bool step_on_critter,
}
}

bool cramped = false; // applies an effect if monster does end up moving there
if( !can_move_to_vehicle_tile( here.getglobal( p ), cramped ) ) {
return false;
}

// Allows climbing monsters to move on terrain with movecost <= 0
Creature *critter = get_creature_tracker().creature_at( destination, is_hallucination() );
if( here.has_flag( ter_furn_flag::TFLAG_CLIMBABLE, destination ) ) {
Expand Down Expand Up @@ -1905,7 +1900,7 @@ bool monster::move_to( const tripoint &p, bool force, bool step_on_critter,
optional_vpart_position vp_dest = here.veh_at( destination );
if( vp_dest ) {
vp_dest->vehicle().invalidate_mass();
if( cramped ) {
if( will_be_cramped_in_vehicle_tile( here.getglobal( p ) ) ) {
add_effect( effect_cramped_space, 2_turns, true );
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3365,10 +3365,7 @@ void monster::process_effects()
}
}

bool cramped = false;
// return is intentionally discarded, sets cramped if appropriate
can_move_to_vehicle_tile( get_map().getglobal( pos() ), cramped );
if( !cramped ) {
if( !will_be_cramped_in_vehicle_tile( get_map().getglobal( pos() ) ) ) {
remove_effect( effect_cramped_space );
}

Expand Down
3 changes: 0 additions & 3 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3358,9 +3358,6 @@ std::function<bool( const tripoint & )> npc::get_path_avoid() const
if( sees_dangerous_field( p ) ) {
return true;
}
if( !can_move_to_vehicle_tile( here.getglobal( p ) ) ) {
return true;
}
return false;
};
}
Expand Down
22 changes: 1 addition & 21 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ bool npc::could_move_onto( const tripoint &p ) const
if( !here.passable( p ) ) {
return false;
}
if( !can_move_to_vehicle_tile( here.getglobal( p ) ) ) {
return false;
}

if( !sees_dangerous_field( p ) ) {
return true;
Expand Down Expand Up @@ -2900,20 +2897,6 @@ void npc::move_to( const tripoint &pt, bool no_bashing, std::set<tripoint> *nomo
}
}

if( !can_move_to_vehicle_tile( here.getglobal( p ) ) ) {
auto other_points = here.get_dir_circle( pos(), p );
for( const tripoint &ot : other_points ) {
if( could_move_onto( ot ) && ( nomove == nullptr || nomove->find( ot ) == nomove->end() ) ) {
p = ot;
break;
} else {
path.clear();
move_pause();
return;
}
}
}

recoil = MAX_RECOIL;

if( has_effect( effect_stunned ) || has_effect( effect_psi_stunned ) ) {
Expand Down Expand Up @@ -3144,10 +3127,7 @@ void npc::move_to( const tripoint &pt, bool no_bashing, std::set<tripoint> *nomo
here.creature_on_trap( *this );
here.creature_in_field( *this );

bool cramped = false;
if( !can_move_to_vehicle_tile( here.getglobal( p ), cramped ) ) {
debugmsg( "NPC %s somehow moved to a too-cramped vehicle tile", disp_name() );
} else if( cramped ) { //set by above call to Creature::can_move_to_vehicle_tile
if( will_be_cramped_in_vehicle_tile( here.getglobal( p ) ) ) {
if( !has_effect( effect_cramped_space ) ) {
add_msg_if_player_sees( *this, m_warning,
string_format( _( "%s has to really cram their huge body to fit." ), disp_name() ) );
Expand Down
21 changes: 7 additions & 14 deletions tests/char_volume_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_CASE( "character_baseline_volumes", "[volume]" )
CHECK( your_volume_with_trait( trait_HUGE ) == 156228_ml );
}

TEST_CASE( "character_at_volume_can_or_cannot_enter_vehicle", "[volume]" )
TEST_CASE( "character_at_volume_will_be_cramped_in_vehicle", "[volume]" )
{
clear_avatar();
clear_map();
Expand All @@ -81,17 +81,13 @@ TEST_CASE( "character_at_volume_can_or_cannot_enter_vehicle", "[volume]" )

// Empty aisle
dest_loc = dest_loc + tripoint_north_west;
bool cramped = false;
CHECK( you.can_move_to_vehicle_tile( dest_loc, cramped ) );
CHECK( !cramped );
CHECK( !you.will_be_cramped_in_vehicle_tile( dest_loc ) );
dest_loc = you.get_location(); //reset

// Aisle with 10L rock, a tight fit but not impossible
dest_loc = dest_loc + tripoint_north;
CHECK( you.can_move_to_vehicle_tile( dest_loc, cramped ) );
CHECK( cramped );
CHECK( you.will_be_cramped_in_vehicle_tile( dest_loc ) );
dest_loc = you.get_location(); //reset
cramped = false;

// Empty aisle, but we've put on a backpack and a 10L rock in that backpack
item backpack( itype_backpack_giant );
Expand All @@ -101,27 +97,24 @@ TEST_CASE( "character_at_volume_can_or_cannot_enter_vehicle", "[volume]" )
CHECK( 75_liter <= you.get_total_volume() );
CHECK( you.get_total_volume() <= 100_liter );
dest_loc = dest_loc + tripoint_north_west;
CHECK( you.can_move_to_vehicle_tile( dest_loc, cramped ) );
CHECK( cramped );
CHECK( you.will_be_cramped_in_vehicle_tile( dest_loc ) );
dest_loc = you.get_location(); //reset
cramped = false;

// Try the cramped aisle with a rock again, but now we are tiny, so it is easy.
CHECK( your_volume_with_trait( trait_SMALL2 ) == 23326_ml );
you.setpos( test_pos ); // set our position again, clear_avatar() moved us
dest_loc = dest_loc + tripoint_north;
CHECK( you.can_move_to_vehicle_tile( dest_loc, cramped ) );
CHECK( !cramped );
CHECK( !you.will_be_cramped_in_vehicle_tile( dest_loc ) );
dest_loc = you.get_location(); //reset

// Same aisle, but now we have HUGE GUTS. We will never fit.
CHECK( your_volume_with_trait( trait_HUGE ) == 156228_ml );
you.setpos( test_pos ); // set our position again, clear_avatar() moved us
dest_loc = dest_loc + tripoint_north;
CHECK( !you.can_move_to_vehicle_tile( dest_loc ) );
CHECK( you.will_be_cramped_in_vehicle_tile( dest_loc ) );
dest_loc = you.get_location(); //reset

// And finally, check that our HUGE body won't fit even into an empty aisle.
dest_loc = dest_loc + tripoint_north_west;
CHECK( !you.can_move_to_vehicle_tile( dest_loc ) );
CHECK( you.will_be_cramped_in_vehicle_tile( dest_loc ) );
}

0 comments on commit 17b6b9c

Please sign in to comment.