From 17b6b9c35bd85cdfcf3c5c7acc6d8683d9fa917a Mon Sep 17 00:00:00 2001 From: Fris0uman <41293484+Fris0uman@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:40:17 +0200 Subject: [PATCH] Allow getting in vehicles anyway (#74981) * 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 Co-authored-by: Kevin Granade --- src/character.cpp | 5 +---- src/creature.cpp | 20 +++++++------------- src/creature.h | 6 ++---- src/game.cpp | 8 +------- src/monmove.cpp | 13 ++++--------- src/monster.cpp | 5 +---- src/npc.cpp | 3 --- src/npcmove.cpp | 22 +--------------------- tests/char_volume_test.cpp | 21 +++++++-------------- 9 files changed, 24 insertions(+), 79 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 7b234d89d692a..3164ded2c0109 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -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( *this ); as_npc.complain_about( "cramped_vehicle", 30_minutes, "", false ); diff --git a/src/creature.cpp b/src/creature.cpp index 2448d2eacea7e..c891fef698385 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -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(); @@ -257,12 +257,12 @@ 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 @@ -270,23 +270,17 @@ bool Creature::can_move_to_vehicle_tile( const tripoint_abs_ms &loc, bool &cramp 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 ) diff --git a/src/creature.h b/src/creature.h index f19152b67202a..de1f3678db319 100644 --- a/src/creature.h +++ b/src/creature.h @@ -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 ); diff --git a/src/game.cpp b/src/game.cpp index cb9e47ba73b5d..84f59374aadc4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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 harmful_stuff = get_dangerous_tile( dest_loc ); if( harmful_stuff.size() == 1 && harmful_stuff[0] == "ledge" ) { @@ -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() ) { diff --git a/src/monmove.cpp b/src/monmove.cpp index 9034695953503..bb0c3a000e1b5 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -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; } @@ -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 ); @@ -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 ) ) { @@ -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 ); } } diff --git a/src/monster.cpp b/src/monster.cpp index 30954780b6a7c..7c9929780985c 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -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 ); } diff --git a/src/npc.cpp b/src/npc.cpp index 07af54cf15d63..a67a9cd65bd88 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -3358,9 +3358,6 @@ std::function 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; }; } diff --git a/src/npcmove.cpp b/src/npcmove.cpp index 530554d0f2913..6825b387bba02 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -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; @@ -2900,20 +2897,6 @@ void npc::move_to( const tripoint &pt, bool no_bashing, std::set *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 ) ) { @@ -3144,10 +3127,7 @@ void npc::move_to( const tripoint &pt, bool no_bashing, std::set *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() ) ); diff --git a/tests/char_volume_test.cpp b/tests/char_volume_test.cpp index 82cca754a9494..c7b164b1b7419 100644 --- a/tests/char_volume_test.cpp +++ b/tests/char_volume_test.cpp @@ -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(); @@ -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 ); @@ -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 ) ); }