Enumify terrain blockage and generalize the line of sight function

This should probably be two separate commits, but they're tangled together and I don't want to spend the effort to disentangle them.
This commit is contained in:
2014-12-01 19:50:19 -05:00
parent afd45b3774
commit d900c7edef
19 changed files with 150 additions and 300 deletions

View File

@@ -1203,3 +1203,48 @@ void tileImage(RgnHandle area, GWorldPtr img, RECT srcRect, short mode){
}
}
#endif
short can_see(location p1,location p2,std::function<short(short,short)> get_obscurity) {
short storage = 0;
if(p1.y == p2.y) {
if(p1.x > p2.x) {
for(short count = p2.x + 1; count < p1.x; count++)
storage += get_obscurity(count, p1.y);
} else {
for(short count = p1.x + 1; count < p2.x; count++)
storage += get_obscurity(count, p1.y);
}
} else if(p1.x == p2.x) {
if(p1.y > p2.y) {
for(short count = p1.y - 1; count > p2.y; count--)
storage += get_obscurity(p1.x, count);
} else {
for(short count = p1.y + 1; count < p2.y; count++)
storage += get_obscurity(p1.x, count);
}
} else {
short dx = p2.x - p1.x;
short dy = p2.y - p1.y;
if(abs(dy) > abs(dx)) {
if(p2.y > p1.y) {
for(short count = 1; count < dy; count++)
storage += get_obscurity(p1.x + (count * dx) / dy, p1.y + count);
} else {
for(short count = -1; count > dy; count--)
storage += get_obscurity(p1.x + (count * dx) / dy, p1.y + count);
}
}
if(abs(dy) <= abs(dx)) {
if(p2.x > p1.x) {
for(short count = 1; count < dx; count++)
storage += get_obscurity(p1.x + count, p1.y + (count * dy) / dx);
} else {
for(short count = -1; count > dx; count--)
storage += get_obscurity(p1.x + count, p1.y + (count * dy) / dx);
}
}
}
return storage;
}