2
2
3
3
import json
4
4
import pkgutil
5
+ from collections import OrderedDict
5
6
from sc2reader .log_utils import loggable
6
7
7
8
ABIL_LOOKUP = dict ()
@@ -28,14 +29,30 @@ def __init__(self, unit_id, flags):
28
29
self .id = unit_id
29
30
self .flags = flags
30
31
self ._type_class = None
32
+ self .type_history = OrderedDict ()
31
33
self .hallucinated = (flags & 2 == 2 )
32
34
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
37
48
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 ()
39
56
40
57
@property
41
58
def name (self ):
@@ -101,17 +118,17 @@ def __init__(self, build_id):
101
118
self .units = dict ()
102
119
self .abilities = dict ()
103
120
104
- def create_unit (self , unit_id , unit_type , unit_flags ):
121
+ def create_unit (self , unit_id , unit_type , unit_flags , frame ):
105
122
unit = Unit (unit_id , unit_flags )
106
- self .change_type (unit , unit_type )
123
+ self .change_type (unit , unit_type , frame )
107
124
return unit
108
125
109
- def change_type (self , unit , new_type ):
126
+ def change_type (self , unit , new_type , frame ):
110
127
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 )
113
130
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 ))
115
132
116
133
def add_ability (self , ability_id , name , title = None , is_build = False , build_time = None , build_unit = None ):
117
134
ability = type (name ,(Ability ,), dict (
0 commit comments