Warcraft II map files: C++/STL parsing library

Warcraft II game engine uses this format for map files. External maps can be edited by official Warcraft II map editor and saved in .pud files. Maps supplied with the game (i.e. single player campaign) follow the same format, but are instead embedded inside the game container files.

There are two major versions: 0x11 (original one) and 0x13 (roughly corresponds to v1.33 of the game engine, although some of the features got limited support in v1.3).

File consists of a sequence of typed sections.

Application

Warcraft II engine

File extension

pud

KS implementation details

License: CC0-1.0
Minimal Kaitai Struct required: 0.6

This page hosts a formal specification of Warcraft II map files using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Using Kaitai Struct in C++/STL usually consists of 3 steps.

  1. We need to create an STL input stream (std::istream).
    • One can open a stream for reading from a local file:
      #include <fstream>
      
      std::ifstream is("path/to/local/file.pud", std::ifstream::binary);
    • Or one can prepare a stream for reading from existing std::string str:
      #include <sstream>
      
      std::istringstream is(str);
    • Or one can parse arbitrary char* buffer in memory, given that we know its size:
      #include <sstream>
      
      const char buf[] = { ... };
      std::string str(buf, sizeof buf);
      std::istringstream is(str);
  2. We need to wrap our input stream into Kaitai stream:
    #include <kaitai/kaitaistream.h>
    
    kaitai::kstream ks(&is);
  3. And finally, we can invoke the parsing:
    warcraft_2_pud_t data(&ks);

After that, one can get various attributes from the structure by invoking getter methods like:

data.sections() // => get sections

C++/STL source code to parse Warcraft II map files

warcraft_2_pud.h

#ifndef WARCRAFT_2_PUD_H_
#define WARCRAFT_2_PUD_H_

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "kaitai/kaitaistruct.h"

#include <stdint.h>
#include <vector>

#if KAITAI_STRUCT_VERSION < 7000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.7 or later is required"
#endif

/**
 * Warcraft II game engine uses this format for map files. External
 * maps can be edited by official Warcraft II map editor and saved in
 * .pud files. Maps supplied with the game (i.e. single player
 * campaign) follow the same format, but are instead embedded inside
 * the game container files.
 * 
 * There are two major versions: 0x11 (original one) and 0x13 (roughly
 * corresponds to v1.33 of the game engine, although some of the
 * features got limited support in v1.3).
 * 
 * File consists of a sequence of typed sections.
 * \sa Source
 */

class warcraft_2_pud_t : public kaitai::kstruct {

public:
    class section_starting_resource_t;
    class section_era_t;
    class section_ver_t;
    class section_dim_t;
    class section_type_t;
    class section_unit_t;
    class section_t;
    class section_ownr_t;
    class unit_t;

    enum controller_t {
        CONTROLLER_COMPUTER = 1,
        CONTROLLER_PASSIVE_COMPUTER = 2,
        CONTROLLER_NOBODY = 3,
        CONTROLLER_COMPUTER = 4,
        CONTROLLER_HUMAN = 5,
        CONTROLLER_RESCUE_PASSIVE = 6,
        CONTROLLER_RESCUE_ACTIVE = 7
    };

    enum terrain_type_t {
        TERRAIN_TYPE_FOREST = 0,
        TERRAIN_TYPE_WINTER = 1,
        TERRAIN_TYPE_WASTELAND = 2,
        TERRAIN_TYPE_SWAMP = 3
    };

