# Path: mgz/util.py
# def find_version(ctx):
#     """Find version."""
#     if 'version' not in ctx:
#         return find_version(ctx._)
#     return ctx.version
# 
# def find_save_version(ctx):
#     """Find save version."""
#     if 'save_version' not in ctx:
#         return find_save_version(ctx._)
#     return ctx.save_version
# 
# class Version(Enum):
#     """Version enumeration.
# 
#     Using consts from https://github.com/goto-bus-stop/recanalyst/blob/master/src/Model/Version.php
#     for consistency.
#     """
#     AOK = 1
#     AOC = 4
#     AOC10 = 5
#     AOC10C = 8
#     USERPATCH12 = 12
#     USERPATCH13 = 13
#     USERPATCH14 = 11
#     USERPATCH15 = 20
#     DE = 21
#     USERPATCH14RC2 = 22
#     MCP = 30
#     HD = 19


from construct import (
    Struct, Float32l, Int16ul, Byte, Embedded, Switch, If,
    Int32ul, Array, String, Padding, IfThenElse, this
)
from mgz.util import find_version, find_save_version, Version
    "trailing_spacing"/Float32l,
    "move_algorithm"/Byte,
    "turn_radius"/Float32l,
    "turn_radius_speed"/Float32l,
    "maximum_yaw_per_second_moving"/Float32l,
    "stationary_yaw_per_revolution_time"/Float32l,
    "maximum_yaw_per_second_stationary"/Float32l
)

action = "action"/Struct(
    moving,
    "default_task"/Int16ul,
    "search_radius"/Float32l,
    "work_rate"/Float32l,
    "handicap_work_rate"/If(lambda ctx: find_save_version(ctx) >= 25.06, Float32l),
    "drop_site"/Int16ul,
    "backup_drop_site"/Int16ul,
    "task_by_group"/Byte,
    "command_sound"/Int16ul,
    "move_sound"/Int16ul,
    "run_pattern"/Byte
)

weapon = "weapon"/Struct(
    "type"/Int16ul,
    "value"/Int16ul
)

base_combat = "base_combat"/Struct(
    action,

# Path: mgz/util.py
# def find_version(ctx):
#     """Find version."""
#     if 'version' not in ctx:
#         return find_version(ctx._)
#     return ctx.version
# 
# def find_save_version(ctx):
#     """Find save version."""
#     if 'save_version' not in ctx:
#         return find_save_version(ctx._)
#     return ctx.save_version
# 
# class Version(Enum):
#     """Version enumeration.
# 
#     Using consts from https://github.com/goto-bus-stop/recanalyst/blob/master/src/Model/Version.php
#     for consistency.
#     """
#     AOK = 1
#     AOC = 4
#     AOC10 = 5
#     AOC10C = 8
#     USERPATCH12 = 12
#     USERPATCH13 = 13
#     USERPATCH14 = 11
#     USERPATCH15 = 20
#     DE = 21
#     USERPATCH14RC2 = 22
#     MCP = 30
#     HD = 19


# Path: mgz/header/unit_type.py
from construct import (
    Struct, Float32l, Int16ul, Byte, Embedded, Switch, If,
    Int32ul, Array, String, Padding, IfThenElse, this
)
from mgz.util import find_version, find_save_version, Version

    "trailing_spacing"/Float32l,
    "move_algorithm"/Byte,
    "turn_radius"/Float32l,
    "turn_radius_speed"/Float32l,
    "maximum_yaw_per_second_moving"/Float32l,
    "stationary_yaw_per_revolution_time"/Float32l,
    "maximum_yaw_per_second_stationary"/Float32l
)

action = "action"/Struct(
    moving,
    "default_task"/Int16ul,
    "search_radius"/Float32l,
    "work_rate"/Float32l,
    "handicap_work_rate"/If(lambda ctx: find_save_version(ctx) >= 25.06, Float32l),
    "drop_site"/Int16ul,
    "backup_drop_site"/Int16ul,
    "task_by_group"/Byte,
    "command_sound"/Int16ul,
    "move_sound"/Int16ul,
    "run_pattern"/Byte
)

weapon = "weapon"/Struct(
    "type"/Int16ul,
    "value"/Int16ul
)

base_combat = "base_combat"/Struct(
    action,

    "base_armour"/IfThenElse(lambda ctx: find_version(ctx) != Version.AOK, Int16ul, Byte),