예제 #1
0
 public Embarkment(GameStates.Overworld Overworld)
 {
     foreach (var dwarf in Overworld.Difficulty.Dwarves)
     {
         Employees.Add(Applicant.Random(dwarf, Overworld.Company));
     }
 }
예제 #2
0
        public void CalculateRain(int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                float currentMoisture = Settings.RainfallScale * 10;
                for (int x = 0; x < width; x++)
                {
                    float h       = Overworld.Map[x, y].Height;
                    bool  isWater = h < Settings.SeaLevel;

                    if (isWater)
                    {
                        currentMoisture += MathFunctions.Rand(0.1f, 0.3f);
                        currentMoisture  = Math.Min(currentMoisture, Settings.RainfallScale * 20);
                        Overworld.Map[x, y].Rainfall = 0.5f;
                    }
                    else
                    {
                        float rainAmount = currentMoisture * 0.017f * h + currentMoisture * 0.0006f;
                        currentMoisture -= rainAmount;
                        float evapAmount = MathFunctions.Rand(0.01f, 0.02f);
                        currentMoisture += evapAmount;
                        Overworld.Map[x, y].Rainfall = rainAmount * Settings.RainfallScale * Settings.Width * 0.015f;
                    }
                }
            }

            Overworld.Distort(width, height, 5.0f, 0.03f, Overworld.ScalarFieldType.Rainfall);
        }
예제 #3
0
        public static InstanceSettings.ValidationResult ValidateEmbarkment(GameStates.Overworld Settings, out String Message)
        {
            if (Settings.InstanceSettings.TotalCreationCost() > Settings.PlayerCorporationFunds)
            {
                Message = "You do not have enough funds. Save Anyway?";
                return(InstanceSettings.ValidationResult.Query);
            }

            var supervisionCap = Settings.InstanceSettings.InitalEmbarkment.Employees.Where(e => e.Class.Managerial).Select(e => e.Level.BaseStats.Intelligence).Sum() + 4;
            var employeeCount  = Settings.InstanceSettings.InitalEmbarkment.Employees.Where(e => !e.Class.Managerial).Count();

            if (employeeCount > supervisionCap)
            {
                Message = "You do not have enough supervision.";
                return(InstanceSettings.ValidationResult.Reject);
            }

            if (employeeCount == 0)
            {
                Message = "Are you sure you don't want any employees?";
                return(InstanceSettings.ValidationResult.Query);
            }

            Message = "Looks good, let's go!";
            return(InstanceSettings.ValidationResult.Pass);
        }
예제 #4
0
        public void MakeMenu()
        {
            var frame = CreateMenu("Are you sure?\nThis will create a very large world that\nonly the most powerful machines can handle.\nReally. It's big. Like super big.");

            CreateMenuItem(frame, "I'M SURE", "If my computer catches on fire it's my own fault!",
                           (sender, args) =>
            {
                DwarfGame.LogSentryBreadcrumb("Menu", "User generating a random world.");

                var overworldSettings = Overworld.Create();
                overworldSettings.InstanceSettings.Cell = new ColonyCell {
                    Bounds = new Rectangle(0, 0, 64, 64), Faction = overworldSettings.ColonyCells.GetCellAt(0, 0).Faction
                };
                overworldSettings.InstanceSettings.InitalEmbarkment       = new Embarkment(overworldSettings);
                overworldSettings.InstanceSettings.InitalEmbarkment.Funds = 1000u;
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Crafter", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Manager", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Miner", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Wizard", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Soldier", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Musketeer", overworldSettings.Company));

                GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.GenerateOverworld));
            }).AutoLayout = AutoLayout.DockBottom;

            CreateMenuItem(frame, "NEVERMIND!", "This was probably a bad idea.",
                           (sender, args) => GameStateManager.PopState()).AutoLayout = AutoLayout.DockBottom;

            FinishMenu();
        }
예제 #5
0
        private void Erode(int width, int height, float seaLevel, Overworld.MapData[,] heightMap, int numRains, int rainLength, int numRainSamples, float[,] buffer)
        {
            float remaining = 1.0f - Progress.Value - 0.2f;
            float orig      = Progress.Value;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    buffer[x, y] = heightMap[x, y].Height;
                }
            }

            for (int i = 0; i < numRains; i++)
            {
                LoadingMessage = "Erosion " + i + "/" + numRains;
                Progress.Value = orig + remaining * ((float)i / (float)numRains);
                Vector2 currentPos = new Vector2(0, 0);
                Vector2 bestPos    = currentPos;
                float   bestHeight = 0.0f;
                for (int k = 0; k < numRainSamples; k++)
                {
                    int randX = PlayState.Random.Next(1, width - 1);
                    int randY = PlayState.Random.Next(1, height - 1);

                    currentPos = new Vector2(randX, randY);
                    float h = Overworld.GetHeight(buffer, currentPos);

                    if (h > bestHeight)
                    {
                        bestHeight = h;
                        bestPos    = currentPos;
                    }
                }

                currentPos = bestPos;

                const float erosionRate = 0.99f;
                Vector2     velocity    = Vector2.Zero;
                for (int j = 0; j < rainLength; j++)
                {
                    Vector2 g = Overworld.GetMinNeighbor(buffer, currentPos);

                    float h = Overworld.GetHeight(buffer, currentPos);

                    if (h < seaLevel || g.LengthSquared() < 1e-12)
                    {
                        break;
                    }

                    Overworld.MinBlend(Overworld.Map, currentPos, erosionRate * Overworld.GetValue(Overworld.Map, currentPos, Overworld.ScalarFieldType.Erosion), Overworld.ScalarFieldType.Erosion);

                    velocity    = 0.1f * g + 0.7f * velocity + 0.2f * MathFunctions.RandVector2Circle();
                    currentPos += velocity;
                }
            }
        }
예제 #6
0
        public bool CreateIfNeeded(Overworld Overworld)
        {
            if (LandMesh == null || LandMesh.IsDisposed || LandMesh.GraphicsDevice.IsDisposed)
            {
                CreateMesh(Device, Overworld);
                return(true);
            }

            return(false);
        }
