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

Consolidate raw ability methods

Instead of having two ways of using abilities directly, have one
way which is consistent with the API. Now unit has one method called
`ability` which takes a AbilityID and optionally either a Position or
another Unit which to use the ability at.
parent a85e38fc
No related branches found
No related tags found
No related merge requests found
...@@ -29,8 +29,9 @@ void define_unit(py::module & m) ...@@ -29,8 +29,9 @@ void define_unit(py::module & m)
.def("stop", &Unit::stop) .def("stop", &Unit::stop)
.def("attack_unit", &Unit::attackUnit) .def("attack_unit", &Unit::attackUnit)
.def("attack_move", &Unit::attackMove) .def("attack_move", &Unit::attackMove)
.def("ability", &Unit::ability) .def("ability", py::overload_cast<sc2::AbilityID>(&Unit::ability, py::const_))
.def("ability_at_target", &Unit::ability_at_target) .def("ability", py::overload_cast<sc2::AbilityID, const CCPosition &>(&Unit::ability, py::const_))
.def("ability", py::overload_cast<sc2::AbilityID, const Unit &>(&Unit::ability, py::const_))
.def("move", py::overload_cast<const CCPosition &>(&Unit::move, py::const_)) .def("move", py::overload_cast<const CCPosition &>(&Unit::move, py::const_))
.def("move", py::overload_cast<const CCTilePosition &>(&Unit::move, py::const_)) .def("move", py::overload_cast<const CCTilePosition &>(&Unit::move, py::const_))
.def("right_click", &Unit::rightClick, "Same as right-clicking in the game, for example making workers mine minerals") .def("right_click", &Unit::rightClick, "Same as right-clicking in the game, for example making workers mine minerals")
......
...@@ -85,10 +85,7 @@ PYBIND11_MODULE(library, m) ...@@ -85,10 +85,7 @@ PYBIND11_MODULE(library, m)
.def_property_readonly("minerals", &IDABot::GetMinerals, "How much minerals we currently have") .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("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("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("use_ability", &IDABot::UseAbility, "Use an ability with the given unit")
.def("use_ability", &IDABot::UseAbilityWithPoint, "Use ability at point with the given unit")
.def("use_ability", &IDABot::UseAbilityWithTarget, "Use ability at target with the given unit");
py::class_<sc2::PlayerSetup>(m, "PlayerSetup"); py::class_<sc2::PlayerSetup>(m, "PlayerSetup");
......
...@@ -31,4 +31,4 @@ typedef size_t CCPlayer; ...@@ -31,4 +31,4 @@ typedef size_t CCPlayer;
namespace Players namespace Players
{ {
enum {Self = 0u, Enemy = 1u, Neutral = 2u, Ally = 3u, Size = 4u, None = 5u}; enum {Self = 0u, Enemy = 1u, Neutral = 2u, Ally = 3u, Size = 4u, None = 5u};
} }
\ No newline at end of file
...@@ -218,18 +218,3 @@ const TypeData & IDABot::Data(const MetaType & type) const ...@@ -218,18 +218,3 @@ const TypeData & IDABot::Data(const MetaType & type) const
{ {
return m_techTree.getData(type); return m_techTree.getData(type);
} }
void IDABot::UseAbility(const Unit& unit, sc2::AbilityID ability)
{
Actions()->UnitCommand(unit.getUnitPtr(), ability, false);
}
void IDABot::UseAbilityWithPoint(const Unit& unit, sc2::AbilityID ability, const sc2::Point2D& point)
{
Actions()->UnitCommand(unit.getUnitPtr(), ability, point, false);
}
void IDABot::UseAbilityWithTarget(const Unit& unit, sc2::AbilityID ability, const Unit* target)
{
Actions()->UnitCommand(unit.getUnitPtr(), ability, target->getUnitPtr(), false);
}
...@@ -62,9 +62,4 @@ public: ...@@ -62,9 +62,4 @@ public:
const TypeData & Data(const CCUpgrade & type) const; const TypeData & Data(const CCUpgrade & type) const;
const TypeData & Data(const MetaType & type) const; const TypeData & Data(const MetaType & type) const;
const TypeData & Data(const Unit & unit) const; const TypeData & Data(const Unit & unit) const;
// Used for giving "raw" commands to units
void UseAbility(const Unit& unit, sc2::AbilityID ability);
void UseAbilityWithPoint(const Unit& unit, sc2::AbilityID ability, const sc2::Point2D& point);
void UseAbilityWithTarget(const Unit& unit, sc2::AbilityID ability, const Unit* target);
}; };
...@@ -296,18 +296,6 @@ void Unit::morph(const UnitType & type) const ...@@ -296,18 +296,6 @@ void Unit::morph(const UnitType & type) const
m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(type).morphAbility); m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(type).morphAbility);
} }
void Unit::ability(sc2::AbilityID & ability) const
{
BOT_ASSERT(isValid(), "Unit is not valid");
m_bot->Actions()->UnitCommand(m_unit, ability);
}
void Unit::ability_at_target(sc2::AbilityID & ability, const Unit & target) const
{
BOT_ASSERT(isValid(), "Unit is not valid");
m_bot->Actions()->UnitCommand(m_unit, ability, target.getUnitPtr());
}
void Unit::research(sc2::UpgradeID upgrade) const void Unit::research(sc2::UpgradeID upgrade) const
{ {
BOT_ASSERT(isValid(), "Unit is not valid"); BOT_ASSERT(isValid(), "Unit is not valid");
...@@ -319,3 +307,18 @@ bool Unit::isConstructing(const UnitType & type) const ...@@ -319,3 +307,18 @@ bool Unit::isConstructing(const UnitType & type) const
sc2::AbilityID buildAbility = m_bot->Data(type).buildAbility; sc2::AbilityID buildAbility = m_bot->Data(type).buildAbility;
return (getUnitPtr()->orders.size() > 0) && (getUnitPtr()->orders[0].ability_id == buildAbility); return (getUnitPtr()->orders.size() > 0) && (getUnitPtr()->orders[0].ability_id == buildAbility);
} }
void Unit::ability(sc2::AbilityID ability) const
{
m_bot->Actions()->UnitCommand(getUnitPtr(), ability, false);
}
void Unit::ability(sc2::AbilityID ability, const sc2::Point2D& point) const
{
m_bot->Actions()->UnitCommand(getUnitPtr(), ability, point, false);
}
void Unit::ability(sc2::AbilityID ability, const Unit& target) const
{
m_bot->Actions()->UnitCommand(getUnitPtr(), ability, target.getUnitPtr(), false);
}
...@@ -52,8 +52,6 @@ public: ...@@ -52,8 +52,6 @@ public:
void attackUnit (const Unit & target) const; void attackUnit (const Unit & target) const;
void attackMove (const CCPosition & targetPosition) const; void attackMove (const CCPosition & targetPosition) const;
void move (const CCPosition & targetPosition) const; void move (const CCPosition & targetPosition) const;
void ability (sc2::AbilityID & ability) const;
void ability_at_target (sc2::AbilityID & ability, const Unit & target) const;
void move (const CCTilePosition & targetTilePosition) const; void move (const CCTilePosition & targetTilePosition) const;
void rightClick (const Unit & target) const; void rightClick (const Unit & target) const;
void repair (const Unit & target) const; void repair (const Unit & target) const;
...@@ -62,4 +60,7 @@ public: ...@@ -62,4 +60,7 @@ public:
void train (const UnitType & buildingType) const; void train (const UnitType & buildingType) const;
void morph (const UnitType & type) const; void morph (const UnitType & type) const;
void research (sc2::UpgradeID upgrade) const; void research (sc2::UpgradeID upgrade) const;
void ability (sc2::AbilityID ability) const;
void ability (sc2::AbilityID ability, const sc2::Point2D & point) const;
void ability (sc2::AbilityID ability, const Unit & target) 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