diff --git a/src/Building.cpp b/src/Building.cpp deleted file mode 100644 index 9cf55bf682290fe779e14588a6805daaf148be8a..0000000000000000000000000000000000000000 --- a/src/Building.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "Building.h" - -Building::Building() - : desiredPosition (0,0) - , finalPosition (0,0) - , position (0,0) - , type () - , buildingUnit () - , builderUnit () - , lastOrderFrame (0) - , status (BuildingStatus::Unassigned) - , buildCommandGiven (false) - , underConstruction (false) -{} - -// constructor we use most often -Building::Building(UnitType t, CCTilePosition desired) - : desiredPosition (desired) - , finalPosition (0,0) - , position (0,0) - , type (t) - , buildingUnit () - , builderUnit () - , lastOrderFrame (0) - , status (BuildingStatus::Unassigned) - , buildCommandGiven (false) - , underConstruction (false) -{} - -// equals operator -bool Building::operator == (const Building & b) -{ - // buildings are equal if their worker unit and building unit are equal - return (b.buildingUnit == buildingUnit) - && (b.builderUnit == builderUnit) - && (b.finalPosition.x == finalPosition.x) - && (b.finalPosition.y == finalPosition.y); -} \ No newline at end of file diff --git a/src/Building.h b/src/Building.h deleted file mode 100644 index e5ba8a2bfe961a7f8517205b9afb9ab5cc991754..0000000000000000000000000000000000000000 --- a/src/Building.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "Common.h" -#include "Unit.h" -#include "UnitType.h" - -namespace BuildingStatus -{ - enum { Unassigned = 0, Assigned = 1, UnderConstruction = 2, Size = 3 }; -} - -class Building -{ -public: - - CCTilePosition desiredPosition; - CCTilePosition finalPosition; - CCTilePosition position; - UnitType type; - Unit buildingUnit; - Unit builderUnit; - size_t status; - int lastOrderFrame; - bool buildCommandGiven; - bool underConstruction; - - Building(); - - // constructor we use most often - Building(UnitType t, CCTilePosition desired); - - // equals operator - bool operator == (const Building & b); -}; diff --git a/src/BuildingData.cpp b/src/BuildingData.cpp deleted file mode 100644 index 6c1a6877cb5f2eec9ecc0c2b6424b52e60b9ea33..0000000000000000000000000000000000000000 --- a/src/BuildingData.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "BuildingData.h" - -BuildingData::BuildingData() -{ - -} - -void BuildingData::removeBuilding(const Building & b) -{ - const auto & building = std::find(_buildings.begin(), _buildings.end(), b); - - if (building != _buildings.end()) - { - _buildings.erase(building); - } -} - -std::vector<Building> & BuildingData::getBuildings() -{ - return _buildings; -} - -void BuildingData::addBuilding(const Building & b) -{ - _buildings.push_back(b); -} - -bool BuildingData::isBeingBuilt(UnitType type) -{ - for (auto & b : _buildings) - { - if (b.type == type) - { - return true; - } - } - - return false; -} - -void BuildingData::removeBuildings(const std::vector<Building> & buildings) -{ - for (const auto & b : buildings) - { - removeBuilding(b); - } -} \ No newline at end of file diff --git a/src/BuildingData.h b/src/BuildingData.h deleted file mode 100644 index a748ad6fac015e637f00c6925e8582b0b97a6d9b..0000000000000000000000000000000000000000 --- a/src/BuildingData.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Common.h" -#include "Building.h" - -class BuildingData -{ - std::vector<Building> _buildings; - -public: - - BuildingData(); - - std::vector<Building> & getBuildings(); - - void addBuilding(const Building & b); - void removeBuilding(const Building & b); - void removeBuildings(const std::vector<Building> & buildings); - bool isBeingBuilt(UnitType type); -}; \ No newline at end of file diff --git a/src/BuildingPlacer.cpp b/src/BuildingPlacer.cpp index b9c9f347cbac6f786e358ee7edf1e6faf3b00860..c3d14327ad536f6c3561d6b194b2e48cd5c02673 100644 --- a/src/BuildingPlacer.cpp +++ b/src/BuildingPlacer.cpp @@ -1,7 +1,6 @@ #include "Common.h" #include "BuildingPlacer.h" #include "IDABot.h" -#include "Building.h" #include "Util.h" BuildingPlacer::BuildingPlacer(IDABot & bot) @@ -21,7 +20,7 @@ bool BuildingPlacer::isInResourceBox(int tileX, int tileY) const } // makes final checks to see if a building can be built at a certain location -bool BuildingPlacer::canBuildHere(int bx, int by, const Building & b) const +bool BuildingPlacer::canBuildHere(int bx, int by, const UnitType & type) const { if (isInResourceBox(bx, by)) { @@ -29,9 +28,9 @@ bool BuildingPlacer::canBuildHere(int bx, int by, const Building & b) const } // check the reserve map - for (int x = bx; x < bx + b.type.tileWidth(); x++) + for (int x = bx; x < bx + type.tileWidth(); x++) { - for (int y = by; y < by + b.type.tileHeight(); y++) + for (int y = by; y < by + type.tileHeight(); y++) { if (!m_bot.Map().isValidTile(x, y) || m_reserveMap[x][y]) { @@ -41,7 +40,7 @@ bool BuildingPlacer::canBuildHere(int bx, int by, const Building & b) const } // if it overlaps a base location return false - if (tileOverlapsBaseLocation(bx, by, b.type)) + if (tileOverlapsBaseLocation(bx, by, type)) { return false; } @@ -50,19 +49,17 @@ bool BuildingPlacer::canBuildHere(int bx, int by, const Building & b) const } //returns true if we can build this type of unit here with the specified amount of space. -bool BuildingPlacer::canBuildHereWithSpace(int bx, int by, const Building & b, int buildDist) const +bool BuildingPlacer::canBuildHereWithSpace(int bx, int by, const UnitType & type, int buildDist) const { - UnitType type = b.type; - //if we can't build here, we of course can't build here with space - if (!canBuildHere(bx, by, b)) + if (!canBuildHere(bx, by, type)) { return false; } // height and width of the building - int width = b.type.tileWidth(); - int height = b.type.tileHeight(); + int width = type.tileWidth(); + int height = type.tileHeight(); // TODO: make sure we leave space for add-ons. These types of units can have addons: @@ -85,9 +82,9 @@ bool BuildingPlacer::canBuildHereWithSpace(int bx, int by, const Building & b, i { for (int y = starty; y < endy; y++) { - if (!b.type.isRefinery()) + if (!type.isRefinery()) { - if (!buildable(b, x, y) || m_reserveMap[x][y]) + if (!buildable(type, x, y) || m_reserveMap[x][y]) { return false; } @@ -98,13 +95,13 @@ bool BuildingPlacer::canBuildHereWithSpace(int bx, int by, const Building & b, i return true; } -CCTilePosition BuildingPlacer::getBuildLocationNear(const Building & b, int buildDist) const +CCTilePosition BuildingPlacer::getBuildLocationNear(const CCTilePosition & p, const UnitType & t, int buildDist) const { //Timer t; //t.start(); // get the precomputed vector of tile positions which are sorted closes to this location - auto & closestToBuilding = m_bot.Map().getClosestTilesTo(b.desiredPosition); + auto & closestToBuilding = m_bot.Map().getClosestTilesTo(p); //double ms1 = t.getElapsedTimeInMilliSec(); @@ -113,7 +110,7 @@ CCTilePosition BuildingPlacer::getBuildLocationNear(const Building & b, int buil { auto & pos = closestToBuilding[i]; - if (canBuildHereWithSpace(pos.x, pos.y, b, buildDist)) + if (canBuildHereWithSpace(pos.x, pos.y, t, buildDist)) { //double ms = t.getElapsedTimeInMilliSec(); //printf("Building Placer Took %d iterations, lasting %lf ms @ %lf iterations/ms, %lf setup ms\n", (int)i, ms, (i / ms), ms1); @@ -165,10 +162,10 @@ bool BuildingPlacer::tileOverlapsBaseLocation(int x, int y, UnitType type) const return false; } -bool BuildingPlacer::buildable(const Building & b, int x, int y) const +bool BuildingPlacer::buildable(const UnitType & type, int x, int y) const { // TODO: does this take units on the map into account? - if (!m_bot.Map().isValidTile(x, y) || !m_bot.Map().canBuildTypeAtPosition(x, y, b.type)) + if (!m_bot.Map().isValidTile(x, y) || !m_bot.Map().canBuildTypeAtPosition(x, y, type)) { return false; } @@ -259,12 +256,7 @@ CCTilePosition BuildingPlacer::getRefineryPosition() } } } - -#ifdef SC2API return CCTilePosition((int)closestGeyser.x, (int)closestGeyser.y); -#else - return CCTilePosition(closestGeyser); -#endif } bool BuildingPlacer::isReserved(int x, int y) const diff --git a/src/BuildingPlacer.h b/src/BuildingPlacer.h index 6bf0db3789d44c91b6054cac197b4c7addf46924..7e762b5f81add17a9a52e680562ac41a9643bde2 100644 --- a/src/BuildingPlacer.h +++ b/src/BuildingPlacer.h @@ -1,10 +1,10 @@ #pragma once #include "Common.h" -#include "BuildingData.h" class IDABot; class BaseLocation; +class UnitType; class BuildingPlacer { @@ -13,12 +13,11 @@ class BuildingPlacer std::vector< std::vector<bool> > m_reserveMap; // queries for various BuildingPlacer data - bool buildable(const Building & b, int x, int y) const; + bool buildable(const UnitType & type, int x, int y) const; bool isReserved(int x, int y) const; bool isInResourceBox(int x, int y) const; bool tileOverlapsBaseLocation(int x, int y, UnitType type) const; - public: BuildingPlacer(IDABot & bot); @@ -26,11 +25,11 @@ public: void onStart(); // determines whether we can build at a given location - bool canBuildHere(int bx, int by, const Building & b) const; - bool canBuildHereWithSpace(int bx, int by, const Building & b, int buildDist) const; + bool canBuildHere(int bx, int by, const UnitType & type) const; + bool canBuildHereWithSpace(int bx, int by, const UnitType & type, int buildDist) const; // returns a build location near a building's desired location - CCTilePosition getBuildLocationNear(const Building & b, int buildDist) const; + CCTilePosition getBuildLocationNear(const CCTilePosition & p, const UnitType & type, int buildDist) const; void drawReservedTiles(); diff --git a/src/IDABot.cpp b/src/IDABot.cpp index 6934e31d18365852d10ba5e50a989d306d55400b..07e9046a8b033ba805237e8657b4ca1e373e5684 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -391,8 +391,7 @@ CCTilePosition IDABot::getBuildPosition(UnitType & building) else { CCPosition position = Bases().getPlayerStartingBaseLocation(Players::Self)->getPosition(); - Building b{ building, Util::GetTilePosition(position)}; - tile_position = m_buildingPlacer.getBuildLocationNear(b, 1); + tile_position = m_buildingPlacer.getBuildLocationNear(Util::GetTilePosition(position), building, 1); } return tile_position; } @@ -424,7 +423,8 @@ std::vector<Unit> IDABot::getWorkers() for (auto & unit : GetMyUnits()) { - if (unit.getType().isWorker()) { + if (unit.getType().isWorker()) + { workers.push_back(unit); } }