Skip to content

Commit

Permalink
Update to SteamHammer 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Sep 4, 2020
1 parent 97513d4 commit 870d342
Show file tree
Hide file tree
Showing 40 changed files with 859 additions and 374 deletions.
18 changes: 16 additions & 2 deletions Steamhammer/Source/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ Base::Base(BWAPI::TilePosition pos, const BWAPI::Unitset availableResources)
}
}

// The base is on an island, unconnected by ground to any starting base.
bool Base::isIsland() const
{
for (BWAPI::TilePosition tile : BWAPI::Broodwar->getStartLocations())
{
if (tile != getTilePosition() && getTileDistance(tile) > 0)
{
return false;
}
}

return true;
}

// Recalculate the base's set of geysers, including refineries (completed or not).
// This only works for visible geysers, so it should be called only for bases we own.
// Called to work around a bug related to BWAPI 4.1.2.
Expand Down Expand Up @@ -149,10 +163,10 @@ int Base::getInitialGas() const
// NOTE This doesn't account for mineral patches mining out, decreasing the maximum.
int Base::getMaxWorkers() const
{
return 2 * minerals.size() + 3 * geysers.size();
return 2 * minerals.size() + Config::Macro::WorkersPerRefinery * geysers.size();
}

// Two per mineral patch plus three per geyser.
// How many workers are acually assigned?
int Base::getNumWorkers() const
{
// The number of assigned mineral workers.
Expand Down
1 change: 1 addition & 0 deletions Steamhammer/Source/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Base
BWAPI::Unit getDepot() const { return resourceDepot; };
BWAPI::Player getOwner() const { return owner; };
bool isAStartingBase() const { return startingBase; };
bool isIsland() const;

void findGeysers();

Expand Down
33 changes: 14 additions & 19 deletions Steamhammer/Source/Bases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,10 @@ void Bases::updateBaseOwners()
);
// Is one of the units a resource depot?
BWAPI::Unit depot = nullptr;
for (const auto unit : units)
for (BWAPI::Unit unit : units)
{
if (unit->getType().isResourceDepot() && !unit->isLifted())
{
UAB_ASSERT(unit->getType() != BWAPI::UnitTypes::Zerg_Infested_Command_Center, "infested resource depot");
depot = unit;
break;
}
Expand Down Expand Up @@ -907,9 +906,9 @@ int Bases::geyserCount() const
return count;
}

// Current number of completed refineries at my completed bases,
// Current number of my completed refineries at my completed bases,
// and number of bare geysers available to be taken.
// Not counted: The number of refineries currently under construction.
// Not counted: Enemy stolen refineries; refineries under construction.
void Bases::gasCounts(int & nRefineries, int & nFreeGeysers) const
{
int refineries = 0;
Expand All @@ -921,25 +920,21 @@ void Bases::gasCounts(int & nRefineries, int & nFreeGeysers) const
{
// Recalculate the base's geysers every time.
// This is a slow but accurate way to work around the BWAPI geyser bug.
// To save cycles, call findGeysers() only when necessary (e.g. a refinery is destroyed).
base->findGeysers();

for (BWAPI::Unit geyser : base->getGeysers())
{
if (geyser && geyser->exists())
{
if (geyser->getPlayer() == BWAPI::Broodwar->self() &&
geyser->getType().isRefinery() &&
geyser->isCompleted())
{
++refineries;
}
else if (geyser->getPlayer() == BWAPI::Broodwar->neutral())
{
++geysers;
}
}
}
if (geyser->getPlayer() == BWAPI::Broodwar->self() &&
geyser->getType().isRefinery() &&
geyser->isCompleted())
{
++refineries;
}
else if (geyser->getType() == BWAPI::UnitTypes::Resource_Vespene_Geyser)
{
++geysers;
}
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions Steamhammer/Source/BuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,21 @@ bool BuildingManager::isGasStealInQueue() const
return false;
}

// We have queued an expansion to the given base.
// (Or at least some building at the same location.)
bool BuildingManager::isBasePlanned(const Base * base) const
{
for (const Building & b : _buildings)
{
if (b.finalPosition == base->getTilePosition())
{
return true;
}
}

return false;
}

void BuildingManager::drawBuildingInformation(int x, int y)
{
if (!Config::Debug::DrawBuildingInfo)
Expand Down
1 change: 1 addition & 0 deletions Steamhammer/Source/BuildingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class BuildingManager
size_t getNumUnstarted() const;
size_t getNumUnstarted(BWAPI::UnitType type) const;
bool isGasStealInQueue() const;
bool isBasePlanned(const Base * base) const;

std::vector<BWAPI::UnitType> buildingsQueued();

Expand Down
Loading

0 comments on commit 870d342

Please sign in to comment.