From 0ff7a375d53af6e12d57f315942c0f03c90d9b6f Mon Sep 17 00:00:00 2001 From: Rojikku98 <be.edvin@gmail.com> Date: Fri, 11 Mar 2022 09:47:05 +0100 Subject: [PATCH] Fixed some issues --- python-api-src/lib_map_tools.cpp | 2 +- src/BaseLocationManager.cpp | 3 ++- src/IDABot.cpp | 12 ++++++++---- src/MapTools.cpp | 2 +- src/MapTools.h | 2 +- src/Unit.cpp | 12 ++++++------ src/Unit.h | 1 + 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/python-api-src/lib_map_tools.cpp b/python-api-src/lib_map_tools.cpp index 2f8e344..ecf9520 100644 --- a/python-api-src/lib_map_tools.cpp +++ b/python-api-src/lib_map_tools.cpp @@ -17,7 +17,7 @@ void define_map_tools(py::module & m) .def_property_readonly("width", &MapTools::width, "The width of the map") .def_property_readonly("height", &MapTools::height, "The height of the map") .def_property_readonly("map_name", &MapTools::name, "The name of the map") - //.def("terrainHeight", &MapTools::terrainHeight, py::const_) + .def("terrainHeight", &MapTools::terrainHeightCord, "x"_a, "y"_a) .def("draw_line", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawLine, py::const_), py::arg("start"), py::arg("stop"), py::arg("color") = sc2::Colors::White, "Draws a line with the given color between to two points.") .def("draw_tile", py::overload_cast<const CCTilePosition &, const CCColor &>(&MapTools::drawTile, py::const_), py::arg("tile"), py::arg("color") = sc2::Colors::White, "Draws an outline with the given color to the given tile.") .def("draw_box", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawBox, py::const_), py::arg("top_left"), py::arg("bottom_right"), py::arg("color") = sc2::Colors::White, "Draws a box with the given color from the top left cornor to the botom right") diff --git a/src/BaseLocationManager.cpp b/src/BaseLocationManager.cpp index 93a89d9..28b9b2d 100644 --- a/src/BaseLocationManager.cpp +++ b/src/BaseLocationManager.cpp @@ -136,7 +136,8 @@ void BaseLocationManager::onStart() void BaseLocationManager::onFrame() { - drawBaseLocations(); + + //drawBaseLocations(); // make sure that mineralfields and geysers are up to date in the different bases for (BaseLocation & baselocation : m_baseLocationData) { diff --git a/src/IDABot.cpp b/src/IDABot.cpp index ba787df..b89e541 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -158,7 +158,11 @@ int IDABot::GetGas() const } Unit IDABot::GetUnit(const CCUnitID & tag) const -{ +{ + auto a = Observation()->GetUnit(tag); + if (a == nullptr) { + return Unit(); + } return Unit(Observation()->GetUnit(tag), *(IDABot *)this); } @@ -392,10 +396,10 @@ float IDABot::GetScore() const } const sc2::GameResult IDABot::GetPlayerResults() const { - - for each (auto var in (Observation()->GetResults())) + auto res = Observation()->GetResults(); + for(int i = 0; i < res.size(); i++) { - if (var.player_id == Observation()->GetPlayerID()) return var.result; + 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; diff --git a/src/MapTools.cpp b/src/MapTools.cpp index 23d5b21..3df35a3 100644 --- a/src/MapTools.cpp +++ b/src/MapTools.cpp @@ -280,7 +280,7 @@ bool MapTools::isPowered(int tileX, int tileY) const #endif } -float MapTools::terrainHeight(float x, float y) const +float MapTools::terrainHeightCord(float x, float y) const { return m_terrainHeight[(int)x][(int)y]; } diff --git a/src/MapTools.h b/src/MapTools.h index b5490ad..6c86121 100644 --- a/src/MapTools.h +++ b/src/MapTools.h @@ -47,7 +47,7 @@ public: int width() const; int height() const; std::string name() const; - float terrainHeight(float x, float y) const; + float terrainHeightCord(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; diff --git a/src/Unit.cpp b/src/Unit.cpp index 130eaa3..1013911 100644 --- a/src/Unit.cpp +++ b/src/Unit.cpp @@ -1,5 +1,7 @@ #include "Unit.h" #include "IDABot.h" +#include "sc2api/sc2_gametypes.h" + Unit::Unit() : m_bot(nullptr) @@ -339,30 +341,28 @@ Unit Unit::getTarget() const 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; - // if it doesn't have a target. Return itself - if (m_bot->GetUnit(t_id) == nullptr) { + if (!m_bot->GetUnit(t_id).isValid()) { return *this; } // IDABot finds the unit with this tag return m_bot->GetUnit(t_id); } + return *this; } bool Unit::hasTarget() const -{ +{ BOT_ASSERT(isValid(), "Unit is not valid"); - if (getUnitPtr()->orders.size() > 0) { - if (getUnitPtr()->orders[0].target_unit_tag != NULL) { + if (getUnitPtr()->orders[0].target_unit_tag != sc2::NullTag) { CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag; // IDABot finds the unit with this tag, and returns true if valid return m_bot->GetUnit(t_id).isValid(); } } - return false; } diff --git a/src/Unit.h b/src/Unit.h index a33c6ff..003f536 100644 --- a/src/Unit.h +++ b/src/Unit.h @@ -3,6 +3,7 @@ #include "Common.h" #include "UnitType.h" + class IDABot; class Unit -- GitLab