# Path: mgz/enums.py
# def VictoryEnum(ctx):
#     """Victory Type Enumeration."""
#     return Enum(
#         ctx,
#         standard=0,
#         conquest=1,
#         exploration=2,
#         ruins=3,
#         artifacts=4,
#         discoveries=5,
#         gold=6,
#         time_limit=7,
#         score=8,
#         standard2=9,
#         regicide=10,
#         last_man=11
#     )
# 
# def ResourceLevelEnum(ctx):
#     """Resource Level Enumeration."""
#     return Enum(
#         ctx,
#         none=-1,
#         standard=0,
#         low=1,
#         medium=2,
#         high=3,
#         unknown1=4,
#         unknown2=5,
#         unknown3=6
#     )
# 
# def AgeEnum(ctx):
#     """Age Enumeration."""
#     return Enum(
#         ctx,
#         what=-2,
#         unset=-1,
#         dark=0,
#         feudal=1,
#         castle=2,
#         imperial=3,
#         postimperial=4,
#         dmpostimperial=6,
#         default='unknown'
#     )
# 
# def PlayerTypeEnum(ctx):
#     """Player Type Enumeration."""
#     return Enum(
#         ctx,
#         absent=0,
#         closed=1,
#         human=2,
#         eliminated=3,
#         computer=4,
#         cyborg=5,
#         spectator=6
#     )
# 
# def DifficultyEnum(ctx):
#     """Difficulty Enumeration."""
#     return Enum(
#         ctx,
#         hardest=0,
#         hard=1,
#         moderate=2,
#         standard=3,
#         easiest=4,
#         extreme=5,
#         unknown=6
#     )
# 
# Path: mgz/util.py
# 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 (
    Struct, Int32ul, Float32l, Array, Padding, Flag, If,
    Byte, Int16ul, Bytes, Int32sl, Peek, Const, RepeatUntil,
    Int64ul, Computed
)
from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
from mgz.util import find_save_version
    "predators_enabled"/Flag,
    "turbo_enabled"/Flag,
    "shared_exploration"/Flag,
    "team_positions"/Flag,
    "sub_game_mode"/If(lambda ctx: find_save_version(ctx) >= 13.34, Int32ul),
    "battle_royale_time"/If(lambda ctx: find_save_version(ctx) >= 13.34, Int32ul),
    "handicap"/If(lambda ctx: find_save_version(ctx) >= 25.06, Flag),
    separator,
    "players"/Array(8, player),
    Bytes(9),
    "fog_of_war"/Flag,
    "cheat_notifications"/Flag,
    "colored_chat"/Flag,
    separator,
    "ranked"/Flag,
    "allow_specs"/Flag,
    "lobby_visibility"/Int32ul,
    "hidden_civs"/Flag,
    "matchmaking"/Flag,
    "spec_delay"/Int32ul,
    "scenario_civ"/If(lambda ctx: ctx._.save_version >= 13.13, Byte),
    "rms_crc"/If(lambda ctx: ctx._.save_version >= 13.13, Bytes(4)),
    "strings"/Array(23,
        Struct(
            "string"/de_string,
            "nums"/RepeatUntil(lambda x, lst, ctx: lst[-1] not in [3, 21, 23, 42, 44, 45, 46, 47], Int32ul)
        )
    ),
    # There's probably a right way to do this, but this is not it.
    "num_sn"/Computed(lambda ctx: ctx.strings[22].nums[1]),

# Path: mgz/enums.py
# def VictoryEnum(ctx):
#     """Victory Type Enumeration."""
#     return Enum(
#         ctx,
#         standard=0,
#         conquest=1,
#         exploration=2,
#         ruins=3,
#         artifacts=4,
#         discoveries=5,
#         gold=6,
#         time_limit=7,
#         score=8,
#         standard2=9,
#         regicide=10,
#         last_man=11
#     )
# 
# def ResourceLevelEnum(ctx):
#     """Resource Level Enumeration."""
#     return Enum(
#         ctx,
#         none=-1,
#         standard=0,
#         low=1,
#         medium=2,
#         high=3,
#         unknown1=4,
#         unknown2=5,
#         unknown3=6
#     )
# 
# def AgeEnum(ctx):
#     """Age Enumeration."""
#     return Enum(
#         ctx,
#         what=-2,
#         unset=-1,
#         dark=0,
#         feudal=1,
#         castle=2,
#         imperial=3,
#         postimperial=4,
#         dmpostimperial=6,
#         default='unknown'
#     )
# 
# def PlayerTypeEnum(ctx):
#     """Player Type Enumeration."""
#     return Enum(
#         ctx,
#         absent=0,
#         closed=1,
#         human=2,
#         eliminated=3,
#         computer=4,
#         cyborg=5,
#         spectator=6
#     )
# 
# def DifficultyEnum(ctx):
#     """Difficulty Enumeration."""
#     return Enum(
#         ctx,
#         hardest=0,
#         hard=1,
#         moderate=2,
#         standard=3,
#         easiest=4,
#         extreme=5,
#         unknown=6
#     )
# 
# Path: mgz/util.py
# 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/de.py
from construct import (
    Struct, Int32ul, Float32l, Array, Padding, Flag, If,
    Byte, Int16ul, Bytes, Int32sl, Peek, Const, RepeatUntil,
    Int64ul, Computed
)
from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
from mgz.util import find_save_version

    "predators_enabled"/Flag,
    "turbo_enabled"/Flag,
    "shared_exploration"/Flag,
    "team_positions"/Flag,
    "sub_game_mode"/If(lambda ctx: find_save_version(ctx) >= 13.34, Int32ul),
    "battle_royale_time"/If(lambda ctx: find_save_version(ctx) >= 13.34, Int32ul),
    "handicap"/If(lambda ctx: find_save_version(ctx) >= 25.06, Flag),
    separator,
    "players"/Array(8, player),
    Bytes(9),
    "fog_of_war"/Flag,
    "cheat_notifications"/Flag,
    "colored_chat"/Flag,
    separator,
    "ranked"/Flag,
    "allow_specs"/Flag,
    "lobby_visibility"/Int32ul,
    "hidden_civs"/Flag,
    "matchmaking"/Flag,
    "spec_delay"/Int32ul,
    "scenario_civ"/If(lambda ctx: ctx._.save_version >= 13.13, Byte),
    "rms_crc"/If(lambda ctx: ctx._.save_version >= 13.13, Bytes(4)),
    "strings"/Array(23,
        Struct(
            "string"/de_string,
            "nums"/RepeatUntil(lambda x, lst, ctx: lst[-1] not in [3, 21, 23, 42, 44, 45, 46, 47], Int32ul)
        )
    ),
    # There's probably a right way to do this, but this is not it.
    "num_sn"/Computed(lambda ctx: ctx.strings[22].nums[1]),

    "strategic_numbers"/Array(lambda ctx: ctx.num_sn if find_save_version(ctx) >= 25.22 else 59, Int32sl),