Skip to content
Snippets Groups Projects
lib_unit.cpp 3.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include "library.h"
    
    namespace py = pybind11;
    
    void define_unit(py::module & m)
    {
        py::class_<Unit>(m, "Unit")
    
    David Bergström's avatar
    David Bergström committed
            .def_property_readonly("unit_type", &Unit::getType, "The :class:`library.UnitType` of the unit")
    
            .def_property_readonly("position", &Unit::getPosition, "The :class:`library.Point2D` of the unit")
    
    David Bergström's avatar
    David Bergström committed
            .def_property_readonly("tile_position", &Unit::getTilePosition, "The :class:`library.Point2DI` of the unit")
    
            .def_property_readonly("hit_points", &Unit::getHitPoints)
            .def_property_readonly("shields", &Unit::getShields)
            .def_property_readonly("energy", &Unit::getEnergy)
            .def_property_readonly("player", &Unit::getPlayer)
            .def_property_readonly("id", &Unit::getID)
            .def_property_readonly("build_percentage", &Unit::getBuildPercentage)
            .def_property_readonly("weapon_cooldown", &Unit::getWeaponCooldown)
    
            .def_property_readonly("is_completed", &Unit::isCompleted)
            .def_property_readonly("is_being_constructed", &Unit::isBeingConstructed)
            .def_property_readonly("is_cloaked", &Unit::isCloaked)
            .def_property_readonly("is_flying", &Unit::isFlying)
            .def_property_readonly("is_alive", &Unit::isAlive)
            .def_property_readonly("is_powered", &Unit::isPowered)
            .def_property_readonly("is_idle", &Unit::isIdle)
            .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)
    
    Sopi (sofab194)'s avatar
    Sopi (sofab194) committed
            .def_property_readonly("has_target", &Unit::hasTarget)
    
    Sopi Abaied's avatar
    Sopi Abaied committed
            .def_property_readonly("max_hit_points", &Unit::getMaxHitPoints)
            .def_property_readonly("progress", &Unit::getProgress)
    
    Sofia Abaied's avatar
    Sofia Abaied committed
            .def_property_readonly("current_ability_id", &Unit::getCurrentAbilityID, "The AbilityID of currently used ability")
    
    Sopi Abaied's avatar
    Sopi Abaied committed
            .def_property_readonly("facing", &Unit::getFacing)
            .def_property_readonly("radius", &Unit::getRadius)
            .def("hold_position", &Unit::holdPosition)
            .def("patrol", py::overload_cast<const CCPosition &>(&Unit::patrol, py::const_))
            .def("stop_dance", &Unit::stopDance)
    
    David Bergström's avatar
    David Bergström committed
            .def("attack_unit", &Unit::attackUnit)
            .def("attack_move", &Unit::attackMove)
    
            .def("move", py::overload_cast<const CCPosition &>(&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("repair", &Unit::repair)
    
            .def("build", &Unit::build, "Build unit of type building_type at given position", "building_type"_a, "position"_a)
            .def("build_target", &Unit::buildTarget, "Build building_type on top of target Unit, useful for building refineries", "building_type"_a, "target"_a)
            .def("train", &Unit::train, "Train unit of type", "unit_type"_a)
            .def("morph", &Unit::morph, "Morph into type of unit_type", "unit_type"_a)
            .def("research", &Unit::research, "Research the given :class:`library.UPGRADE_ID`", "upgrade_id"_a)
    
            .def("is_constructing", &Unit::isConstructing, "unit_type"_a)
    
            .def("__hash__", [](const Unit & unit) { return std::hash<const sc2::Unit *>{}(unit.getUnitPtr()); })
    
            .def(py::self == py::self)
    
            .def("__repr__", [](const Unit & unit) { return "<Unit of type: '" + unit.getType().getName() + "'>"; });
    }