Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. void GridManager::addThreat(UnitInfo& unit)
  2.     {
  3.         if (unit.getType().isWorker() && (!unit.unit()->exists() || (Terrain().isInAllyTerritory(unit.getTilePosition()) && (Broodwar->getFrameCount() - unit.getLastAttackFrame() > 500))))
  4.             return;
  5.  
  6.         if (unit.getVisibleGroundStrength() <= 0.0 && unit.getVisibleAirStrength() <= 0.0)
  7.             return;
  8.  
  9.         if (unit.getType() == UnitTypes::Protoss_Interceptor)
  10.             return;
  11.  
  12.         // Speed multipled by 4.0 because we want WalkPositions per second
  13.         // unit.getSpeed() returns pixels per frame
  14.         // Walks/Second = speed * 24 / 8
  15.  
  16.         // Setup parameters
  17.         int maxRange = int(max({ unit.getGroundRange(), unit.getAirRange(), 64.0 }) / 8.0);
  18.         int speed = int(unit.getSpeed());
  19.         int radius = maxRange + (speed * 3);
  20.         int walkWidth = (int)ceil(unit.getType().width() / 8.0);
  21.         int walkHeight = (int)ceil(unit.getType().height() / 8.0);
  22.         int grdReach = int(max(unit.getGroundRange(), 64.0) + (speed * 24.0) + (unit.getType().width() / 2));
  23.         int airReach = int(max(unit.getAirRange(), 64.0) + (speed * 24.0) + (unit.getType().width() / 2));
  24.         //int frame = Broodwar->getFrameCount();       
  25.  
  26.  
  27.         // Choose the grid - NULL self grid for now
  28.         auto grdGrid = unit.getPlayer() == Broodwar->self() ? nullptr : eGroundThreat;
  29.         auto airGrid = unit.getPlayer() == Broodwar->self() ? nullptr : eAirThreat;
  30.  
  31.         WalkPosition start(unit.getWalkPosition());
  32.  
  33.         // Safety
  34.         if (!grdGrid || !airGrid)
  35.             return;
  36.  
  37.         // Iterate tiles and add to grid
  38.         for (int x = start.x - radius; x < start.x + walkWidth + radius; x++) {
  39.             for (int y = start.y - radius; y < start.y + walkHeight + radius; y++) {
  40.  
  41.                 WalkPosition w(x, y);
  42.                 Position p = Position(w) + Position(4, 4);
  43.  
  44.                 if (!w.isValid() || !p.isValid())
  45.                     continue;          
  46.  
  47.                 grdGrid[x][y] += (unit.getVisibleGroundStrength() * (p.getDistance(unit.getPosition()) < grdReach));
  48.                 airGrid[x][y] += (unit.getVisibleAirStrength() * (p.getDistance(unit.getPosition()) < airReach));
  49.                 saveReset(w);
  50.             }
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement