MCPcopy Create free account
hub / github.com/TurningWheel/Barony / gyrobotSetPathToReturnLocation

Method gyrobotSetPathToReturnLocation

src/actmonster.cpp:13293–13363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13291}
13292
13293bool Entity::gyrobotSetPathToReturnLocation(int destX, int destY, int adjacentTilesToCheck, bool tryRandomSpot)
13294{
13295 int u, v;
13296 bool foundplace = false;
13297 int pathToX = destX;
13298 int pathToY = destY;
13299
13300 if ( static_cast<int>(x / 16) == destX && static_cast<int>(y / 16) == destY )
13301 {
13302 return true; // we're trying to move to the spot we're already at!
13303 }
13304 else if ( !checkObstacle((destX << 4) + 8, (destY << 4) + 8, this, nullptr) )
13305 {
13306 int index = (destY)* MAPLAYERS + (destX)* MAPLAYERS * map.height;
13307 if ( !tryRandomSpot && map.tiles[index] )
13308 {
13309 foundplace = true; // we can path directly to the destination specified.
13310 }
13311 }
13312
13313 std::vector<std::pair<int, std::pair<int, int>>> possibleDestinations; // store distance and the x, y coordinates in each element.
13314
13315 if ( !foundplace )
13316 {
13317 for ( u = destX - adjacentTilesToCheck; u <= destX + adjacentTilesToCheck; u++ )
13318 {
13319 for ( v = destY - adjacentTilesToCheck; v <= destY + adjacentTilesToCheck; v++ )
13320 {
13321 if ( static_cast<int>(x / 16) == u && static_cast<int>(y / 16) == v )
13322 {
13323 // we're trying to move to the spot we're already at!
13324 }
13325 else if ( !checkObstacle((u << 4) + 8, (v << 4) + 8, this, nullptr) )
13326 {
13327 int index = (v) * MAPLAYERS + (u) * MAPLAYERS * map.height;
13328 if ( !map.tiles[index] )
13329 {
13330 continue; // bad spot to land
13331 }
13332 int distance = pow(destX - u, 2) + pow(destY - v, 2);
13333 possibleDestinations.push_back(std::make_pair(distance, std::make_pair(u, v)));
13334 }
13335 }
13336 }
13337 }
13338
13339 if ( !possibleDestinations.empty() )
13340 {
13341 // sort by distance from monster, first result is shortest path.
13342 std::sort(possibleDestinations.begin(), possibleDestinations.end());
13343 pathToX = possibleDestinations.at(0).second.first;
13344 pathToY = possibleDestinations.at(0).second.second;
13345 foundplace = true;
13346 }
13347
13348 path = generatePath(static_cast<int>(floor(x / 16)), static_cast<int>(floor(y / 16)), pathToX, pathToY,
13349 this, nullptr, GeneratePathTypes::GENERATE_PATH_PLAYER_GYRO_RETURN);
13350 if ( children.first != NULL )

Callers

nothing calls this directly

Calls 7

checkObstacleFunction · 0.85
generatePathFunction · 0.85
list_RemoveNodeFunction · 0.85
list_AddNodeFirstFunction · 0.85
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected