MCPcopy Create free account
hub / github.com/bwapi/bwapi / UpdateRegionRelations

Method UpdateRegionRelations

bwapi/BWAPI/Source/BWAPI/RegionImpl.cpp:36–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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;

Callers 1

onGameStartMethod · 0.80

Calls 7

getNeighborMethod · 0.80
getApproxDistanceMethod · 0.80
isConnectedToMethod · 0.80
clearMethod · 0.45
getRegionMethod · 0.45
getIndexMethod · 0.45
getCenterMethod · 0.45

Tested by

no test coverage detected