Esempio n. 1
0
        void LoadMap( string path )
        {
            IMapFileFormat mapFile = null;
            if( path.EndsWith( ".dat" ) ) {
                mapFile = new MapDat();
            } else if( path.EndsWith( ".fcm" ) ) {
                mapFile = new MapFcm3();
            } else if( path.EndsWith( ".cw" ) ) {
                mapFile = new MapCw();
            }

            try {
                using( FileStream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) ) {
                    int width, height, length;
                    game.Map.Reset();

                    byte[] blocks = mapFile.Load( fs, game, out width, out height, out length );
                    game.Map.SetData( blocks, width, height, length );
                    game.Events.RaiseOnNewMapLoaded();

                    LocalPlayer p = game.LocalPlayer;
                    LocationUpdate update = LocationUpdate.MakePos( p.SpawnPoint, false );
                    p.SetLocation( update, false );
                }
            } catch( Exception ex ) {
                ErrorHandler.LogError( "loading map", ex );
                game.Chat.Add( "&e/client loadmap: Failed to load map \"" + path + "\"" );
            }
        }
        void LoadMap(string path)
        {
            IMapFileFormat mapFile = null;

            if (path.EndsWith(".dat"))
            {
                mapFile = new MapDat();
            }
            else if (path.EndsWith(".fcm"))
            {
                mapFile = new MapFcm3();
            }
            else if (path.EndsWith(".cw"))
            {
                mapFile = new MapCw();
            }

            try {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    int width, height, length;
                    game.Map.Reset();

                    byte[] blocks = mapFile.Load(fs, game, out width, out height, out length);
                    game.Map.SetData(blocks, width, height, length);
                    game.MapEvents.RaiseOnNewMapLoaded();

                    LocalPlayer    p      = game.LocalPlayer;
                    LocationUpdate update = LocationUpdate.MakePos(p.SpawnPoint, false);
                    p.SetLocation(update, false);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("loading map", ex);
                game.Chat.Add("&e/client loadmap: Failed to load map \"" + path + "\"");
            }
        }
Esempio n. 3
0
        void LoadMap(string path)
        {
            IMapFileFormat mapFile = null;

            if (path.EndsWith(".dat"))
            {
                mapFile = new MapDat();
            }
            else if (path.EndsWith(".fcm"))
            {
                mapFile = new MapFcm3();
            }
            else if (path.EndsWith(".cw"))
            {
                mapFile = new MapCw();
            }

            try {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    int width, height, length;
                    game.Map.Reset();
                    game.Map.TextureUrl = null;
                    for (int tile = BlockInfo.CpeBlocksCount; tile < BlockInfo.BlocksCount; tile++)
                    {
                        game.BlockInfo.ResetBlockInfo((byte)tile, false);
                    }
                    game.BlockInfo.SetupCullingCache();
                    game.BlockInfo.InitLightOffsets();

                    byte[] blocks = mapFile.Load(fs, game, out width, out height, out length);
                    game.Map.SetData(blocks, width, height, length);
                    game.MapEvents.RaiseOnNewMapLoaded();
                    if (game.AllowServerTextures && game.Map.TextureUrl != null)
                    {
                        game.Network.RetrieveTexturePack(game.Map.TextureUrl);
                    }

                    LocalPlayer    p      = game.LocalPlayer;
                    LocationUpdate update = LocationUpdate.MakePosAndOri(p.SpawnPoint, p.SpawnYaw, p.SpawnPitch, false);
                    p.SetLocation(update, false);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("loading map", ex);
                game.Chat.Add("&e/client loadmap: Failed to load map \"" + path + "\"");
            }
        }