Ticket #1756: MakeGoalReacheable_improved.patch
File MakeGoalReacheable_improved.patch, 2.7 KB (added by , 10 years ago) |
---|
-
source/simulation2/components/CCmpPathfinder_Hier.cpp
(this hunk was shorter than expected) 531 539 532 540 bool CCmpPathfinder_Hier::MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass) 533 541 { 534 542 RegionID source = Get(i0, j0, passClass); 535 543 536 // Find everywhere that's reachable537 std::set<RegionID> reachableRegions;538 FindReachableRegions(source, reachableRegions, passClass);539 540 544 // debug_printf(L"\nReachable from (%d,%d): ", i0, j0); 541 545 // for (std::set<RegionID>::iterator it = reachableRegions.begin(); it != reachableRegions.end(); ++it) 542 546 // debug_printf(L"[%d,%d,%d], ", it->ci, it->cj, it->r); … … 543 548 // debug_printf(L"\n"); 544 549 545 550 // Check whether any reachable region contains the goal 546 for (std::set<RegionID>::const_iterator it = reachableRegions.begin(); it != reachableRegions.end(); ++it) 551 552 u16 gi0, gj0, gi1, gj1; 553 m_Pathfinder.NearestNavcell(goal.x - goal.hw - goal.hh, goal.z - goal.hw - goal.hh, gi0, gj0); 554 m_Pathfinder.NearestNavcell(goal.x + goal.hw + goal.hh, goal.z + goal.hw + goal.hh, gi1, gj1); 555 556 u16 ci0 = gi0 / CHUNK_SIZE; 557 u16 cj0 = gj0 / CHUNK_SIZE; 558 u16 ci1 = gi1 / CHUNK_SIZE; 559 u16 cj1 = gj1 / CHUNK_SIZE; 560 561 for (u16 ci = ci0; ci <= ci1; ci++) 547 562 { 548 // Skip region if its chunk doesn't contain the goal area 549 entity_pos_t x0 = ICmpObstructionManager::NAVCELL_SIZE * (it->ci * CHUNK_SIZE); 550 entity_pos_t z0 = ICmpObstructionManager::NAVCELL_SIZE * (it->cj * CHUNK_SIZE); 551 entity_pos_t x1 = x0 + ICmpObstructionManager::NAVCELL_SIZE * CHUNK_SIZE; 552 entity_pos_t z1 = z0 + ICmpObstructionManager::NAVCELL_SIZE * CHUNK_SIZE; 553 if (!goal.RectContainsGoal(x0, z0, x1, z1)) 554 continue; 555 556 // If the region contains the goal area, the goal is reachable 557 // and we don't need to move it 558 if (GetChunk(it->ci, it->cj, passClass).RegionContainsGoal(it->r, goal)) 559 return false; 563 for (u16 cj = cj0; cj <= cj1; cj++) 564 { 565 Chunk& cnk = GetChunk(ci, cj, passClass); 566 // If the region contains the goal area, the goal is reachable 567 // and we don't need to move it 568 if (cnk.RegionContainsGoal(source.r , goal)) 569 return false; 570 } 560 571 } 561 572 562 573 // The goal area wasn't reachable, … … 565 576 u16 iGoal, jGoal; 566 577 m_Pathfinder.NearestNavcell(goal.x, goal.z, iGoal, jGoal); 567 578 579 // Find everywhere that's reachable 580 std::set<RegionID> reachableRegions; 581 FindReachableRegions(source, reachableRegions, passClass); 582 568 583 FindNearestNavcellInRegions(reachableRegions, iGoal, jGoal, passClass); 569 584 570 585 // Construct a new point goal at the nearest reachable navcell