Esempio n. 1
0
        // #############################################################################################
        /// Function:<summary>
        ///          	
        ///          </summary>
        ///
        /// In:		<param name="_filename"></param>
        ///
        // #############################################################################################
        public void Save(string _filename)
        {
            Buffer buff = new Buffer(1024 * 1024 * 8);
            unchecked
            {
                buff.Write((UInt32)4);       // Map Version
                buff.Write((UInt32)0);       // spare space.
                buff.Write((UInt32)0);
                buff.Write((UInt32)0);
                buff.Write((UInt32)0);
                buff.Write((UInt32)0);
                buff.Write((UInt32)0);
                buff.Write((UInt32)0);
                buff.Write((UInt32)0);
                buff.Write((UInt16)Width);
                buff.Write((UInt16)Height);
                buff.Write((UInt16)Depth);
                buff.Write((UInt16)0);
                buff.Write((UInt16)LidBase);
                buff.Write((UInt16)TileWidth);
                buff.Write((UInt16)70);
                buff.Write((UInt16)Pavement);
                buff.Write((UInt16)16);

                // in RAW mode, just copy the buffer
                buff.Write((Byte)0);            // set no compression
                int sprite_count = 0;
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        // Write out block column
                        List<int> column = map[x + (y * Width)].column;
                        List<Sprite> sprites = map[x + (y * Width)].sprites;
                        int flags = 0;
                        if (sprites.Count != 0) flags |= 0x8000;

                        // Top bit set IF there are sprites in this column
                        buff.Write((UInt16)(column.Count | flags));
                        foreach (int i in column)
                        {
                            buff.Write(((UInt16)(i & 0xffff)));
                            buff.Write( ((Byte) ((i>>16)&0xff)) );
                        }

                        if (sprites.Count != 0)
                        {
                            // If we have sprites here, save them out...
                            buff.Write((UInt16)sprites.Count);
                            foreach (Sprite s in sprites)
                            {
                                buff.Write((UInt16) ((int)s.SpriteType & 0xffff) );
                                UInt32 pos = (UInt32)((s.x & 0xff) | ((s.y & 0xff) << 8) | ((s.z & 0xffff) << 16));
                                buff.Write((UInt32)pos);
                                buff.Write((UInt32)0);
                                sprite_count++;
                            }
                        }

                    }
                }

                Console.WriteLine("Sprites = " + sprite_count.ToString());
                Console.WriteLine("BlockInfos = " + BlockInfo.Count.ToString());
                // Write out number of block info structs we have
                buff.Write((UInt32)BlockInfo.Count);
                foreach (block_info info in BlockInfo)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        buff.Write((UInt16)info[i]);
                    }
                    // Do we need to save extended block info?
                    UInt32 f = 0;
                    if (info.Flags2 != 0 || info.Offsets1 != 0 || info.Offsets2 != 0 || info.Offsets3 != 0)
                    {
                        f = 0x80000000;
                    }
                    // Clear off the temp bit, and or in the extended flag
                    buff.Write(((UInt32)info.Flags1&0x7fffffff)|f);
                    if (f != 0)
                    {
                        buff.Write((UInt32)info.Flags2);
                        buff.Write((UInt32)info.Offsets1);
                        buff.Write((UInt32)info.Offsets2);
                        buff.Write((UInt32)info.Offsets3);
                    }
                }
            }

            buff.Save(_filename);
        }