# Path: mgz/enums.py
# def GameTypeEnum(ctx):
#     """Game Type Enumeration."""
#     return Enum(
#         ctx,
#         RM=0,
#         Regicide=1,
#         DM=2,
#         Scenario=3,
#         Campaign=4,
#         KingOfTheHill=5,
#         WonderRace=6,
#         DefendTheWonder=7,
#         TurboRandom=8,
#         CaptureTheRelic=10,
#         SuddenDeath=11,
#         BattleRoyale=12,
#         EmpireWars=13
#     )
# 
# def RevealMapEnum(ctx):
#     """Reveal Map Enumeration."""
#     return Enum(
#         ctx,
#         normal=0,
#         explored=1,
#         all_visible=2,
#         no_fog=3,
#     )
# 
# Path: mgz/util.py
# 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
# 
# def find_save_version(ctx):
#     """Find save version."""
#     if 'save_version' not in ctx:
#         return find_save_version(ctx._)
#     return ctx.save_version


from construct import Array, Byte, Bytes, Flag, Int32ul, Padding, Peek, Struct, If, Computed, Embedded, Int32sl
from mgz.enums import GameTypeEnum, RevealMapEnum
from mgz.util import Version, find_save_version
"""Lobby."""



# pylint: disable=invalid-name, bad-continuation


# Player inputs in the lobby, and several host settings.
lobby = "lobby"/Struct(
    If(lambda ctx: find_save_version(ctx) >= 13.34, Padding(5)),
    If(lambda ctx: find_save_version(ctx) >= 20.06, Padding(9)),
    Array(8, "teams"/Byte), # team number selected by each player
    If(lambda ctx: ctx._.version not in (Version.DE, Version.HD),
        Padding(1),
    ),
    Peek("reveal_map_id"/Int32ul),
    RevealMapEnum("reveal_map"/Int32ul),
    "fog_of_war"/Int32ul,
    "map_size"/Int32ul,
    "population_limit_encoded"/Int32ul,
    "population_limit"/Computed(lambda ctx: ctx.population_limit_encoded * (25 if ctx._.version in [Version.USERPATCH14, Version.USERPATCH15] else 1)),
    Embedded(If(lambda ctx: ctx._.version != Version.AOK,
        Struct(
            Peek("game_type_id"/Byte),
            GameTypeEnum("game_type"/Byte),
            "lock_teams"/Flag
        )
    )),

# Path: mgz/enums.py
# def GameTypeEnum(ctx):
#     """Game Type Enumeration."""
#     return Enum(
#         ctx,
#         RM=0,
#         Regicide=1,
#         DM=2,
#         Scenario=3,
#         Campaign=4,
#         KingOfTheHill=5,
#         WonderRace=6,
#         DefendTheWonder=7,
#         TurboRandom=8,
#         CaptureTheRelic=10,
#         SuddenDeath=11,
#         BattleRoyale=12,
#         EmpireWars=13
#     )
# 
# def RevealMapEnum(ctx):
#     """Reveal Map Enumeration."""
#     return Enum(
#         ctx,
#         normal=0,
#         explored=1,
#         all_visible=2,
#         no_fog=3,
#     )
# 
# Path: mgz/util.py
# 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
# 
# def find_save_version(ctx):
#     """Find save version."""
#     if 'save_version' not in ctx:
#         return find_save_version(ctx._)
#     return ctx.save_version


# Path: mgz/header/lobby.py
from construct import Array, Byte, Bytes, Flag, Int32ul, Padding, Peek, Struct, If, Computed, Embedded, Int32sl
from mgz.enums import GameTypeEnum, RevealMapEnum
from mgz.util import Version, find_save_version

"""Lobby."""



# pylint: disable=invalid-name, bad-continuation


# Player inputs in the lobby, and several host settings.
lobby = "lobby"/Struct(
    If(lambda ctx: find_save_version(ctx) >= 13.34, Padding(5)),
    If(lambda ctx: find_save_version(ctx) >= 20.06, Padding(9)),
    Array(8, "teams"/Byte), # team number selected by each player
    If(lambda ctx: ctx._.version not in (Version.DE, Version.HD),
        Padding(1),
    ),
    Peek("reveal_map_id"/Int32ul),
    RevealMapEnum("reveal_map"/Int32ul),
    "fog_of_war"/Int32ul,
    "map_size"/Int32ul,
    "population_limit_encoded"/Int32ul,
    "population_limit"/Computed(lambda ctx: ctx.population_limit_encoded * (25 if ctx._.version in [Version.USERPATCH14, Version.USERPATCH15] else 1)),
    Embedded(If(lambda ctx: ctx._.version != Version.AOK,
        Struct(
            Peek("game_type_id"/Byte),
            GameTypeEnum("game_type"/Byte),
            "lock_teams"/Flag
        )
    )),

    If(lambda ctx: ctx._.version in (Version.DE, Version.HD),