Пример #1
0
  @Override
  public void process(Building building, Map map, long tickCount) {
    blocked = false;
    Player player = map.getPlayerById(building.getOwnerId());

    if (building.getTicksAccumulated() >= unitType.getTicksToBuild()) {
      if (placeUnit(map, building)) {
        building.setTicksAccumulated(0);
        building.removeGoal(this);
      } else {
        blocked = true;
      }
    } else {
      if (player.getElectricity() < 0) {
        // throttle 3/4 of ticks, if not enough electricity
        if (tickCount % 4 != 3) {
          return;
        }
      }

      if (player.getMoney() >= unitType.getCostPerTick()) {
        player.setMoney(player.getMoney() - unitType.getCostPerTick());
        building.setTicksAccumulated(building.getTicksAccumulated() + 1);
        if (building.getTicksAccumulated() >= unitType.getTicksToBuild()) {
          if (placeUnit(map, building)) {
            building.setTicksAccumulated(0);
            building.removeGoal(this);
          }
        }
      }
    }
  }