Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ElKrist opened this issue Apr 13, 2019 · 6 comments
Closed

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

ElKrist opened this issue Apr 13, 2019 · 6 comments

Comments

@ElKrist
Copy link

ElKrist commented Apr 13, 2019

Steps to reproduce:

import sys
from mgz import header, body
import pprint

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
Copy link
Author

ElKrist commented Apr 13, 2019

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
Copy link
Owner

Hi, do you mean ai_move or move?

@ElKrist
Copy link
Author

ElKrist commented Apr 14, 2019

move

@happyleavesaoc
Copy link
Owner

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
Copy link
Author

ElKrist commented Apr 14, 2019

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
Copy link
Owner

Fixed in 247c246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants