Closed GraylinKim closed 11 years ago
I've implemented a fix to this issue in the new_unit
branch. The idea is to switch from a unit being a type to a unit having a type. Example:
unit # <class 'Unit'>
unit.name # SeigeTank
unit.type # <class 'SeigeTank'>
unit.type.race # Terran
Additionally, units are no longer unique based on type. Only uid is considered when comparing units for identity.
class Unit(object):
def __cmp__(self, other):
return cmp(self.uid, other.uid)
This will reduce the total number of unit objects created when processing replays because new units won't be created when their type changes (SeigeTanks, Hatcheries, Roaches[Burrowed]). This makes it more important to understand the circumstances that the engine changes the type instead of creating a new unit. Type is changed for events like Burrow and Morphing (type changed to cocoon) but the finished Baneling is a new unit.
I added property methods to the unit class to make the same interface available that was there before.
unit.type => 188
unit.race => 'Zerg'
unit.minerals => 75
unit.vespene => 25
unit.supply => 2
All tests passed. Any further issues on this line of inquiry can go in a new issue.
The old model of having instantiating units of a specific unit type is broken because a unit can be upgraded or change modes into a different type but still be the same unit.
The easiest way to do this will be to just instantiate raw
Unit
objects and setunit.name
andunit.type
appropriately. When type changing events occur, just update theunit.name
andunit.type
values.