Example #1
0
        /// <summary>
        /// Loads map from stream and assigns an id.
        /// </summary>
        /// <param name="id">
        /// Id of map.
        /// </param>
        /// <param name="stream">
        /// Source stream.
        /// </param>
        public Map(int id, Stream stream)
        {
            Id = id;

            BinaryReader reader = new BinaryReader(stream, TextCore.DefaultEncoding);

            //Basic info
            Flags  = reader.ReadByte();
            NumNPC = reader.ReadByte();
            Type   = (MapType)reader.ReadByte();
            if (Type != MapType.Map2D && Type != MapType.Map3D)
            {
                throw new InvalidDataException("Unknown map format.");
            }
            BackgroundMusic = reader.ReadByte();
            byte width  = reader.ReadByte();
            byte height = reader.ReadByte();

            tilesid  = reader.ReadByte();
            ComGFX   = reader.ReadByte();
            Palette  = reader.ReadByte();
            AnimRate = reader.ReadByte();

            //NPCs
            int npcstruct;

            if (NumNPC == 0)
            {
                npcstruct = 32;
            }
            else if (NumNPC == 64)
            {
                npcstruct = 96;
            }
            else
            {
                npcstruct = NumNPC;
            }
            NPCs = new NPC[npcstruct];
            for (int i = 0; i < npcstruct; i++)
            {
                NPCs[i] = new NPC(stream);
            }

            if (Type == MapType.Map2D)
            {
                //Tile data
                tiledata = new Tile[width, height];
                for (byte y = 0; y < height; y++)
                {
                    for (byte x = 0; x < width; x++)
                    {
                        tiledata[x, y] = new Tile(x, y, stream);
                    }
                }
            }
            else if (Type == MapType.Map3D)
            {
                //Block data
                blockdata = new Block[width, height];
                for (byte y = 0; y < height; y++)
                {
                    for (byte x = 0; x < width; x++)
                    {
                        blockdata[x, y] = new Block(x, y, stream);
                    }
                }
            }

            try{
                short autoevents = reader.ReadInt16();
                AutoEvents = new EventHeader[autoevents];
                for (int i = 0; i < autoevents; i++)
                {
                    AutoEvents[i] = new EventHeader(reader);
                }

                //EventHeader[][] tileEvents = new EventHeader[height][];
                for (int y = 0; y < height; y++)
                {
                    short events = reader.ReadInt16();
                    //tileEvents[y] = new EventHeader[events];
                    for (int i = 0; i < events; i++)
                    {
                        EventHeader e = new EventHeader(reader);
                        if (Type == MapType.Map2D)
                        {
                            TileData[e.XPos, y].Event = e;
                        }
                        else if (Type == MapType.Map3D)
                        {
                            BlockData[e.XPos, y].Event = e;
                        }
                    }
                }

                short numevents = reader.ReadInt16();
                Events = new MapEvent[numevents];
                for (int i = 0; i < numevents; i++)
                {
                    Events[i] = new MapEvent(i, reader);
                }

                //NPC positions
                foreach (NPC npc in UsedNPCs)
                {
                    if ((npc.Movement & 3) != 0)
                    {
                        npc.Positions    = new Position[1];
                        npc.Positions[0] = new Position((byte)(reader.ReadByte() - 1), (byte)(reader.ReadByte() - 1));
                    }
                    else
                    {
                        npc.Positions = new Position[1152];
                        for (int i = 0; i < 1152; i++)
                        {
                            npc.Positions[i] = new Position((byte)(reader.ReadByte() - 1), (byte)(reader.ReadByte() - 1));
                        }
                    }
                }

                //Active events
                int aesize;
                if (Type == MapType.Map2D)
                {
                    aesize = 250;
                }
                else
                {
                    //Goto-points
                    short numgotop = reader.ReadInt16();
                    gotopoints = new GotoPoint[numgotop];
                    for (int i = 0; i < numgotop; i++)
                    {
                        GotoPoint gp = gotopoints[i] = new GotoPoint(reader);
                        if (gp.X < width && gp.Y < height)
                        {
                            BlockData[gp.X, gp.Y].GotoPoint = gp;
                        }
                    }
                    //Automap gfx remapping structure
                    automap = reader.ReadBytes(64);
                    //Active events
                    aesize = 64;
                }
                ActiveEvents = new short[aesize];
                for (int i = 0; i < aesize; i++)
                {
                    ActiveEvents[i] = reader.ReadInt16();
                }
            }catch (EndOfStreamException e)
            {
                Error = e;
            }
        }
Example #2
0
 public void Store(MapEvent evnt)
 {
     X     = evnt.Byte1;
     Y     = evnt.Byte2;
     MapId = evnt.Word6;
 }
Example #3
0
 public void Restore(MapEvent evnt)
 {
     evnt.Byte1 = X;
     evnt.Byte2 = Y;
     evnt.Word6 = MapId;
 }
Example #4
0
 public void Restore(MapEvent evnt)
 {
     evnt.Byte5 = TextId;
 }
Example #5
0
 public MapExit(MapEvent evnt)
 {
     Store(evnt);
 }
Example #6
0
 public void Store(MapEvent evnt)
 {
     TextId = evnt.Byte5;
 }
Example #7
0
 public Text(MapEvent evnt)
 {
     Store(evnt);
 }
Example #8
0
 public void Restore(MapEvent evnt)
 {
     evnt.Word6 = ScriptId;
 }
Example #9
0
 public void Store(MapEvent evnt)
 {
     ScriptId = evnt.Word6;
 }
Example #10
0
 public DoScript(MapEvent evnt)
 {
     Store(evnt);
 }