MapGenerator that creates a flat, featureless, layered map. This is a singleton class -- use FlatMapGen.Instance.
Наследование: MapGenerator
Пример #1
0
        static FlatMapGen() {
            List<string> presetList = new List<string> {
                "Default",
                "Ocean"
            };
            presetList.AddRange( Enum.GetNames( typeof( MapGenTheme ) ) );

            Instance = new FlatMapGen {
                Name = "Flat",
                Presets = presetList.ToArray(),
                Help = "&S\"Flat\" map generator:\n" + 
                       "Creates a flat, featureless, layered map. " +
                       "Takes an optional preset name. Presets are: " +
                       presetList.JoinToString()
            };
        }
Пример #2
0
        public Map LoadMap()
        {
            var tempMap = Map;

            if (tempMap != null)
            {
                return(tempMap);
            }

            lock (SyncRoot) {
                if (Map != null)
                {
                    return(Map);
                }

                if (File.Exists(MapFileName))
                {
                    try {
                        Map = MapUtility.Load(MapFileName, true);
                    } catch (Exception ex) {
                        Logger.Log(LogType.Error,
                                   "World.LoadMap: Failed to load map ({0}): {1}",
                                   MapFileName,
                                   ex);
                    }
                }

                // or generate a default one
                if (Map == null)
                {
                    Server.Message("&WMap file is missing for world {0}&W. A new map has been created.", ClassyName);
                    Logger.Log(LogType.Warning,
                               "World.LoadMap: Map file missing for world {0}. Generating default flatgrass map.",
                               Name);
                    Map = FlatMapGen.MakeFlatgrass(128, 128, 64).Generate();
                }

                if (Map == null)
                {
                    // should never happen, theoretically, unless FlatMapGen messes up
                    throw new NullReferenceException("World.LoadMap failed to produce a map file!");
                }

                return(Map);
            }
        }
Пример #3
0
        static FlatMapGen()
        {
            List <string> presetList = new List <string> {
                "Default",
                "Ocean"
            };

            presetList.AddRange(Enum.GetNames(typeof(MapGenTheme)));

            Instance = new FlatMapGen {
                Name    = "Flat",
                Presets = presetList.ToArray(),
                Help    = "&S\"Flat\" map generator:\n" +
                          "Creates a flat, featureless, layered map. " +
                          "Takes an optional preset name. Presets are: " +
                          presetList.JoinToString()
            };
        }
Пример #4
0
        internal static bool LoadWorldList()
        {
            World newMainWorld = null;

            Worlds = new World[0];
            if (File.Exists(Paths.WorldListFileName))
            {
#if !DEBUG
                try {
#endif
                XDocument doc = XDocument.Load(Paths.WorldListFileName);
                XElement root = doc.Root;
                if (root != null)
                {
                    foreach (XElement el in root.Elements("World"))
                    {
#if DEBUG
                        LoadWorldListEntry(el);
#else
                        try {
                            LoadWorldListEntry(el);
                        } catch (Exception ex) {
                            Logger.LogAndReportCrash("An error occurred while trying to parse one of the entries on the world list",
                                                     "fCraft", ex, false);
                        }
#endif
                    }

                    XAttribute temp;
                    if ((temp = root.Attribute("main")) != null)
                    {
                        World suggestedMainWorld = FindWorldExact(temp.Value);

                        if (suggestedMainWorld != null)
                        {
                            newMainWorld = suggestedMainWorld;
                        }
                        else if (firstWorld != null)
                        {
                            // if specified main world does not exist, use first-defined world
                            Logger.Log(LogType.Warning,
                                       "The specified main world \"{0}\" does not exist. " +
                                       "\"{1}\" was designated main instead. You can use /WMain to change it.",
                                       temp.Value, firstWorld.Name);
                            newMainWorld = firstWorld;
                        }
                        // if firstWorld was also null, LoadWorldList() should try creating a new mainWorld
                    }
                    else if (firstWorld != null)
                    {
                        newMainWorld = firstWorld;
                    }
                }
#if !DEBUG
            }
            catch (Exception ex) {
                Logger.LogAndReportCrash("Error occurred while trying to load the world list.", "fCraft", ex, true);
                return(false);
            }
#endif

                if (newMainWorld == null)
                {
                    Logger.Log(LogType.Error,
                               "Server.Start: Could not load any of the specified worlds, or no worlds were specified. " +
                               "Creating default \"main\" world.");
                    newMainWorld = AddWorld(null, "main", FlatMapGen.MakeFlatgrass(128, 128, 64).Generate(), true);
                }
            }
            else
            {
                Logger.Log(LogType.SystemActivity,
                           "Server.Start: No world list found. Creating default \"main\" world.");
                newMainWorld = AddWorld(null, "main", FlatMapGen.MakeFlatgrass(128, 128, 64).Generate(), true);
            }

            // if there is no default world still, die.
            if (newMainWorld == null)
            {
                throw new Exception("Could not create any worlds.");
            }
            else if (newMainWorld.AccessSecurity.HasRestrictions)
            {
                Logger.Log(LogType.Warning,
                           "Server.LoadWorldList: Main world cannot have any access restrictions. " +
                           "Access permission for \"{0}\" has been reset.",
                           newMainWorld.Name);
                newMainWorld.AccessSecurity.Reset();
            }

            MainWorld = newMainWorld;

            return(true);
        }