Ticket #1756: MakeGoalReacheable_improved_v2.patch
File MakeGoalReacheable_improved_v2.patch, 2.8 KB (added by , 10 years ago) |
---|
-
source/simulation2/components/CCmpPathfinder_Hier.cpp
533 533 { 534 534 RegionID source = Get(i0, j0, passClass); 535 535 536 // Find everywhere that's reachable537 std::set<RegionID> reachableRegions;538 FindReachableRegions(source, reachableRegions, passClass);539 540 536 // debug_printf(L"\nReachable from (%d,%d): ", i0, j0); 541 537 // for (std::set<RegionID>::iterator it = reachableRegions.begin(); it != reachableRegions.end(); ++it) 542 538 // debug_printf(L"[%d,%d,%d], ", it->ci, it->cj, it->r); … … 543 539 // debug_printf(L"\n"); 544 540 545 541 // Check whether any reachable region contains the goal 546 for (std::set<RegionID>::const_iterator it = reachableRegions.begin(); it != reachableRegions.end(); ++it) 542 u16 iGoal, jGoal; 543 m_Pathfinder.NearestNavcell(goal.x, goal.z, iGoal, jGoal); 544 if (goal.type == PathGoal::POINT || goal.type == PathGoal::CIRCLE || goal.type == PathGoal::SQUARE) 547 545 { 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)) 546 if (source.r == Get(iGoal, jGoal, passClass).r) 559 547 return false; 560 548 } 561 549 550 u16 gi0, gj0, gi1, gj1; 551 m_Pathfinder.NearestNavcell(goal.x - goal.hw - goal.hh, goal.z - goal.hw - goal.hh, gi0, gj0); 552 m_Pathfinder.NearestNavcell(goal.x + goal.hw + goal.hh, goal.z + goal.hw + goal.hh, gi1, gj1); 553 554 u16 ci0 = gi0 / CHUNK_SIZE; 555 u16 cj0 = gj0 / CHUNK_SIZE; 556 u16 ci1 = gi1 / CHUNK_SIZE; 557 u16 cj1 = gj1 / CHUNK_SIZE; 558 559 for (u16 ci = ci0; ci <= ci1; ci++) 560 { 561 for (u16 cj = cj0; cj <= cj1; cj++) 562 { 563 Chunk& cnk = GetChunk(ci, cj, passClass); 564 // If the region contains the goal area, the goal is reachable 565 // and we don't need to move it 566 if (cnk.RegionContainsGoal(source.r , goal)) 567 return false; 568 } 569 } 570 562 571 // The goal area wasn't reachable, 563 572 // so find the navcell that's nearest to the goal's center 564 573 565 u16 iGoal, jGoal; 566 m_Pathfinder.NearestNavcell(goal.x, goal.z, iGoal, jGoal); 574 // Find everywhere that's reachable 575 std::set<RegionID> reachableRegions; 576 FindReachableRegions(source, reachableRegions, passClass); 567 577 568 578 FindNearestNavcellInRegions(reachableRegions, iGoal, jGoal, passClass); 569 579