/// <summary> /// Loads the standard ruleset. /// </summary> private void LoadRuleset() { var ruleExtBasicHeight1 = new RuleDeterministic(Enums.HeightLevel.Height1, Enums.HeightLevel.Height0) { Neighbourhood = RuleEnums.Neighbourhood .MooreExtended }; ruleExtBasicHeight1.AddCondition(18, Enums.HeightLevel.Height1); var ruleExtAdvHeight2 = new RuleDeterministic(Enums.HeightLevel.Height2) { Neighbourhood = RuleEnums.Neighbourhood .MooreExtended }; ruleExtAdvHeight2.AddCondition(18, Enums.HeightLevel.Height2); var ruleBasicHeight2 = new RuleDeterministic(Enums.HeightLevel.Height2); ruleBasicHeight2.AddCondition(5, Enums.HeightLevel.Height2); var ruleBasicHeight1 = new RuleDeterministic(Enums.HeightLevel.Height1); ruleBasicHeight1.AddCondition(5, Enums.HeightLevel.Height1); var ruleAdvHeight1 = new RuleDeterministic(Enums.HeightLevel.Height1, Enums.HeightLevel.Height0); ruleAdvHeight1.AddCondition(3, Enums.HeightLevel.Height1); ruleAdvHeight1.AddCondition(3, Enums.HeightLevel.Height2); var ruleAdvHeight2 = new RuleDeterministic(Enums.HeightLevel.Height2, Enums.HeightLevel.Height1); ruleAdvHeight2.AddCondition(3, Enums.HeightLevel.Height1); ruleAdvHeight2.AddCondition(3, Enums.HeightLevel.Height2); var ruleRemoveHeight0 = new RuleDeterministic(Enums.HeightLevel.Height1, Enums.HeightLevel.Height0); ruleRemoveHeight0.AddCondition(2, Enums.HeightLevel.Height0, RuleEnums.Comparison.LessThanEqualTo); var ruleList = new List <Rule> { ruleExtBasicHeight1, ruleExtAdvHeight2, ruleBasicHeight2, ruleBasicHeight1, ruleAdvHeight1, ruleRemoveHeight0 }; this.ruleSet = new Ruleset(ruleList); }
/// <summary> /// Loads the old rulesets. /// </summary> private void LoadOldRuleset() { var ruleList = new List <Rule>(); var ruleNoInterestingNeighbours = new RuleDeterministic(Enums.HeightLevel.Height0); ruleNoInterestingNeighbours.AddCondition(8, Enums.HeightLevel.Height0); var ruleSmoothLandscape = new RuleDeterministic(Enums.HeightLevel.Height1); ruleSmoothLandscape.AddCondition(3, Enums.HeightLevel.Height2); ruleSmoothLandscape.AddCondition(3, Enums.HeightLevel.Height0); var ruleSimpleHeight1 = new RuleDeterministic(Enums.HeightLevel.Height1); ruleSimpleHeight1.AddCondition(5, Enums.HeightLevel.Height1); var ruleSimpleHeight2 = new RuleDeterministic(Enums.HeightLevel.Height2, Enums.HeightLevel.Height1); ruleSimpleHeight2.AddCondition(5, Enums.HeightLevel.Height2); var ruleSimpleHeight2Again = new RuleDeterministic(Enums.HeightLevel.Height2, Enums.HeightLevel.Height1); ruleSimpleHeight2Again.AddCondition(5, Enums.HeightLevel.Height1); ruleSimpleHeight2Again.AddCondition(2, Enums.HeightLevel.Height2); var ruleShrinkHeight2 = new RuleDeterministic(Enums.HeightLevel.Height1, Enums.HeightLevel.Height2); ruleShrinkHeight2.AddCondition(0, Enums.HeightLevel.Height2, RuleEnums.Comparison.LessThanEqualTo); ruleList.Add(ruleNoInterestingNeighbours); ////ruleList.Add(ruleSmoothLandscape); ruleList.Add(ruleSimpleHeight2); ruleList.Add(ruleSimpleHeight2Again); ruleList.Add(ruleSimpleHeight1); ruleList.Add(ruleShrinkHeight2); this.ruleSet = new Ruleset(ruleList); }
/// <summary> /// Adds impassable terrain at random positions in the map. /// </summary> /// <param name="sections"> The number of impassable terrain sections. </param> /// <param name="maxLength"> The max length of a section. </param> /// <param name="placementIntervals"> The interval between placements of points in the section. </param> /// <param name="maxPathNoiseDisplacement"> The max displacement of any point in the section. </param> /// <param name="maxWidth"> The max width of a point. </param> public void CreateImpassableTerrain(int sections = 4, int maxLength = 50, double placementIntervals = 0.1, int maxPathNoiseDisplacement = 3, int maxWidth = 4) { if (sections <= 0) { return; } var tempMap = (Enums.HeightLevel[, ]) this.Map.Clone(); var moves = new List <int> { 0 }; // Get the moves to make to reach the entire area around the drop zone. for (var r = 1; r <= maxWidth; r++) { moves.Add(r); } for (var sec = 0; sec < sections; sec++) { // Calculate section placement var x1 = this.random.Next(this.caXStart, this.caXEnd); var y1 = this.random.Next(this.caYStart, this.caYEnd); var x2 = x1 + (this.random.Next(maxLength * 2) - maxLength); var y2 = y1 + (this.random.Next(maxLength * 2) - maxLength); var dist = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)); // Recalculate 2nd point if it is outside map or too far away while (dist > maxLength || !MapHelper.WithinMapBounds(x2, y2, this.XSize, this.YSize)) { x2 = x1 + (this.random.Next(maxLength * 2) - maxLength); y2 = y1 + (this.random.Next(maxLength * 2) - maxLength); dist = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)); } // Minimum width needed for each "drop" in order to connect the entire section var minWidth = (int)Math.Round((dist * placementIntervals) / 2); var prevX = -100000; var prevY = -100000; // Create the points and place impassable terrain for (var placement = 0d; placement < 1d; placement += placementIntervals) { var x = (int)Math.Round(x1 + (placement * (x2 - x1))); var y = (int)Math.Round(y1 + (placement * (y2 - y1))); // Add noise var tempX = x + this.random.Next(maxPathNoiseDisplacement * 2) - maxPathNoiseDisplacement; var tempY = y + this.random.Next(maxPathNoiseDisplacement * 2) - maxPathNoiseDisplacement; while (!MapHelper.WithinMapBounds(tempX, tempY, this.XSize, this.YSize)) { tempX = x + this.random.Next(maxPathNoiseDisplacement * 2) - maxPathNoiseDisplacement; tempY = y + this.random.Next(maxPathNoiseDisplacement * 2) - maxPathNoiseDisplacement; } x = tempX; y = tempY; // Adjust minWidth if (prevX >= 0 && prevY >= 0) { minWidth = (int)Math.Round(Math.Sqrt(Math.Pow(x - prevX, 2) + Math.Pow(y - prevY, 2))); } if (minWidth > maxWidth) { maxWidth = minWidth; } var actualPos = new Position(x, y); // Place impassable terrain var width = this.random.Next(minWidth, maxWidth); for (var widthX = 0; widthX < width; widthX++) { for (var widthY = 0; widthY < width; widthY++) { var widthPos = new Position(x + widthX, y + widthY); if (MapHelper.WithinMapBounds(widthPos, this.XSize, this.YSize) && MapHelper.CloseTo(widthPos, actualPos, width)) { tempMap[widthPos.Item1, widthPos.Item2] = Enums.HeightLevel.Impassable; } } } prevX = x; prevY = y; } } var ruleSmoothImpassable = new RuleDeterministic(Enums.HeightLevel.Impassable); ruleSmoothImpassable.AddCondition(6, Enums.HeightLevel.Impassable); var ruleList = new List <Rule> { ruleSmoothImpassable }; var tempRuleSet = new Ruleset(ruleList); for (var g = 0; g < 10; g++) { tempMap = tempRuleSet.NextGeneration(tempMap, this.caXStart, this.caXEnd, this.caYStart, this.caYEnd, false, this.random); } this.Map = tempMap; }