Example #1
0
        /// <summary>
        /// Creates a new blank map.
        /// </summary>
        public HypercubeMap(Hypercube Core, string Filename, string MapName, short SizeX, short SizeY, short SizeZ)
        {
            ServerCore = Core;
            Map        = new ClassicWorld(SizeX, SizeZ, SizeY);

            HCSettings          = new HypercubeMetadata(); // -- Hypercube specific settings, woo.
            HCSettings.Building = true;                    // -- Enable building and physics by default.
            HCSettings.Physics  = true;
            HCSettings.History  = new int[Map.BlockData.Length];

            foreach (Rank r in Core.Rankholder.Ranks)   // -- Allow all ranks to access this map by default.
            {
                JoinRanks.Add(r);
                BuildRanks.Add(r);
                ShowRanks.Add(r);
            }

            Map.MetadataParsers.Add("Hypercube", HCSettings); // -- Add the parser so it will save with the map :)

            Map.MapName = MapName;
            Path        = Filename;

            Map.GeneratingSoftware = "Hypercube";
            Map.GeneratorName      = "Blank";
            Map.CreatingService    = "Classicube";
            Map.CreatingUsername   = "******";

            var myRef = (CPEMetadata)Map.MetadataParsers["CPE"];

            if (myRef.CustomBlocksFallback == null)
            {
                myRef.CustomBlocksLevel    = 1;
                myRef.CustomBlocksVersion  = 1;
                myRef.CustomBlocksFallback = new byte[256];

                for (int i = 50; i < 66; i++)
                {
                    myRef.CustomBlocksFallback[i] = (byte)Core.Blockholder.GetBlock(i).CPEReplace;
                }

                Map.MetadataParsers["CPE"] = myRef;
            }

            Map.Save(Path);

            LastClient = DateTime.UtcNow;
            Clients    = new List <NetworkClient>();
            Entities   = new List <Entity>();

            ClientThread = new Thread(MapMain);
            ClientThread.Start();

            EntityThread = new Thread(MapEntities);
            EntityThread.Start();
        }
Example #2
0
        /// <summary>
        /// Reloads a map that was unloaded for memory conservation.
        /// </summary>
        public void LoadMap()
        {
            Map        = new ClassicWorld(Path);
            HCSettings = new HypercubeMetadata();             // -- Create our HC Specific settings
            Map.MetadataParsers.Add("Hypercube", HCSettings); // -- Register it with the map loader
            Map.Load();                                       // -- Load the map

            if (HCSettings.History == null)
            {
                HCSettings.History = new int[Map.BlockData.Length];
            }

            Path   = Path.Replace(".cwu", ".cw");
            Loaded = true;
            System.IO.File.Move(Path + "u", Path);
        }
Example #3
0
        /// <summary>
        /// Loads a pre-existing map
        /// </summary>
        /// <param name="Filename">The path to the map.</param>
        public HypercubeMap(Hypercube Core, string Filename)
        {
            ServerCore = Core;
            Path       = Filename;

            Map        = new ClassicWorld(Filename);
            HCSettings = new HypercubeMetadata();             // -- Create our HC Specific settings
            Map.MetadataParsers.Add("Hypercube", HCSettings); // -- Register it with the map loader
            Map.Load();                                       // -- Load the map

            // -- Creates HC Metadata if it does not exist.
            if (HCSettings.BuildRanks == null)
            {
                foreach (Rank r in Core.Rankholder.Ranks)  // -- Allow all ranks to access this map by default.
                {
                    BuildRanks.Add(r);
                }
            }

            if (HCSettings.ShowRanks == null)
            {
                foreach (Rank r in Core.Rankholder.Ranks)  // -- Allow all ranks to access this map by default.
                {
                    ShowRanks.Add(r);
                }
            }

            if (HCSettings.JoinRanks == null)
            {
                foreach (Rank r in Core.Rankholder.Ranks)  // -- Allow all ranks to access this map by default.
                {
                    JoinRanks.Add(r);
                }

                HCSettings.Building = true;
                HCSettings.Physics  = true;
            }

            HCSettings.Building = true;
            HCSettings.Physics  = true;

            if (HCSettings.History == null)
            {
                HCSettings.History = new int[Map.BlockData.Length];
            }

            LastClient = DateTime.UtcNow;
            Clients    = new List <NetworkClient>();
            Entities   = new List <Entity>();

            // -- Set CPE Information...
            var myRef = (CPEMetadata)Map.MetadataParsers["CPE"];

            if (myRef.CustomBlocksFallback == null)
            {
                myRef.CustomBlocksLevel    = 1;
                myRef.CustomBlocksVersion  = 1;
                myRef.CustomBlocksFallback = new byte[256];

                for (int i = 50; i < 66; i++)
                {
                    myRef.CustomBlocksFallback[i] = (byte)Core.Blockholder.GetBlock(i).CPEReplace;
                }

                Map.MetadataParsers["CPE"] = myRef;
            }

            // -- Memory Conservation:
            if (Path.Substring(Path.Length - 1, 1) == "u")   // -- Unloads anything with a ".cwu" file extension. (ClassicWorld unloaded)
            {
                Map.BlockData      = null;
                HCSettings.History = null;
                GC.Collect();
                Loaded = false;
                var testing = (HypercubeMetadata)Map.MetadataParsers["Hypercube"];
                testing.History = null;
            }
        }