|
|
|
@ -118,51 +118,7 @@ Point Map::center_camera(const Point &around, size_t view_x, size_t view_y) { |
|
|
|
|
* in and out. |
|
|
|
|
*/ |
|
|
|
|
bool Map::neighbors(Point &out, bool random, int direction) { |
|
|
|
|
Matrix &paths = $paths.$paths; |
|
|
|
|
bool zero_found = false; |
|
|
|
|
|
|
|
|
|
// just make a list of the four directions
|
|
|
|
|
std::array<Point, 4> dirs{{ |
|
|
|
|
{out.x,out.y-1}, // north
|
|
|
|
|
{out.x+1,out.y}, // east
|
|
|
|
|
{out.x,out.y+1}, // south
|
|
|
|
|
{out.x-1,out.y} // west
|
|
|
|
|
}}; |
|
|
|
|
|
|
|
|
|
// get the current dijkstra number
|
|
|
|
|
int cur = paths[out.y][out.x]; |
|
|
|
|
|
|
|
|
|
// pick a random start of directions
|
|
|
|
|
// BUG: is uniform inclusive of the dir.size()?
|
|
|
|
|
int rand_start = Random::uniform<int>(0, dirs.size()); |
|
|
|
|
|
|
|
|
|
// go through all possible directions
|
|
|
|
|
for(size_t i = 0; i < dirs.size(); i++) { |
|
|
|
|
// but start at the random start, effectively randomizing
|
|
|
|
|
// which valid direction to go
|
|
|
|
|
// BUG: this might be wrong given the above ranom from 0-size
|
|
|
|
|
Point dir = dirs[(i + rand_start) % dirs.size()]; |
|
|
|
|
if(!inmap(dir.x, dir.y)) continue; //skip unpathable stuff
|
|
|
|
|
int weight = cur - paths[dir.y][dir.x]; |
|
|
|
|
|
|
|
|
|
if(weight == direction) { |
|
|
|
|
// no matter what we follow direct paths
|
|
|
|
|
out = dir; |
|
|
|
|
return true; |
|
|
|
|
} else if(random && weight == 0) { |
|
|
|
|
// if random is selected and it's a 0 path take it
|
|
|
|
|
out = dir; |
|
|
|
|
return true; |
|
|
|
|
} else if(weight == 0) { |
|
|
|
|
// otherwise keep the last zero path for after
|
|
|
|
|
out = dir; |
|
|
|
|
zero_found = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if we reach this then either zero was found and
|
|
|
|
|
// zero_found is set true, or it wasn't and nothing found
|
|
|
|
|
return zero_found; |
|
|
|
|
return $paths.random_walk(out, random, direction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Map::INVARIANT() { |
|
|
|
|