예제 #7
0
        public static ValidationResult ValidateEmbarkment(GameStates.Overworld Settings, out String Message)
        {
            if (Settings.InstanceSettings.TotalCreationCost() > Settings.PlayerCorporationFunds)
            {
                Message = "You do not have enough funds.";
                return(ValidationResult.Reject);
            }

            return(Embarkment.ValidateEmbarkment(Settings, out Message));
        }
예제 #8
0
        public LoadState(DwarfGame game, Overworld settings, LoadTypes LoadType) :
            base(game)
        {
            this.LoadType     = LoadType;
            Settings          = settings;
            EnableScreensaver = true;
            InitialEmbarkment = settings.InstanceSettings.InitalEmbarkment;
            InitialCell       = settings.InstanceSettings.Cell;

            Runner = new DwarfRunner(game);
        }
예제 #9
0
        public void SetGenerator(OverworldGenerator Generator, Overworld Overworld)
        {
            this.Generator = Generator;
            this.Overworld = Overworld;

            if (Mesh != null)
            {
                Mesh.Dispose();
            }
            Mesh = new OverworldPreviewMesh();
        }
예제 #10
0
        public OverworldGenerator(Overworld Overworld, bool ClearOverworld)
        {
            CurrentState   = GenerationState.NotStarted;
            this.Overworld = Overworld;

            Random = new Random(Overworld.Seed);

            if (ClearOverworld)
            {
                Overworld.Map = new OverworldMap(Overworld.Width, Overworld.Height);
            }
        }
예제 #11
0
        public LaunchPanel(DwarfGame Game, OverworldGenerator Generator, Overworld Settings, WorldGeneratorState Preview)
        {
            this.Generator = Generator;
            this.Settings  = Settings;
            this.Game      = Game;
            this.Preview   = Preview;

            if (Generator != null && Generator.CurrentState != OverworldGenerator.GenerationState.Finished)
            {
                throw new InvalidProgramException();
            }
        }
예제 #12
0
        public static Overworld Create()
        {
            var r = new Overworld();

            r.Name    = GetRandomWorldName();
            r.Seed    = r.Name.GetHashCode();
            r.Company = new CompanyInformation();
            r.Map     = new OverworldMap(r.Width, r.Height);
            r.PlayerCorporationResources = new ResourceSet();

            r.ColonyCells      = new CellSet("World\\colonies");
            r.InstanceSettings = new InstanceSettings(r.ColonyCells.GetCellAt(16, 0), r);

            return(r);
        }
