GraylinKim / sc2reader

A python library that extracts data from various Starcraft II resources to power tools and services for the SC2 community. Who doesn't want to hack on the games they play?
http://sc2reader.readthedocs.org
MIT License
413 stars 85 forks source link

Properly recognize hellbat vs hellion #136

Closed dsjoerg closed 11 years ago

dsjoerg commented 11 years ago

http://ggtracker.com/matches/3481336

>>> [u.started_at for u in fun.players[0].units if u.name == 'Hellion']
[5180, 5183, 6736, 6741, 7215, 7220]
>>> [u.started_at for u in fun.players[0].units if u.name == 'BattleHellion']
[12004, 12038]

However the truth, as seen by watching the replay and in the tracker events as seen using s2protocol, is that the first two units made were hellions, and all the ones after that were hellbats.

So it's more than a simple matter of the labels being wrong.

GraylinKim commented 11 years ago

The issue is that in SelectionEvents the BattleHellions are selected as Hellions. The last 2 battle hellions were created 10 seconds before the end of the game and were never selected.

The culprit is this bit of code in the SelectionEvent processing. You can see we already have a weird exception for Vikings here so there are likely some VikingAssault issues to be found. Other transforming unit types may also be affected.

units = list()
for (unit_id, unit_type, subgroup, intra_subgroup) in self.new_unit_info:
    # Hack that defaults viking selection to fighter mode instead of assault
    if replay.versions[1] == 2 and replay.build >= 23925 and unit_type == 71:
        unit_type = 72

    if unit_id in replay.objects:
        unit = replay.objects[unit_id]
        if not unit.is_type(unit_type):
            replay.datapack.change_type(unit, unit_type, self.frame)
    else:
        unit = replay.datapack.create_unit(unit_id, unit_type, 0x00, self.frame)
        replay.objects[unit_id] = unit

    units.append(unit)

We should skip this type manipulation logic when tracker events are available because they are 100% accurate on their own. When tracker events are not available (older builds of SCII) then this becomes one of the only sources of reliable type change information and we'll just have to live with the issues that you've brought up here.

dsjoerg commented 11 years ago

Perfect, agree with your suggested course of action.