public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"]; bool[,] subArea = new bool[3, 3]; for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { this.GetComputedLandType(altitudeLandLayerGenerator, area, i, j, out LandType landType, out LandType secondType, out LandTransition landTransition); int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i); GroundLandObject groundLandObject = new GroundLandObject(area.Left + j, area.Top + i, altitude, landType); GroundLandObject secondGroundLandObject = new GroundLandObject(area.Left + j, area.Top + i, altitude, secondType); secondGroundLandObject.SetTransition(landTransition); AssignGround(landChunk, i, j, altitude, altitudeOffset, groundLandObject, secondGroundLandObject); this.powerArea[i + 2, j + 2] = (int)this.GetLandTypeFromPower(altitude); } } landChunk.AddTypeInChunk(typeof(GroundLandObject)); return(seed); }
protected void GetComputedLandType( IntRect area, ref int[,] subAreaInt, int maxValue, out LandTransition landtransition) { bool[,] subAreaBool = new bool[3, 3]; landtransition = LandTransition.NONE; if (subAreaInt[1, 1] < maxValue) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (subAreaInt[y, x] <= subAreaInt[1, 1]) { subAreaBool[y, x] = false; } else { subAreaBool[y, x] = true; } } } landtransition = ALandLayerGenerator.GetLandTransitionFrom(ref subAreaBool); } }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator groundLandLayerGenerator = worldGenerator.Generators["defaultGround"]; ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"]; ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"]; bool isThereSandElement = false; Random random = new Random(seed); for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i); int elementIndex = random.Next(0, 8); int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i)); LandType landType = (LandType)groundLandLayerGenerator.GetComputedPowerAt(j, i); if (landType == LandType.SAND) { if (power >= 8 && random.Next(0, 3) > 0 && altitudeOffset == 0) { float trueAltitude = altitudeLandLayerGenerator.GetPowerAt(new SFML.System.Vector2f(area.Left + j, area.Top + i)); if ((elementIndex == 1 || elementIndex == 3) && trueAltitude > 0.6 && random.Next(0, 4) > 0) { elementIndex -= 1; } GroundElementLandObject groundElement = new GroundElementLandObject(area.Left + j, area.Top + i, altitude, landType, elementIndex); LandCase landCase = landChunk.GetLandCase(i, j, altitude); landCase.LandOverGround = groundElement; isThereSandElement = true; } } } } if (isThereSandElement) { landChunk.AddTypeInChunk(typeof(GroundElementLandObject)); } return(random.Next()); }
private void GetComputedLandType( ALandLayerGenerator altitudeLandLayerGenerator, IntRect area, int i, int j, out LandType landType, out LandType secondType, out LandTransition landtransition) { bool[,] subAreaBool = new bool[3, 3]; int[,] subAreaInt = new int[3, 3]; int maxValue = int.MinValue; int minValue = int.MaxValue; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { int power = altitudeLandLayerGenerator.GetComputedPowerAt(j + x, i + y); int currentValue = (int)this.GetLandTypeFromPower(power); maxValue = Math.Max(maxValue, currentValue); minValue = Math.Min(minValue, currentValue); subAreaInt[y + 1, x + 1] = currentValue; } } landType = (LandType)subAreaInt[1, 1]; landtransition = LandTransition.NONE; secondType = landType; if (subAreaInt[1, 1] != maxValue) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (subAreaInt[y, x] != maxValue) { subAreaBool[y, x] = false; } else { subAreaBool[y, x] = true; } } } landtransition = ALandLayerGenerator.GetLandTransitionFrom(ref subAreaBool); if (landtransition != LandTransition.NONE) { secondType = (LandType)maxValue; } } }
private int NeedToFillSandAt( WorldGenerator worldGenerator, IntRect area, int i, int j) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; bool[,] subAreaBool = new bool[3, 3]; int[,] subAreaInt = new int[3, 3]; int maxValue = int.MinValue; int minValue = int.MaxValue; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { double preAltitude = altitudeLandLayerGenerator.GetPowerAt(new Vector2f(area.Left + j + x, area.Top + i + y)); int altitude = (int)Math.Round(preAltitude); maxValue = Math.Max(maxValue, altitude); minValue = Math.Min(minValue, altitude); subAreaInt[y + 1, x + 1] = altitude; } } bool needToFill = false; if (subAreaInt[1, 1] != maxValue) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (subAreaInt[y, x] != maxValue) { subAreaBool[y, x] = false; } else { subAreaBool[y, x] = true; } } } needToFill = ALandLayerGenerator.NeedToFill(ref subAreaBool); } if (needToFill) { return(maxValue); } return(subAreaInt[1, 1]); }
public static int NeedToFillLandAt( int[,] mountainArea, IntRect area, int i, int j) { bool[,] subAreaBool = new bool[3, 3]; int[,] subAreaInt = new int[3, 3]; int maxValue = int.MinValue; int minValue = int.MaxValue; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { int altitude = mountainArea[i + y + 2, j + x + 2]; maxValue = Math.Max(maxValue, altitude); minValue = Math.Min(minValue, altitude); subAreaInt[y + 1, x + 1] = altitude; } } bool needToFill = false; if (subAreaInt[1, 1] != maxValue) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (subAreaInt[y, x] != maxValue) { subAreaBool[y, x] = false; } else { subAreaBool[y, x] = true; } } } needToFill = ALandLayerGenerator.NeedToFill(ref subAreaBool); } if (needToFill) { return(maxValue); } return(subAreaInt[1, 1]); }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator grassLandLayerGenerator = worldGenerator.Generators["grass"]; ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"]; ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"]; bool isThereGrassElement = false; Random random = new Random(seed); for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i); int elementIndex = random.Next(0, 12); int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i)); GrassType grassType = (GrassType)grassLandLayerGenerator.GetComputedPowerAt(j, i); if (power >= 2 && random.Next(0, 3) > 0 && altitudeOffset == 0 && grassType != GrassType.NONE) { GrassElementLandObject grassElement = new GrassElementLandObject(area.Left + j, area.Top + i, altitude, grassType, elementIndex); LandCase landCase = landChunk.GetLandCase(i, j, altitude); landCase.LandOverGround = grassElement; isThereGrassElement = true; } } } if (isThereGrassElement) { landChunk.AddTypeInChunk(typeof(GrassElementLandObject)); } return(random.Next()); }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; bool[,] subArea = new bool[3, 3]; this.powerArea = new int[area.Height + 4, area.Width + 4]; for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int[,] subAreaInt = new int[3, 3]; int maxLocalAltitude = int.MinValue; maxLocalAltitude = this.GetComputedMatrix(altitudeLandLayerGenerator, i, j, ref subAreaInt); int diffAltitude = maxLocalAltitude - subAreaInt[1, 1]; this.powerArea[i + 2, j + 2] = diffAltitude; for (int offset = 0; offset < diffAltitude; offset++) { this.GetComputedLandType(area, ref subAreaInt, maxLocalAltitude, out LandTransition landTransition); if (landTransition != LandTransition.NONE) { AltitudeLandObject altitudeLandObject = new AltitudeLandObject(area.Left + j, area.Top + i, subAreaInt[1, 1], LandType.GRASS); landChunk.InitializeLandCase(i, j, subAreaInt[1, 1]); landChunk.GetLandCase(i, j, subAreaInt[1, 1]).LandWall = altitudeLandObject; altitudeLandObject.SetLandTransition(landTransition); } subAreaInt[1, 1]++; } } } landChunk.AddTypeInChunk(typeof(AltitudeLandObject)); return(seed); }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; bool isThereWater = false; this.ConstructAltitudeArea(worldGenerator, area); for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int altitude = this.powerArea[i + 1, j + 1]; int[,] subAreaInt = new int[3, 3]; int maxLocalAltitude = int.MinValue; maxLocalAltitude = this.GetComputedMatrix(i, j, ref subAreaInt); for (int z = altitude; z <= 0; z++) { this.GetComputedLandType(area, ref subAreaInt, maxLocalAltitude, out LandTransition landTransition); WaterLandObject waterLandObject = new WaterLandObject(area.Left + j, area.Top + i, z); waterLandObject.SetLandTransition(landTransition); landChunk.InitializeLandCase(i, j, z); landChunk.GetLandCase(i, j, z).LandWater = waterLandObject; isThereWater = true; subAreaInt[1, 1]++; } } } if (isThereWater) { landChunk.AddTypeInChunk(typeof(WaterLandObject)); } return(seed); }
protected int GetComputedMatrix(ALandLayerGenerator altitudeLandLayerGenerator, int i, int j, ref int[,] subAreaInt) { int maxValue = int.MinValue; int minValue = int.MaxValue; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j + x, i + y); maxValue = Math.Max(maxValue, altitude); minValue = Math.Min(minValue, altitude); subAreaInt[y + 1, x + 1] = altitude; } } return(maxValue); }
private void ConstructAltitudeArea(WorldGenerator worldGenerator, IntRect area) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; //this.powerArea = new int[area.Height + 2, area.Width + 2]; for (int i = -1; i < area.Height + 1; i++) { for (int j = -1; j < area.Width + 1; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); if (altitude == 0) { //double preAltitude = altitudeLandLayerGenerator.GetPowerAt(new Vector2f(area.Left + j, area.Top + i)); altitude = this.NeedToFillSandAt(worldGenerator, area, i, j); altitude = Math.Max(0, altitude); } this.powerArea[i + 1, j + 1] = altitude; } } }
private void ConstructMountainArea(WorldGenerator worldGenerator, IntRect area) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator groundLandLayerGenerator = worldGenerator.Generators["ground"]; this.mountainArea = new int[area.Height + 4, area.Width + 4]; for (int i = -2; i < area.Height + 2; i++) { for (int j = -2; j < area.Width + 2; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int power = groundLandLayerGenerator.GetComputedPowerAt(j, i); int currentValue = -1; int mountainType = (int)this.GetMountainTypeFromPower(power); if (altitude > 22) { currentValue = -1; } else if (altitude > 18) { if (mountainType == 0) { currentValue = 1; } else { currentValue = mountainType; } } else if (altitude > 8) { currentValue = mountainType; } else if (altitude > 6) { if (mountainType == 1) { currentValue = -1; } else { currentValue = mountainType; } } else { currentValue = -1; } this.mountainArea[i + 2, j + 2] = currentValue; } } for (int i = 0; i < area.Height + 2; i++) { for (int j = 0; j < area.Width + 2; j++) { this.powerArea[i + 1, j + 1] = LandCreationHelper.NeedToFillLandAt(this.mountainArea, area, i - 1, j - 1); //this.powerArea[i + 1, j + 1] = this.NeedToFillMountainAt(area, i - 1, j - 1); } } }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"]; bool[,] subArea = new bool[3, 3]; bool isThereMountain = false; this.ConstructMountainArea(worldGenerator, area); for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i); if ((altitude > 6 || (altitude == 6 && altitudeOffset > 0)) && altitude < 23) { LandCreationHelper.GetComputedLandType(this, area, i, j, out int mountainTypeInt, out int secondTypeInt, out LandTransition landTransition, out LandTransition secondLandTransition); //this.GetComputedLandType(area, i, j, out MountainType mountainType, out MountainType secondType, out LandTransition landTransition, out LandTransition secondLandTransition); MountainType mountainType = (MountainType)mountainTypeInt; MountainType secondType = (MountainType)secondTypeInt; MountainLandObject groundLandObject = null; MountainLandObject secondGroundLandObject = null; if (mountainType != MountainType.NONE) { groundLandObject = new MountainLandObject(area.Left + j, area.Top + i, altitude, mountainType); groundLandObject.SetTransition(landTransition); isThereMountain = true; } if (secondType != mountainType && secondType != MountainType.NONE) { secondGroundLandObject = new MountainLandObject(area.Left + j, area.Top + i, 0, secondType); secondGroundLandObject.SetTransition(secondLandTransition); isThereMountain = true; } bool onlyGround = altitude == 22 && altitudeOffset > 0; AssignGround(landChunk, i, j, altitude, altitudeOffset, groundLandObject, secondGroundLandObject, onlyGround); } } } if (isThereMountain) { landChunk.AddTypeInChunk(typeof(MountainLandObject)); } return(seed); }
public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude) { ALandLayerGenerator mountainLandLayerGenerator = worldGenerator.Generators["mountain"]; ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"]; ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"]; ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"]; bool isThereMountainElement = false; Random random = new Random(seed); for (int i = 0; i < area.Height; i++) { for (int j = 0; j < area.Width; j++) { int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i); int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i); int elementIndex = random.Next(0, 5); int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i)); MountainType mountainType = (MountainType)mountainLandLayerGenerator.GetComputedPowerAt(j, i); if (mountainType == MountainType.PROJECTING) { if (elementIndex == 3 && random.Next(0, 3) > 0) { elementIndex = random.Next(0, 3); } } else if (mountainType == MountainType.ROUGH) { if (elementIndex < 3 && random.Next(0, 3) > 0) { elementIndex = 3; } } if (power >= 2 && random.Next(0, 3) > 0 && altitudeOffset == 0 && mountainType != MountainType.NONE) { MountainElementLandObject mountainElement = new MountainElementLandObject(area.Left + j, area.Top + i, altitude, mountainType, elementIndex); LandCase landCase = landChunk.GetLandCase(i, j, altitude); landCase.LandOverGround = mountainElement; isThereMountainElement = true; } } } if (isThereMountainElement) { landChunk.AddTypeInChunk(typeof(MountainElementLandObject)); } return(random.Next()); }
public static void GetComputedLandType( ALandLayerGenerator generator, IntRect area, int i, int j, out int mountainType, out int secondType, out LandTransition landtransition, out LandTransition secondLandtransition) { bool[,] subAreaBool = new bool[3, 3]; int[,] subAreaInt = new int[3, 3]; int maxValue = int.MinValue; int minValue = int.MaxValue; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { int currentValue = generator.GetComputedPowerAt(j + x, i + y); maxValue = Math.Max(maxValue, currentValue); minValue = Math.Min(minValue, currentValue); subAreaInt[y + 1, x + 1] = currentValue; } } mountainType = subAreaInt[1, 1]; landtransition = LandTransition.NONE; secondLandtransition = LandTransition.NONE; secondType = mountainType; if (subAreaInt[1, 1] != maxValue) { int primaryType = -1; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (subAreaInt[y, x] != maxValue) { subAreaBool[y, x] = false; if (subAreaInt[y, x] != -1) { primaryType = subAreaInt[y, x]; } } else { subAreaBool[y, x] = true; } } } secondLandtransition = ALandLayerGenerator.GetLandTransitionFrom(ref subAreaBool); if (secondLandtransition != LandTransition.NONE) { secondType = maxValue; } if (subAreaInt[1, 1] == -1 && primaryType != -1) { mountainType = primaryType; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (subAreaInt[y, x] != primaryType) { subAreaBool[y, x] = false; } else { subAreaBool[y, x] = true; } } } landtransition = ALandLayerGenerator.GetLandTransitionFrom(ref subAreaBool); } } }