예제 #13
0
        public void DisplayModeModified(string type)
        {
            if (!GenerationComplete)
            {
                return;
            }

            switch (type)
            {
            case "Height":
                ColorKeys.ColorEntries = Overworld.HeightColors;
                Overworld.TextureFromHeightMap(type, Overworld.Map, Overworld.ScalarFieldType.Height, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Biomes":
                ColorKeys.ColorEntries = BiomeLibrary.CreateBiomeColors();
                Overworld.TextureFromHeightMap(type, Overworld.Map, Overworld.ScalarFieldType.Height, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Temp.":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Temperature, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Rain":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Rainfall, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Erosion":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Erosion, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Faults":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Faults, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Factions":
                ColorKeys.ColorEntries   = GenerateFactionColors();
                Overworld.NativeFactions = NativeCivilizations;
                Overworld.TextureFromHeightMap(type, Overworld.Map, Overworld.ScalarFieldType.Factions, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;
            }
        }
예제 #14
0
        public static void Generate(Overworld Overworld, bool ShowPolitics, Texture2D TerrainTexture, Texture2D FullTexture)
        {
            var colorData = new Color[Overworld.Width * Overworld.Height * 4 * 4];
            var stride    = Overworld.Width * 4;

            Overworld.Map.CreateTexture(Overworld.Natives, 4, colorData, Overworld.GenerationSettings.SeaLevel);
            OverworldMap.Smooth(4, Overworld.Width, Overworld.Height, colorData);
            Overworld.Map.ShadeHeight(4, colorData);

            TerrainTexture.SetData(colorData);

            // Draw political boundaries
            if (ShowPolitics)
            {
                for (var x = 0; x < Overworld.Width; ++x)
                {
                    for (var y = 0; y < Overworld.Height; ++y)
                    {
                        var thisCell = Overworld.ColonyCells.GetCellAt(x, y);
                        var rect     = new Rectangle(x * 4, y * 4, 4, 4);

                        if (EnumerateNeighbors(new Point(x, y)).Select(p => Overworld.ColonyCells.GetCellAt(p.X, p.Y)).Any(c => c == null || !Object.ReferenceEquals(c.Faction, thisCell.Faction)))
                        {
                            FillSolidRectangle(rect, colorData, thisCell.Faction.PrimaryColor, stride);
                        }
                        else
                        {
                            FillPoliticalRectangle(rect, colorData, thisCell.Faction.PrimaryColor, stride);
                        }
                    }
                }
            }

            foreach (var cell in Overworld.ColonyCells.EnumerateCells())
            {
                DrawRectangle(new Rectangle(cell.Bounds.X * 4, cell.Bounds.Y * 4, cell.Bounds.Width * 4, cell.Bounds.Height * 4), colorData, Color.Black, stride);
            }

            var spawnRect = new Rectangle((int)Overworld.InstanceSettings.Origin.X * 4, (int)Overworld.InstanceSettings.Origin.Y * 4,
                                          Overworld.InstanceSettings.Cell.Bounds.Width * 4, Overworld.InstanceSettings.Cell.Bounds.Height * 4);

            DrawRectangle(spawnRect, colorData, Color.Red, stride);

            FullTexture.SetData(colorData);
        }
예제 #15
0
        public void CreatBalloonMesh(Overworld Overworld)
        {
            BalloonPrimitive = new RawPrimitive();
            if (IconTexture == null)
            {
                IconTexture = AssetManager.GetContentTexture("GUI\\map_icons");
            }
            var iconSheet = new SpriteSheet(IconTexture, 16, 16);
            var bounds    = Vector4.Zero;
            var uvs       = iconSheet.GenerateTileUVs(new Point(2, 0), out bounds);
            var angle     = MathFunctions.Rand() * (float)System.Math.PI;

            BalloonPrimitive.AddQuad(
                Matrix.CreateRotationX(-(float)System.Math.PI / 2)
                * Matrix.CreateScale(6.0f / Overworld.Width),
                Color.White, Color.White, uvs, bounds);

            BalloonPrimitive.AddQuad(
                Matrix.CreateRotationX(-(float)System.Math.PI / 2)
                * Matrix.CreateRotationY((float)System.Math.PI / 2)
                * Matrix.CreateScale(6.0f / Overworld.Width),
                Color.White, Color.White, uvs, bounds);
        }
예제 #16
0
        public void GenerateWorld(int seed, int width, int height)
        {
#if CREATE_CRASH_LOGS
            try
#endif
            {
                GUI.MouseMode = GUISkin.MousePointer.Wait;

                PlayState.Random   = new ThreadSafeRandom(Seed);
                GenerationComplete = false;

                LoadingMessage             = "Init..";
                Overworld.heightNoise.Seed = Seed;
                worldMap      = new Texture2D(Game.GraphicsDevice, width, height);
                worldData     = new Color[width * height];
                Overworld.Map = new Overworld.MapData[width, height];

                Progress.Value = 0.01f;

                LoadingMessage = "Height Map ...";
                Overworld.GenerateHeightMap(width, height, 1.0f, false);

                Progress.Value = 0.05f;

                int numRains       = (int)Settings.NumRains;
                int rainLength     = 250;
                int numRainSamples = 3;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Erosion    = 1.0f;
                        Overworld.Map[x, y].Weathering = 0;
                        Overworld.Map[x, y].Faults     = 1.0f;
                    }
                }

                LoadingMessage = "Climate";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = ((float)(y) / (float)(height)) * Settings.TemperatureScale;
                        //Overworld.Map[x, y].Rainfall = Math.Max(Math.Min(Overworld.noise(x, y, 1000.0f, 0.01f) + Overworld.noise(x, y, 100.0f, 0.1f) * 0.05f, 1.0f), 0.0f) * RainfallScale;
                    }
                }

                //Overworld.Distort(width, height, 60.0f, 0.005f, Overworld.ScalarFieldType.Rainfall);
                Overworld.Distort(width, height, 30.0f, 0.005f, Overworld.ScalarFieldType.Temperature);
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = Math.Max(Math.Min(Overworld.Map[x, y].Temperature, 1.0f), 0.0f);
                    }
                }

                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);

                int numVoronoiPoints = (int)Settings.NumFaults;


                Progress.Value = 0.1f;
                LoadingMessage = "Faults ...";

                #region voronoi

                Voronoi(width, height, numVoronoiPoints);

                #endregion

                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                Progress.Value = 0.2f;

                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                Progress.Value = 0.25f;
                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                LoadingMessage = "Erosion...";

                #region erosion

                float[,] buffer = new float[width, height];
                Erode(width, height, Settings.SeaLevel, Overworld.Map, numRains, rainLength, numRainSamples, buffer);
                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                #endregion

                Progress.Value = 0.9f;


                LoadingMessage = "Blur.";
                Overworld.Blur(Overworld.Map, width, height, Overworld.ScalarFieldType.Erosion);

                LoadingMessage = "Generate height.";
                Overworld.GenerateHeightMap(width, height, 1.0f, true);


                LoadingMessage = "Rain";
                CalculateRain(width, height);

                LoadingMessage = "Biome";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Biome = Overworld.GetBiome(Overworld.Map[x, y].Temperature, Overworld.Map[x, y].Rainfall, Overworld.Map[x, y].Height);
                    }
                }

                LoadingMessage = "Volcanoes";

                GenerateVolcanoes(width, height);

                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);

                LoadingMessage      = "Factions";
                NativeCivilizations = new List <Faction>();
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, "fake", "fake", null, Color.Blue);
                for (int i = 0; i < Settings.NumCivilizations; i++)
                {
                    NativeCivilizations.Add(library.GenerateFaction(i, Settings.NumCivilizations));
                }
                SeedCivs(Overworld.Map, Settings.NumCivilizations, NativeCivilizations);
                GrowCivs(Overworld.Map, 200, NativeCivilizations);


                for (int x = 0; x < width; x++)
                {
                    Overworld.Map[x, 0]          = Overworld.Map[x, 1];
                    Overworld.Map[x, height - 1] = Overworld.Map[x, height - 2];
                }

                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[0, y]         = Overworld.Map[1, y];
                    Overworld.Map[width - 1, y] = Overworld.Map[width - 2, y];
                }

                GenerationComplete = true;

                MapPanel.Image       = new ImageFrame(worldMap, new Rectangle(0, 0, worldMap.Width, worldMap.Height));
                MapPanel.LocalBounds = new Rectangle(300, 30, worldMap.Width, worldMap.Height);


                Progress.Value = 1.0f;
                IsGenerating   = false;
                GUI.MouseMode  = GUISkin.MousePointer.Pointer;
                DoneGenerating = true;
            }
#if CREATE_CRASH_LOGS
            catch (Exception exception)
            {
                ProgramData.WriteExceptionLog(exception);
                throw;
            }
#endif
        }
