Ticket #2725: AtGoal.patch
File AtGoal.patch, 2.0 KB (added by , 10 years ago) |
---|
-
source/simulation2/components/CCmpPathfinder_Tile.cpp
32 32 33 33 typedef PriorityQueueHeap<std::pair<u16, u16>, u32> PriorityQueue; 34 34 35 #define PATHFIND_STATS 0 35 #define PATHFIND_STATS 1 36 #if PATHFIND_STATS 37 #include "lib/timer.h" 38 TIMER_ADD_CLIENT(tc_AtGoal); 39 #endif 36 40 37 41 #define USE_DIAGONAL_MOVEMENT 1 38 42 … … 215 219 #endif 216 220 }; 217 221 218 static bool AtGoal(u16 i, u16 j, const ICmpPathfinder::Goal& goal )222 static bool AtGoal(u16 i, u16 j, const ICmpPathfinder::Goal& goal, const u32 h) 219 223 { 224 #if PATHFIND_STATS 225 TIMER_ACCRUE(tc_AtGoal); 226 #endif 220 227 // Allow tiles slightly more than sqrt(2) from the actual goal, 221 228 // i.e. adjacent diagonally to the target tile 222 fixed tolerance = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*3/2);229 const fixed tolerance = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*3/2); 223 230 231 entity_pos_t margin = tolerance; 232 233 if (goal.type == ICmpPathfinder::Goal::SQUARE) 234 // diagonal line is always shorter than max(height, width) * 1.5 235 margin += (goal.hh > goal.hw ? goal.hh : goal.hw) * 3 / entity_pos_t::FromInt(2 * TERRAIN_TILE_SIZE); 236 237 if (h > g_CostPerTile * margin.ToFloat()) 238 return false; 239 224 240 entity_pos_t x, z; 225 241 CCmpPathfinder::TileCenter(i, j, x, z); 226 242 fixed dist = CCmpPathfinder::DistanceToGoal(CFixedVector2D(x, z), goal); … … 377 393 NearestTile(goal.x, goal.z, state.iGoal, state.jGoal); 378 394 379 395 // If we're already at the goal tile, then move directly to the exact goal coordinates 380 if (AtGoal(i0, j0, goal ))396 if (AtGoal(i0, j0, goal, 0)) 381 397 { 382 398 Waypoint w = { goal.x, goal.z }; 383 399 path.m_Waypoints.push_back(w); … … 438 454 state.tiles->get(i, j).SetStatusClosed(); 439 455 440 456 // If we've reached the destination, stop 441 if (AtGoal(i, j, goal ))457 if (AtGoal(i, j, goal, state.tiles->get(i, j).h)) 442 458 { 443 459 state.iBest = i; 444 460 state.jBest = j;