Skip to content

Commit

Permalink
Merge pull request #77446 from harakka/v_lorge_paths
Browse files Browse the repository at this point in the history
[CR] Pathfinding accounts for SMALL_PASSAGE
  • Loading branch information
kevingranade authored Nov 5, 2024
2 parents 0968b5e + a4befb6 commit 582f33f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ Character::Character() :
name.clear();
custom_profession.clear();

*path_settings = pathfinding_settings{ 0, 1000, 1000, 0, true, true, true, true, false, true };
*path_settings = pathfinding_settings{ 0, 1000, 1000, 0, true, true, true, true, false, true, creature_size::medium };

move_mode = move_mode_walk;
next_expected_position = std::nullopt;
Expand Down
4 changes: 4 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10810,6 +10810,10 @@ void map::update_pathfinding_cache( const tripoint_bub_ms &p ) const
cur_value |= PathfindingFlag::Sharp;
}

if( terrain.has_flag( ter_furn_flag::TFLAG_SMALL_PASSAGE ) ) {
cur_value |= ( PathfindingFlag::RestrictLarge | PathfindingFlag::RestrictHuge );
}

cache.special[p.x()][p.y()] = cur_value;
}

Expand Down
2 changes: 2 additions & 0 deletions src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "options.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pathfinding.h"
#include "pimpl.h"
#include "player_activity.h"
#include "rng.h"
Expand Down Expand Up @@ -555,6 +556,7 @@ void Character::recalculate_size()
size_class = creature_size::medium;
}
}
path_settings->size = size_class;
}

void Character::mutation_effect( const trait_id &mut, const bool worn_destroyed_override )
Expand Down
3 changes: 2 additions & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ npc::npc()
patience = 0;
attitude = NPCATT_NULL;

*path_settings = pathfinding_settings( 0, 1000, 1000, 10, true, true, true, true, false, true );
*path_settings = pathfinding_settings( 0, 1000, 1000, 10, true, true, true, true, false, true,
get_size() );
for( direction threat_dir : npc_threat_dir ) {
ai_cache.threat_map[ threat_dir ] = 0.0f;
}
Expand Down
20 changes: 20 additions & 0 deletions src/pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ int map::cost_to_pass( const tripoint_bub_ms &cur, const tripoint_bub_ms &p,
return PF_IMPASSABLE;
}

// RestrictTiny isn't checked since it's unclear how it would actually work as there's no category smaller than tiny
if( settings.size && (
( p_special & PathfindingFlag::RestrictSmall && settings.size > creature_size::tiny ) ||
( p_special & PathfindingFlag::RestrictMedium && settings.size > creature_size::small ) ||
( p_special & PathfindingFlag::RestrictLarge && settings.size > creature_size::medium ) ||
( p_special & PathfindingFlag::RestrictHuge && settings.size > creature_size::large ) ) ) {
return PF_IMPASSABLE;
}

const int bash = settings.bash_strength;
const bool allow_open_doors = settings.allow_open_doors;
const bool allow_unlock_doors = settings.allow_unlock_doors;
Expand Down Expand Up @@ -296,6 +305,17 @@ int map::cost_to_pass( const tripoint_bub_ms &cur, const tripoint_bub_ms &p,
return climb_cost;
}

// If terrain/furniture is openable but we can't fit through the open version, ignore the tile
if( settings.size && allow_open_doors &&
( ( terrain.open && terrain.open->has_flag( ter_furn_flag::TFLAG_SMALL_PASSAGE ) ) ||
( furniture.open && furniture.open->has_flag( ter_furn_flag::TFLAG_SMALL_PASSAGE ) ) ||
// Windows with curtains need to be opened twice
( terrain.open->open && terrain.open->open->has_flag( ter_furn_flag::TFLAG_SMALL_PASSAGE ) ) ) &&
settings.size > creature_size::medium
) {
return PF_IMPASSABLE;
}

// If it's a door and we can open it from the tile we're on, cool.
if( allow_open_doors && ( terrain.open || furniture.open ) &&
( ( !terrain.has_flag( ter_furn_flag::TFLAG_OPENCLOSE_INSIDE ) &&
Expand Down
9 changes: 7 additions & 2 deletions src/pathfinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#ifndef CATA_SRC_PATHFINDING_H
#define CATA_SRC_PATHFINDING_H

#include <optional>

#include "coords_fwd.h"
#include "game_constants.h"
#include "mdarray.h"
#include "character.h"

// An attribute of a particular map square that is of interest in pathfinding.
// Has a maximum of 32 members. For more, the datatype underlying PathfindingFlags
Expand Down Expand Up @@ -146,14 +149,16 @@ struct pathfinding_settings {
bool avoid_sharp = false;
bool avoid_dangerous_fields = false;

std::optional<creature_size> size = std::nullopt;

pathfinding_settings() = default;
pathfinding_settings( const pathfinding_settings & ) = default;

pathfinding_settings( int bs, int md, int ml, int cc, bool aod, bool aud, bool at, bool acs,
bool art, bool as )
bool art, bool as, std::optional<creature_size> sz = std::nullopt )
: bash_strength( bs ), max_dist( md ), max_length( ml ), climb_cost( cc ),
allow_open_doors( aod ), allow_unlock_doors( aud ), avoid_traps( at ), allow_climb_stairs( acs ),
avoid_rough_terrain( art ), avoid_sharp( as ) {}
avoid_rough_terrain( art ), avoid_sharp( as ), size( sz ) {}

pathfinding_settings &operator=( const pathfinding_settings & ) = default;
};
Expand Down

0 comments on commit 582f33f

Please sign in to comment.