    enum unit_type_t {
        UNIT_TYPE_INFANTRY = 0,
        UNIT_TYPE_GRUNT = 1,
        UNIT_TYPE_PEASANT = 2,
        UNIT_TYPE_PEON = 3,
        UNIT_TYPE_BALLISTA = 4,
        UNIT_TYPE_CATAPULT = 5,
        UNIT_TYPE_KNIGHT = 6,
        UNIT_TYPE_OGRE = 7,
        UNIT_TYPE_ARCHER = 8,
        UNIT_TYPE_AXETHROWER = 9,
        UNIT_TYPE_MAGE = 10,
        UNIT_TYPE_DEATH_KNIGHT = 11,
        UNIT_TYPE_PALADIN = 12,
        UNIT_TYPE_OGRE_MAGE = 13,
        UNIT_TYPE_DWARVES = 14,
        UNIT_TYPE_GOBLIN_SAPPER = 15,
        UNIT_TYPE_ATTACK_PEASANT = 16,
        UNIT_TYPE_ATTACK_PEON = 17,
        UNIT_TYPE_RANGER = 18,
        UNIT_TYPE_BERSERKER = 19,
        UNIT_TYPE_ALLERIA = 20,
        UNIT_TYPE_TERON_GOREFIEND = 21,
        UNIT_TYPE_KURDAN_AND_SKY_REE = 22,
        UNIT_TYPE_DENTARG = 23,
        UNIT_TYPE_KHADGAR = 24,
        UNIT_TYPE_GROM_HELLSCREAM = 25,
        UNIT_TYPE_HUMAN_TANKER = 26,
        UNIT_TYPE_ORC_TANKER = 27,
        UNIT_TYPE_HUMAN_TRANSPORT = 28,
        UNIT_TYPE_ORC_TRANSPORT = 29,
        UNIT_TYPE_ELVEN_DESTROYER = 30,
        UNIT_TYPE_TROLL_DESTROYER = 31,
        UNIT_TYPE_BATTLESHIP = 32,
        UNIT_TYPE_JUGGERNAUGHT = 33,
        UNIT_TYPE_DEATHWING = 35,
        UNIT_TYPE_GNOMISH_SUBMARINE = 38,
        UNIT_TYPE_GIANT_TURTLE = 39,
        UNIT_TYPE_GNOMISH_FLYING_MACHINE = 40,
        UNIT_TYPE_GOBLIN_ZEPPLIN = 41,
        UNIT_TYPE_GRYPHON_RIDER = 42,
        UNIT_TYPE_DRAGON = 43,
        UNIT_TYPE_TURALYON = 44,
        UNIT_TYPE_EYE_OF_KILROGG = 45,
        UNIT_TYPE_DANATH = 46,
        UNIT_TYPE_KHORGATH_BLADEFIST = 47,
        UNIT_TYPE_CHO_GALL = 49,
        UNIT_TYPE_LOTHAR = 50,
        UNIT_TYPE_GUL_DAN = 51,
        UNIT_TYPE_UTHER_LIGHTBRINGER = 52,
        UNIT_TYPE_ZULJIN = 53,
        UNIT_TYPE_SKELETON = 55,
        UNIT_TYPE_DAEMON = 56,
        UNIT_TYPE_CRITTER = 57,
        UNIT_TYPE_FARM = 58,
        UNIT_TYPE_PIG_FARM = 59,
        UNIT_TYPE_HUMAN_BARRACKS = 60,
        UNIT_TYPE_ORC_BARRACKS = 61,
        UNIT_TYPE_CHURCH = 62,
        UNIT_TYPE_ALTAR_OF_STORMS = 63,
        UNIT_TYPE_HUMAN_SCOUT_TOWER = 64,
        UNIT_TYPE_ORC_SCOUT_TOWER = 65,
        UNIT_TYPE_STABLES = 66,
        UNIT_TYPE_OGRE_MOUND = 67,
        UNIT_TYPE_GNOMISH_INVENTOR = 68,
        UNIT_TYPE_GOBLIN_ALCHEMIST = 69,
        UNIT_TYPE_GRYPHON_AVIARY = 70,
        UNIT_TYPE_DRAGON_ROOST = 71,
        UNIT_TYPE_HUMAN_SHIPYARD = 72,
        UNIT_TYPE_ORC_SHIPYARD = 73,
        UNIT_TYPE_TOWN_HALL = 74,
        UNIT_TYPE_GREAT_HALL = 75,
        UNIT_TYPE_ELVEN_LUMBER_MILL = 76,
        UNIT_TYPE_TROLL_LUMBER_MILL = 77,
        UNIT_TYPE_HUMAN_FOUNDRY = 78,
        UNIT_TYPE_ORC_FOUNDRY = 79,
        UNIT_TYPE_MAGE_TOWER = 80,
        UNIT_TYPE_TEMPLE_OF_THE_DAMNED = 81,
        UNIT_TYPE_HUMAN_BLACKSMITH = 82,
        UNIT_TYPE_ORC_BLACKSMITH = 83,
        UNIT_TYPE_HUMAN_REFINERY = 84,
        UNIT_TYPE_ORC_REFINERY = 85,
        UNIT_TYPE_HUMAN_OIL_WELL = 86,
        UNIT_TYPE_ORC_OIL_WELL = 87,
        UNIT_TYPE_KEEP = 88,
        UNIT_TYPE_STRONGHOLD = 89,
        UNIT_TYPE_CASTLE = 90,
        UNIT_TYPE_FORTRESS = 91,
        UNIT_TYPE_GOLD_MINE = 92,
        UNIT_TYPE_OIL_PATCH = 93,
        UNIT_TYPE_HUMAN_START = 94,
        UNIT_TYPE_ORC_START = 95,
        UNIT_TYPE_HUMAN_GUARD_TOWER = 96,
        UNIT_TYPE_ORC_GUARD_TOWER = 97,
        UNIT_TYPE_HUMAN_CANNON_TOWER = 98,
        UNIT_TYPE_ORC_CANNON_TOWER = 99,
        UNIT_TYPE_CIRCLE_OF_POWER = 100,
        UNIT_TYPE_DARK_PORTAL = 101,
        UNIT_TYPE_RUNESTONE = 102,
        UNIT_TYPE_HUMAN_WALL = 103,
        UNIT_TYPE_ORC_WALL = 104
    };

    warcraft_2_pud_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, warcraft_2_pud_t* p__root = 0);

private:
    void _read();

public:
    ~warcraft_2_pud_t();

    class section_starting_resource_t : public kaitai::kstruct {

    public:

        section_starting_resource_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_starting_resource_t();

    private:
        std::vector<uint16_t>* m_resources_by_player;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        std::vector<uint16_t>* resources_by_player() const { return m_resources_by_player; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    /**
     * Section that specifies terrain type for this map.
     */

    class section_era_t : public kaitai::kstruct {

    public:

        section_era_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_era_t();

    private:
        terrain_type_t m_terrain;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        terrain_type_t terrain() const { return m_terrain; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    /**
     * Section that specifies format version.
     */

    class section_ver_t : public kaitai::kstruct {

    public:

        section_ver_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_ver_t();

    private:
        uint16_t m_version;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        uint16_t version() const { return m_version; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    class section_dim_t : public kaitai::kstruct {

    public:

        section_dim_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_dim_t();

    private:
        uint16_t m_x;
        uint16_t m_y;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        uint16_t x() const { return m_x; }
        uint16_t y() const { return m_y; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    /**
     * Section that confirms that this file is a "map file" by certain
     * magic string and supplies a tag that could be used in
     * multiplayer to check that all player use the same version of the
     * map.
     */

    class section_type_t : public kaitai::kstruct {

    public:

        section_type_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_type_t();

    private:
        std::string m_magic;
        std::string m_unused;
        uint32_t m_id_tag;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        std::string magic() const { return m_magic; }

        /**
         * unused (always set to $0a and $ff by editor, but can be anything for the game)
         */
        std::string unused() const { return m_unused; }

        /**
         * id tag (for consistency check in multiplayer)
         */
        uint32_t id_tag() const { return m_id_tag; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    class section_unit_t : public kaitai::kstruct {

    public:

        section_unit_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_unit_t();

    private:
        std::vector<unit_t*>* m_units;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        std::vector<unit_t*>* units() const { return m_units; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    class section_t : public kaitai::kstruct {

    public:

        section_t(kaitai::kstream* p__io, warcraft_2_pud_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_t();

    private:
        std::string m_name;
        uint32_t m_size;
        kaitai::kstruct* m_body;
        bool n_body;

    public:
        bool _is_null_body() { body(); return n_body; };

    private:
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t* m__parent;
        std::string m__raw_body;
        kaitai::kstream* m__io__raw_body;

    public:
        std::string name() const { return m_name; }
        uint32_t size() const { return m_size; }
        kaitai::kstruct* body() const { return m_body; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t* _parent() const { return m__parent; }
        std::string _raw_body() const { return m__raw_body; }
        kaitai::kstream* _io__raw_body() const { return m__io__raw_body; }
    };

    /**
     * Section that specifies who controls each player.
     */

    class section_ownr_t : public kaitai::kstruct {

    public:

        section_ownr_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~section_ownr_t();

    private:
        std::vector<controller_t>* m_controller_by_player;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_t* m__parent;

    public:
        std::vector<controller_t>* controller_by_player() const { return m_controller_by_player; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_t* _parent() const { return m__parent; }
    };

    class unit_t : public kaitai::kstruct {

    public:

        unit_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_unit_t* p__parent = 0, warcraft_2_pud_t* p__root = 0);

    private:
        void _read();

    public:
        ~unit_t();

    private:
        bool f_resource;
        int32_t m_resource;
        bool n_resource;

    public:
        bool _is_null_resource() { resource(); return n_resource; };

    private:

    public:
        int32_t resource();

    private:
        uint16_t m_x;
        uint16_t m_y;
        unit_type_t m_u_type;
        uint8_t m_owner;
        uint16_t m_options;
        warcraft_2_pud_t* m__root;
        warcraft_2_pud_t::section_unit_t* m__parent;

    public:
        uint16_t x() const { return m_x; }
        uint16_t y() const { return m_y; }
        unit_type_t u_type() const { return m_u_type; }
        uint8_t owner() const { return m_owner; }

        /**
         * if gold mine or oil well, contains 2500 * this, otherwise 0 passive 1 active
         */
        uint16_t options() const { return m_options; }
        warcraft_2_pud_t* _root() const { return m__root; }
        warcraft_2_pud_t::section_unit_t* _parent() const { return m__parent; }
    };

private:
    std::vector<section_t*>* m_sections;
    warcraft_2_pud_t* m__root;
    kaitai::kstruct* m__parent;

public:
    std::vector<section_t*>* sections() const { return m_sections; }
    warcraft_2_pud_t* _root() const { return m__root; }
    kaitai::kstruct* _parent() const { return m__parent; }
};

#endif  // WARCRAFT_2_PUD_H_

warcraft_2_pud.cpp

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "warcraft_2_pud.h"



warcraft_2_pud_t::warcraft_2_pud_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = this;
    _read();
}

void warcraft_2_pud_t::_read() {
    m_sections = new std::vector<section_t*>();
    {
        int i = 0;
        while (!m__io->is_eof()) {
            m_sections->push_back(new section_t(m__io, this, m__root));
            i++;
        }
    }
}

warcraft_2_pud_t::~warcraft_2_pud_t() {
    for (std::vector<section_t*>::iterator it = m_sections->begin(); it != m_sections->end(); ++it) {
        delete *it;
    }
    delete m_sections;
}

warcraft_2_pud_t::section_starting_resource_t::section_starting_resource_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_starting_resource_t::_read() {
    m_resources_by_player = new std::vector<uint16_t>();
    {
        int i = 0;
        while (!m__io->is_eof()) {
            m_resources_by_player->push_back(m__io->read_u2le());
            i++;
        }
    }
}

warcraft_2_pud_t::section_starting_resource_t::~section_starting_resource_t() {
    delete m_resources_by_player;
}

warcraft_2_pud_t::section_era_t::section_era_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_era_t::_read() {
    m_terrain = static_cast<warcraft_2_pud_t::terrain_type_t>(m__io->read_u2le());
}

warcraft_2_pud_t::section_era_t::~section_era_t() {
}

warcraft_2_pud_t::section_ver_t::section_ver_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_ver_t::_read() {
    m_version = m__io->read_u2le();
}

warcraft_2_pud_t::section_ver_t::~section_ver_t() {
}

warcraft_2_pud_t::section_dim_t::section_dim_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_dim_t::_read() {
    m_x = m__io->read_u2le();
    m_y = m__io->read_u2le();
}

warcraft_2_pud_t::section_dim_t::~section_dim_t() {
}

warcraft_2_pud_t::section_type_t::section_type_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_type_t::_read() {
    m_magic = m__io->ensure_fixed_contents(std::string("\x57\x41\x52\x32\x20\x4D\x41\x50\x00\x00", 10));
    m_unused = m__io->read_bytes(2);
    m_id_tag = m__io->read_u4le();
}

warcraft_2_pud_t::section_type_t::~section_type_t() {
}

warcraft_2_pud_t::section_unit_t::section_unit_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_unit_t::_read() {
    m_units = new std::vector<unit_t*>();
    {
        int i = 0;
        while (!m__io->is_eof()) {
            m_units->push_back(new unit_t(m__io, this, m__root));
            i++;
        }
    }
}

warcraft_2_pud_t::section_unit_t::~section_unit_t() {
    for (std::vector<unit_t*>::iterator it = m_units->begin(); it != m_units->end(); ++it) {
        delete *it;
    }
    delete m_units;
}

warcraft_2_pud_t::section_t::section_t(kaitai::kstream* p__io, warcraft_2_pud_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_t::_read() {
    m_name = kaitai::kstream::bytes_to_str(m__io->read_bytes(4), std::string("ASCII"));
    m_size = m__io->read_u4le();
    n_body = true;
    {
        std::string on = name();
        if (on == std::string("SLBR")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_starting_resource_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("ERAX")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_era_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("OWNR")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_ownr_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("ERA ")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_era_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("SGLD")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_starting_resource_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("VER ")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_ver_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("SOIL")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_starting_resource_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("UNIT")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_unit_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("DIM ")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_dim_t(m__io__raw_body, this, m__root);
        }
        else if (on == std::string("TYPE")) {
            n_body = false;
            m__raw_body = m__io->read_bytes(size());
            m__io__raw_body = new kaitai::kstream(m__raw_body);
            m_body = new section_type_t(m__io__raw_body, this, m__root);
        }
        else {
            m__raw_body = m__io->read_bytes(size());
        }
    }
}

warcraft_2_pud_t::section_t::~section_t() {
    if (!n_body) {
        delete m__io__raw_body;
        delete m_body;
    }
}

warcraft_2_pud_t::section_ownr_t::section_ownr_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void warcraft_2_pud_t::section_ownr_t::_read() {
    m_controller_by_player = new std::vector<controller_t>();
    {
        int i = 0;
        while (!m__io->is_eof()) {
            m_controller_by_player->push_back(static_cast<warcraft_2_pud_t::controller_t>(m__io->read_u1()));
            i++;
        }
    }
}

warcraft_2_pud_t::section_ownr_t::~section_ownr_t() {
    delete m_controller_by_player;
}

warcraft_2_pud_t::unit_t::unit_t(kaitai::kstream* p__io, warcraft_2_pud_t::section_unit_t* p__parent, warcraft_2_pud_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    f_resource = false;
    _read();
}

void warcraft_2_pud_t::unit_t::_read() {
    m_x = m__io->read_u2le();
    m_y = m__io->read_u2le();
    m_u_type = static_cast<warcraft_2_pud_t::unit_type_t>(m__io->read_u1());
    m_owner = m__io->read_u1();
    m_options = m__io->read_u2le();
}

warcraft_2_pud_t::unit_t::~unit_t() {
}

int32_t warcraft_2_pud_t::unit_t::resource() {
    if (f_resource)
        return m_resource;
    n_resource = true;
    if ( ((u_type() == UNIT_TYPE_GOLD_MINE) || (u_type() == UNIT_TYPE_HUMAN_OIL_WELL) || (u_type() == UNIT_TYPE_ORC_OIL_WELL) || (u_type() == UNIT_TYPE_OIL_PATCH)) ) {
        n_resource = false;
        m_resource = (options() * 2500);
    }
    f_resource = true;
    return m_resource;
}