Skip to content

Commit

Permalink
Fix too large iteration range:
Browse files Browse the repository at this point in the history
`map::build_obstacle_cache` requires start (inclusive) and end (exclusive).
But note that `tripoint_range` exposes minimum and maximum points (both *inclusive*).
  • Loading branch information
BevapDin committed Sep 25, 2019
1 parent 1f06640 commit 6dffe13
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ static std::vector<tripoint> shrapnel( const tripoint &src, int power,
// TODO: Calculate range based on max effective range for projectiles.
// Basically bisect between 0 and map diameter using shrapnel_calc().
// Need to update shadowcasting to support limiting range without adjusting initial distance.
const tripoint start = { 0, 0, src.z };
const tripoint end = { g->m.getmapsize() *SEEX, g->m.getmapsize() *SEEY, src.z };
const tripoint_range area = g->m.points_on_zlevel( src.z );

g->m.build_obstacle_cache( start, end, obstacle_cache );
g->m.build_obstacle_cache( area.min(), area.max() + tripoint( 1, 1, 0 ), obstacle_cache );

// Shadowcasting normally ignores the origin square,
// so apply it manually to catch monsters standing on the explosive.
Expand All @@ -374,7 +373,7 @@ static std::vector<tripoint> shrapnel( const tripoint &src, int power,
( visited_cache, obstacle_cache, src.xy(), 0, initial_cloud );

// Now visited_caches are populated with density and velocity of fragments.
for( const tripoint &target : tripoint_range( start, end ) ) {
for( const tripoint &target : area ) {
fragment_cloud &cloud = visited_cache[target.x][target.y];
if( cloud.density <= MIN_FRAGMENT_DENSITY ||
cloud.velocity <= MIN_EFFECTIVE_VELOCITY ) {
Expand Down

0 comments on commit 6dffe13

Please sign in to comment.