Skip to content

Commit

Permalink
Add 2D test cases for avoidance/allowance, and fix some bugs found.
Browse files Browse the repository at this point in the history
  • Loading branch information
prharvey committed Dec 29, 2023
1 parent 330448f commit e1a006a
Show file tree
Hide file tree
Showing 4 changed files with 531 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void RealityBubblePathfindingCache::update( const map &here, const tripoint_bub_
flags |= PathfindingFlag::Slow;
}

if( !terrain.has_flag( ter_furn_flag::TFLAG_BURROWABLE ) ||
if( !terrain.has_flag( ter_furn_flag::TFLAG_BURROWABLE ) &&
!terrain.has_flag( ter_furn_flag::TFLAG_DIGGABLE ) ) {
flags |= PathfindingFlag::HardGround;
}
Expand Down Expand Up @@ -442,7 +442,7 @@ std::optional<int> transition_cost( const map &here, const tripoint_bub_ms &from
}


const PathfindingFlags flags = cache.flags( from );
const PathfindingFlags flags = cache.flags( to );
if( flags.is_set( PathfindingFlag::Obstacle ) ) {
if( !settings.is_digging() ) {
if( flags.is_set( PathfindingFlag::Door ) && !settings.avoid_opening_doors() &&
Expand Down
43 changes: 40 additions & 3 deletions tests/map_test_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,51 @@ tile_predicate ifchar( char c, const tile_predicate &f )
}

tile_predicate ter_set(
ter_str_id ter,
ter_str_id id,
tripoint shift
)
{
return [ = ]( map_test_case::tile t ) {
REQUIRE( ter.is_valid() );
REQUIRE( id.is_valid() );
tripoint p = t.p + shift;
get_map().ter_set( p, ter );
get_map().ter_set( p, id );
return true;
};
}

tile_predicate ter_set(
ter_id id,
tripoint shift
)
{
return [ = ]( map_test_case::tile t ) {
tripoint p = t.p + shift;
get_map().ter_set( p, id );
return true;
};
}

tile_predicate furn_set(
furn_id id,
tripoint shift
)
{
return [ = ]( map_test_case::tile t ) {
tripoint p = t.p + shift;
get_map().furn_set( p, id );
return true;
};
}

tile_predicate trap_set(
trap_str_id id,
tripoint shift
)
{
return [ = ]( map_test_case::tile t ) {
REQUIRE( id.is_valid() );
tripoint p = t.p + shift;
get_map().trap_set( p, id );
return true;
};
}
Expand Down
18 changes: 15 additions & 3 deletions tests/map_test_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,25 @@ namespace tiles
tile_predicate ifchar( char c, const tile_predicate &f );

/**
* Returns the function that sets the map `ter` at the `map_test_case::tile` coords to the given ter_id
* @param ter ter id to set
* Returns the function that sets the map `ter/furn/trap` at the `map_test_case::tile` coords to the given id
* @param id id to set
* @param shift shift from the current tile coordinates (e.g. to have the ability to set tiles above)
* @return function that sets tiles
*/
tile_predicate ter_set(
ter_str_id ter,
ter_str_id id,
tripoint shift = tripoint_zero
);
tile_predicate ter_set(
ter_id id,
tripoint shift = tripoint_zero
);
tile_predicate furn_set(
furn_id id,
tripoint shift = tripoint_zero
);
tile_predicate trap_set(
trap_str_id id,
tripoint shift = tripoint_zero
);

Expand Down
Loading

0 comments on commit e1a006a

Please sign in to comment.