예제 #1
0
        private void btnSave_Click(object sender, EventArgs e) {
            var result = saveMap.ShowDialog();

            if (result != DialogResult.OK) 
                return;

            if (_loaded) {
                var timer = new Stopwatch();
                timer.Start();

                _map.Save(saveMap.FileName);

                timer.Stop();

                lblTime.Text = "Time: " + timer.Elapsed.TotalSeconds;
            } else {
                // -- Create a map and save it.
                var timer = new Stopwatch();
                timer.Start();

                _map = new Classicworld(128, 128, 128) {MapName = "New Map!"};
                _map.Save(saveMap.FileName);

                timer.Stop();

                lblTime.Text = "Time: " + timer.Elapsed.TotalSeconds;
            }
        }
예제 #2
0
        private void btnLoad_Click(object sender, EventArgs e) {
            var result = openMap.ShowDialog();

            if (result == DialogResult.OK) {
                var timer = new Stopwatch();
                timer.Start();

                _map = new Classicworld(openMap.FileName);
                _map.Load();

                timer.Stop();
                lblTime.Text = "Time: " + timer.Elapsed.TotalSeconds;
                _loaded = true;
            }
        }
예제 #3
0
파일: D3Map.cs 프로젝트: umby24/Hypercube
        public void LoadMap(string directory, string mapName)
        {
            if (!File.Exists(directory + "/Data-Layer.gz") || !File.Exists(directory + "/Config.txt"))
                return; // -- Not a valid map.

            // -- Load the Config data first..
            var configfile = new Settings("TempD3Config.txt", LoadConfig, directory, false);
            configfile.LoadFile();

            Mapsize = new Vector3S {
                X = (short) configfile.Read("Size_X", 128),
                Y = (short) configfile.Read("Size_Y", 128),
                Z = (short) configfile.Read("Size_Z", 128)
            };

            Spawn = new Vector3S {
                X = (short) float.Parse(configfile.Read("Spawn_X", "1.0")),
                Y = (short) float.Parse(configfile.Read("Spawn_Y", "1.0")),
                Z = (short) float.Parse(configfile.Read("Spawn_Z", "1.0"))
            };

            SpawnRot = (byte)configfile.Read("Spawn_Rot", 0);
            SpawnLook = (byte)configfile.Read("Spawn_Look", 0);

            Motd = configfile.Read("MOTD_Override", "");
            PhysicsStopped = Convert.ToBoolean(configfile.Read("Physic_Stopped", 0));

            // -- Load the block data
            GZip.DecompressFile(directory + "/Data-Layer.gz");
            byte[] allData;

            using (var br = new BinaryReader(new FileStream(directory + "/Data-Layer.gz", FileMode.Open)))
                allData = br.ReadBytes((int)br.BaseStream.Length);

            GZip.CompressFile(directory + "/Data-Layer.gz");

            if (allData.Length != (Mapsize.X * Mapsize.Y * Mapsize.Z) * 4) {
                // -- Size error..
                return;
            }

            Blockdata = new byte[Mapsize.X * Mapsize.Y * Mapsize.Z];
            // -- Converts block data from the D3 array format to the ClassicWorld array format.
            for (var x = 0; x < Mapsize.X; x++) {
                for (var y = 0; y < Mapsize.Y; y++) {
                    for (var z = 0; z < Mapsize.Z; z++)
                        Blockdata[GetIndex(x, y, z)] = allData[GetBlock(x, y, z)];
                }
            }

            // -- Now, Block data will be properly oriented for use in ClassicWorld maps, and we have all the data we need to create a classicworld map.

            var cwMap = new Classicworld(Mapsize.X, Mapsize.Z, Mapsize.Y) {
                BlockData = Blockdata,
                SpawnX = Spawn.X,
                SpawnY = Spawn.Z,
                SpawnZ = Spawn.Y,
                SpawnRotation = SpawnRot,
                SpawnLook = SpawnLook,
                MapName = mapName
            }; // -- Classicworld is in notchian Coordinates.

            cwMap.Save("Maps/" + mapName + ".cw");
            Blockdata = null;
            cwMap.BlockData = null;
            GC.Collect();
            // -- Conversion Complete.
        }