예제 #17
0
        private void Voronoi(int width, int height, int numVoronoiPoints)
        {
            List <List <Vector2> > vPoints = new List <List <Vector2> >();
            List <float>           rands   = new List <float>();

            /*
             * List<Vector2> edge = new List<Vector2>
             * {
             *  new Vector2(0, 0),
             *  new Vector2(width, 0),
             *  new Vector2(width, height),
             *  new Vector2(0, height),
             *  new Vector2(0, 0)
             * };
             *
             * List<Vector2> randEdge = new List<Vector2>();
             * for (int i = 1; i < edge.Count; i++)
             * {
             *  if (MathFunctions.RandEvent(0.5f))
             *  {
             *      randEdge.Add(edge[i]);
             *      randEdge.Add(edge[i - 1]);
             *  }
             * }
             *
             * vPoints.Add(randEdge);
             */
            for (int i = 0; i < numVoronoiPoints; i++)
            {
                Vector2 v = GetEdgePoint(width, height);

                for (int j = 0; j < 4; j++)
                {
                    List <Vector2> line = new List <Vector2>();
                    rands.Add(1.0f);

                    line.Add(v);
                    v += new Vector2(MathFunctions.Rand() - 0.5f, MathFunctions.Rand() - 0.5f) * Settings.Width * 0.5f;
                    line.Add(v);
                    vPoints.Add(line);
                }
            }


            List <VoronoiNode> nodes = new List <VoronoiNode>();

            foreach (List <Vector2> pts in vPoints)
            {
                for (int j = 0; j < pts.Count - 1; j++)
                {
                    VoronoiNode node = new VoronoiNode
                    {
                        pointA = pts[j],
                        pointB = pts[j + 1]
                    };
                    nodes.Add(node);
                }
            }

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[x, y].Faults = GetVoronoiValue(nodes, x, y);
                }
            }

            ScaleMap(Overworld.Map, width, height, Overworld.ScalarFieldType.Faults);
            Overworld.Distort(width, height, 20, 0.01f, Overworld.ScalarFieldType.Faults);
        }
예제 #18
0
        public void PreparePreview(GraphicsDevice device)
        {
            if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
            {
                KeyMesh = null;
                return;
            }

            if (PreviewRenderTarget == null)
            {
                PreviewRenderTarget = new RenderTarget2D(Device, PreviewPanel.Rect.Width, PreviewPanel.Rect.Height);
            }

            if (PreviewTexture == null || UpdatePreview)
            {
                UpdatePreview = false;
                InitializePreviewRenderTypes();

                if (PreviewTexture == null || PreviewTexture.Width != Overworld.Map.GetLength(0) ||
                    PreviewTexture.Height != Overworld.Map.GetLength(1))
                {
                    PreviewTexture = new Texture2D(Device, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1));
                }

                // Check combo box for style of preview to draw.
                Overworld.NativeFactions = Generator.NativeCivilizations;

                var style = PreviewRenderTypes[PreviewSelector.SelectedItem];
                Overworld.TextureFromHeightMap(style.DisplayType, Overworld.Map,
                                               style.Scalar, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), null,
                                               Generator.worldData, PreviewTexture, Generator.Settings.SeaLevel);

                var colorKeyEntries = style.GetColorKeys(Generator);
                var font            = Root.GetTileSheet("font8");
                var stringMeshes    = new List <Gui.Mesh>();
                var y        = Rect.Y;
                var maxWidth = 0;

                foreach (var color in colorKeyEntries)
                {
                    Rectangle bounds;
                    var       mesh = Gui.Mesh.CreateStringMesh(color.Key, font, new Vector2(1, 1), out bounds);
                    stringMeshes.Add(mesh.Translate(PreviewPanel.Rect.Right - bounds.Width - (font.TileHeight + 4), y).Colorize(new Vector4(0, 0, 0, 1)));
                    if (bounds.Width > maxWidth)
                    {
                        maxWidth = bounds.Width;
                    }
                    stringMeshes.Add(Gui.Mesh.Quad().Scale(font.TileHeight, font.TileHeight)
                                     .Translate(PreviewPanel.Rect.Right - font.TileHeight + 2, y)
                                     .Texture(Root.GetTileSheet("basic").TileMatrix(1))
                                     .Colorize(color.Value.ToVector4()));
                    y += bounds.Height;
                }


                KeyMesh = Gui.Mesh.Merge(stringMeshes.ToArray());
                var thinBorder = Root.GetTileSheet("border-thin");
                var bgMesh     = Gui.Mesh.CreateScale9Background(
                    new Rectangle(Rect.Right - thinBorder.TileWidth - maxWidth - 8 - font.TileHeight,
                                  Rect.Y, maxWidth + thinBorder.TileWidth + 8 + font.TileHeight, y - Rect.Y + thinBorder.TileHeight),
                    thinBorder, Scale9Corners.Bottom | Scale9Corners.Left);
                KeyMesh = Gui.Mesh.Merge(bgMesh, KeyMesh);
            }

            Device.BlendState        = BlendState.Opaque;
            Device.DepthStencilState = DepthStencilState.Default;
            Device.SetRenderTarget(PreviewRenderTarget);
            PreviewEffect.World = Matrix.Identity;

            PreviewEffect.View            = ViewMatrix;
            PreviewEffect.Projection      = ProjectionMatrix;
            cameraTarget                  = newTarget * 0.1f + cameraTarget * 0.9f;
            PreviewEffect.TextureEnabled  = true;
            PreviewEffect.Texture         = PreviewTexture;
            PreviewEffect.LightingEnabled = true;

            if (Generator.LandMesh == null)
            {
                Generator.CreateMesh(Device);
                UpdatePreview = true;
            }

            if (UpdatePreview || Trees == null)
            {
                Trees = new List <Point3>();
                int       width      = Overworld.Map.GetLength(0);
                int       height     = Overworld.Map.GetLength(1);
                const int resolution = 1;

                for (int x = 0; x < width; x += resolution)
                {
                    for (int y = 0; y < height; y += resolution)
                    {
                        if (!MathFunctions.RandEvent(TreeProbability))
                        {
                            continue;
                        }
                        var h = Overworld.Map[x, y].Height;
                        if (!(h > Generator.Settings.SeaLevel))
                        {
                            continue;
                        }
                        var biome = BiomeLibrary.Biomes[Overworld.Map[x, y].Biome];
                        Trees.Add(new Point3(x, y, biome.Icon));
                    }
                }
            }

            Device.Clear(ClearOptions.Target, Color.Black, 1024.0f, 0);
            Device.DepthStencilState = DepthStencilState.Default;

            if (previewSampler == null)
            {
                previewSampler = new SamplerState
                {
                    Filter = TextureFilter.MinLinearMagPointMipPoint
                };
            }

            Device.SamplerStates[0] = previewSampler;
            foreach (EffectPass pass in PreviewEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Device.SetVertexBuffer(Generator.LandMesh);
                Device.Indices = Generator.LandIndex;
                Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, Generator.LandMesh.VertexCount, 0,
                                             Generator.LandIndex.IndexCount / 3);
            }
            Device.SetRenderTarget(null);
            Device.Textures[0] = null;
            Device.Indices     = null;
            Device.SetVertexBuffer(null);
        }
