@@ -43,9 +43,7 @@ def __repr__(self) -> str:
4343 return f"UnitOrder({ self .ability } , { self .target } , { self .progress } )"
4444
4545
46- class PassengerUnit :
47- """ Is inherited by the Unit class. Everything in here is also available in Unit. """
48-
46+ class Unit :
4947 def __init__ (self , proto_data ):
5048 self ._proto = proto_data
5149 self .cache = {}
@@ -302,11 +300,6 @@ def energy_percentage(self) -> Union[int, float]:
302300 return 0
303301 return self ._proto .energy / self ._proto .energy_max
304302
305-
306- class Unit (PassengerUnit ):
307-
308- # All type data is in PassengerUnit.
309-
310303 @property_immutable_cache
311304 def is_snapshot (self ) -> bool :
312305 """ Checks if the unit is only available as a snapshot for the bot.
@@ -396,6 +389,11 @@ def is_revealed(self) -> bool:
396389 """ Checks if the unit is revealed. """
397390 return self ._proto .cloak is CloakState .CloakedDetected .value
398391
392+ @property_immutable_cache
393+ def can_be_attacked (self ) -> bool :
394+ """ Checks if the unit is revealed or not cloaked and therefore can be attacked """
395+ return self ._proto .cloak in {CloakState .NotCloaked .value , CloakState .CloakedDetected .value }
396+
399397 @property_immutable_cache
400398 def buffs (self ) -> Set :
401399 """ Returns the set of current buffs the unit has. """
@@ -558,7 +556,8 @@ def is_idle(self) -> bool:
558556 return not self .orders
559557
560558 def is_using_ability (self , abilities : Union [AbilityId , Set [AbilityId ]]) -> bool :
561- """ Check if the unit is using one of the given abilities. """
559+ """ Check if the unit is using one of the given abilities.
560+ Only works for own units. """
562561 if not self .orders :
563562 return False
564563 if isinstance (abilities , AbilityId ):
@@ -567,12 +566,14 @@ def is_using_ability(self, abilities: Union[AbilityId, Set[AbilityId]]) -> bool:
567566
568567 @property_immutable_cache
569568 def is_moving (self ) -> bool :
570- """ Checks if the unit is moving. """
569+ """ Checks if the unit is moving.
570+ Only works for own units. """
571571 return self .is_using_ability (AbilityId .MOVE )
572572
573573 @property_immutable_cache
574574 def is_attacking (self ) -> bool :
575- """ Checks if the unit is attacking. """
575+ """ Checks if the unit is attacking.
576+ Only works for own units. """
576577 return self .is_using_ability (
577578 {
578579 AbilityId .ATTACK ,
@@ -585,27 +586,32 @@ def is_attacking(self) -> bool:
585586
586587 @property_immutable_cache
587588 def is_patrolling (self ) -> bool :
588- """ Checks if a unit is patrolling. """
589+ """ Checks if a unit is patrolling.
590+ Only works for own units. """
589591 return self .is_using_ability (AbilityId .PATROL )
590592
591593 @property_immutable_cache
592594 def is_gathering (self ) -> bool :
593- """ Checks if a unit is on its way to a mineral field or vespene geyser to mine. """
595+ """ Checks if a unit is on its way to a mineral field or vespene geyser to mine.
596+ Only works for own units. """
594597 return self .is_using_ability (AbilityId .HARVEST_GATHER )
595598
596599 @property_immutable_cache
597600 def is_returning (self ) -> bool :
598- """ Checks if a unit is returning from mineral field or vespene geyser to deliver resources to townhall. """
601+ """ Checks if a unit is returning from mineral field or vespene geyser to deliver resources to townhall.
602+ Only works for own units. """
599603 return self .is_using_ability (AbilityId .HARVEST_RETURN )
600604
601605 @property_immutable_cache
602606 def is_collecting (self ) -> bool :
603- """ Checks if a unit is gathering or returning. """
607+ """ Checks if a unit is gathering or returning.
608+ Only works for own units. """
604609 return self .is_using_ability ({AbilityId .HARVEST_GATHER , AbilityId .HARVEST_RETURN })
605610
606611 @property_immutable_cache
607612 def is_constructing_scv (self ) -> bool :
608- """ Checks if the unit is an SCV that is currently building. """
613+ """ Checks if the unit is an SCV that is currently building.
614+ Only works for own units. """
609615 return self .is_using_ability (
610616 {
611617 AbilityId .TERRANBUILD_ARMORY ,
@@ -626,12 +632,14 @@ def is_constructing_scv(self) -> bool:
626632
627633 @property_immutable_cache
628634 def is_transforming (self ) -> bool :
629- """ Checks if the unit transforming. """
635+ """ Checks if the unit transforming.
636+ Only works for own units. """
630637 return self .type_id in transforming and self .is_using_ability (transforming [self .type_id ])
631638
632639 @property_immutable_cache
633640 def is_repairing (self ) -> bool :
634- """ Checks if the unit is an SCV or MULE that is currently repairing. """
641+ """ Checks if the unit is an SCV or MULE that is currently repairing.
642+ Only works for own units. """
635643 return self .is_using_ability (
636644 {AbilityId .EFFECT_REPAIR , AbilityId .EFFECT_REPAIR_MULE , AbilityId .EFFECT_REPAIR_SCV }
637645 )
@@ -653,9 +661,9 @@ def add_on_land_position(self) -> Point2:
653661 return self .position .offset (Point2 ((- 2.5 , 0.5 )))
654662
655663 @property_mutable_cache
656- def passengers (self ) -> Set ["PassengerUnit " ]:
664+ def passengers (self ) -> Set ["Unit " ]:
657665 """ Returns the units inside a Bunker, CommandCenter, PlanetaryFortress, Medivac, Nydus, Overlord or WarpPrism. """
658- return {PassengerUnit (unit ) for unit in self ._proto .passengers }
666+ return {Unit (unit ) for unit in self ._proto .passengers }
659667
660668 @property_mutable_cache
661669 def passengers_tags (self ) -> Set [int ]:
0 commit comments