Skip to content
Snippets Groups Projects
Commit 2d160564 authored by David Bergström's avatar David Bergström
Browse files

Merge branch 'sofab194/pycommandcenter-master'

Following change description:

* Added getTarget() to Unit: (Accessed via unit.target in python)
  Returns target if unit has one, otherwise will fail the assertion (make
  sure not to call this unless certain that the unit has a target!).
* Added hasTarget() to Unit: (Accessed via unit.has_target in python)
  Returns true if unit has a valid target.
* Added isBlip() to Unit: (Accessed via unit.is_blip in python) Returns
  true if unit is a "blip" - a ping on the map.
* Added possible access to the current frame of the game in python
  (IDABot.current_frame).
parents 6ea4b918 70bf07fe
No related branches found
Tags 1.1
No related merge requests found
Pipeline #1826 passed
......@@ -26,6 +26,10 @@ void define_unit(py::module & m)
.def_property_readonly("is_burrowed", &Unit::isBurrowed)
.def_property_readonly("is_valid", &Unit::isValid)
.def_property_readonly("is_training", &Unit::isTraining)
.def_property_readonly("is_blip", &Unit::isBlip)
.def_property_readonly("target", &Unit::getTarget)
.def_property_readonly("has_target", &Unit::hasTarget)
.def_property_readonly("max_hit_points", &Unit::getMaxHitPoints)
.def("stop", &Unit::stop)
.def("attack_unit", &Unit::attackUnit)
.def("attack_move", &Unit::attackMove)
......
......@@ -10,6 +10,7 @@ void define_unittype(py::module & m)
.def_property_readonly("unit_typeid", [](UnitType & unit_type) { return static_cast<sc2::UNIT_TYPEID>(unit_type.getAPIUnitType()); })
.def_property_readonly("name", &UnitType::getName)
.def_property_readonly("race", &UnitType::getRace)
.def_property_readonly("movement_speed", &UnitType::getMovementSpeed)
.def_property_readonly("is_valid", &UnitType::isValid)
.def_property_readonly("is_building", &UnitType::isBuilding)
.def_property_readonly("is_combat_unit", &UnitType::isCombatUnit, "The unit is not any of the following: worker, supply provider, building, larva, egg")
......@@ -43,4 +44,4 @@ void define_unittype(py::module & m)
// Not implemented in CommandCenter
//.def("whatBuilds", &UnitType::whatBuilds);
}
\ No newline at end of file
}
......@@ -82,10 +82,12 @@ PYBIND11_MODULE(library, m)
.def_property_readonly("map_tools", &IDABot::Map)
.def_property_readonly("building_placer", &IDABot::GetBuildingPlacer)
.def_property_readonly("start_location", &IDABot::GetStartLocation, "CCPosition representing the start location")
.def_property_readonly("start_locations", &IDABot::GetStartLocations, "CCPosition representing the start locations")
.def_property_readonly("minerals", &IDABot::GetMinerals, "How much minerals we currently have")
.def_property_readonly("current_supply", &IDABot::GetCurrentSupply, "How much supply we are currently using")
.def_property_readonly("max_supply", &IDABot::GetMaxSupply, "How much supply we can currently use")
.def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have");
.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");
py::class_<sc2::PlayerSetup>(m, "PlayerSetup");
......
......@@ -322,3 +322,51 @@ void Unit::ability(sc2::AbilityID ability, const Unit& target) const
{
m_bot->Actions()->UnitCommand(getUnitPtr(), ability, target.getUnitPtr(), false);
}
Unit Unit::getTarget() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
BOT_ASSERT(hasTarget(), "Unit has no target");
// 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;
// IDABot finds the unit with this tag
return m_bot->GetUnit(t_id);
}
Unit this_unit = Unit(m_unit, *m_bot);
return this_unit;
}
bool Unit::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;
// IDABot finds the unit with this tag, and returns true if valid
return m_bot->GetUnit(t_id).isValid();
}
}
return false;
}
bool Unit::isBlip() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
#ifdef SC2API
return m_unit->is_blip;
#else
return m_unit->isBlip();
#endif
}
CCHealth Unit::getMaxHitPoints() const
{
BOT_ASSERT(isValid(), "Unit is not valid");
return m_unit->health_max;
}
......@@ -48,6 +48,11 @@ public:
bool isTraining() const;
bool isConstructing(const UnitType & type) const;
bool isBlip() const;
bool hasTarget() const;
Unit getTarget() const;
CCHealth getMaxHitPoints() const;
void stop () const;
void attackUnit (const Unit & target) const;
void attackMove (const CCPosition & targetPosition) const;
......
......@@ -372,3 +372,8 @@ bool UnitType::isMorphedBuilding() const
m_type == BWAPI::UnitTypes::Zerg_Greater_Spire;
#endif
}
int UnitType::getMovementSpeed() const
{
return m_bot->Observation()->GetUnitTypeData()[m_type].movement_speed;
}
......@@ -22,6 +22,8 @@ public:
std::string getName() const;
CCRace getRace() const;
int getMovementSpeed() const;
bool isValid() const;
bool isBuilding() const;
......
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