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

Initial UnitBornEvent #140

Closed jonomon closed 11 years ago

jonomon commented 11 years ago

I was running this function:

summary = sc2reader.load_replay("ggtracker_3621402.SC2Replay",load_map= True,load_level=4)

(The replay is here: http://ggtracker.com/matches/3621402)

While working on the creep tracker, I was printing the UnitBornEvents as follows

    for event in replay.events:
        if event.name == "UnitBornEvent":
            print "EVENT", event, "Unit name", event.unit_type_name

The output for the initial base (hatchery and command centre) was as follows:

EVENT 00.00 Player 2 - Exiledz (Zerg) - Unit born Hive [3480001] Unit name Hatchery EVENT 00.00 Player 1 - Patch (Terran) - Unit born OrbitalCommand [32C0001] Unit name CommandCenter

Are the events supposed to print out "Hive" and "OrbitalCommand" ?

dsjoerg commented 11 years ago

Yes. See https://github.com/GraylinKim/sc2reader/blob/master/sc2reader/data/__init__.py#L152

def str(self): return "{0} [{1:X}]".format(self.name, self.id)

And self.name is: https://github.com/GraylinKim/sc2reader/blob/master/sc2reader/data/__init__.py#L103

@property def name(self): """The name of the unit type currently active. None if no type is assigned""" return self._type_class.name if self._type_class else None

You are probably calling this after all events have been processed, so the _type_class for those objects is whatever they were at the end of the game.

Graylin is working on a refactoring of the code (https://github.com/graylinkim/sc2reader/tree/event_loop) in which plugins will be given events in the order they occur; once that happens, then this problem will go away. Graylin please correct me if I am lying. :)

--dj

On Tue, Jul 9, 2013 at 3:32 PM, jonomon notifications@github.com wrote:

I was running this function:

summary = sc2reader.load_replay("ggtracker_3621402.SC2Replay",load_map= True,load_level=4)

(The replay is here: http://ggtracker.com/matches/3621402)

While working on the creep tracker, I was printing the UnitBornEvents as follows

for event in replay.events:
    if event.name == "UnitBornEvent":
        print "EVENT", event, "Unit name", event.unit_type_name

The output for the initial base (hatchery and command centre) was as follows:

EVENT 00.00 Player 2 - Exiledz (Zerg) - Unit born Hive [3480001] Unit name Hatchery EVENT 00.00 Player 1 - Patch (Terran) - Unit born OrbitalCommand [32C0001] Unit name CommandCenter

Are the events supposed to print out "Hive" and "OrbitalCommand" ?

— Reply to this email directly or view it on GitHubhttps://github.com/GraylinKim/sc2reader/issues/140 .

GraylinKim commented 11 years ago

With the current processing model there is no way around this. If you want the initial name you can use the unit's type history as seen here.

Soon I'll be adding an event loop processing model that will allow you to insert code into sc2reader's processing loop. See the #111 for details and the event_loop branch for the WIP.