예제 #19
0
 public InstanceSettings(ColonyCell Cell, GameStates.Overworld Overworld)
 {
     this.Cell        = Cell;
     InitalEmbarkment = new Embarkment(Overworld);
 }
예제 #20
0
 public WorldGeneratorState(DwarfGame Game, Overworld Settings, PanelStates StartingState) :
     base(Game)
 {
     this.PanelState = StartingState;
     this.Settings   = Settings;
 }
예제 #21
0
        public void MakeMenu()
        {
            var frame = CreateMenu(Library.GetString("main-menu-title"));

            CreateMenuItem(frame,
                           Library.GetString("new-game"),
                           Library.GetString("new-game-tooltip"),
                           (sender, args) => GameStateManager.PushState(new WorldGeneratorState(Game, Overworld.Create(), WorldGeneratorState.PanelStates.Generate)));

            CreateMenuItem(frame,
                           Library.GetString("load-game"),
                           Library.GetString("load-game-tooltip"),
                           (sender, args) => GameStateManager.PushState(new WorldLoaderState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("options"),
                           Library.GetString("options-tooltip"),
                           (sender, args) => GameStateManager.PushState(new OptionsState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("manage-mods"),
                           Library.GetString("manage-mods-tooltip"),
                           (sender, args) => GameStateManager.PushState(new ModManagement.ManageModsState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("credits"),
                           Library.GetString("credits-tooltip"),
                           (sender, args) => GameStateManager.PushState(new CreditsState(GameState.Game)));

#if DEBUG
            CreateMenuItem(frame, "QUICKPLAY", "",
                           (sender, args) =>
            {
                DwarfGame.LogSentryBreadcrumb("Menu", "User generating a random world.");

                var overworldSettings = Overworld.Create();
                overworldSettings.InstanceSettings.InitalEmbarkment.Funds = 1000u;
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Crafter", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Manager", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Miner", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Wizard", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Soldier", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Musketeer", overworldSettings.Company));

                GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.GenerateOverworld));
            });

            CreateMenuItem(frame, "GIANT QUICKPLAY", "",
                           (sender, args) =>
            {
                DwarfGame.LogSentryBreadcrumb("Menu", "User generating a random world.");

                var overworldSettings = Overworld.Create();
                overworldSettings.InstanceSettings.Cell = new ColonyCell {
                    Bounds = new Rectangle(0, 0, 64, 64), Faction = overworldSettings.ColonyCells.GetCellAt(0, 0).Faction
                };
                overworldSettings.InstanceSettings.InitalEmbarkment.Funds = 1000u;
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Crafter", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Manager", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Miner", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Wizard", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Soldier", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Musketeer", overworldSettings.Company));

                GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.GenerateOverworld));
            });

            CreateMenuItem(frame, "Dwarf Designer", "Open the dwarf designer.",
                           (sender, args) =>
            {
                GameStateManager.PushState(new Debug.DwarfDesignerState(GameState.Game));
            });

            CreateMenuItem(frame, "Yarn test", "", (sender, args) =>
            {
                GameStateManager.PushState(new YarnState(null, "test.conv", "Start", new Yarn.MemoryVariableStore()));
            });
#endif

            CreateMenuItem(frame,
                           Library.GetString("quit"),
                           Library.GetString("quit-tooltip"),
                           (sender, args) => Game.Exit());

            FinishMenu();
        }
