|
33 | 33 |
|
34 | 34 |
|
35 | 35 | class Unit(object):
|
36 |
| - """ |
37 |
| - Represents an in-game unit. |
38 |
| - """ |
39 |
| - |
| 36 | + """Represents an in-game unit.""" |
40 | 37 | def __init__(self, unit_id):
|
41 | 38 | #: A reference to the player that currently owns this unit. Only available for 2.0.8+ replays.
|
42 | 39 | self.owner = None
|
@@ -195,22 +192,64 @@ def __repr__(self):
|
195 | 192 | return str(self)
|
196 | 193 |
|
197 | 194 |
|
| 195 | +class UnitType(object): |
| 196 | + """ Represents an in game unit type """ |
| 197 | + def __init__(self, type_id, str_id=None, name=None, title=None, race=None, minerals=0, |
| 198 | + vespene=0, supply=0, is_building=False, is_worker=False, is_army=False): |
| 199 | + #: The internal integer id representing this unit type |
| 200 | + self.id = type_id |
| 201 | + |
| 202 | + #: The internal string id representing this unit type |
| 203 | + self.str_id = str_id |
| 204 | + |
| 205 | + #: The name of this unit type |
| 206 | + self.name = name |
| 207 | + |
| 208 | + #: The printable title of this unit type; has spaces and possibly punctuation |
| 209 | + self.title = title |
| 210 | + |
| 211 | + #: The race this unit type belongs to |
| 212 | + self.race = race |
| 213 | + |
| 214 | + #: The mineral cost of this unit type |
| 215 | + self.minerals = minerals |
| 216 | + |
| 217 | + #: The vespene cost of this unit type |
| 218 | + self.vespene = vespene |
| 219 | + |
| 220 | + #: The supply cost of this unit type |
| 221 | + self.supply = supply |
| 222 | + |
| 223 | + #: Boolean flagging this unit type as a building |
| 224 | + self.is_building = is_building |
| 225 | + |
| 226 | + #: Boolean flagging this unit type as a worker |
| 227 | + self.is_worker = is_worker |
| 228 | + |
| 229 | + #: Boolean flagging this unit type as an army unit |
| 230 | + self.is_army = is_army |
| 231 | + |
| 232 | + |
198 | 233 | class Ability(object):
|
| 234 | + """ Represents an in-game ability """ |
| 235 | + def __init__(self, id, name=None, title=None, is_build=False, build_time=0, build_unit=None): |
| 236 | + #: The internal integer id representing this ability. |
| 237 | + self.id = id |
199 | 238 |
|
200 |
| - #: The internal integer id representing this ability. |
201 |
| - id = None |
| 239 | + #: The name of this ability |
| 240 | + self.name = name |
202 | 241 |
|
203 |
| - #: The name of this ability |
204 |
| - name = "" |
| 242 | + #: The printable title of this ability; has spaces and possibly punctuation. |
| 243 | + self.title = title |
205 | 244 |
|
206 |
| - #: Boolean flagging this ability as creating a new unit. |
207 |
| - is_build = False |
| 245 | + #: Boolean flagging this ability as creating a new unit. |
| 246 | + self.is_build = is_build |
208 | 247 |
|
209 |
| - #: The number of seconds required to build this unit. 0 if not ``is_build``. |
210 |
| - build_time = 0 |
| 248 | + #: The number of seconds required to build this unit. 0 if not ``is_build``. |
| 249 | + self.build_time = build_time |
211 | 250 |
|
212 |
| - #: A reference to the :class:`Unit` type built by this ability. None if not ``is_build``. |
213 |
| - build_unit = None |
| 251 | + #: A reference to the :class:`UnitType` type built by this ability. Default to None. |
| 252 | + self.build_unit = build_unit |
214 | 253 |
|
215 | 254 |
|
216 | 255 | @loggable
|
@@ -260,20 +299,20 @@ def change_type(self, unit, new_type, frame):
|
260 | 299 | self.logger.error("Unable to change type of {0} to {1} [frame {2}]; unit type not found in build {3}".format(unit, new_type, frame, self.id))
|
261 | 300 |
|
262 | 301 | def add_ability(self, ability_id, name, title=None, is_build=False, build_time=None, build_unit=None):
|
263 |
| - ability = type(str(name), (Ability,), dict( |
264 |
| - id=ability_id, |
| 302 | + ability = Ability( |
| 303 | + ability_id, |
265 | 304 | name=name,
|
266 | 305 | title=title or name,
|
267 | 306 | is_build=is_build,
|
268 | 307 | build_time=build_time,
|
269 | 308 | build_unit=build_unit
|
270 |
| - )) |
| 309 | + ) |
271 | 310 | setattr(self, name, ability)
|
272 | 311 | self.abilities[ability_id] = ability
|
273 | 312 |
|
274 | 313 | def add_unit_type(self, type_id, str_id, name, title=None, race='Neutral', minerals=0, vespene=0, supply=0, is_building=False, is_worker=False, is_army=False):
|
275 |
| - unit = type(str(name), (Unit,), dict( |
276 |
| - id=type_id, |
| 314 | + unit = UnitType( |
| 315 | + type_id, |
277 | 316 | str_id=str_id,
|
278 | 317 | name=name,
|
279 | 318 | title=title or name,
|
|
0 commit comments