# Path: mgz/enums.py
# def DifficultyEnum(ctx):
#     """Difficulty Enumeration."""
#     return Enum(
#         ctx,
#         hardest=0,
#         hard=1,
#         moderate=2,
#         standard=3,
#         easiest=4,
#         extreme=5,
#         unknown=6
#     )
# 
# def PlayerTypeEnum(ctx):
#     """Player Type Enumeration."""
#     return Enum(
#         ctx,
#         absent=0,
#         closed=1,
#         human=2,
#         eliminated=3,
#         computer=4,
#         cyborg=5,
#         spectator=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'
#     )
# 
# Path: mgz/util.py
# class Find(Construct):
#     """Find bytes, and read past them."""
# 
#     __slots__ = ["find", "max_length"]
# 
#     def __init__(self, find, max_length):
#         """Initiallize."""
#         Construct.__init__(self)
#         if not isinstance(find, list):
#             find = [find]
#         self.find = find
#         self.max_length = max_length
# 
#     def _parse(self, stream, context, path):
#         """Parse stream to find a given byte string."""
#         start = stream.tell()
#         read_bytes = ""
#         if self.max_length:
#             read_bytes = stream.read(self.max_length)
#         else:
#             read_bytes = stream.read()
#         candidates = []
#         for f in self.find:
#             match = re.search(f, read_bytes)
#             if not match:
#                 continue
#             candidates.append(match.end())
#         if not candidates:
#             raise RuntimeError('could not find bytes: {}'.format(f))
#         choice = min(candidates)
#         stream.seek(start + choice)
#         return choice
# 
# 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
# 
# def find_version(ctx):
#     """Find version."""
#     if 'version' not in ctx:
#         return find_version(ctx._)
#     return ctx.version


from construct import (Array, Float32l, Int16ul, Int32sl, Int32ul, Padding,
                       PascalString, Peek, String, Struct, Bytes, If, IfThenElse)
from mgz.enums import DifficultyEnum, PlayerTypeEnum, AgeEnum
from mgz.util import Find, Version, find_save_version, find_version
"""Scenario."""



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


# Scenario header.
scenario_header = "scenario_header"/Struct(
    "next_uid"/Int32ul,
    "scenario_version"/Float32l,
    Array(16, "names"/String(256)),
    Array(16, "player_ids"/Int32ul),
    Array(16, "player_data"/Struct(
        "active"/Int32ul,
        "human"/Int32ul,
        "civilization"/Int32ul,
        "constant"/Int32ul, # 0x04 0x00 0x00 0x00
    )),
    Padding(5),
    "elapsed_time"/Float32l,
    "scenario_filename"/PascalString(lengthfield="scenario_filename_length"/Int16ul),

# Path: mgz/enums.py
# def DifficultyEnum(ctx):
#     """Difficulty Enumeration."""
#     return Enum(
#         ctx,
#         hardest=0,
#         hard=1,
#         moderate=2,
#         standard=3,
#         easiest=4,
#         extreme=5,
#         unknown=6
#     )
# 
# def PlayerTypeEnum(ctx):
#     """Player Type Enumeration."""
#     return Enum(
#         ctx,
#         absent=0,
#         closed=1,
#         human=2,
#         eliminated=3,
#         computer=4,
#         cyborg=5,
#         spectator=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'
#     )
# 
# Path: mgz/util.py
# class Find(Construct):
#     """Find bytes, and read past them."""
# 
#     __slots__ = ["find", "max_length"]
# 
#     def __init__(self, find, max_length):
#         """Initiallize."""
#         Construct.__init__(self)
#         if not isinstance(find, list):
#             find = [find]
#         self.find = find
#         self.max_length = max_length
# 
#     def _parse(self, stream, context, path):
#         """Parse stream to find a given byte string."""
#         start = stream.tell()
#         read_bytes = ""
#         if self.max_length:
#             read_bytes = stream.read(self.max_length)
#         else:
#             read_bytes = stream.read()
#         candidates = []
#         for f in self.find:
#             match = re.search(f, read_bytes)
#             if not match:
#                 continue
#             candidates.append(match.end())
#         if not candidates:
#             raise RuntimeError('could not find bytes: {}'.format(f))
#         choice = min(candidates)
#         stream.seek(start + choice)
#         return choice
# 
# 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
# 
# def find_version(ctx):
#     """Find version."""
#     if 'version' not in ctx:
#         return find_version(ctx._)
#     return ctx.version


# Path: mgz/header/scenario.py
from construct import (Array, Float32l, Int16ul, Int32sl, Int32ul, Padding,
                       PascalString, Peek, String, Struct, Bytes, If, IfThenElse)
from mgz.enums import DifficultyEnum, PlayerTypeEnum, AgeEnum
from mgz.util import Find, Version, find_save_version, find_version

"""Scenario."""



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


# Scenario header.
scenario_header = "scenario_header"/Struct(
    "next_uid"/Int32ul,
    "scenario_version"/Float32l,
    Array(16, "names"/String(256)),
    Array(16, "player_ids"/Int32ul),
    Array(16, "player_data"/Struct(
        "active"/Int32ul,
        "human"/Int32ul,
        "civilization"/Int32ul,
        "constant"/Int32ul, # 0x04 0x00 0x00 0x00
    )),
    Padding(5),
    "elapsed_time"/Float32l,
    "scenario_filename"/PascalString(lengthfield="scenario_filename_length"/Int16ul),

    If(lambda ctx: ctx._._.version == Version.DE, Struct(