예제 #22
0
        public void GenerateWorld(int seed, int width, int height)
        {
#if CREATE_CRASH_LOGS
            try
#endif
            {
                Seed = seed;
                MathFunctions.Random       = new ThreadSafeRandom(Seed);
                Overworld.heightNoise.Seed = seed;
                CurrentState = GenerationState.Generating;

                if (Overworld.Name == null)
                {
                    Overworld.Name = WorldGenerationSettings.GetRandomWorldName();
                }

                LoadingMessage             = "Init..";
                Overworld.heightNoise.Seed = Seed;
                worldData     = new Color[width * height];
                Overworld.Map = new Overworld.MapData[width, height];

                Progress = 0.01f;

                LoadingMessage           = "Height Map ...";
                float[,] heightMapLookup = null;
                heightMapLookup          = Overworld.GenerateHeightMapLookup(width, height);
                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, false);

                Progress = 0.05f;

                int numRains       = (int)Settings.NumRains;
                int rainLength     = 250;
                int numRainSamples = 3;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Erosion    = 1.0f;
                        Overworld.Map[x, y].Weathering = 0;
                        Overworld.Map[x, y].Faults     = 1.0f;
                    }
                }

                LoadingMessage = "Climate";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = ((float)(y) / (float)(height)) * Settings.TemperatureScale;
                        //Overworld.Map[x, y].Rainfall = Math.Max(Math.Min(Overworld.noise(x, y, 1000.0f, 0.01f) + Overworld.noise(x, y, 100.0f, 0.1f) * 0.05f, 1.0f), 0.0f) * RainfallScale;
                    }
                }

                //Overworld.Distort(width, height, 60.0f, 0.005f, Overworld.ScalarFieldType.Rainfall);
                Overworld.Distort(width, height, 30.0f, 0.005f, Overworld.ScalarFieldType.Temperature);
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = Math.Max(Math.Min(Overworld.Map[x, y].Temperature, 1.0f), 0.0f);
                    }
                }

                int numVoronoiPoints = (int)Settings.NumFaults;

                if (UpdatePreview != null)
                {
                    UpdatePreview();
                }

                Progress       = 0.1f;
                LoadingMessage = "Faults ...";

                #region voronoi

                Voronoi(width, height, numVoronoiPoints);

                #endregion

                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);

                Progress = 0.2f;

                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);

                Progress = 0.25f;
                if (UpdatePreview != null)
                {
                    UpdatePreview();
                }
                LoadingMessage = "Erosion...";

                #region erosion

                float[,] buffer = new float[width, height];
                Erode(width, height, Settings.SeaLevel, Overworld.Map, numRains, rainLength, numRainSamples, buffer);
                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);

                #endregion

                Progress = 0.9f;


                LoadingMessage = "Blur.";
                Overworld.Blur(Overworld.Map, width, height, Overworld.ScalarFieldType.Erosion);

                LoadingMessage = "Generate height.";
                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);


                LoadingMessage = "Rain";
                CalculateRain(width, height);

                LoadingMessage = "Biome";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Biome = Overworld.GetBiome(Overworld.Map[x, y].Temperature, Overworld.Map[x, y].Rainfall, Overworld.Map[x, y].Height).Biome;
                    }
                }

                LoadingMessage = "Volcanoes";

                GenerateVolcanoes(width, height);

                if (UpdatePreview != null)
                {
                    UpdatePreview();
                }


                LoadingMessage = "Factions";
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, new CompanyInformation());

                if (Settings.Natives == null || Settings.Natives.Count == 0)
                {
                    NativeCivilizations = new List <Faction>();
                    for (int i = 0; i < Settings.NumCivilizations; i++)
                    {
                        NativeCivilizations.Add(library.GenerateFaction(null, i, Settings.NumCivilizations));
                    }
                    Settings.Natives = NativeCivilizations;
                }
                else
                {
                    NativeCivilizations = Settings.Natives;

                    if (Settings.NumCivilizations > Settings.Natives.Count)
                    {
                        int count = Settings.Natives.Count;
                        for (int i = count; i < Settings.NumCivilizations; i++)
                        {
                            NativeCivilizations.Add(library.GenerateFaction(null, i, Settings.NumCivilizations));
                        }
                    }
                }
                SeedCivs(Overworld.Map, Settings.NumCivilizations, NativeCivilizations);
                GrowCivs(Overworld.Map, 200, NativeCivilizations);


                for (int x = 0; x < width; x++)
                {
                    Overworld.Map[x, 0]          = Overworld.Map[x, 1];
                    Overworld.Map[x, height - 1] = Overworld.Map[x, height - 2];
                }

                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[0, y]         = Overworld.Map[1, y];
                    Overworld.Map[width - 1, y] = Overworld.Map[width - 2, y];
                }

                LoadingMessage = "Selecting Spawn Point";
                AutoSelectSpawnRegion();

                CurrentState   = GenerationState.Finished;
                LoadingMessage = "";
                Progress       = 1.0f;
            }
#if CREATE_CRASH_LOGS
            catch (Exception exception)
            {
                ProgramData.WriteExceptionLog(exception);
                throw;
            }
#endif
        }
