Save() public method

Saves this map to a file in the default format (FCMv3).
public Save ( [ fileName ) : bool
fileName [
return bool
Example #1
0
 void SaveMap(object param)
 {
     if (lockDown)
     {
         return;
     }
     if (map.changesSinceSave > 0)
     {
         tasks.Add(
             delegate {
             map.changesSinceSave = 0;
             map.Save();
         }, null, false);
     }
 }
Example #2
0
 public void SaveMap() {
     lock( SyncRoot ) {
         if( Map != null ) {
             Map.Save( MapFileName );
         }
     }
 }
Example #3
0
 /// <summary> Forces the map to be saved to file. Acquires SyncRoot. </summary>
 public void SaveMap() {
     lock( SyncRoot ) {
         if( Map != null ) {
             if( Map.Save( MapFileName ) ) {
                 HasChangedSinceBackup = true;
             }
         }
     }
 }
Example #4
0
 public void SaveMap()
 {
     lock ( WorldLock ) {
         if (Map != null)
         {
             Map.Save(GetMapName());
         }
     }
 }
Example #5
0
 public void Generate()
 {
     double[,] heightmap = GenerateHeightmap(map.widthX, map.widthY);
     Feedback("Filling...");
     for (int x = 0; x < map.widthX; x++)
     {
         for (int y = 0; y < map.widthY; y++)
         {
             double level = heightmap[x, y];
             if (level > water)
             {
                 level = (level - water) * smoothingOver + water;
                 map.SetBlock(x, y, (int)(level * map.height), Block.Grass);
                 if (!hollow)
                 {
                     for (int i = (int)(level * map.height) - 1; i > 0; i--)
                     {
                         if ((int)(level * map.height) - i < 5)
                         {
                             map.SetBlock(x, y, i, Block.Dirt);
                         }
                         else
                         {
                             map.SetBlock(x, y, i, Block.Stone);
                         }
                     }
                 }
             }
             else
             {
                 level = (level - water) * smoothingUnder + water;
                 map.SetBlock(x, y, (int)(water * map.height), Block.Water);
                 if (!hollow)
                 {
                     for (int i = (int)(water * map.height) - 1; i >= (int)(level * map.height); i--)
                     {
                         map.SetBlock(x, y, i, Block.Water);
                     }
                 }
                 map.SetBlock(x, y, (int)(level * map.height), Block.Sand);
                 if (!hollow)
                 {
                     for (int i = (int)(level * map.height) - 1; i > 0; i--)
                     {
                         map.SetBlock(x, y, i, Block.Stone);
                     }
                 }
             }
         }
     }
     map.MakeFloodBarrier();
     map.Save(filename);
     Feedback("Done.");
 }
Example #6
0
        public static void Start(Player player)
        {
            Map map = MapGeneratorOld.GenerateEmpty(64, 128, 16);

            map.Save("maps/minefield.fcm");
            if (_world != null)
            {
                WorldManager.RemoveWorld(_world);
            }
            WorldManager.AddWorld(Player.Console, "Minefield", map, true);
            _map   = map;
            _world = WorldManager.FindWorldExact("Minefield");
            SetUpRed();
            SetUpMiddleWater();
            SetUpGreen();
            SetUpMines();
            _map.Spawn = new Position(_map.Width / 2, 5, _ground + 3).ToVector3I().ToPlayerCoords();
            _world.LoadMap();
            _world.gameMode = GameMode.MineField;
            _world.EnableTNTPhysics(Player.Console, false);
            Server.Message("{0}&S started a game of MineField on world Minefield!", player.ClassyName);
            WorldManager.SaveWorldList();
            Server.RequestGC();
        }
Example #7
0
        public void LoadMap(string mapName)
        {
            try {
                map = Map.Load(this, mapName);
            } catch (Exception ex) {
                log.Log("Could not open the specified file ({0}): {1}", LogType.Error, mapName, ex.Message);
            }

            // or generate a default one
            if (map == null)
            {
                log.Log("World.Init: Generating default flatgrass level.", LogType.SystemActivity);
                map = new Map(this, 64, 64, 64);

                map.spawn.Set(map.widthX / 2 * 32 + 16, map.widthY / 2 * 32 + 16, map.height * 32, 0, 0);

                MapCommands.GenerateFlatgrass(map, false);

                if (!map.Save())
                {
                    throw new Exception("Could not save file.");
                }
            }
        }
Example #8
0
        public static Map Load(World world, string fileName)
        {
            world.log.Log("Converting {0}...", LogType.SystemActivity, fileName);
            byte[] temp = new byte[8];
            Map    map  = new Map(world);

            byte[] data;
            int    length;

            try {
                using (FileStream stream = File.OpenRead(fileName)) {
                    stream.Seek(-4, SeekOrigin.End);
                    stream.Read(temp, 0, sizeof(int));
                    stream.Seek(0, SeekOrigin.Begin);
                    length = BitConverter.ToInt32(temp, 0);
                    data   = new byte[length];
                    using (GZipStream reader = new GZipStream(stream, CompressionMode.Decompress)) {
                        reader.Read(data, 0, length);
                    }
                }

                //if( data[0] == 0xBE && data[1] == 0xEE && data[2] == 0xEF ) {
                for (int i = 0; i < length - 1; i++)
                {
                    if (data[i] == 0xAC && data[i + 1] == 0xED)
                    {
                        // bypassing the header crap
                        int pointer = i + 6;
                        Array.Copy(data, pointer, temp, 0, sizeof(short));
                        pointer += Server.htons(BitConverter.ToInt16(temp, 0));
                        pointer += 13;

                        int headerEnd = 0;
                        // find the end of serialization listing
                        for (headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++)
                        {
                            if (data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70)
                            {
                                headerEnd += 2;
                                break;
                            }
                        }

                        // start parsing serialization listing
                        int offset = 0;
                        while (pointer < headerEnd)
                        {
                            if (data[pointer] == 'Z')
                            {
                                offset++;
                            }
                            else if (data[pointer] == 'I' || data[pointer] == 'F')
                            {
                                offset += 4;
                            }
                            else if (data[pointer] == 'J')
                            {
                                offset += 8;
                            }

                            pointer += 1;
                            Array.Copy(data, pointer, temp, 0, sizeof(short));
                            short skip = Server.htons(BitConverter.ToInt16(temp, 0));
                            pointer += 2;

                            // look for relevant variables
                            Array.Copy(data, headerEnd + offset - 4, temp, 0, sizeof(int));
                            if (MemCmp(data, pointer, "width"))
                            {
                                map.widthX = (ushort)Server.htons(BitConverter.ToInt32(temp, 0));
                            }
                            else if (MemCmp(data, pointer, "depth"))
                            {
                                map.height = (ushort)Server.htons(BitConverter.ToInt32(temp, 0));
                            }
                            else if (MemCmp(data, pointer, "height"))
                            {
                                map.widthY = (ushort)Server.htons(BitConverter.ToInt32(temp, 0));
                            }
                            else if (MemCmp(data, pointer, "xSpawn"))
                            {
                                map.spawn.x = (short)(Server.htons(BitConverter.ToInt32(temp, 0)) * 32 + 16);
                            }
                            else if (MemCmp(data, pointer, "ySpawn"))
                            {
                                map.spawn.h = (short)(Server.htons(BitConverter.ToInt32(temp, 0)) * 32 + 16);
                            }
                            else if (MemCmp(data, pointer, "zSpawn"))
                            {
                                map.spawn.y = (short)(Server.htons(BitConverter.ToInt32(temp, 0)) * 32 + 16);
                            }

                            pointer += skip;
                        }

                        // find the start of the block array
                        bool foundBlockArray = false;
                        offset = Array.IndexOf <byte>(data, 0x00, headerEnd);
                        while (offset != -1 && offset < data.Length - 2)
                        {
                            if (data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70)
                            {
                                foundBlockArray = true;
                                pointer         = offset + 7;
                            }
                            offset = Array.IndexOf <byte>(data, 0x00, offset + 1);
                        }

                        // copy the block array... or fail
                        if (foundBlockArray)
                        {
                            map.CopyBlocks(data, pointer);
                            if (!map.ValidateBlockTypes())
                            {
                                throw new Exception("Map validation failed: unknown block types found. Either parsing has done wrong, or this is an incompatible format.");
                            }
                        }
                        else
                        {
                            throw new Exception("Could not locate block array.");
                        }
                        break;
                    }
                    //}
                }
            } catch (Exception ex) {
                world.log.Log("Conversion failed: {0}", LogType.Error, ex.Message);
                world.log.Log(ex.StackTrace, LogType.Debug);
                return(null);
            }
            map.Save();
            world.log.Log("Conversion completed succesfully succesful.", LogType.SystemActivity, fileName);
            return(map);
        }
Example #9
0
        internal static void DoGenerate( Map map, Player player, string mode, string filename, Random rand, bool hollow )
        {
            switch( mode ) {
                case "flatgrass":
                    player.Message( "Generating flatgrass map..." );
                    GenerateFlatgrass( map, hollow );

                    if( map.Save( filename ) ) {
                        player.Message( "Map generation: Done." );
                    } else {
                        player.Message( Color.Red, "An error occured while generating the map." );
                    }
                    break;

                case "lag":
                    player.Message( "Generating laggy map..." );
                    for( int x = 0; x < map.widthX; x+=2 ) {
                        for( int y = 0; y < map.widthY; y+=2 ) {
                            for( int h = 0; h < map.widthY; h+=2 ) {
                                map.SetBlock( x, y, h, Block.Lava );
                            }
                        }
                    }

                    if( map.Save( filename ) ) {
                        player.Message( "Map generation: Done." );
                    } else {
                        player.Message( Color.Red, "An error occured while generating the map." );
                    }
                    break;

                case "empty":
                    player.Message( "Generating empty map..." );
                    map.MakeFloodBarrier();

                    if( map.Save( filename ) ) {
                        player.Message( "Map generation: Done." );
                    } else {
                        player.Message( Color.Red, "An error occured while generating the map." );
                    }

                    break;

                case "hills":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              1, 1, 0.5, 0.5, 0, 0.5, hollow ), false );
                    break;

                case "mountains":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              4, 1, 0.5, 0.5, 0.1, 0.5, hollow ), false );
                    break;

                case "lake":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              1, 0.6, 0.9, 0.5, -0.35, 0.55, hollow ), false );
                    break;

                case "island":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              1, 0.6, 1, 0.5, 0.3, 0.35, hollow ), false );
                    break;

                default:
                    player.Message( "Unknown map generation mode: " + mode );
                    break;
            }
        }
