Skip to content
Snippets Groups Projects
unit.rst 3.55 KiB
Newer Older
David Bergström's avatar
David Bergström committed
Unit
====

.. class:: library.Unit

   An instance of the class Unit represents one unit in the game. The units are 
   not limited to moveable units, but every entity which is not part of the 
   background is a unit. For example, the minerals and geysers are units as 
   well as all buildings.

   For all possible types of units see the enum :class:`library.UNIT_TYPEID`. 
   Some types of objects are almost the same, for example there are many types 
   of mineral deposits, but all of them are mineable. This is one of the 
   motivations behind the :class:`library.UnitType` which aims to to make the 
   list of types more manageable. The UnitType can be accessed by the 
   :any:`Unit.unit_type` property.

   It is possible to use Unit as keys in a dictionary, which might be helpful
   for bookkeeping.

   Properties:

   .. autoattribute:: buffs

      Returns a list of BuffID

David Bergström's avatar
David Bergström committed
   .. autoattribute:: build_percentage
   .. autoattribute:: energy
   .. autoattribute:: facing

      Returns the direction the unit is facing

David Bergström's avatar
David Bergström committed
   .. autoattribute:: hit_points 
   .. autoattribute:: max_hit_points
David Bergström's avatar
David Bergström committed
   .. autoattribute:: id 
   .. autoattribute:: is_alive 
   .. autoattribute:: is_blip

      Returns true if unit is a "blip" - a ping on the map.

David Bergström's avatar
David Bergström committed
   .. autoattribute:: is_being_constructed 
David Bergström's avatar
David Bergström committed
   .. autoattribute:: is_burrowed 
   .. autoattribute:: is_cloaked 
   .. autoattribute:: is_completed 
David Bergström's avatar
David Bergström committed
   .. autoattribute:: is_flying 
   .. autoattribute:: is_idle 
   .. autoattribute:: is_powered 
   .. autoattribute:: is_training 
   .. autoattribute:: is_valid 
   .. attribute:: Unit.player 

      Returns the constant corresponding to player which this unit belongs to.
David Bergström's avatar
David Bergström committed
      See :ref:`playerconstants` for more information.
David Bergström's avatar
David Bergström committed
   .. autoattribute:: position 
   .. autoattribute:: current_ability_id

   .. autoattribute:: progress

      Returns the progress of currently used ability (-1 if not using ability)

   .. autoattribute:: radius

      Retruns the radius of the unit

David Bergström's avatar
David Bergström committed
   .. autoattribute:: shields 
   .. autoattribute:: tile_position 
   .. autoattribute:: unit_type 
   .. autoattribute:: weapon_cooldown 
   .. autoattribute:: is_carrying_minerals
   
      Returns if this unit is currently holding minerals
David Bergström's avatar
David Bergström committed

   .. attribute:: Unit.target

      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!).

David Bergström's avatar
David Bergström committed
   Methods:

   .. automethod:: ability

      Call an ability directly, different abilities has different targets. Some target the unit itself (no argument), target a point (Point2D as argument) and some target a Unit (instance of Unit as argument).

   .. method:: Unit.is_constructing(self, unit_type: library.UnitType)

      Returns true if the unit is currently constructing another unit of type `unit_type`. Note that `unit_type` needs to be an instance of :class:`library.UnitType`.

David Bergström's avatar
David Bergström committed
   .. automethod:: stop
   .. automethod:: attack_unit
   .. automethod:: attack_move
   .. method:: Unit.move(self, point)

      Move the unit to the given point, the point being an instance of either 
      :class:`library.Point2D` or :class:`library.Point2DI`.
   .. automethod:: right_click
   .. automethod:: repair
   .. automethod:: build
   .. automethod:: build_target
   .. automethod:: train
   .. automethod:: research
David Bergström's avatar
David Bergström committed
   .. automethod:: morph
   .. method:: Unit.has_target

      Returns True if the target has a valid target and False otherwise.
David Bergström's avatar
David Bergström committed

   .. automethod:: hold_position
   .. automethod:: stop_dance

      Stop and dance