Skip to content
Snippets Groups Projects
lib_unit.cpp 2.18 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")
            .def_property_readonly("unit_type", &Unit::getType)
            .def_property_readonly("position", &Unit::getPosition)
            .def_property_readonly("tile_position", &Unit::getTilePosition)
            .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("completed", &Unit::isCompleted)
            .def_property_readonly("being_constructed", &Unit::isBeingConstructed)
            .def_property_readonly("cloaked", &Unit::isCloaked)
            .def_property_readonly("flying", &Unit::isFlying)
            .def_property_readonly("alive", &Unit::isAlive)
            .def_property_readonly("powered", &Unit::isPowered)
            .def_property_readonly("idle", &Unit::isIdle)
            .def_property_readonly("burrowed", &Unit::isBurrowed)
            .def_property_readonly("valid", &Unit::isValid)
            .def_property_readonly("training", &Unit::isTraining)
            .def_property_readonly("constructing", &Unit::isConstructing)
            .def("stop", &Unit::stop)
    
    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_))
    
    David Bergström's avatar
    David Bergström committed
            .def("right_click", &Unit::rightClick)
    
            .def("repair", &Unit::repair)
            .def("build", &Unit::build)
    
    David Bergström's avatar
    David Bergström committed
            .def("build_target", &Unit::buildTarget)
    
            .def("train", &Unit::train)
            .def("morph", &Unit::morph)
    
            .def("__hash__", [](const Unit & unit) { return std::hash<CCUnitID>{}(unit.getID()); })
            .def(py::self == py::self)
    
            .def("__repr__", [](const Unit & unit) { return "<Unit of type: '" + unit.getType().getName() + "'>"; });
    }