예제 #4
0
        /// <summary>
        /// Loads a new file into this map object.
        /// </summary>
        /// <param name="filename">The file to load into this map.</param>
        public void Load(string filename)
        {
            if (!File.Exists(filename)) {
                if (File.Exists(filename + "u"))
                    File.Move(filename + "u", filename);
                else
                    return;
            }

            Path = filename;
            CWMap = new Classicworld(filename);
            HCSettings = new HypercubeMetadata();
            CWMap.MetadataParsers.Add("Hypercube", HCSettings);
            CWMap.Load();

            _physicsBitmask = new byte[(CWMap.BlockData.Length / 8) + 1];

            HCSettings = (HypercubeMetadata)CWMap.MetadataParsers["Hypercube"];

            if (HCSettings.BuildPerms == null) {
                Buildperms.Add("player.build", ServerCore.Permholder.GetPermission("player.build"));
            } else
                Buildperms = PermissionContainer.SplitPermissions(HCSettings.BuildPerms);

            if (HCSettings.ShowPerms == null) {
                Showperms.Add("map.joinmap", ServerCore.Permholder.GetPermission("map.joinmap"));
            } else
                Showperms = PermissionContainer.SplitPermissions(HCSettings.ShowPerms);

            if (HCSettings.JoinPerms == null) {
                Joinperms.Add("map.joinmap", ServerCore.Permholder.GetPermission("map.joinmap"));

                HCSettings.Building = true;
                HCSettings.Physics = true;
                HCSettings.History = true;
            } else
                Joinperms = PermissionContainer.SplitPermissions(HCSettings.JoinPerms);

            if (HCSettings.SaveInterval == 0)
                HCSettings.SaveInterval = 10;

            CPESettings = (CPEMetadata)CWMap.MetadataParsers["CPE"];

            if (CPESettings.CustomBlocksFallback == null) {
                CPESettings.CustomBlocksLevel = CPE.CustomBlocksSupportLevel;
                CPESettings.CustomBlocksVersion = CPE.CustomBlocksVersion;
                CPESettings.CustomBlocksFallback = new byte[256];

                for (var i = 50; i < 66; i++)
                    CPESettings.CustomBlocksFallback[i] = (byte)ServerCore.Blockholder.GetBlock(i).CPEReplace;

                CWMap.MetadataParsers["CPE"] = CPESettings;
            }

            if (CPESettings.EnvMapAppearanceVersion != CPE.EnvMapAppearanceVersion) {
                CPESettings.TextureUrl = "";
                CPESettings.EdgeBlock = 8;
                CPESettings.SideBlock = 7;
                CPESettings.SideLevel = (short)(CWMap.SizeY / 2);
                CPESettings.EnvMapAppearanceVersion = CPE.EnvMapAppearanceVersion;
            }

            if (HCSettings.History)
                History = new MapHistory(this);
        }
예제 #5
0
        /// <summary>
        /// Reloads the map after being unloaded to conserve memory.
        /// </summary>
        public void Load()
        {
            if (Loaded)
                return;

            CWMap = new Classicworld(Path);
            HCSettings = new HypercubeMetadata();
            CWMap.MetadataParsers.Add("Hypercube", HCSettings);
            CWMap.Load();

            _physicsBitmask = new byte[(CWMap.BlockData.Length / 8) + 1];

            HCSettings = (HypercubeMetadata)CWMap.MetadataParsers["Hypercube"];
            Path = Path.Replace(".cwu", ".cw");
            if (File.Exists(Path))
                File.Delete(Path);

            File.Move(Path + "u", Path);

            if (HCSettings.History && History != null)
                History.ReloadHistory();
            else if (HCSettings.History)
                History = new MapHistory(this);

            Loaded = true;
            ServerCore.Logger.Log("Map", CWMap.MapName + " reloaded.", LogType.Info);
            ServerCore.Luahandler.RunFunction("E_MapReloaded", this);
        }
예제 #6
0
        private byte[] _physicsBitmask; // -- A simple bitmask for determineing what blocks are in the physics queue.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Creates a new map.
        /// </summary>
        /// <param name="filename">Where to save the file</param>
        /// <param name="mapName">What to name the map</param>
        /// <param name="sizeX">Map's X size</param>
        /// <param name="sizeY">Map's Y size</param>
        /// <param name="sizeZ">Map's Z size</param>
        public HypercubeMap(string filename, string mapName, short sizeX, short sizeY, short sizeZ)
        {
            CWMap = new Classicworld(sizeX, sizeZ, sizeY);

            HCSettings = new HypercubeMetadata {Building = true, Physics = true, History = true, SaveInterval = 10}; // -- Hypercube specific settings, woo.

            var joinPerm = ServerCore.Permholder.GetPermission("map.joinmap");

            Joinperms.Add("map.joinmap", joinPerm);
            Showperms.Add("map.joinmap", joinPerm);
            Buildperms.Add("player.build", ServerCore.Permholder.GetPermission("player.build"));

            CWMap.MetadataParsers.Add("Hypercube", HCSettings);
            CWMap.MapName = mapName;
            CWMap.GeneratingSoftware = "Hypercube";
            CWMap.GeneratorName = "Blank";
            CWMap.CreatingService = "Classicube";
            CWMap.CreatingUsername = "******";

            CPESettings = (CPEMetadata) CWMap.MetadataParsers["CPE"];

            if (CPESettings.CustomBlocksFallback == null) {
                CPESettings.CustomBlocksLevel = CPE.CustomBlocksSupportLevel;
                CPESettings.CustomBlocksVersion = CPE.CustomBlocksVersion;
                CPESettings.CustomBlocksFallback = new byte[256];

                for (var i = 50; i < 66; i++)
                    CPESettings.CustomBlocksFallback[i] = (byte)ServerCore.Blockholder.GetBlock(i).CPEReplace;

                CWMap.MetadataParsers["CPE"] = CPESettings;
            }

            CPESettings.TextureUrl = "";
            CPESettings.EdgeBlock = 8;
            CPESettings.SideBlock = 7;
            CPESettings.SideLevel = (short)(CWMap.SizeY / 2);
            CPESettings.EnvMapAppearanceVersion = CPE.EnvMapAppearanceVersion;

            Lastclient = DateTime.UtcNow;
            Clients = new Dictionary<short, NetworkClient>();
            Entities = new Dictionary<int, Entity>();
            CreateClientList();

            Path = filename;
            Save(Path);
            History = new MapHistory(this);

            for (sbyte i = 0; i < 127; i++)
                FreeIds.Push(i);

            _physicsBitmask = new byte[(CWMap.BlockData.Length / 8) + 1];
        }