예제 #23
0
        public void OnItemClicked(ListItem item)
        {
            switch (item.Label)
            {
            case "Continue Game":
                StateManager.PopState();
                break;

            case "New Game":
                PlayItems();
                StateManager.PushState("CompanyMakerState");
                MaintainState = true;
                break;

            case "Quit":
                Game.Exit();
                break;

            case "Generate World":
                MaintainState = true;
                StateManager.PushState("WorldSetupState");
                break;

            case "Options":
                MaintainState = true;
                StateManager.PushState("OptionsState");
                break;

            case "Back":
                DefaultItems();
                break;

            case "Debug World":
                DebugWorldItems();
                break;

            case "Flat World":
            {
                MaintainState = false;
                Overworld.CreateUniformLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Hills World":
            {
                MaintainState = false;
                Overworld.CreateHillsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Cliffs World":
            {
                MaintainState = false;
                Overworld.CreateCliffsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Ocean World":
            {
                MaintainState = false;
                Overworld.CreateOceanLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Load World":
                MaintainState = true;
                StateManager.PushState("WorldLoaderState");
                break;

            case "Load Game":
                MaintainState = true;
                StateManager.PushState("GameLoaderState");
                break;
            }
        }
예제 #24
0
        public void MakeDebugWorldMenu()
        {
            GuiRoot.RootItem.Clear();

            var frame = MakeMenuFrame("DEBUG WORLDS");

            MakeMenuItem(frame, "Hills", "Create a hilly world.", (sender, args) =>
            {
                Overworld.CreateHillsLand(Game.GraphicsDevice);
                StateManager.ClearState();
                WorldGenerationSettings settings = new WorldGenerationSettings()
                {
                    ExistingFile = null,
                    ColonySize   = new Point3(8, 1, 8),
                    WorldScale   = 2.0f,
                    WorldOrigin  = new Vector2(Overworld.Map.GetLength(0) / 2.0f,
                                               Overworld.Map.GetLength(1) / 2.0f) * 0.5f
                };
                StateManager.PushState(new LoadState(Game, StateManager, settings));
            });

            MakeMenuItem(frame, "Cliffs", "Create a cliff-y world.", (sender, args) =>
            {
                Overworld.CreateCliffsLand(Game.GraphicsDevice);
                StateManager.ClearState();
                WorldGenerationSettings settings = new WorldGenerationSettings()
                {
                    ExistingFile = null,
                    ColonySize   = new Point3(8, 1, 8),
                    WorldScale   = 2.0f,
                    WorldOrigin  = new Vector2(Overworld.Map.GetLength(0) / 2.0f,
                                               Overworld.Map.GetLength(1) / 2.0f) * 0.5f
                };
                StateManager.PushState(new LoadState(Game, StateManager, settings));
            });

            MakeMenuItem(frame, "Flat", "Create a flat world.", (sender, args) =>
            {
                Overworld.CreateUniformLand(Game.GraphicsDevice);
                StateManager.ClearState();
                WorldGenerationSettings settings = new WorldGenerationSettings()
                {
                    ExistingFile = null,
                    ColonySize   = new Point3(8, 1, 8),
                    WorldScale   = 2.0f,
                    WorldOrigin  = new Vector2(Overworld.Map.GetLength(0) / 2.0f,
                                               Overworld.Map.GetLength(1) / 2.0f) * 0.5f
                };
                StateManager.PushState(new LoadState(Game, StateManager, settings));
            });

            MakeMenuItem(frame, "Ocean", "Create an ocean world", (sender, args) =>
            {
                Overworld.CreateOceanLand(Game.GraphicsDevice, 0.17f);
                StateManager.ClearState();
                WorldGenerationSettings settings = new WorldGenerationSettings()
                {
                    ExistingFile = null,
                    ColonySize   = new Point3(8, 1, 8),
                    WorldScale   = 2.0f,
                    WorldOrigin  = new Vector2(Overworld.Map.GetLength(0) / 2.0f,
                                               Overworld.Map.GetLength(1) / 2.0f) * 0.5f
                };
                StateManager.PushState(new LoadState(Game, StateManager, settings));
            });

            MakeMenuItem(frame, "Back", "Go back to the main menu.", (sender, args) => StateManager.PopState());

            GuiRoot.RootItem.Layout();
        }
예제 #25
0
        private void CreateMesh(GraphicsDevice Device, Overworld Overworld)
        {
            var numVerts = (Overworld.Width + 1) * (Overworld.Height + 1);

            LandMesh = new VertexBuffer(Device, VertexPositionNormalTexture.VertexDeclaration, numVerts, BufferUsage.None);
            var verts = new VertexPositionNormalTexture[numVerts];

            int i = 0;

            for (int x = 0; x <= Overworld.Width; x += 1)
            {
                for (int y = 0; y <= Overworld.Height; y += 1)
                {
                    var landHeight = Overworld.Map.Height((x < Overworld.Width) ? x : x - 1, (y < Overworld.Height) ? y : y - 1);
                    verts[i].Position          = new Vector3((float)x / Overworld.Width, landHeight * HeightScale, (float)y / Overworld.Height);
                    verts[i].TextureCoordinate = new Vector2((float)x / Overworld.Width, (float)y / Overworld.Height);

                    var normal = new Vector3(
                        Overworld.Map.Height(MathFunctions.Clamp(x + 1, 0, Overworld.Width - 1), MathFunctions.Clamp(y, 0, Overworld.Height - 1)) - Overworld.Height,
                        1.0f,
                        Overworld.Map.Height(MathFunctions.Clamp(x, 0, Overworld.Width - 1), MathFunctions.Clamp(y + 1, 0, Overworld.Height - 1)) - Overworld.Height);
                    normal.Normalize();
                    verts[i].Normal = normal;

                    i++;
                }
            }

            LandMesh.SetData(verts);

            var indices = SetUpTerrainIndices((Overworld.Width + 1), (Overworld.Height + 1));

            LandIndex = new IndexBuffer(Device, typeof(int), indices.Length, BufferUsage.None);
            LandIndex.SetData(indices);

            // Create tree mesh.

            TreePrimitive = new RawPrimitive();
            if (IconTexture == null)
            {
                IconTexture = AssetManager.GetContentTexture("GUI\\map_icons");
            }
            var iconSheet = new SpriteSheet(IconTexture, 16, 16);

            for (int x = 0; x < Overworld.Width; x += 1)
            {
                for (int y = 0; y < Overworld.Height; y += 1)
                {
                    if (!MathFunctions.RandEvent(0.05f))
                    {
                        continue;
                    }
                    var elevation = Overworld.Map.Height(x, y);
                    if (elevation <= Overworld.GenerationSettings.SeaLevel)
                    {
                        continue;
                    }
                    if (Library.GetBiome(Overworld.Map.Map[x, y].Biome).HasValue(out var biome))
                    {
                        if (biome.Icon.X > 0 || biome.Icon.Y > 0)
                        {
                            var bounds = Vector4.Zero;
                            var uvs    = iconSheet.GenerateTileUVs(biome.Icon, out bounds);
                            var angle  = MathFunctions.Rand() * (float)System.Math.PI;

                            TreePrimitive.AddQuad(
                                Matrix.CreateRotationX(-(float)System.Math.PI / 2)
                                * Matrix.CreateRotationY(angle)
                                * Matrix.CreateScale(2.0f / Overworld.Width)
                                * Matrix.CreateTranslation((float)x / Overworld.Width, elevation * HeightScale + 1.0f / Overworld.Width, (float)y / Overworld.Height),
                                Color.White, Color.White, uvs, bounds);

                            TreePrimitive.AddQuad(
                                Matrix.CreateRotationX(-(float)System.Math.PI / 2)
                                * Matrix.CreateRotationY((float)System.Math.PI / 2)
                                * Matrix.CreateRotationY(angle)
                                * Matrix.CreateScale(2.0f / Overworld.Width)
                                * Matrix.CreateTranslation((float)x / Overworld.Width, elevation * HeightScale + 1.0f / Overworld.Width, (float)y / Overworld.Height),
                                Color.White, Color.White, uvs, bounds);
                        }
                    }
                }
            }
        }
예제 #26
0
        private void Weather(int width, int height, float T, Vector2[] neighbs, float[,] buffer)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    buffer[x, y] = Overworld.Map[x, y].Height * Overworld.Map[x, y].Faults;
                }
            }

            int weatheringIters = 10;

            for (int iter = 0; iter < weatheringIters; iter++)
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Vector2 p              = new Vector2(x, y);
                        Vector2 maxDiffNeigh   = Vector2.Zero;
                        float   maxDiff        = 0;
                        float   totalDiff      = 0;
                        float   h              = Overworld.GetHeight(buffer, p);
                        float   lowestNeighbor = 0.0f;
                        for (int i = 0; i < 4; i++)
                        {
                            float nh   = Overworld.GetHeight(buffer, p + neighbs[i]);
                            float diff = h - nh;
                            totalDiff += diff;
                            if (diff > maxDiff)
                            {
                                maxDiffNeigh   = neighbs[i];
                                maxDiff        = diff;
                                lowestNeighbor = nh;
                            }
                        }

                        if (maxDiff > T)
                        {
                            Overworld.AddValue(Overworld.Map, p + maxDiffNeigh, Overworld.ScalarFieldType.Weathering, (float)(maxDiff * 0.4f));
                            Overworld.AddValue(Overworld.Map, p, Overworld.ScalarFieldType.Weathering, (float)(-maxDiff * 0.4f));
                        }
                    }
                }

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Vector2 p = new Vector2(x, y);
                        float   w = Overworld.GetValue(Overworld.Map, p, Overworld.ScalarFieldType.Weathering);
                        Overworld.AddHeight(buffer, p, w);
                        Overworld.Map[x, y].Weathering = 0.0f;
                    }
                }
            }

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[x, y].Weathering = buffer[x, y] - Overworld.Map[x, y].Height * Overworld.Map[x, y].Faults;
                }
            }
        }
