Skip to content
Snippets Groups Projects
Commit 14ab444b authored by Hannes Jämtner's avatar Hannes Jämtner
Browse files

Changed structure of functions and added functions instead of techtree

parent d80d972b
No related branches found
No related tags found
1 merge request!7Uppdaterat API
......@@ -89,6 +89,9 @@ TechTree
this can be found under the folder data in this link_.
A recent file is included in the `template repository`_.
Instead of using TechTree, it's possible to use the functions in UnitType for
structure, etc. In IDABot there is functions for getting data about upgrades.
.. method:: get_data(argument) -> library.TypeData
Argument is either an instance of the class :class:`library.UnitType` or
......
......@@ -67,6 +67,22 @@ IDABot
Move the camera to the position
.. method:: IDABot.ability_for_upgrade(self, UpgradeID)
Ability that researches this upgrade
.. method:: IDABot.upgrade_mineral_cost(self, UpgradeID)
Mineral cost of researching the upgrade
.. method:: IDABot.upgrade_gas_cost(self, UpgradeID)
Vespene/gas cost of researching the upgrade
.. method:: IDABot.upgrade_research_time(self, UpgradeID)
Time in GameLoops to research this upgrade
Attributes:
.. autoattribute:: minerals
......
......@@ -40,6 +40,9 @@ void define_unittype(py::module & m)
.def_property_readonly("is_egg", &UnitType::isEgg)
.def_property_readonly("is_queen", &UnitType::isQueen)
.def_property_readonly("is_tank", &UnitType::isTank)
.def_property_readonly("get_equivalent_units", &UnitType::getEquivalentUnits)
.def_property_readonly("required_attached", &UnitType::requiredAttached)
.def_property_readonly("build_time", &UnitType::getBuildTime)
.def("__hash__", [](const UnitType & unit_type) { return std::hash<CCUnitID>{}(unit_type.getAPIUnitType()); })
.def(py::self == py::self)
.def("__repr__", [](const UnitType & unit_type) { return "<UnitType: '" + unit_type.getName() + "'>"; });
......
......@@ -99,6 +99,10 @@ PYBIND11_MODULE(library, m)
.def("get_enemy_base_location", &IDABot::GetEnemyBaseLocations, "Return the CCpostion of the enemy base")
.def("move_camera", &IDABot::CameraMove, "Move the camera to p postion", "p"_a)
.def("has_creep", &IDABot::HasCreep, "Returns true if there is creep at position p", "p"_a)
.def("ability_for_upgrade", &IDABot::abilityForUpgrade, "Ability that researches this upgrade", "upgrade"_a)
.def("upgrade_mineral_cost", &IDABot::UpgradeMineralCost, "Mineral cost of researching the upgrade", "upgrade"_a)
.def("upgrade_gas_cost", &IDABot::UpgradeGasCost, "Vespene/gas cost of researching the upgrade", "upgrade"_a)
.def("upgrade_research_time", &IDABot::UpgradeResearchTime, "Time in GameLoops to research this upgrade", "upgrade"_a)
.def_property_readonly("base_location_manager", &IDABot::Bases)
.def_property_readonly("tech_tree", &IDABot::GetTechTree)
.def_property_readonly("map_tools", &IDABot::Map)
......@@ -111,6 +115,9 @@ PYBIND11_MODULE(library, m)
.def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have")
.def_property_readonly("current_frame", &IDABot::GetCurrentFrame, "Which frame we are currently on");
// API extended summer 2020
py::class_<sc2::PlayerSetup>(m, "PlayerSetup");
......
......@@ -320,7 +320,7 @@ void IDABot::DebugSetShields(float value, const Unit unit)
Debug()->DebugSetShields(value, unit.getUnitPtr());
}
// There is a bug in the latest SC2
// 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
......@@ -329,10 +329,37 @@ const std::vector<Point2D> IDABot::GetEnemyBaseLocations()
return Observation()->GetGameInfo().enemy_start_locations;
}
bool IDABot::HasCreep(Point2D p) const {
bool IDABot::HasCreep(Point2D p) const
{
return Observation()->HasCreep(p);
}
void IDABot::CameraMove(Point2DI p) {
void IDABot::CameraMove(Point2DI p)
{
ActionsFeatureLayer()->CameraMove(p);
}
const char* IDABot::abilityForUpgrade(sc2::UpgradeID upgrade_id) const
{
return sc2::AbilityTypeToName(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;
}
\ No newline at end of file
......@@ -87,6 +87,12 @@ public:
const std::vector<Point2D> GetEnemyBaseLocations();
bool HasCreep(Point2D p) const;
void CameraMove(Point2DI p);
const char* 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;
// Not needed, just convenience functions
......
......@@ -464,10 +464,10 @@ int Unit::getOwner() const
// Implemented with Blizzard SC2 API
bool Unit::isCarryingGas() const
{
return m_bot->Observation()->IsUnitCarryVespene(*m_unit);
return sc2::IsCarryingVespene(*m_unit);
}
bool Unit::isCarryingMinerals() const
{
return m_bot->Observation()->IsUnitCarryMineral(*m_unit);
return sc2::IsCarryingMinerals(*m_unit);
}
\ No newline at end of file
......@@ -385,7 +385,22 @@ int UnitType::getSightRange() const
return m_bot->Observation()->GetUnitTypeData()[m_type].sight_range;
}
sc2::UnitTypeID UnitType::getRequiredStructure() const
UnitTypeID UnitType::getRequiredStructure() const
{
return m_bot->Observation()->GetUnitTypeData()[m_type].tech_requirement;
}
std::vector<sc2::UnitTypeID> UnitType::getEquivalentUnits() const
{
return m_bot->Observation()->GetUnitTypeData()[m_type].tech_alias;
}
bool UnitType::requiredAttached() const
{
return m_bot->Observation()->GetUnitTypeData()[m_type].require_attached;
}
float UnitType::getBuildTime() const
{
return m_bot->Observation()->GetUnitTypeData()[m_type].build_time;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
#include "Common.h"
class IDABot;
class UnitType
......@@ -25,7 +26,7 @@ public:
int getMovementSpeed() const;
int getSightRange() const;
sc2::UnitTypeID getRequiredStructure() const;
sc2::UnitTypeID getRequiredStructure() const;
bool isValid() const;
bool isBuilding() const;
......@@ -50,6 +51,9 @@ public:
int gasPrice() const;
const std::vector<UnitType> & whatBuilds() const;
std::vector<sc2::UnitTypeID> getEquivalentUnits() const;
bool requiredAttached() const;
float getBuildTime() const;
static UnitType GetUnitTypeFromName(const std::string & name, IDABot & bot);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment