Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • stebr364/pycommandcenter
  • starcraft-ai-course/pycommandcenter
  • eriah592/pycommandcenter
  • edvbe696/pycommandcenter
  • dawab699/pycommandcenter
  • hanja189/pycommandcenter
  • teoga849/pycommandcenter
  • musab250/pycommandcenter
  • emibr898/pycommandcenter
  • chrgu102/pycommandcenter
  • axega544/pycommandcenter
  • edvth289/pycommandcenter
  • jonbo278/py-command-center-v-2
13 results
Show changes
......@@ -24,10 +24,11 @@ typedef sc2::Tag CCUnitID;
typedef sc2::Race CCRace;
typedef float CCHealth;
typedef float CCPositionType;
typedef sc2::BuffID CCBuff;
typedef size_t CCPlayer;
namespace Players
{
enum {Self = 0u, Enemy = 1u, Neutral = 2u, Ally = 3u, Size = 4u, None = 5u};
}
\ No newline at end of file
}
#include "IDABot.h"
#include "Util.h"
#include "sc2api/sc2_score.h"
IDABot::IDABot()
: m_map(*this)
......@@ -72,11 +74,21 @@ void IDABot::OnStep()
m_unitInfo.onFrame();
m_bases.onFrame();
// suppress warnings while we update the tiles occupied by units
bool old_suppress = m_techTree.getSuppressWarnings();
m_techTree.setSuppressWarnings(true);
m_buildingPlacer.updateReserved(GetAllUnits());
m_techTree.setSuppressWarnings(old_suppress);
// -----------------------------------------------------------------
// Draw debug interface, and send debug interface to the Sc2 client.
// -----------------------------------------------------------------
Debug()->SendDebug();
m_buildingPlacer.drawReservedTiles();
m_buildingPlacer.drawReservedTiles();
}
void IDABot::OnGameEnd()
{
}
void IDABot::setUnits()
......@@ -124,7 +136,7 @@ int IDABot::GetCurrentFrame() const
return (int)Observation()->GetGameLoop();
}
const TechTree & IDABot::TechTree() const
const TechTree & IDABot::GetTechTree() const
{
return m_techTree;
}
......@@ -151,6 +163,10 @@ int IDABot::GetGas() const
Unit IDABot::GetUnit(const CCUnitID & tag) const
{
if (Observation()->GetUnit(tag) == nullptr) {
return Unit();
}
return Unit(Observation()->GetUnit(tag), *(IDABot *)this);
}
......@@ -194,11 +210,17 @@ void IDABot::OnError(const std::vector<sc2::ClientError> & client_errors, const
// This is called when the sc2api (Google's API) has an error.
}
BuildingPlacer & IDABot::BuildingPlacer()
BuildingPlacer & IDABot::GetBuildingPlacer()
{
return m_buildingPlacer;
}
void IDABot::SendChat(const std::string & message)
{
Actions()->SendChat(message);
}
const TypeData & IDABot::Data(const UnitType & type) const
{
return m_techTree.getData(type);
......@@ -219,3 +241,176 @@ const TypeData & IDABot::Data(const MetaType & type) const
return m_techTree.getData(type);
}
/*
API extended summer 2020
*/
void IDABot::DebugCreateUnit(UnitTypeID unit_type, const CCPosition& p, uint32_t player_id, uint32_t count)
{
switch (player_id) // playerconstants for the IDAbot is not the same as for the sc2 API
{
case 0:
Debug()->DebugCreateUnit(unit_type, p, 1, count);
break;
case 1:
Debug()->DebugCreateUnit(unit_type, p, 2, count);
break;
case 2:
Debug()->DebugCreateUnit(unit_type, p, 0, count);
break;
case 3:
Debug()->DebugCreateUnit(unit_type, p, 3, count);
default:
break;
}
}
void IDABot::DebugKillUnit(const Unit unit)
{
Debug()->DebugKillUnit(unit.getUnitPtr());
}
void IDABot::DebugShowMap()
{
Debug()->DebugShowMap();
}
void IDABot::DebugFastBuild()
{
Debug()->DebugFastBuild();
}
void IDABot::DebugEnemyControl()
{
Debug()->DebugEnemyControl();
}
void IDABot::DebugIgnoreFood()
{
Debug()->DebugIgnoreFood();
}
void IDABot::DebugIgnoreResourceCost()
{
Debug()->DebugIgnoreResourceCost();
}
void IDABot::DebugGiveAllResources()
{
Debug()->DebugGiveAllResources();
}
void IDABot::DebugGodMode()
{
Debug()->DebugGodMode();
}
void IDABot::DebugIgnoreMineral()
{
Debug()->DebugIgnoreMineral();
}
void IDABot::DebugNoCooldowns()
{
Debug()->DebugIgnoreMineral();
}
void IDABot::DebugGiveAllTech()
{
Debug()->DebugGiveAllTech();
}
void IDABot::DebugGiveAllUpgrades()
{
Debug()->DebugGiveAllUpgrades();
}
void IDABot::DebugSetScore(float score)
{
Debug()->DebugSetScore(score);
}
void IDABot::DebugEndGame(bool victory)
{
Debug()->DebugEndGame(victory);
}
void IDABot::DebugSetEnergy(float value, const Unit unit)
{
Debug()->DebugSetEnergy(value, unit.getUnitPtr());
}
void IDABot::DebugSetLife(float value, const Unit unit)
{
Debug()->DebugSetLife(value, unit.getUnitPtr());
}
void IDABot::DebugSetShields(float value, const Unit unit)
{
Debug()->DebugSetShields(value, unit.getUnitPtr());
}
// There is a bug in the latest SC2 (if using Blizzard API with game >=4.10)
// This a function to get the enemy base instead of using build location manager
// Switched over to other API where this is solved
// Leaving function incase of it breaking
const std::vector<Point2D> IDABot::GetEnemyBaseLocations()
{
return Observation()->GetGameInfo().enemy_start_locations;
}
bool IDABot::HasCreep(Point2D p) const
{
return Observation()->HasCreep(p);
}
void IDABot::CameraMove(Point2DI p)
{
ActionsFeatureLayer()->CameraMove(p);
}
sc2::ABILITY_ID IDABot::abilityForUpgrade(sc2::UpgradeID upgrade_id) const
{
return (sc2::ABILITY_ID)Observation()->GetUpgradeData()[upgrade_id].ability_id;
}
uint32_t IDABot::UpgradeMineralCost(sc2::UpgradeID upgrade_id) const
{
return Observation()->GetUpgradeData()[upgrade_id].mineral_cost;
}
uint32_t IDABot::UpgradeGasCost(sc2::UpgradeID upgrade_id) const
{
return Observation()->GetUpgradeData()[upgrade_id].vespene_cost;
}
float IDABot::UpgradeResearchTime(sc2::UpgradeID upgrade_id) const
{
return Observation()->GetUpgradeData()[upgrade_id].research_time;
}
float IDABot::RadiusEffect(sc2::EffectID effect_id) const
{
return Observation()->GetEffectData()[effect_id].radius;
}
float IDABot::GetScore() const
{
return Observation()->GetScore().score;
}
const sc2::GameResult IDABot::GetPlayerResults() const
{
auto res = Observation()->GetResults();
for(int i = 0; i < res.size(); i++)
{
if (res.at(i).player_id == Observation()->GetPlayerID()) return res.at(i).result;
}
std::cout << "The player can not be found" << std::endl;
return sc2::GameResult::Undecided;
}
bool IDABot::SaveReplay(const std::string& path)
{
return this->Control()->SaveReplay(path);
}
\ No newline at end of file
......@@ -10,9 +10,14 @@
#include "UnitInfoManager.h"
#include "BuildingPlacer.h"
#include "TechTree.h"
#include "TechTreeImproved.h"
#include "MetaType.h"
#include "Unit.h"
using sc2::UnitTypeID;
using sc2::Point2D;
using sc2::Point2DI;
class IDABot : public sc2::Agent
{
MapTools m_map;
......@@ -33,17 +38,20 @@ public:
void OnGameStart() override;
void OnStep() override;
void OnGameEnd() override;
/*
API for students
*/
const TechTree & TechTree() const;
const TechTree & GetTechTree() const;
const BaseLocationManager & Bases() const;
const MapTools & Map() const;
const UnitInfoManager & UnitInfo() const;
CCRace GetPlayerRace(int player) const;
CCPosition GetStartLocation() const;
BuildingPlacer & BuildingPlacer();
BuildingPlacer & GetBuildingPlacer();
void SendChat(const std::string & message);
int GetCurrentFrame() const;
int GetMinerals() const;
......@@ -56,9 +64,46 @@ public:
const std::vector<Unit> GetUnits(const UnitType & type, int player = Players::Self) const;
const std::vector<CCPosition> & GetStartLocations() const;
/*
API extended summer 2020
*/
void DebugCreateUnit(UnitTypeID unit_type, const CCPosition& p, uint32_t player_id = 1, uint32_t count = 1);
void DebugKillUnit(const Unit unit);
void DebugShowMap();
void DebugFastBuild();
void DebugEnemyControl();
void DebugIgnoreFood();
void DebugIgnoreResourceCost();
void DebugGiveAllResources();
void DebugGodMode();
void DebugIgnoreMineral();
void DebugNoCooldowns();
void DebugGiveAllTech();
void DebugGiveAllUpgrades();
void DebugSetScore(float score);
void DebugEndGame(bool victory);
void DebugSetEnergy(float value, const Unit unit);
void DebugSetLife(float value, const Unit unit);
void DebugSetShields(float value, const Unit unit);
const std::vector<Point2D> GetEnemyBaseLocations();
bool HasCreep(Point2D p) const;
void CameraMove(Point2DI p);
sc2::ABILITY_ID abilityForUpgrade(sc2::UpgradeID upgrade_id) const;
uint32_t UpgradeMineralCost(sc2::UpgradeID upgrade_id) const;
uint32_t UpgradeGasCost(sc2::UpgradeID upgrade_id) const;
float UpgradeResearchTime(sc2::UpgradeID upgrade_id) const;
float RadiusEffect(sc2::EffectID effect_id) const;
float GetScore() const;
const sc2::GameResult GetPlayerResults() const;
bool SaveReplay(const std::string & path);
// Not needed, just convenience functions
const TypeData & Data(const UnitType & type) const;
const TypeData & Data(const CCUpgrade & type) const;
const TypeData & Data(const MetaType & type) const;
const TypeData & Data(const Unit & unit) const;
};
\ No newline at end of file
};
#include "IDAReplayObserver.h"
#include "Util.h"
void IDAReplayObserver::setUnits()
{
m_allUnits.clear();
m_allUnitsID.clear();
for (auto & unit : Observation()->GetUnits())
{
ReplayUnit replayUnit = ReplayUnit(unit, *this);
m_allUnits.push_back(replayUnit);
m_allUnitsID.insert(replayUnit.getID());
}
}
IDAReplayObserver::IDAReplayObserver():
sc2::ReplayObserver(),
m_techTree(*this)
{
}
void IDAReplayObserver::OnGameStart()
{
setUnits();
m_techTree.onStart();
}
void IDAReplayObserver::OnStep()
{
setUnits();
}
void IDAReplayObserver::OnGameEnd()
{
}
void IDAReplayObserver::OnUnitDestroyed(const sc2::Unit* unit)
{
ReplayUnit unitInformation = ReplayUnit(unit, *this);
OnReplayUnitDestroyed(&unitInformation);
}
void IDAReplayObserver::OnReplayUnitDestroyed(const ReplayUnit *)
{
}
void IDAReplayObserver::OnUnitCreated(const sc2::Unit * unit)
{
ReplayUnit unitInformation = ReplayUnit(unit, *this);
OnReplayUnitCreated(&unitInformation);
}
void IDAReplayObserver::OnReplayUnitCreated(const ReplayUnit *)
{
}
void IDAReplayObserver::OnBuildingConstructionComplete(const sc2::Unit *unit)
{
ReplayUnit unitInformation = ReplayUnit(unit, *this);
OnReplayUnitCreated(&unitInformation);
}
ReplayUnit IDAReplayObserver::GetUnit(const CCUnitID tag) const
{
return ReplayUnit(Observation()->GetUnit(tag), *(IDAReplayObserver *)this);
}
bool IDAReplayObserver::UnitExists(const CCUnitID tag) const
{
return m_allUnitsID.find(tag) != m_allUnitsID.end();
}
const std::vector<ReplayUnit>& IDAReplayObserver::GetAllUnits() const
{
return m_allUnits;
}
CCRace IDAReplayObserver::GetPlayerRace(int player)
{
return ReplayControl()->GetReplayInfo().players[player].race;
}
std::string IDAReplayObserver::GetReplayPath()
{
return ReplayControl()->GetReplayInfo().replay_path;
}
sc2::GameResult IDAReplayObserver::GetResultForPlayer(int player)
{
return ReplayControl()->GetReplayInfo().players[player].game_result;
}
const TechTree & IDAReplayObserver::GetTechTree() const
{
return m_techTree;
}
const TypeData & IDAReplayObserver::Data(const UnitType & type) const
{
return m_techTree.getData(type);
}
const TypeData & IDAReplayObserver::Data(const CCUpgrade & type) const
{
return m_techTree.getData(type);
}
const TypeData & IDAReplayObserver::Data(const MetaType & type) const
{
return m_techTree.getData(type);
}
const TypeData & IDAReplayObserver::Data(const Unit & unit) const
{
return m_techTree.getData(unit.getType());
}
#pragma once
#include <deque>
#include <limits>
#include "Common.h"
#include "ReplayUnit.h"
#include "TechTree.h"
class ReplayUnit;
class IDAReplayObserver : public sc2::ReplayObserver
{
void setUnits();
std::vector<ReplayUnit> m_allUnits;
std::set<CCUnitID> m_allUnitsID;
TechTree m_techTree;
public:
IDAReplayObserver();
void OnGameStart() override;
void OnStep() override;
void OnGameEnd() override;
void OnUnitDestroyed(const sc2::Unit*) override;
virtual void OnReplayUnitDestroyed(const ReplayUnit*);
void OnUnitCreated(const sc2::Unit*);
virtual void OnReplayUnitCreated(const ReplayUnit*);
void OnBuildingConstructionComplete(const sc2::Unit*);
ReplayUnit GetUnit(const CCUnitID tag) const;
bool UnitExists(const CCUnitID tag) const;
const std::vector<ReplayUnit> & GetAllUnits() const;
CCRace GetPlayerRace(int player);
std::string GetReplayPath();
sc2::GameResult GetResultForPlayer(int player);
const TechTree & GetTechTree() const;
const TypeData & Data(const UnitType & type) const;
const TypeData & Data(const CCUpgrade & type) const;
const TypeData & Data(const MetaType & type) const;
const TypeData & Data(const Unit & unit) const;
};
......@@ -7,6 +7,23 @@
#include <fstream>
#include <array>
namespace {
bool getBit(const sc2::ImageData& grid, int tileX, int tileY) {
assert(grid.bits_per_pixel == 1);
sc2::Point2DI pointI(tileX, tileY);
if (pointI.x < 0 || pointI.x >= grid.width || pointI.y < 0 || pointI.y >= grid.height)
{
return false;
}
div_t idx = div(pointI.x + pointI.y * grid.width, 8);
return (grid.data[idx.quot] >> (7 - idx.rem)) & 1;
}
} // namespace
const size_t LegalActions = 4;
const int actionX[LegalActions] ={1, -1, 0, 0};
const int actionY[LegalActions] ={0, 0, 1, -1};
......@@ -23,7 +40,8 @@ typedef std::vector<std::vector<float>> vvf;
// constructor for MapTools
MapTools::MapTools(IDABot & bot)
: m_bot (bot)
: m_bot(bot)
, m_mapName ("")
, m_width (0)
, m_height (0)
, m_maxZ (0.0f)
......@@ -37,6 +55,7 @@ void MapTools::onStart()
#ifdef SC2API
m_width = m_bot.Observation()->GetGameInfo().width;
m_height = m_bot.Observation()->GetGameInfo().height;
m_mapName= m_bot.Observation()->GetGameInfo().map_name;
#else
m_width = BWAPI::Broodwar->mapWidth();
m_height = BWAPI::Broodwar->mapHeight();
......@@ -160,8 +179,6 @@ void MapTools::onFrame()
}
}
}
draw();
}
void MapTools::computeConnectivity()
......@@ -263,7 +280,7 @@ bool MapTools::isPowered(int tileX, int tileY) const
#endif
}
float MapTools::terrainHeight(float x, float y) const
float MapTools::terrainHeightFromCoord(float x, float y) const
{
return m_terrainHeight[(int)x][(int)y];
}
......@@ -329,7 +346,8 @@ bool MapTools::isValidPosition(const CCPosition & pos) const
void MapTools::drawLine(CCPositionType x1, CCPositionType y1, CCPositionType x2, CCPositionType y2, const CCColor & color) const
{
#ifdef SC2API
m_bot.Debug()->DebugLineOut(sc2::Point3D(x1, y1, terrainHeight(x1, y1) + 0.2f), sc2::Point3D(x2, y2, terrainHeight(x2, y2) + 0.2f), color);
//m_bot.Debug()->DebugLineOut(sc2::Point3D(x1, y1, terrainHeight(x1, y1) + 0.2f), sc2::Point3D(x2, y2, terrainHeight(x2, y2) + 0.2f), color);
m_bot.Debug()->DebugLineOut(sc2::Point3D(x1, y1, m_maxZ), sc2::Point3D(x2, y2, m_maxZ), color); // changed to m_maxZ instead fo terrainHeight since it doesnot work correctly
#else
BWAPI::Broodwar->drawLineMap(BWAPI::Position(x1, y1), BWAPI::Position(x2, y2), color);
#endif
......@@ -356,6 +374,10 @@ void MapTools::drawTile(int tileX, int tileY, const CCColor & color) const
drawLine(px, py + d, px, py, color);
}
void MapTools::drawTile(const CCTilePosition & pos, const CCColor & color) const {
drawTile(pos.x, pos.y, color);
}
void MapTools::drawBox(CCPositionType x1, CCPositionType y1, CCPositionType x2, CCPositionType y2, const CCColor & color) const
{
#ifdef SC2API
......@@ -386,6 +408,15 @@ void MapTools::drawCircle(const CCPosition & pos, CCPositionType radius, const C
#endif
}
void MapTools::drawResourceSphere(const sc2::Point3D & pos, CCPositionType radius, const CCColor & color) const
{
#ifdef SC2API
m_bot.Debug()->DebugSphereOut(pos, radius, color);
#else
BWAPI::Broodwar->drawCircleMap(pos, radius, color);
#endif
}
void MapTools::drawCircle(CCPositionType x, CCPositionType y, CCPositionType radius, const CCColor & color) const
{
#ifdef SC2API
......@@ -514,6 +545,11 @@ int MapTools::height() const
return m_height;
}
std::string MapTools::name() const
{
return m_mapName;
}
const std::vector<CCTilePosition> & MapTools::getClosestTilesTo(const CCTilePosition & pos) const
{
return getDistanceMap(pos).getSortedTiles();
......@@ -543,17 +579,7 @@ CCTilePosition MapTools::getLeastRecentlySeenTile() const
bool MapTools::canWalk(int tileX, int tileY)
{
#ifdef SC2API
auto & info = m_bot.Observation()->GetGameInfo();
sc2::Point2DI pointI(tileX, tileY);
if (pointI.x < 0 || pointI.x >= info.width || pointI.y < 0 || pointI.y >= info.width)
{
return false;
}
assert(info.pathing_grid.data.size() == info.width * info.height);
unsigned char encodedPlacement = info.pathing_grid.data[pointI.x + ((info.height - 1) - pointI.y) * info.width];
bool decodedPlacement = encodedPlacement == 255 ? false : true;
return decodedPlacement;
return getBit(m_bot.Observation()->GetGameInfo().pathing_grid, tileX, tileY);
#else
for (int i=0; i<4; ++i)
{
......@@ -573,17 +599,7 @@ bool MapTools::canWalk(int tileX, int tileY)
bool MapTools::canBuild(int tileX, int tileY)
{
#ifdef SC2API
auto & info = m_bot.Observation()->GetGameInfo();
sc2::Point2DI pointI(tileX, tileY);
if (pointI.x < 0 || pointI.x >= info.width || pointI.y < 0 || pointI.y >= info.width)
{
return false;
}
assert(info.placement_grid.data.size() == info.width * info.height);
unsigned char encodedPlacement = info.placement_grid.data[pointI.x + ((info.height - 1) - pointI.y) * info.width];
bool decodedPlacement = encodedPlacement == 255 ? true : false;
return decodedPlacement;
return getBit(m_bot.Observation()->GetGameInfo().placement_grid, tileX, tileY);
#else
return BWAPI::Broodwar->isBuildable(BWAPI::TilePosition(tileX, tileY));
#endif
......@@ -608,48 +624,3 @@ float MapTools::terrainHeight(const CCPosition & point) const
#endif
}
void MapTools::draw() const
{
#ifdef SC2API
CCPosition camera = m_bot.Observation()->GetCameraPos();
int sx = (int)(camera.x - 12.0f);
int sy = (int)(camera.y - 8);
int ex = sx + 24;
int ey = sy + 20;
#else
BWAPI::TilePosition screen(BWAPI::Broodwar->getScreenPosition());
int sx = screen.x;
int sy = screen.y;
int ex = sx + 20;
int ey = sy + 15;
#endif
for (int x = sx; x < ex; ++x)
{
for (int y = sy; y < ey; y++)
{
if (!isValidTile((int)x, (int)y))
{
continue;
}
// TODO: This maybe should be restored somehow? (Check git blame)
if (false)
{
std::stringstream ss;
ss << getSectorNumber(x, y);
drawText(CCPosition(Util::TileToPosition(x + 0.5f), Util::TileToPosition(y + 0.5f)), ss.str());
}
if (false)
{
CCColor color = isWalkable(x, y) ? CCColor(0, 255, 0) : CCColor(255, 0, 0);
if (isWalkable(x, y) && !isBuildable(x, y)) { color = CCColor(255, 255, 0); }
if (isBuildable(x, y) && !isDepotBuildableTile(x, y)) { color = CCColor(127, 255, 255); }
drawTile(x, y, color);
}
}
}
}
......@@ -8,11 +8,12 @@ class IDABot;
class MapTools
{
IDABot & m_bot;
int m_width;
int m_height;
float m_maxZ;
int m_frame;
IDABot & m_bot;
std::string m_mapName;
int m_width;
int m_height;
float m_maxZ;
int m_frame;
// a cache of already computed distance maps, which is mutable since it only acts as a cache
......@@ -41,19 +42,22 @@ public:
void onStart();
void onFrame();
void draw() const;
int width() const;
int height() const;
float terrainHeight(float x, float y) const;
std::string name() const;
float terrainHeightFromCoord(float x, float y) const;
void drawLine(CCPositionType x1, CCPositionType y1, CCPositionType x2, CCPositionType y2, const CCColor & color = CCColor(255, 255, 255)) const;
void drawLine(const CCPosition & p1, const CCPosition & p2, const CCColor & color = CCColor(255, 255, 255)) const;
void drawTile(int tileX, int tileY, const CCColor & color = CCColor(255, 255, 255)) const;
void drawTile(const CCTilePosition & pos, const CCColor & color) const;
void drawBox(CCPositionType x1, CCPositionType y1, CCPositionType x2, CCPositionType y2, const CCColor & color = CCColor(255, 255, 255)) const;
void drawBox(const CCPosition & tl, const CCPosition & br, const CCColor & color = CCColor(255, 255, 255)) const;
void drawCircle(CCPositionType x1, CCPositionType x2, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const;
void drawCircle(const CCPosition & pos, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const;
void drawResourceSphere(const sc2::Point3D & pos, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const;
void drawText(const CCPosition & pos, const std::string & str, const CCColor & color = CCColor(255, 255, 255)) const;
void drawTextScreen(float xPerc, float yPerc, const std::string & str, const CCColor & color = CCColor(255, 255, 255)) const;
......
......@@ -8,6 +8,20 @@ MyAgent::MyAgent()
void MyAgent::OnGameStart()
{
IDABot::OnGameStart();
sc2::UnitTypeID wanted_type = sc2::UNIT_TYPEID::TERRAN_GHOST;
sc2::UnitTypeData wanted_data = Observation()->GetUnitTypeData()[wanted_type];
std::cout << "Looking up: " << wanted_data.name << std::endl;
sc2::UnitTypeData requirement = Observation()->GetUnitTypeData()[wanted_data.tech_requirement];
std::cout << "Found tech requirement: " << requirement.name << "(" << wanted_data.tech_requirement << ")" << std::endl;
std::cout << std::boolalpha;
std::cout << "Require attached (Is addon?): " << wanted_data.require_attached << std::endl;
std::cout << "Found ability_id" << wanted_data.ability_id << std::endl;
// TODO: What/who can use this ability??
sc2::AbilityData ability_to_create = Observation()->GetAbilityData()[wanted_data.ability_id];
std::cout << "Button name for ability " << ability_to_create.button_name << std::endl;
}
void MyAgent::OnStep()
......@@ -71,7 +85,7 @@ void MyAgent::manageBuilding(std::vector<UnitType> & build_plan)
BuildStatus status{ type, position };
currently_building[worker] = status;
// Reserve the location
BuildingPlacer().reserveTiles(position.x, position.y, type.tileWidth(), type.tileHeight());
GetBuildingPlacer().reserveTiles(position.x, position.y, type.tileWidth(), type.tileHeight());
// Update economy book-keeping
if (type.isRefinery() || type.isResourceDepot())
......@@ -289,7 +303,7 @@ void MyAgent::manageWorkers(std::vector<UnitType> & build_plan)
if (worker.isIdle())
{
BuildStatus status = currently_building[worker];
BuildingPlacer().freeTiles(status.position.x, status.position.y, status.type.tileWidth(), status.type.tileHeight());
GetBuildingPlacer().freeTiles(status.position.x, status.position.y, status.type.tileWidth(), status.type.tileHeight());
currently_building.erase(worker);
assignWork(worker, Assignment::Mineral);
}
......@@ -401,7 +415,7 @@ CCTilePosition MyAgent::getBuildPosition(UnitType & building)
else
{
CCPosition position = Bases().getPlayerStartingBaseLocation(Players::Self)->getPosition();
tile_position = BuildingPlacer().getBuildLocationNear(Util::GetTilePosition(position), building, 1);
tile_position = GetBuildingPlacer().getBuildLocationNear(Util::GetTilePosition(position), building, 1);
}
return tile_position;
}
......
#include "ReplayUnit.h"
ReplayUnit::ReplayUnit(const sc2::Unit * unit, IDAReplayObserver & replayObserver)
: m_replayObserver(&replayObserver), Unit(unit), m_type(unit->unit_type, replayObserver, replayObserver)
{
}
const UnitType & ReplayUnit::getType() const
{
return m_type;
}
bool ReplayUnit::hasTarget() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
if (getUnitPtr()->orders.size() > 0) {
if (getUnitPtr()->orders[0].target_unit_tag != NULL) {
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
// IDAReplayObserver checks if the unit with this tag still exists
if (m_replayObserver->UnitExists(t_id)){
// IDAReplayObserver finds the unit with this tag, and returns true if valid
return m_replayObserver->GetUnit(t_id).isValid();
}
}
}
return false;
}
ReplayUnit ReplayUnit::getTarget() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
// if unit has order, check tag of target of first order
if (getUnitPtr()->orders.size() > 0) {
// t_id is set to the unit tag of the target
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
// Checks if the tag is a null tag or the unit have been removed
if (t_id != sc2::NullTag && m_replayObserver->UnitExists(t_id)){
// IDAReplayObserver finds the unit with this tag
return m_replayObserver->GetUnit(t_id);
}
}
return *this;
}
int ReplayUnit::getPlayer() const
{
return m_unit->owner;
}
#pragma once
#include "Unit.h"
#include "IDAReplayObserver.h"
class IDAReplayObserver;
//! A Unit that have a replayobserver insted of an Agent,
class ReplayUnit: public Unit
{
mutable IDAReplayObserver * m_replayObserver;
UnitType m_type;
public:
ReplayUnit(const sc2::Unit * unit, IDAReplayObserver & replayObserver);
const UnitType & getType() const;
bool hasTarget() const;
ReplayUnit getTarget() const;
int getPlayer() const;
};
\ No newline at end of file
This diff is collapsed.
......@@ -24,23 +24,29 @@ struct TypeData
sc2::AbilityID warpAbility = 0; // the ability that creates this item via warp-in
std::vector<UnitType> whatBuilds; // any of these units can build the item
std::vector<UnitType> requiredUnits; // owning ONE of these is required to make
std::vector<CCUpgrade> requiredUpgrades; // having ALL of these is required to make
std::vector<sc2::UPGRADE_ID> requiredUpgrades; // having ALL of these is required to make
std::vector<UnitType> requiredAddons; // a unit of this type must be present next to the producer
sc2::AbilityID morphAbility = 0; // the ability which morphes the producer into this type
};
class TechTree
{
IDABot & m_bot;
sc2::Client & m_client;
std::map<UnitType, TypeData> m_unitTypeData;
std::map<CCUpgrade, TypeData> m_upgradeData;
void initUnitTypeData();
void initUpgradeData();
bool suppressWarnings;
public:
TechTree(IDABot & bot);
TechTree(sc2::Client & client);
void onStart();
void setSuppressWarnings(bool b);
bool getSuppressWarnings() const;
const TypeData & getData(const UnitType & type) const;
const TypeData & getData(const CCUpgrade & type) const;
const TypeData & getData(const MetaType & type) const;
......
This diff is collapsed.
This diff is collapsed.
#pragma once
#include "nlohmann/json.hpp"
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include "sc2api/sc2_typeenums.h"
struct BuildDescription
{
sc2::UNIT_TYPEID producer_type;
sc2::UNIT_TYPEID result_type;
sc2::AbilityID build_ability;
sc2::AbilityID morph_ability;
std::vector<sc2::UNIT_TYPEID> buildings_needed;
std::vector<sc2::UNIT_TYPEID> addons_needed;
std::vector<sc2::UPGRADE_ID> upgrades_needed;
int buildTime; // The time in seconds it takes to create the unit
};
struct ResearchDescription
{
sc2::UPGRADE_ID result_type;
sc2::UNIT_TYPEID producer_type;
sc2::AbilityID ability_used;
std::vector<sc2::UNIT_TYPEID> buildings_needed;
std::vector<sc2::UPGRADE_ID> upgrades_needed;
};
class TechTreeImproved
{
std::map<sc2::UNIT_TYPEID, std::vector<BuildDescription>> result_to_data;
std::map<sc2::UPGRADE_ID, std::vector<ResearchDescription>> upgrade_to_data;
std::vector<BuildDescription> build_descriptions;
std::vector<ResearchDescription> research_descriptions;
// If there is no BuildDescription for a given type, a reference to tihs list is returned.
const std::vector<BuildDescription> empty_build {};
const std::vector<ResearchDescription> empty_research {};
void parse_unit(nlohmann::json::iterator it);
public:
TechTreeImproved();
bool LoadData();
// Given a unit, how can we build it?
const std::vector<BuildDescription> & HowToBuild(sc2::UnitTypeID unit) const;
const std::vector<ResearchDescription> & HowToResearch(sc2::UpgradeID upgrade) const;
const std::vector<BuildDescription> & BuildDescriptions() const { return build_descriptions; }
const std::vector<ResearchDescription> & ResearchDescriptions() const { return research_descriptions; }
};
This diff is collapsed.
This diff is collapsed.
......@@ -13,7 +13,7 @@ UnitInfoManager::UnitInfoManager(IDABot & bot)
void UnitInfoManager::onStart()
{
updateUnitInfo();
}
void UnitInfoManager::onFrame()
......
This diff is collapsed.
This diff is collapsed.