예제 #27
0
        public void MakeDebugWorldMenu()
        {
            GuiRoot.RootItem.Clear();

            var frame = MakeMenuFrame("DEBUG WORLDS");

            MakeMenuItem(frame, "Hills", "Create a hilly world.", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateHillsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Cliffs", "Create a cliff-y world.", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateCliffsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;
                PlayState.Natives      = new List <Faction>();
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, "fake", "fake", null, Color.Blue);
                for (int i = 0; i < 10; i++)
                {
                    PlayState.Natives.Add(library.GenerateFaction(i, 10));
                }

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Flat", "Create a flat world.", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateUniformLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Ocean", "Create an ocean world", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateOceanLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Back", "Go back to the main menu.", (sender, args) => MakeDefaultMenu());

            GuiRoot.RootItem.Layout();
        }
예제 #28
0
 public FactionViewState(DwarfGame game, Overworld Overworld) : base(game)
 {
     this.Overworld = Overworld;
 }
예제 #29
0
 public EmbarkmentEditor(Overworld Settings)
 {
     this.Settings = Settings;
 }
예제 #30
0
        public void MakeMenu(DirectoryInfo GameToContinue)
        {
            var frame = CreateMenu(Library.GetString("main-menu-title"));

            if (GameToContinue != null && NewOverworldFile.CheckCompatibility(GameToContinue.FullName))
            {
                CreateMenuItem(frame,
                               "Continue",
                               NewOverworldFile.GetOverworldName(GameToContinue.FullName),
                               (sender, args) => {
                    var file = NewOverworldFile.Load(GameToContinue.FullName);
                    GameStateManager.PopState();
                    var overworldSettings = file.CreateSettings();
                    overworldSettings.InstanceSettings.LoadType = LoadType.LoadFromFile;
                    GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.UseExistingOverworld));
                });
            }

            CreateMenuItem(frame,
                           Library.GetString("new-game"),
                           Library.GetString("new-game-tooltip"),
                           (sender, args) => GameStateManager.PushState(new WorldGeneratorState(Game, Overworld.Create(), WorldGeneratorState.PanelStates.Generate)));

            CreateMenuItem(frame,
                           Library.GetString("load-game"),
                           Library.GetString("load-game-tooltip"),
                           (sender, args) => GameStateManager.PushState(new WorldLoaderState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("options"),
                           Library.GetString("options-tooltip"),
                           (sender, args) => GameStateManager.PushState(new OptionsState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("manage-mods"),
                           Library.GetString("manage-mods-tooltip"),
                           (sender, args) => GameStateManager.PushState(new ModManagement.ManageModsState(Game)));

            CreateMenuItem(frame,
                           Library.GetString("credits"),
                           Library.GetString("credits-tooltip"),
                           (sender, args) => GameStateManager.PushState(new CreditsState(GameState.Game)));

            CreateMenuItem(frame, "QUICKPLAY", "",
                           (sender, args) =>
            {
                DwarfGame.LogSentryBreadcrumb("Menu", "User generating a random world.");

                var overworldSettings = Overworld.Create();
                overworldSettings.InstanceSettings.InitalEmbarkment       = new Embarkment(overworldSettings);
                overworldSettings.InstanceSettings.InitalEmbarkment.Funds = 1000u;
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Crafter", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Manager", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Miner", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Wizard", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Soldier", overworldSettings.Company));
                overworldSettings.InstanceSettings.InitalEmbarkment.Employees.Add(Applicant.Random("Musketeer", overworldSettings.Company));

                GameStateManager.PushState(new LoadState(Game, overworldSettings, LoadTypes.GenerateOverworld));
            });

            CreateMenuItem(frame, "GIANT QUICKPLAY", "",
                           (sender, args) =>
            {
                GameStateManager.PushState(new CheckMegaWorldState(Game));
            });

            CreateMenuItem(frame, "Dwarf Designer", "Open the dwarf designer.",
                           (sender, args) =>
            {
                GameStateManager.PushState(new Debug.DwarfDesignerState(GameState.Game));
            });

#if DEBUG
            CreateMenuItem(frame, "Yarn test", "", (sender, args) =>
            {
                GameStateManager.PushState(new YarnState(null, "test.conv", "Start", new Yarn.MemoryVariableStore()));
            });

            CreateMenuItem(frame, "Debug GUI", "", (sender, args) =>
            {
                GameStateManager.PushState(new Debug.GuiDebugState(GameState.Game));
            });
#endif

            CreateMenuItem(frame,
                           Library.GetString("quit"),
                           Library.GetString("quit-tooltip"),
                           (sender, args) => Game.Exit());

            FinishMenu();
        }