Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GridManager::addThreat(UnitInfo& unit)
- {
- if (unit.getType().isWorker() && (!unit.unit()->exists() || (Terrain().isInAllyTerritory(unit.getTilePosition()) && (Broodwar->getFrameCount() - unit.getLastAttackFrame() > 500))))
- return;
- if (unit.getVisibleGroundStrength() <= 0.0 && unit.getVisibleAirStrength() <= 0.0)
- return;
- if (unit.getType() == UnitTypes::Protoss_Interceptor)
- return;
- // Speed multipled by 4.0 because we want WalkPositions per second
- // unit.getSpeed() returns pixels per frame
- // Walks/Second = speed * 24 / 8
- // Setup parameters
- int maxRange = int(max({ unit.getGroundRange(), unit.getAirRange(), 64.0 }) / 8.0);
- int speed = int(unit.getSpeed());
- int radius = maxRange + (speed * 3);
- int walkWidth = (int)ceil(unit.getType().width() / 8.0);
- int walkHeight = (int)ceil(unit.getType().height() / 8.0);
- int grdReach = int(max(unit.getGroundRange(), 64.0) + (speed * 24.0) + (unit.getType().width() / 2));
- int airReach = int(max(unit.getAirRange(), 64.0) + (speed * 24.0) + (unit.getType().width() / 2));
- //int frame = Broodwar->getFrameCount();
- // Choose the grid - NULL self grid for now
- auto grdGrid = unit.getPlayer() == Broodwar->self() ? nullptr : eGroundThreat;
- auto airGrid = unit.getPlayer() == Broodwar->self() ? nullptr : eAirThreat;
- WalkPosition start(unit.getWalkPosition());
- // Safety
- if (!grdGrid || !airGrid)
- return;
- // Iterate tiles and add to grid
- for (int x = start.x - radius; x < start.x + walkWidth + radius; x++) {
- for (int y = start.y - radius; y < start.y + walkHeight + radius; y++) {
- WalkPosition w(x, y);
- Position p = Position(w) + Position(4, 4);
- if (!w.isValid() || !p.isValid())
- continue;
- grdGrid[x][y] += (unit.getVisibleGroundStrength() * (p.getDistance(unit.getPosition()) < grdReach));
- airGrid[x][y] += (unit.getVisibleAirStrength() * (p.getDistance(unit.getPosition()) < airReach));
- saveReset(w);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement