using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic;
using System.IO;

namespace HaloMap
{
    public class Reflexive
    {
        #region Fields
        public int Offset, PureOffset;
        public int ChunkCount;
        public int ChunkSize;
        public int RawTranslation;
        public int Translation;
        public byte[] Buffer;
        public List<Reflexive> Nesteds = new List<Reflexive>();
        #endregion

        #region Methods
        public void Read(Map map)
        {
            map.br.BaseStream.Position = map.SelectedTag.Offset + Offset;
            ChunkCount = map.br.ReadInt32();
            RawTranslation = map.br.ReadInt32();
            Translation = RawTranslation - map.Index.SecondaryMagic;
        }

        public void Read(Map map, bool b)
        {
            Offset = (int)map.br.BaseStream.Position;
            ChunkCount = map.br.ReadInt32();
            RawTranslation = map.br.ReadInt32();
            Translation = RawTranslation - map.Index.SecondaryMagic;
        }

        public void Read(Map map, int Offset)
        {
            this.Offset = Offset;
            Read(map);
        }

        public void Read(Map map, int Offset, bool b)
        {
            map.br.BaseStream.Position = Offset;
            Read(map, b);
        }
        public void Read(BinaryReader br, int Magic)
        {
            Offset = (int)br.BaseStream.Position;
            ChunkCount = br.ReadInt32();
            RawTranslation = br.ReadInt32();
            Translation = RawTranslation - Magic;
        }
        #endregion
    }

    public class TagReference
    {
        #region Fields
        public int Offset;
        public string Class;
        public int Ident;
        public Tag Tag;
        bool LoneID = false;
        #endregion

        #region Methods
        public void Read(Map map, int Offset)
        {
            map.br.BaseStream.Position = Offset;
            Ident = map.br.ReadInt32();
        }

        public void Read(BinaryReader br, int Offset)
        {
            br.BaseStream.Position = Offset;
            Ident = br.ReadInt32();
        }
        #endregion
    }

    public class BSPBlock
    {
        public int BSPOffset, BSPSize, BSPIdent;
        public int LightmapOffset, LightmapSize, LightmapIdent;
        public int Magic, MagicBaseAddress;
    }
}
