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

Method getBuildLocationNear

bwapi/TestAIModule/Source/BuildingPlacer.cpp:44–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44BWAPI::TilePosition BuildingPlacer::getBuildLocationNear(BWAPI::TilePosition position, BWAPI::UnitType type, int buildDist)
45{
46 //returns a valid build location near the specified tile position.
47 //searches outward in a spiral.
48 int length = 1;
49 int j = 0;
50 bool first = true;
51 int dx = 0;
52 int dy = 1;
53 while (length < BWAPI::Broodwar->mapWidth()) //We'll ride the spiral to the end
54 {
55 //if we can build here, return this tile position
56 if ( position )
57 if (canBuildHereWithSpace(position, type, buildDist))
58 return position;
59
60 //otherwise, move to another position
61 position += BWAPI::TilePosition(dx, dy);
62 //count how many steps we take in this direction
63 j++;
64 if (j == length) //if we've reached the end, its time to turn
65 {
66 //reset step counter
67 j = 0;
68
69 //Spiral out. Keep going.
70 if (!first)
71 length++; //increment step counter if needed
72
73 //first=true for every other turn so we spiral out at the right rate
74 first = !first;
75
76 //turn counter clockwise 90 degrees:
77 if (dx == 0)
78 {
79 dx = dy;
80 dy = 0;
81 }
82 else
83 {
84 dy = -dx;
85 dx = 0;
86 }
87 }
88 //Spiral out. Keep going.
89 }
90 return BWAPI::TilePositions::None;
91}
92
93bool BuildingPlacer::buildable(BWAPI::TilePosition position)
94{

Callers

nothing calls this directly

Calls 1

mapWidthMethod · 0.45

Tested by

no test coverage detected