Add unit.game_loop and unit.is_memory properties as suggested by DrInfy
@@ -100,6 +100,7 @@ class Unit:
self._bot_object: BotAI = bot_object
# Used by property_immutable_cache
self.cache = {}
+ self.game_loop: int = bot_object.state.game_loop
def __repr__(self) -> str:
""" Returns string of this form: Unit(name='SCV', tag=4396941328). """
@@ -365,6 +366,21 @@ class Unit:
return 0
return self._proto.energy / self._proto.energy_max
+ @property
+ def age_in_frames(self) -> int:
+ """ Returns how old the unit object data is (in game frames). This age does not reflect the unit was created / trained / morphed! """
+ return self._bot_object.state.game_loop - self.game_loop
+
+ @property
+ def age(self) -> float:
+ """ Returns how old the unit object data is (in game seconds). This age does not reflect when the unit was created / trained / morphed! """
+ return (self._bot_object.state.game_loop - self.game_loop) / 22.4
+
+ @property
+ def is_memory(self) -> bool:
+ """ Returns True if this Unit object is referenced from the future and is outdated. """
+ return self.game_loop != self._bot_object.state.game_loop
+
@property_immutable_cache
def is_snapshot(self) -> bool:
""" Checks if the unit is only available as a snapshot for the bot.
