| 34 | this->closestInaccessibleRgn = nullptr; |
| 35 | } |
| 36 | void RegionImpl::UpdateRegionRelations() |
| 37 | { |
| 38 | // Assuming this is called via GameInternals, so no checks are made |
| 39 | const BW::region * const r = &BW::BWDATA::SAIPathing->regions[self->id]; |
| 40 | |
| 41 | // Assign region neighbors |
| 42 | this->neighbors.clear(); |
| 43 | |
| 44 | int accessibleBestDist = 99999; |
| 45 | int inaccessibleBestDist = 99999; |
| 46 | for ( int n = 0; n < r->neighborCount; ++n ) |
| 47 | { |
| 48 | BW::region *neighbor = r->getNeighbor(static_cast<u8>(n)); |
| 49 | BWAPI::Region bwapiNeighbor = Broodwar->getRegion(neighbor->getIndex()); |
| 50 | |
| 51 | // continue if this is null (but it shouldn't be) |
| 52 | if ( !bwapiNeighbor ) |
| 53 | continue; |
| 54 | |
| 55 | // add our neighbor |
| 56 | this->neighbors.insert(bwapiNeighbor); |
| 57 | |
| 58 | // Obtain the closest accessible and inaccessible Regions from their Region center |
| 59 | int dst = r->getCenter().getApproxDistance(neighbor->getCenter()); |
| 60 | if ( r->isConnectedTo( neighbor ) ) |
| 61 | { |
| 62 | if ( dst < accessibleBestDist ) |
| 63 | { |
| 64 | accessibleBestDist = dst; |
| 65 | this->closestAccessibleRgn = bwapiNeighbor; |
| 66 | } |
| 67 | } |
| 68 | else if ( dst < inaccessibleBestDist ) |
| 69 | { |
| 70 | inaccessibleBestDist = dst; |
| 71 | this->closestInaccessibleRgn = bwapiNeighbor; |
| 72 | } |
| 73 | |
| 74 | // Client compatibility for neighbors |
| 75 | ++self->neighborCount; |
| 76 | self->neighbors[n] = neighbor->getIndex(); |
| 77 | } |
| 78 | } |
| 79 | RegionData *RegionImpl::getData() |
| 80 | { |
| 81 | return self; |
no test coverage detected