Example #10
0
        public static Map Load( World world, string fileName ) {
            world.log.Log( "Converting {0}...", LogType.SystemActivity, fileName );
            byte[] temp = new byte[8];
            Map map = new Map( world );
            byte[] data;
            int length;
            try {
                using( FileStream stream = File.OpenRead( fileName ) ) {
                    stream.Seek( -4, SeekOrigin.End );
                    stream.Read( temp, 0, sizeof( int ) );
                    stream.Seek( 0, SeekOrigin.Begin );
                    length = BitConverter.ToInt32( temp, 0 );
                    data = new byte[length];
                    using( GZipStream reader = new GZipStream( stream, CompressionMode.Decompress ) ) {
                        reader.Read( data, 0, length );
                    }
                }

                //if( data[0] == 0xBE && data[1] == 0xEE && data[2] == 0xEF ) {
                    for( int i = 0; i < length - 1; i++ ) {
                        if( data[i] == 0xAC && data[i + 1] == 0xED ) {

                            // bypassing the header crap
                            int pointer = i + 6;
                            Array.Copy( data, pointer, temp, 0, sizeof( short ) );
                            pointer += Server.htons( BitConverter.ToInt16( temp, 0 ) );
                            pointer += 13;

                            int headerEnd = 0;
                            // find the end of serialization listing
                            for( headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++ ) {
                                if( data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70 ) {
                                    headerEnd += 2;
                                    break;
                                }
                            }

                            // start parsing serialization listing
                            int offset = 0;
                            while( pointer < headerEnd ) {
                                if( data[pointer] == 'Z' ) offset++;
                                else if( data[pointer] == 'I' || data[pointer] == 'F' ) offset += 4;
                                else if( data[pointer] == 'J' ) offset += 8;

                                pointer += 1;
                                Array.Copy( data, pointer, temp, 0, sizeof( short ) );
                                short skip = Server.htons( BitConverter.ToInt16( temp, 0 ) );
                                pointer += 2;

                                // look for relevant variables
                                Array.Copy( data, headerEnd + offset - 4, temp, 0, sizeof( int ) );
                                if( MemCmp( data, pointer, "width" ) ) {
                                    map.widthX = (ushort)Server.htons( BitConverter.ToInt32( temp, 0 ) );
                                } else if( MemCmp( data, pointer, "depth" ) ) {
                                    map.height = (ushort)Server.htons( BitConverter.ToInt32( temp, 0 ) );
                                } else if( MemCmp( data, pointer, "height" ) ) {
                                    map.widthY = (ushort)Server.htons( BitConverter.ToInt32( temp, 0 ) );
                                } else if( MemCmp( data, pointer, "xSpawn" ) ) {
                                    map.spawn.x = (short)(Server.htons( BitConverter.ToInt32( temp, 0 ) )*32+16);
                                } else if( MemCmp( data, pointer, "ySpawn" ) ) {
                                    map.spawn.h = (short)(Server.htons( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16);
                                } else if( MemCmp( data, pointer, "zSpawn" ) ) {
                                    map.spawn.y = (short)(Server.htons( BitConverter.ToInt32( temp, 0 ) ) * 32 + 16);
                                }

                                pointer += skip;
                            }

                            // find the start of the block array
                            bool foundBlockArray = false;
                            offset = Array.IndexOf<byte>( data, 0x00, headerEnd );
                            while( offset != -1 && offset < data.Length - 2 ) {
                                if( data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70 ) {
                                    foundBlockArray = true;
                                    pointer = offset + 7;
                                }
                                offset = Array.IndexOf<byte>( data, 0x00, offset + 1 );
                            }

                            // copy the block array... or fail
                            if( foundBlockArray ) {
                                map.CopyBlocks( data, pointer );
                                if( !map.ValidateBlockTypes() ) {
                                    throw new Exception( "Map validation failed: unknown block types found. Either parsing has done wrong, or this is an incompatible format." );
                                }
                            } else {
                                throw new Exception( "Could not locate block array." );
                            }
                            break;
                        }
                    //}
                }
            } catch( Exception ex ) {
                world.log.Log( "Conversion failed: {0}", LogType.Error, ex.Message );
                world.log.Log( ex.StackTrace, LogType.Debug );
                return null;
            }
            map.Save();
            world.log.Log( "Conversion completed succesfully succesful.", LogType.SystemActivity, fileName );
            return map;
        }
Example #11
0
        public void LoadMap( string mapName ) {
            try {
                map = Map.Load( this, mapName );
            } catch( Exception ex ) {
                log.Log( "Could not open the specified file ({0}): {1}", LogType.Error, mapName, ex.Message );
            }

            // or generate a default one
            if( map == null ) {
                log.Log( "World.Init: Generating default flatgrass level.", LogType.SystemActivity );
                map = new Map( this, 64, 64, 64 );

                map.spawn.Set( map.widthX / 2 * 32 + 16, map.widthY / 2 * 32 + 16, map.height * 32, 0, 0 );

                MapCommands.GenerateFlatgrass( map, false );
                
                if( !map.Save() ) throw new Exception( "Could not save file." );
            }
        }
Example #12
0
        void DoGenerate(Map map, Player player, string mode, string filename, Random rand, bool hollow)
        {
            switch (mode)
            {
            case "flatgrass":
                player.Message("Generating flatgrass map...");
                GenerateFlatgrass(map, hollow);

                if (map.Save(filename))
                {
                    player.Message("Map generation: Done.");
                }
                else
                {
                    player.Message(Color.Red, "An error occured while generating the map.");
                }
                break;

            case "lag":
                player.Message("Generating laggy map...");
                for (int x = 0; x < map.widthX; x += 2)
                {
                    for (int y = 0; y < map.widthY; y += 2)
                    {
                        for (int h = 0; h < map.widthY; h += 2)
                        {
                            map.SetBlock(x, y, h, Block.Lava);
                        }
                    }
                }

                if (map.Save(filename))
                {
                    player.Message("Map generation: Done.");
                }
                else
                {
                    player.Message(Color.Red, "An error occured while generating the map.");
                }
                break;

            case "empty":
                player.Message("Generating empty map...");
                map.MakeFloodBarrier();

                if (map.Save(filename))
                {
                    player.Message("Map generation: Done.");
                }
                else
                {
                    player.Message(Color.Red, "An error occured while generating the map.");
                }

                break;

            case "hills":
                player.Message("Generating terrain...");
                world.tasks.Add(MapGenerator.GenerationTask, new MapGenerator(rand, map, player, filename,
                                                                              1, 1, 0.5, 0.45, 0, 0.5, hollow), false);
                break;

            case "mountains":
                player.Message("Generating terrain...");
                world.tasks.Add(MapGenerator.GenerationTask, new MapGenerator(rand, map, player, filename,
                                                                              4, 1, 0.5, 0.45, 0.1, 0.5, hollow), false);
                break;

            case "lake":
                player.Message("Generating terrain...");
                world.tasks.Add(MapGenerator.GenerationTask, new MapGenerator(rand, map, player, filename,
                                                                              1, 0.6, 0.9, 0.45, -0.35, 0.55, hollow), false);
                break;

            case "island":
                player.Message("Generating terrain...");
                world.tasks.Add(MapGenerator.GenerationTask, new MapGenerator(rand, map, player, filename,
                                                                              1, 0.6, 1, 0.45, 0.3, 0.35, hollow), false);
                break;

            default:
                player.Message("Unknown map generation mode: " + mode);
                break;
            }
        }