Skip to content
Snippets Groups Projects
lib_replay_unit.cpp 3.91 KiB
Newer Older
Rojikku98's avatar
Rojikku98 committed
#include "library.h"

namespace py = pybind11;

void define_replay_unit(py::module & m)
{
Rojikku98's avatar
Rojikku98 committed
	py::class_<ReplayUnit>(m, "ReplayUnit")
David Warnquist's avatar
David Warnquist committed
		.def_property_readonly("id", &ReplayUnit::getID, "The ID of the unit")
		.def_property_readonly("unit_type", &ReplayUnit::getType, "The :class:`commandcenter.UnitType` of the unit")
		.def_property_readonly("position", &ReplayUnit::getPosition, "The :class:`commandcenter.Point2D` of the unit")
		.def_property_readonly("tile_position", &ReplayUnit::getTilePosition, "The :class:`commandcenter.Point2DI` of the unit")
David Warnquist's avatar
David Warnquist committed
		.def_property_readonly("hit_points", &ReplayUnit::getHitPoints, "The hit points of the unit")
		.def_property_readonly("shields", &ReplayUnit::getShields, "The shields of the unit")
		.def_property_readonly("energy", &ReplayUnit::getEnergy, "The energy of the unit")
		.def_property_readonly("player", &ReplayUnit::getPlayer, "Returns the constant corresponding to player which this unit belongs to. See :ref:`playerconstants` for more information.")
		.def_property_readonly("build_percentage", &ReplayUnit::getBuildPercentage, "The build percentage of the unit")
		.def_property_readonly("weapon_cooldown", &ReplayUnit::getWeaponCooldown, "The weapon cooldown of the unit")
		.def_property_readonly("is_completed", &ReplayUnit::isCompleted, "Whether the unit is completed, returns build_progress >= 1")
		.def_property_readonly("is_being_constructed", &ReplayUnit::isBeingConstructed, "Whether the unit is being constructed, returns build_progress > 0")
		.def_property_readonly("is_cloaked", &ReplayUnit::isCloaked, "Whether the unit is cloaked")
		.def_property_readonly("is_flying", &ReplayUnit::isFlying, "Whether the unit is flying")
		.def_property_readonly("buffs", &ReplayUnit::buffs, "Returns a list of BuffIDs representing the buffs on the unit")
		.def_property_readonly("is_alive", &ReplayUnit::isAlive, "Whether the unit is alive")
		.def_property_readonly("is_powered", &ReplayUnit::isPowered, "Whether the unit is powered")
		.def_property_readonly("is_idle", &ReplayUnit::isIdle, "Whether the unit is idle")
		.def_property_readonly("is_burrowed", &ReplayUnit::isBurrowed, "Whether the unit is burrowed")
		.def_property_readonly("is_valid", &ReplayUnit::isValid, "Whether the unit is valid")
		.def_property_readonly("is_training", &ReplayUnit::isTraining, "Whether the unit is training")
		.def_property_readonly("is_blip", &ReplayUnit::isBlip, "Whether the unit is a blip ie a ping on the map")
		.def_property_readonly("target", &ReplayUnit::getTarget, "The target of the unit")
		.def_property_readonly("has_target", &ReplayUnit::hasTarget, "Whether the unit has a target")
		.def_property_readonly("max_hit_points", &ReplayUnit::getMaxHitPoints, "The maximum hit points of the unit")
		.def_property_readonly("progress", &ReplayUnit::getProgress, "Returns the progress of currently used ability (-1 if not using ability)")
Rojikku98's avatar
Rojikku98 committed
		.def_property_readonly("current_ability_id", &ReplayUnit::getCurrentAbilityID, "The AbilityID of currently used ability")
David Warnquist's avatar
David Warnquist committed
		.def_property_readonly("facing", &ReplayUnit::getFacing, "Returns the direction the unit is facing")
		.def_property_readonly("radius", &ReplayUnit::getRadius, "The radius of the unit")
		.def_property_readonly("is_carrying_minerals", &ReplayUnit::isCarryingMinerals, "Whether the unit is carrying minerals")
Rojikku98's avatar
Rojikku98 committed
		.def("__hash__", [](const ReplayUnit & unit) { return std::hash<const sc2::Unit *>{}(unit.getUnitPtr()); })
Rojikku98's avatar
Rojikku98 committed
		.def(py::self == py::self)
Edvin Bergström's avatar
Edvin Bergström committed
		.def("__repr__", [](const ReplayUnit & unit) { return "<Unit of type: '" + unit.getType().getName() + "'>"; })
David Warnquist's avatar
David Warnquist committed
		.doc() = R"(
		The ReplayUnit class is used to represent a unit in a replay of a game. 
		A ReplayUnit is a :class:`commandcenter.Unit` white some limitations.
David Warnquist's avatar
David Warnquist committed
   		It provides various properties and methods to access information about the unit, such as its ID, type, position, hit points, energy, and more.
		It is possible to use ReplayUnit as keys in a dictionary, which might be helpful for bookkeeping.
		)";
Rojikku98's avatar
Rojikku98 committed
}