@ -64,11 +64,13 @@ inline uint8_t count_accessibility(const df::coord &unit_pos, const df::coord &m
get_connected_neighbours ( map_pos , connections ) ;
get_connected_neighbours ( map_pos , connections ) ;
uint8_t accessibility = Maps : : canWalkBetween ( unit_pos , map_pos ) ? 1 : 0 ;
uint8_t accessibility = Maps : : canWalkBetween ( unit_pos , map_pos ) ? 1 : 0 ;
for ( auto n : neighbours ) {
for ( auto n : neighbours ) {
if unlikely ( ! Maps : : isValidTilePos ( n ) ) continue ;
if ( Maps : : canWalkBetween ( unit_pos , n ) ) {
if ( Maps : : canWalkBetween ( unit_pos , n ) ) {
accessibility + + ;
accessibility + + ;
}
}
}
}
for ( auto n : connections ) {
for ( auto n : connections ) {
if unlikely ( Maps : : isValidTilePos ( n ) ) continue ;
if ( Maps : : canWalkBetween ( unit_pos , n ) ) {
if ( Maps : : canWalkBetween ( unit_pos , n ) ) {
accessibility + + ;
accessibility + + ;
}
}
@ -77,22 +79,22 @@ inline uint8_t count_accessibility(const df::coord &unit_pos, const df::coord &m
}
}
inline bool isEntombed ( const df : : coord & unit_pos , const df : : coord & map_pos ) {
inline bool isEntombed ( const df : : coord & unit_pos , const df : : coord & map_pos ) {
if ( Maps : : canWalkBetween ( unit_pos , map_pos ) ) {
if likely ( Maps : : canWalkBetween ( unit_pos , map_pos ) ) {
return false ;
return false ;
}
}
df : : coord neighbours [ 8 ] ;
df : : coord neighbours [ 8 ] ;
get_neighbours ( map_pos , neighbours ) ;
get_neighbours ( map_pos , neighbours ) ;
return std : : all_of ( neighbours + 0 , neighbours + 8 , [ & unit_pos ] ( df : : coord n ) {
return std : : all_of ( neighbours + 0 , neighbours + 8 , [ & unit_pos ] ( df : : coord n ) {
return ! Maps : : canWalkBetween( unit_pos , n ) ;
return ! Maps : : isValidTilePos( n ) | | ! Maps : : canWalkBetween( unit_pos , n ) ;
} ) ;
} ) ;
}
}
inline bool is_dig_job ( const df : : job * job ) {
inline bool is_dig_job ( const df : : job * job ) {
return job - > job_type = = df : : job_type : : Dig | | job - > job_type = = df : : job_type : : DigChannel ;
return job & & ( job - > job_type = = df : : job_type : : Dig | | job - > job_type = = df : : job_type : : DigChannel ) ;
}
}
inline bool is_channel_job ( const df : : job * job ) {
inline bool is_channel_job ( const df : : job * job ) {
return job - > job_type = = df : : job_type : : DigChannel ;
return job & & ( job - > job_type = = df : : job_type : : DigChannel ) ;
}
}
inline bool is_group_job ( const ChannelGroups & groups , const df : : job * job ) {
inline bool is_group_job ( const ChannelGroups & groups , const df : : job * job ) {
@ -111,34 +113,48 @@ inline bool is_safe_fall(const df::coord &map_pos) {
df : : coord below ( map_pos ) ;
df : : coord below ( map_pos ) ;
for ( uint8_t zi = 0 ; zi < config . fall_threshold ; + + zi ) {
for ( uint8_t zi = 0 ; zi < config . fall_threshold ; + + zi ) {
below . z - - ;
below . z - - ;
// falling out of bounds is probably considerably unsafe for a dwarf
if unlikely ( ! Maps : : isValidTilePos ( below ) ) {
return false ;
}
// if we require vision, and we can't see below.. we'll need to assume it's safe to get anything done
if ( config . require_vision & & Maps : : getTileDesignation ( below ) - > bits . hidden ) {
if ( config . require_vision & & Maps : : getTileDesignation ( below ) - > bits . hidden ) {
return true ; //we require vision, and we can't see below.. so we gotta assume it's safe
return true ;
}
}
// finally, if we're not looking at open space (air to fall through) it's safe to fall to
df : : tiletype type = * Maps : : getTileType ( below ) ;
df : : tiletype type = * Maps : : getTileType ( below ) ;
if ( ! DFHack : : isOpenTerrain ( type ) ) {
if ( ! DFHack : : isOpenTerrain ( type ) ) {
return true ;
return true ;
}
}
}
}
// we exceeded the fall threshold, so it's not a safe fall
return false ;
return false ;
}
}
inline bool is_safe_to_dig_down ( const df : : coord & map_pos ) {
inline bool is_safe_to_dig_down ( const df : : coord & map_pos ) {
df : : coord pos ( map_pos ) ;
df : : coord pos ( map_pos ) ;
// todo: probably should rely on is_safe_fall, it looks like it could be simplified a great deal
for ( uint8_t zi = 0 ; zi < = config . fall_threshold ; + + zi ) {
for ( uint8_t zi = 0 ; zi < = config . fall_threshold ; + + zi ) {
// assume safe if we can't see and need vision
// if we're digging out of bounds, the game can handle that (hopefully)
if unlikely ( ! Maps : : isValidTilePos ( pos ) ) {
return true ;
}
// if we require vision, and we can't see the tiles in question.. we'll need to assume it's safe to dig to get anything done
if ( config . require_vision & & Maps : : getTileDesignation ( pos ) - > bits . hidden ) {
if ( config . require_vision & & Maps : : getTileDesignation ( pos ) - > bits . hidden ) {
return true ;
return true ;
}
}
df : : tiletype type = * Maps : : getTileType ( pos ) ;
df : : tiletype type = * Maps : : getTileType ( pos ) ;
if ( zi = = 0 & & DFHack : : isOpenTerrain ( type ) ) {
if ( zi = = 0 & & DFHack : : isOpenTerrain ( type ) ) {
// todo: remove? this is probably not useful.. and seems like the only considerable difference to is_safe_fall (aside from where each stops looking)
// the starting tile is open space, that's obviously not safe
// the starting tile is open space, that's obviously not safe
return false ;
return false ;
} else if ( ! DFHack : : isOpenTerrain ( type ) ) {
} else if ( ! DFHack : : isOpenTerrain ( type ) ) {
// a tile after the first one is not open space
// a tile after the first one is not open space
return true ;
return true ;
}
}
pos . z - - ;
pos . z - - ; // todo: this can probably move to the beginning of the loop
}
}
return false ;
return false ;
}
}