Skip to content

Commit

Permalink
Fix impassable broken vehicle parts (CleverRaven#70560)
Browse files Browse the repository at this point in the history
* Update character.cpp

* monsters too

* betterfix

* Update monmove.cpp

* Update character.cpp

* Update monmove.cpp

* fixes

* blaaargh

* fixes

* Update src/character.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/character.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/character.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/character.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/character.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update vehicle_parts.json

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
worm-girl and github-actions[bot] authored Jan 2, 2024
1 parent 53cbdcb commit bef30a5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion data/json/vehicleparts/seats.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"description": "A soft, wide seat with a high back, the kind often used in back seats or older cars. It might be a decent place to sleep.",
"floor_bedding_warmth": 500,
"item": "seat_bench",
"size": "95 L",
"name": { "str": "bench seat" },
"extend": { "flags": [ "BED" ] },
"type": "vehicle_part"
Expand Down Expand Up @@ -181,7 +182,6 @@
"removal": { "skills": [ [ "mechanics", 2 ] ], "time": "30 m", "using": "vehicle_weld_removal" },
"repair": { "skills": [ [ "mechanics", 2 ] ], "time": "60 m", "using": [ [ "repair_welding_standard", 2 ] ] }
},
"size": "62500 ml",
"type": "vehicle_part"
}
]
11 changes: 6 additions & 5 deletions data/json/vehicleparts/vehicle_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"damage_modifier": 60,
"durability": 95,
"description": "A small but comfortable bed.",
"size": "100 L",
"size": "100 L",
"item": "mattress",
"comfort": 4,
"floor_bedding_warmth": 700,
Expand Down Expand Up @@ -1199,7 +1199,7 @@
"looks_like": "inflatable_airbag",
"categories": [ "hull" ],
"color": "green",
"size": "15 L",
"size": "85 L",
"durability": 50,
"item": "inflatable_section",
"location": "structure",
Expand Down Expand Up @@ -2565,7 +2565,7 @@
"comfort": 1,
"item": "frame_wood",
"location": "center",
"size": "62500 ml",
"size": "85 L",
"requirements": {
"install": { "skills": [ [ "mechanics", 1 ] ], "time": "30 m", "using": [ [ "vehicle_nail_install", 1 ] ] },
"removal": { "skills": [ [ "mechanics", 2 ] ], "time": "15 m", "using": [ [ "vehicle_nail_removal", 1 ] ] },
Expand All @@ -2582,6 +2582,7 @@
"name": { "str": "wooden bench" },
"copy-from": "seat_wood",
"durability": 150,
"size": "95 L",
"description": "A benchlike place to sit."
},
{
Expand Down Expand Up @@ -3039,7 +3040,7 @@
},
"repair": { "skills": [ [ "mechanics", 5 ] ], "time": "10 m", "using": [ [ "repair_welding_standard", 6 ] ] }
},
"flags": [ "PLANTER", "PROTRUSION", "CARGO", "EXTRA_DRAG" ],
"flags": [ "PLANTER", "PROTRUSION", "CARGO", "EXTRA_DRAG", "CARGO_PASSABLE" ],
"breaks_into": [ { "item": "plastic_chunk", "count": [ 1, 2 ] }, { "item": "scrap", "count": [ 1, 2 ] } ],
"damage_reduction": { "all": 16 },
"variants": [ { "symbols": "8", "symbols_broken": "*" } ]
Expand Down Expand Up @@ -3072,7 +3073,7 @@
},
"repair": { "skills": [ [ "mechanics", 5 ] ], "time": "10 m", "using": [ [ "repair_welding_standard", 6 ] ] }
},
"flags": [ "PLANTER", "PROTRUSION", "CARGO", "ADVANCED_PLANTER", "EXTRA_DRAG" ],
"flags": [ "PLANTER", "PROTRUSION", "CARGO", "ADVANCED_PLANTER", "EXTRA_DRAG", "CARGO_PASSABLE" ],
"breaks_into": [
{ "item": "cable", "charges": [ 3, 6 ] },
{ "item": "e_scrap", "count": [ 4, 10 ] },
Expand Down
51 changes: 24 additions & 27 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7972,13 +7972,12 @@ bool Character::move_in_vehicle( Creature *c, const tripoint &dest_loc ) const
auto cargo_parts = veh.get_parts_at( dest_loc, "CARGO", part_status_flag::any );
for( vehicle_part *&part : cargo_parts ) {
vehicle_stack contents = veh.get_items( *part );
const vpart_info &vpinfo = part->info();
const optional_vpart_position vp = m.veh_at( dest_loc );
// Check for obstacles and appliances to prevent squishing when the part is
// not a vehicle or when the player is not actually entering the tile IE grabbing.
if( !vp.part_with_feature( "CARGO_PASSABLE", false ) &&
!vp.part_with_feature( "APPLIANCE", false ) && !vp.part_with_feature( "OBSTACLE", false ) ) {
capacity += vpinfo.size;
capacity += contents.max_volume();
free_cargo += contents.free_volume();
}
}
Expand Down Expand Up @@ -8007,8 +8006,8 @@ bool Character::move_in_vehicle( Creature *c, const tripoint &dest_loc ) const
}
const optional_vpart_position vp = m.veh_at( dest_loc );
// Sufficiently gigantic characters aren't comfortable in stock seats, roof or no.
if( in_vehicle && get_size() == creature_size::huge && !vp.part_with_feature( "AISLE", true ) &&
!vp.part_with_feature( "HUGE_OK", true ) && !has_effect( effect_cramped_space ) ) {
if( in_vehicle && get_size() == creature_size::huge && !vp.part_with_feature( "AISLE", false ) &&
!vp.part_with_feature( "HUGE_OK", false ) && !has_effect( effect_cramped_space ) ) {
add_msg_if_player( m_warning, _( "You barely fit in this tiny human vehicle." ) );
add_msg_if_npc( m_warning, _( "%s has to really cram their huge body to fit." ), c->disp_name() );
c->add_effect( effect_cramped_space, 2_turns, true );
Expand Down Expand Up @@ -10906,32 +10905,29 @@ void Character::process_effects()
}

// Being stuck in tight spaces sucks. TODO: could be expanded to apply to non-vehicle conditions.
if( has_effect( effect_cramped_space ) && !in_vehicle ) {
remove_effect( effect_cramped_space );
}
// Check all of this here to ensure the player can't sit in a comfortable seat and then drop 50 liters of junk in their own lap.
if( in_vehicle ) {
if( has_effect( effect_cramped_space ) ) {
map &here = get_map();
const tripoint your_pos = pos();
const optional_vpart_position vp_there = here.veh_at( your_pos );
if( !vp_there ) {
remove_effect( effect_cramped_space );
return;
}
if( is_npc() && !has_effect( effect_narcosis ) && has_effect( effect_cramped_space ) ) {
npc &as_npc = dynamic_cast<npc &>( *this );
as_npc.complain_about( "cramped_vehicle", 1_hours, "<cramped_vehicle>", false );
as_npc.complain_about( "cramped_vehicle", 30_minutes, "<cramped_vehicle>", false );
}
const optional_vpart_position vp_there = here.veh_at( your_pos );
bool is_cramped_space = false;
if( vp_there ) {
vehicle &veh = vp_there->vehicle();
units::volume capacity = 0_ml;
units::volume free_cargo = 0_ml;
auto cargo_parts = veh.get_parts_at( your_pos, "CARGO", part_status_flag::any );
for( vehicle_part *&part : cargo_parts ) {
vehicle_stack contents = veh.get_items( *part );
const vpart_info &vpinfo = part->info();
const optional_vpart_position vp = here.veh_at( your_pos );
if( !vp.part_with_feature( "CARGO_PASSABLE", true ) ) {
capacity += vpinfo.size;
free_cargo += contents.free_volume();
}
vehicle &veh = vp_there->vehicle();
units::volume capacity = 0_ml;
units::volume free_cargo = 0_ml;
auto cargo_parts = veh.get_parts_at( your_pos, "CARGO", part_status_flag::any );
for( vehicle_part *&part : cargo_parts ) {
vehicle_stack contents = veh.get_items( *part );
const optional_vpart_position vp = here.veh_at( your_pos );
if( !vp.part_with_feature( "CARGO_PASSABLE", false ) ) {
capacity += contents.max_volume();
free_cargo += contents.free_volume();
}
const creature_size size = get_size();
if( capacity > 0_ml ) {
Expand All @@ -10948,15 +10944,16 @@ void Character::process_effects()
add_effect( effect_cramped_space, 2_turns, true );
}
is_cramped_space = true;

Check failure on line 10946 in src/character.cpp

View workflow job for this annotation

GitHub Actions / build (src)

Value stored to 'is_cramped_space' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
return;
}
}
const optional_vpart_position vp = here.veh_at( your_pos );
if( get_size() == creature_size::huge && !vp.part_with_feature( "AISLE", true ) &&
!vp.part_with_feature( "HUGE_OK", true ) ) {
if( get_size() == creature_size::huge && !vp.part_with_feature( "AISLE", false ) &&
!vp.part_with_feature( "HUGE_OK", false ) ) {
if( !has_effect( effect_cramped_space ) ) {
add_effect( effect_cramped_space, 2_turns, true );
}
is_cramped_space = true;

Check failure on line 10955 in src/character.cpp

View workflow job for this annotation

GitHub Actions / build (src)

Value stored to 'is_cramped_space' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
return;
}
}
if( !is_cramped_space ) {
Expand Down
20 changes: 10 additions & 10 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ bool monster::monster_move_in_vehicle( const tripoint &p ) const
auto cargo_parts = veh.get_parts_at( p, "CARGO", part_status_flag::any );
for( vehicle_part *&part : cargo_parts ) {
vehicle_stack contents = veh.get_items( *part );
const vpart_info &vpinfo = part->info();
if( !vp.part_with_feature( "CARGO_PASSABLE", true ) ) {
capacity += vpinfo.size;
if( !vp.part_with_feature( "CARGO_PASSABLE", false ) &&
!vp.part_with_feature( "APPLIANCE", false ) && !vp.part_with_feature( "OBSTACLE", false ) ) {
capacity += contents.max_volume();
free_cargo += contents.free_volume();
}
}
Expand All @@ -203,7 +203,7 @@ bool monster::monster_move_in_vehicle( const tripoint &p ) const
( size == creature_size::medium && free_cargo < 46875_ml ) ||
( size == creature_size::large && free_cargo < 93750_ml ) ||
( size == creature_size::huge && free_cargo < 187500_ml ) ||
( get_volume() > 850000_ml && !vp.part_with_feature( "HUGE_OK", true ) ) ) {
( get_volume() > 850000_ml && !vp.part_with_feature( "HUGE_OK", false ) ) ) {
return false; // Return false if there's just no room whatsoever. Anything over 850 liters will simply never fit in a vehicle part that isn't specifically made for it.
// I'm sorry but you can't let a kaiju ride shotgun.
}
Expand All @@ -214,8 +214,8 @@ bool monster::monster_move_in_vehicle( const tripoint &p ) const
critter.add_effect( effect_cramped_space, 2_turns, true );
return true; // Otherwise we add the effect and return true.
}
if( size == creature_size::huge && !vp.part_with_feature( "AISLE", true ) &&
!vp.part_with_feature( "HUGE_OK", true ) ) {
if( size == creature_size::huge && !vp.part_with_feature( "AISLE", false ) &&
!vp.part_with_feature( "HUGE_OK", false ) ) {
critter.add_effect( effect_cramped_space, 2_turns, true );
return true; // Sufficiently gigantic creatures have trouble in stock seats, roof or no.
}
Expand Down Expand Up @@ -243,10 +243,6 @@ bool monster::will_move_to( const tripoint &p ) const
}
}

if( here.veh_at( p ).part_with_feature( VPFLAG_CARGO, true ) && !monster_move_in_vehicle( p ) ) {
return false;
}

if( digs() && !here.has_flag( ter_furn_flag::TFLAG_DIGGABLE, p ) &&
!here.has_flag( ter_furn_flag::TFLAG_BURROWABLE, p ) ) {
return false;
Expand Down Expand Up @@ -1886,6 +1882,10 @@ bool monster::move_to( const tripoint &p, bool force, bool step_on_critter,
}
}

if( here.veh_at( p ).part_with_feature( VPFLAG_CARGO, true ) && !monster_move_in_vehicle( p ) ) {
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
6 changes: 3 additions & 3 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3355,7 +3355,7 @@ void monster::process_effects()
for( vehicle_part *&part : cargo_parts ) {
vehicle_stack contents = veh.get_items( *part );
const vpart_info &vpinfo = part->info();
if( !vp.part_with_feature( "CARGO_PASSABLE", true ) ) {
if( !vp.part_with_feature( "CARGO_PASSABLE", false ) ) {
capacity += vpinfo.size;
free_cargo += contents.free_volume();
}
Expand All @@ -3381,8 +3381,8 @@ void monster::process_effects()
return;
}
}
if( get_size() == creature_size::huge && !vp.part_with_feature( "AISLE", true ) &&
!vp.part_with_feature( "HUGE_OK", true ) ) {
if( get_size() == creature_size::huge && !vp.part_with_feature( "AISLE", false ) &&
!vp.part_with_feature( "HUGE_OK", false ) ) {
if( !has_effect( effect_cramped_space ) ) {
add_effect( effect_cramped_space, 2_turns, true );
}
Expand Down

0 comments on commit bef30a5

Please sign in to comment.