happyleavesaoc / aoc-mgz

Age of Empires II recorded game parsing and summarization in Python 3.
MIT License
197 stars 42 forks source link

Can't get field 'unit_ids' for 'move' action #6

Closed ElKrist closed 4 years ago

ElKrist commented 5 years ago

Steps to reproduce:

if name == "main": pp = pprint.PrettyPrinter(indent=4)

For each input filename

for arg in sys.argv[1:]:
    with open(arg, 'rb') as f:
        # Remember end of file
        f.seek(0, 2)
        eof = f.tell()
        f.seek(0)
        # Parse the header
        h = header.parse_stream(f)
        # Parse the body
        while f.tell() < eof:
            # Parse a body operation
            o = body.operation.parse_stream(f)
            if o.type == 'action' and o.action.type == 'move':
                pp.pprint(o)


**Problem**:  
None of the 'move' action has the field 'unit_ids'

I see that this field should be present (excepted if moving the same unit as previous command):  
https://github.com/happyleavesaoc/aoc-mgz/blob/master/mgz/body/actions.py#L63

I'm not fluent in python so please forgive me if I made a simple mistake

Thanks for your work! 
ElKrist commented 5 years ago

I've found a "trick" to make it work. I replaced (error, see comments below):

If(lambda ctx: ctx.selected > 0x01, Array(
    lambda ctx: ctx.selected, "unit_ids"/Int32ul
))

by

    "unit_ids"/If(lambda ctx: ctx.selected < 0xff, Array(lambda ctx: ctx.selected, Int32ul))

If selected < 255 it gives for example: 'unit_ids': [1910] When selected=255 it gives 'unit_ids': None

happyleavesaoc commented 5 years ago

Hi, do you mean ai_move or move?

ElKrist commented 5 years ago

move

happyleavesaoc commented 5 years ago

I'm looking at the code and it already uses selected < 0xff: https://github.com/happyleavesaoc/aoc-mgz/blob/master/mgz/body/actions.py#L63

ElKrist commented 5 years ago

Oh sorry when I said I replaced that code:

If(lambda ctx: ctx.selected > 0x01, Array(
    lambda ctx: ctx.selected, "unit_ids"/Int32ul
))

I made a mistake (the code above does not exist). I meant I replaced this code:

    If(lambda ctx: ctx.selected < 0xff, Array(
        lambda ctx: ctx.selected, "unit_ids"/Int32ul
))

The trick was to add "unit_ids"/ in front of the If

happyleavesaoc commented 4 years ago

Fixed in https://github.com/happyleavesaoc/aoc-mgz/commit/247c246a77a27e55d33990019e63b1da17c86105