22
33import json
44import pkgutil
5+ from collections import OrderedDict
56from sc2reader .log_utils import loggable
67
78ABIL_LOOKUP = dict ()
@@ -28,14 +29,30 @@ def __init__(self, unit_id, flags):
2829 self .id = unit_id
2930 self .flags = flags
3031 self ._type_class = None
32+ self .type_history = OrderedDict ()
3133 self .hallucinated = (flags & 2 == 2 )
3234
33- def is_type (self , unit_type ):
34- if isinstance (unit_type , int ):
35- # Unknown units have id==0 and should be equal
36- return unit_type == self ._type_class .id if self ._type_class else unit_type == 0
35+ def set_type (self , unit_type , frame ):
36+ self ._type_class = unit_type
37+ self .type_history [frame ] = unit_type
38+
39+ def is_type (self , unit_type , strict = True ):
40+ if strict :
41+ if isinstance (unit_type , int ):
42+ if self ._type_class :
43+ return unit_type == self ._type_class .id
44+ else :
45+ return unit_type == 0
46+ else :
47+ return self ._type_class == unit_type
3748 else :
38- return self ._type_class == unit_type
49+ if isinstance (unit_type , int ):
50+ if self ._type_class :
51+ return unit_type in [utype .id for utype in self .type_history .values ()]
52+ else :
53+ return unit_type == 0
54+ else :
55+ return unit_type in self .type_history .values ()
3956
4057 @property
4158 def name (self ):
@@ -101,17 +118,17 @@ def __init__(self, build_id):
101118 self .units = dict ()
102119 self .abilities = dict ()
103120
104- def create_unit (self , unit_id , unit_type , unit_flags ):
121+ def create_unit (self , unit_id , unit_type , unit_flags , frame ):
105122 unit = Unit (unit_id , unit_flags )
106- self .change_type (unit , unit_type )
123+ self .change_type (unit , unit_type , frame )
107124 return unit
108125
109- def change_type (self , unit , new_type ):
126+ def change_type (self , unit , new_type , frame ):
110127 if new_type in self .units :
111- reference_unit = self .units [new_type ]
112- unit ._type_class = reference_unit
128+ unit_type = self .units [new_type ]
129+ unit .set_type ( unit_type , frame )
113130 else :
114- self .logger .error ("Unable to change type of {0} to {1}; unit type not found in build {2 }" .format (unit ,hex (new_type ),self .id ))
131+ self .logger .error ("Unable to change type of {0} to {1} [frame {2}] ; unit type not found in build {3 }" .format (unit ,hex (new_type ), frame ,self .id ))
115132
116133 def add_ability (self , ability_id , name , title = None , is_build = False , build_time = None , build_unit = None ):
117134 ability = type (name ,(Ability ,), dict (
0 commit comments