public void DrawLightBeam() { float lanceWidth = 4f; if (this.ticksToImpact < (this.maxTicks * .5f)) { lanceWidth *= (float)this.ticksToImpact / this.maxTicks; } if (this.ticksToImpact > (this.maxTicks * .5f)) { lanceWidth *= (float)(this.maxTicks - this.ticksToImpact) / this.maxTicks; } lanceWidth *= Rand.Range(.9f, 1.1f); Vector3 angleVector = Vector3Utility.FromAngleFlat(this.angle - 90) * .5f * beamLength; Vector3 drawPos = base.Position.ToVector3Shifted() + angleVector; Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(drawPos, Quaternion.Euler(0f, this.angle, 0f), new Vector3(lanceWidth, 1f, beamLength)); //drawer for beam Graphics.DrawMesh(MeshPool.plane10, matrix, TM_DropPodIncoming.BeamMat, 0, null, 0, TM_DropPodIncoming.MatPropertyBlock); Matrix4x4 matrix2 = default(Matrix4x4); matrix2.SetTRS(base.Position.ToVector3Shifted() + Vector3Utility.FromAngleFlat(this.angle + 90) * .5f * lanceWidth, Quaternion.Euler(0f, this.angle, 0f), new Vector3(lanceWidth, 1f, lanceWidth)); //drawer for beam start Graphics.DrawMesh(MeshPool.plane10, matrix2, TM_DropPodIncoming.BeamEndMat, 0, null, 0, TM_DropPodIncoming.MatPropertyBlock); }
public void DrawBeams(int i) { float lanceWidth = .5f; if (this.age - sfBeamsStartTick[i] <= 10) { lanceWidth *= (float)(this.age - sfBeamsStartTick[i]) / 10f; } if (this.sfBeamsStep[i] < 10) { lanceWidth *= (float)(sfBeamsStep[i]) / 10f; } float lanceLength = ((float)base.Map.Size.z - sfBeams[i].z) * 1.4f; Vector3 a = Vector3Utility.FromAngleFlat(this.angle - 90f); //angle of beam Vector3 lanceVector = sfBeams[i] + a * lanceLength * 0.5f; Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(lanceVector, Quaternion.Euler(0f, this.angle, 0f), new Vector3(lanceWidth, 1f, lanceLength)); //drawer for beam Graphics.DrawMesh(MeshPool.plane10, matrix, Projectile_Sunfire.BeamMat, 0, null, 0, Projectile_Sunfire.MatPropertyBlock); Matrix4x4 matrix2 = default(Matrix4x4); matrix2.SetTRS(sfBeams[i] - (.5f * a * lanceWidth), Quaternion.Euler(0f, this.angle, 0f), new Vector3(lanceWidth, 1f, lanceWidth)); //drawer for beam start Graphics.DrawMesh(MeshPool.plane10, matrix2, Projectile_Sunfire.BeamEndMat, 0, null, 0, Projectile_Sunfire.MatPropertyBlock); }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vect = start.ToVector3Shifted(); float distcovered = 0f; IntVec3 intVec = start; float num = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; bool flag = false; bool flag2 = false; if (visited == null) { visited = new HashSet <IntVec3>(); } tmpGroupSet.Clear(); tmpGroupSet.AddRange(group); int num2 = 0; while (true) { if (closed) { int num3 = GenRadial.NumCellsInRadius(width / 2f + 1.5f); for (int i = 0; i < num3; i++) { IntVec3 intVec2 = intVec + GenRadial.RadialPattern[i]; if (!visited.Contains(intVec2) && (!tmpGroupSet.Contains(intVec2))) { return; } } } if (num2 >= 15 && width > 1.8f + BranchedTunnelWidthOffset.max) { Rand.PushState(); if (!flag && Rand.Chance(0.05f)) { DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(0.05f)) { DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } Rand.PopState(); } SetCaveAround(intVec, width, map, visited, out bool hitAnotherTunnel); if (hitAnotherTunnel) { // Log.Message(intVec + " hitAnotherTunnel"); break; } while (vect.ToIntVec3() == intVec) { vect += Vector3Utility.FromAngleFlat(dir) * 0.5f; num += 0.5f; } if (!tmpGroupSet.Contains(vect.ToIntVec3())) { // Log.Message(vect.ToIntVec3() + " not in group"); break; } IntVec3 intVec3 = new IntVec3(intVec.x, 0, vect.ToIntVec3().z); if (IsRock(intVec3, elevation, map)) { caves[intVec3] = Mathf.Max(caves[intVec3], width); visited.Add(intVec3); } cavecells.Add(intVec); // Log.Message(intVec + " added to cavecells, currently: "+ cavecells.Count); intVec = vect.ToIntVec3(); /* * // Log.Message(intVec + " added to cavecells, currently: " + cavecells.Count); * // Log.Message("Randomize angel Original: "+ dir); * // Log.Message("Randomize angel num: " + num); * // Log.Message("Randomize angel start.x: " + start.x); * // Log.Message("Randomize angel start.z: " + start.z); */ if (directionNoise == null) { Rand.PushState(); directionNoise = new Perlin(0.0020500000100582838, 2.0, 0.5, 4, Rand.Int, QualityMode.Medium); Rand.PopState(); } dir += (float)directionNoise.GetValue(num * 60f, (float)start.x * 200f, (float)start.z * 200f) * 8f; // Log.Message("angel = "+ dir); width -= 0.005f; // Log.Message("Tunneling heading: " + dir + ", current width: " + width); if (!(width < 1.4f)) { num2++; continue; } distcovered = start.DistanceTo(intVec); break; } // Log.Message("Tunneling from "+ start + " heading: " + dir +" Distance: " + distcovered + " complete"); }
private static Vector3 PosAtDist(Vector3 center, float dist, float angle) { return(center + Vector3Utility.FromAngleFlat(angle - 90f) * dist); }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vector = start.ToVector3Shifted(); IntVec3 intVec = start; float num = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; bool flag = false; bool flag2 = false; if (visited == null) { visited = new HashSet <IntVec3>(); } GenStep_Cavern.tmpGroupSet.Clear(); GenStep_Cavern.tmpGroupSet.AddRange(group); int num2 = 0; while (true) { if (closed) { int num3 = GenRadial.NumCellsInRadius(width / 2f + 1.5f); for (int i = 0; i < num3; i++) { IntVec3 intVec2 = intVec + GenRadial.RadialPattern[i]; if (!visited.Contains(intVec2)) { if (!GenStep_Cavern.tmpGroupSet.Contains(intVec2) || caves[intVec2] > 0f) { return; } } } } if (num2 >= 30 && width > 4f + GenStep_Cavern.BranchedTunnelWidthOffset.max) { if (!flag && Rand.Chance(0.6f)) { this.DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - GenStep_Cavern.BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(0.6f)) { this.DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - GenStep_Cavern.BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } } bool flag3; this.SetCaveAround(intVec, width, map, visited, out flag3); if (flag3) { return; } while (vector.ToIntVec3() == intVec) { vector += Vector3Utility.FromAngleFlat(dir) * 0.5f; num += 0.5f; } if (!GenStep_Cavern.tmpGroupSet.Contains(vector.ToIntVec3())) { return; } IntVec3 intVec3 = new IntVec3(intVec.x, 0, vector.ToIntVec3().z); if (this.IsRock(intVec3, elevation, map)) { caves[intVec3] = Mathf.Max(caves[intVec3], width); visited.Add(intVec3); } intVec = vector.ToIntVec3(); dir += (float)this.directionNoise.GetValue((double)(num * 60f), (double)((float)start.x * 200f), (double)((float)start.z * 200f)) * 8f; width -= 0.01f; if (width < 1.4f) { return; } num2++; } }
public static Vector3 DrawBombFalling(Vector3 center, int ticksToImpact, float angle, float speed) { float dist = (float)ticksToImpact * speed; return(center + Vector3Utility.FromAngleFlat(angle - 90f) * dist); }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vector = start.ToVector3Shifted(); IntVec3 intVec = start; float num = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; bool flag = false; bool flag2 = false; if (visited == null) { visited = new HashSet <IntVec3>(); } GenStep_Caves.tmpGroupSet.Clear(); GenStep_Caves.tmpGroupSet.AddRange(group); int num2 = 0; while (true) { if (closed) { int num3 = GenRadial.NumCellsInRadius((float)(width / 2.0 + 1.5)); for (int i = 0; i < num3; i++) { IntVec3 intVec2 = intVec + GenRadial.RadialPattern[i]; if (!visited.Contains(intVec2)) { if (!GenStep_Caves.tmpGroupSet.Contains(intVec2)) { return; } if (caves[intVec2] > 0.0) { return; } } } } if (num2 >= 15) { float num4 = width; FloatRange branchedTunnelWidthOffset = GenStep_Caves.BranchedTunnelWidthOffset; if (num4 > 1.3999999761581421 + branchedTunnelWidthOffset.max) { if (!flag && Rand.Chance(0.1f)) { this.DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - GenStep_Caves.BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(0.1f)) { this.DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - GenStep_Caves.BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } } } bool flag3 = default(bool); this.SetCaveAround(intVec, width, map, visited, out flag3); if (!flag3) { while (vector.ToIntVec3() == intVec) { vector += Vector3Utility.FromAngleFlat(dir) * 0.5f; num = (float)(num + 0.5); } if (GenStep_Caves.tmpGroupSet.Contains(vector.ToIntVec3())) { int x = intVec.x; IntVec3 intVec3 = vector.ToIntVec3(); IntVec3 intVec4 = new IntVec3(x, 0, intVec3.z); if (this.IsRock(intVec4, elevation, map)) { caves[intVec4] = Mathf.Max(caves[intVec4], width); visited.Add(intVec4); } intVec = vector.ToIntVec3(); dir = (float)(dir + (float)this.directionNoise.GetValue(num * 60.0, (float)start.x * 200.0, (float)start.z * 200.0) * 8.0); width = (float)(width - 0.034000001847743988); if (!(width < 1.3999999761581421)) { num2++; continue; } } } break; } }
public override void Generate(Map map, GenStepParams parms) { IntVec3 mapCenter = map.Center; MapGenFloatGrid fertility = MapGenerator.Fertility; float mapSize = map.Size.x; IntRange distRange = new IntRange(10, 30); distRange.min = (int)(0.18 * map.Size.x); distRange.max = (int)(0.30 * map.Size.x); float angleA = Rand.Range(10f, 120f); float angleB = angleA + Rand.RangeSeeded(60f, 120f, (int)angleA); float angleC = angleB + Rand.RangeSeeded(60f, 120f, (int)angleB); float angleD = angleC + Rand.RangeSeeded(60f, 120, (int)angleC); float angleE = angleD + Rand.RangeSeeded(60f, 120, (int)angleD); float angleF = angleE + Rand.RangeSeeded(60f, 120, (int)angleE); IntVec3 centerA = mapCenter + (distRange.RandomInRange * Vector3Utility.FromAngleFlat(angleA)).ToIntVec3(); IntVec3 centerB = mapCenter + (distRange.RandomInRange * 0.5f * Vector3Utility.FromAngleFlat(angleB)).ToIntVec3(); IntVec3 centerC = mapCenter + (distRange.RandomInRange * 1.3f * Vector3Utility.FromAngleFlat(angleC)).ToIntVec3(); IntVec3 centerD = mapCenter + (distRange.RandomInRange * Vector3Utility.FromAngleFlat(angleD)).ToIntVec3(); IntVec3 centerE = mapCenter + (distRange.RandomInRange * 0.6f * Vector3Utility.FromAngleFlat(angleE)).ToIntVec3(); IntVec3 centerF = mapCenter + (distRange.RandomInRange * 1.3f * Vector3Utility.FromAngleFlat(angleF)).ToIntVec3(); ModuleBase noiseA = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High); ModuleBase noiseB = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High); int islandNumber = Rand.Range(4, 6); foreach (IntVec3 current in map.AllCells) { float distA = (float)Math.Sqrt(Math.Pow(current.x - centerA.x, 2) + Math.Pow(current.z - centerA.z, 2)); float distB = (float)Math.Sqrt(Math.Pow(current.x - centerB.x, 2) + Math.Pow(current.z - centerB.z, 2)); float distC = (float)Math.Sqrt(Math.Pow(current.x - centerC.x, 2) + Math.Pow(current.z - centerC.z, 2)); float distD = (float)Math.Sqrt(Math.Pow(current.x - centerD.x, 2) + Math.Pow(current.z - centerD.z, 2)); float distE = (float)Math.Sqrt(Math.Pow(current.x - centerE.x, 2) + Math.Pow(current.z - centerE.z, 2)); float distF = (float)Math.Sqrt(Math.Pow(current.x - centerF.x, 2) + Math.Pow(current.z - centerF.z, 2)); // island A float addition = Math.Max(0, 20 * (1f - (Rand.RangeSeeded(9f, 12f, 1) * distA / mapSize)) + Rand.RangeSeeded(15f, 20f, centerA.x + centerA.y + centerA.z) * noiseA.GetValue(current)); // island B addition += Math.Max(0, 20 * (1f - (Rand.RangeSeeded(6f, 9f, 2) * distB / mapSize)) + Rand.RangeSeeded(15f, 20f, 2) * noiseA.GetValue(current)); // island C addition += Math.Max(0, 20 * (1f - (Rand.RangeSeeded(9f, 12f, 3) * distC / mapSize)) + Rand.RangeSeeded(15f, 20f, 3) * noiseB.GetValue(current)); // island D addition += Math.Max(0, 20 * (1f - (Rand.RangeSeeded(6f, 9f, 4) * distD / mapSize)) + Rand.RangeSeeded(15f, 20f, 4) * noiseB.GetValue(current)); switch (islandNumber) { case int temp when temp >= 5: addition += Math.Max(0, 20 * (1f - (Rand.RangeSeeded(9f, 12f, 5) * distE / mapSize)) + Rand.RangeSeeded(15f, 20f, 5) * noiseB.GetValue(current)); break; case 5: addition += Math.Max(0, 20 * (1f - (Rand.RangeSeeded(6f, 9f, 6) * distF / mapSize)) + Rand.RangeSeeded(15f, 20f, 6) * noiseB.GetValue(current)); break; } fertility[current] += addition; } }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vector = start.ToVector3Shifted(); IntVec3 intVec = start; float num = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; bool flag = false; bool flag2 = false; if (visited == null) { visited = new HashSet <IntVec3>(); } tmpGroupSet.Clear(); tmpGroupSet.AddRange(group); int num2 = 0; while (true) { if (closed) { int num3 = GenRadial.NumCellsInRadius(width / 2f + 1.5f); for (int i = 0; i < num3; i++) { IntVec3 intVec2 = intVec + GenRadial.RadialPattern[i]; if (!visited.Contains(intVec2) && (!tmpGroupSet.Contains(intVec2) || caves[intVec2] > 0f)) { return; } } } if (num2 >= 15) { float num4 = width; FloatRange branchedTunnelWidthOffset = BranchedTunnelWidthOffset; if (num4 > 1.4f + branchedTunnelWidthOffset.max) { if (!flag && Rand.Chance(0.1f)) { DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(0.1f)) { DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } } } SetCaveAround(intVec, width, map, visited, out bool hitAnotherTunnel); if (hitAnotherTunnel) { break; } while (vector.ToIntVec3() == intVec) { vector += Vector3Utility.FromAngleFlat(dir) * 0.5f; num += 0.5f; } if (!tmpGroupSet.Contains(vector.ToIntVec3())) { break; } int x = intVec.x; IntVec3 intVec3 = vector.ToIntVec3(); IntVec3 intVec4 = new IntVec3(x, 0, intVec3.z); if (IsRock(intVec4, elevation, map)) { caves[intVec4] = Mathf.Max(caves[intVec4], width); visited.Add(intVec4); } intVec = vector.ToIntVec3(); dir += (float)directionNoise.GetValue((double)(num * 60f), (double)((float)start.x * 200f), (double)((float)start.z * 200f)) * 8f; width -= 0.034f; if (width < 1.4f) { break; } num2++; } }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, BranchType branchType, int depth, HashSet <IntVec3> visited = null) { Vector3 vector = start.ToVector3Shifted(); IntVec3 digCell = start; float currTunnelLength = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; int stepBranchLeft = 0; int stepBranchRight = 0; float widthOffsetPerCell = Rand.Range(extCaves.widthOffsetPerCellMin, extCaves.widthOffsetPerCellMax); if (visited == null) { visited = new HashSet <IntVec3>(); } tmpGroupSet.Clear(); tmpGroupSet.AddRange(group); int step = 0; while (true) { // Check for branching if (branchType == BranchType.Normal) { if (step - stepBranchLeft >= extCaves.allowBranchingAfterSteps && Rand.Chance(extCaves.branchChance)) { BranchType newBranchType = RandomBranchTypeByChance(); float newWidth = CalculateBranchWidth(branchType, width); if (newWidth > extCaves.minTunnelWidth) { DigInBestDirection(digCell, dir, new FloatRange(-90f, -40f), newWidth, group, map, newBranchType, depth, visited); stepBranchLeft = step; } } if (step - stepBranchRight >= extCaves.allowBranchingAfterSteps && Rand.Chance(extCaves.branchChance)) { BranchType newBranchType = RandomBranchTypeByChance(); float newWidth = CalculateBranchWidth(branchType, width); if (newWidth > extCaves.minTunnelWidth) { DigInBestDirection(digCell, dir, new FloatRange(40f, 90f), newWidth, group, map, newBranchType, depth, visited); stepBranchRight = step; } } } // Set cave and go further bool hitAnotherTunnel; SetCaveAround(digCell, width, map, visited, out hitAnotherTunnel); if (hitAnotherTunnel) { // Stop digging when stuck on another tunnel return; } // Stop if cave is too long if (branchType == BranchType.Room && step >= extCaves.branchRoomMaxLength) { return; } // Move temp dig cell forward until on another cell while (vector.ToIntVec3() == digCell) { vector += Vector3Utility.FromAngleFlat(dir) * 0.5f; currTunnelLength += 0.5f; } IntVec3 nextDigCell = vector.ToIntVec3(); if (!tmpGroupSet.Contains(nextDigCell)) { // Stop digging if new cell is outside of the rock area return; } // Copy to a new IntVec3 to not just store a reference to the other one in visited IntVec3 visitedCell = new IntVec3(digCell.x, 0, nextDigCell.z); if (IsRock(visitedCell, elevation, map)) { caves[visitedCell] = Math.Max(caves[visitedCell], width); visited.Add(visitedCell); } // Make tunnel smaller for next step if (branchType == BranchType.Tunnel) { width -= widthOffsetPerCell * extCaves.widthOffsetPerCellTunnelFactor; } else { width -= widthOffsetPerCell; } if (width < extCaves.minTunnelWidth) { // Stop digging if tunnel becomes too small return; } digCell = nextDigCell; dir += (float)directionNoise.GetValue(currTunnelLength * 60f, (float)start.x * 200f, (float)start.z * 200f) * extCaves.directionChangeSpeed; step++; } }
public override void Generate(Map map, GenStepParams parms) { IntVec3 mapCenter = map.Center; MapGenFloatGrid Elevation = MapGenerator.Elevation; float mapSize = map.Size.x; IntRange distRange = new IntRange(30, 60); distRange.min = (int)(0.18 * map.Size.x); distRange.max = (int)(0.30 * map.Size.x); int seed = (int)Rand.Value; float angle = Rand.RangeSeeded(0f, 360f, seed); Log.Message("angle = " + angle); float angle2 = angle; switch (angle) { case float temp when temp > 180: angle2 -= 180; break; case float temp when temp < 180: angle2 += 180; break; default: angle2 = 0; break; } Log.Message("angle2 = " + angle2); IntVec3 centerA = mapCenter + (0 * Vector3Utility.FromAngleFlat(angle)).ToIntVec3(); IntVec3 centerB = mapCenter + ((mapSize * 0.1f) * Vector3Utility.FromAngleFlat(angle)).ToIntVec3(); IntVec3 centerC = mapCenter + ((mapSize * 0.2f) * Vector3Utility.FromAngleFlat(angle)).ToIntVec3(); IntVec3 centerD = mapCenter + ((mapSize * 0.3f) * Vector3Utility.FromAngleFlat(angle)).ToIntVec3(); IntVec3 centerE = mapCenter + ((mapSize * 0.4f) * Vector3Utility.FromAngleFlat(angle)).ToIntVec3(); IntVec3 centerF = mapCenter + ((mapSize * 0.5f) * Vector3Utility.FromAngleFlat(angle)).ToIntVec3(); IntVec3 centerG = mapCenter + ((mapSize * 0.1f) * Vector3Utility.FromAngleFlat(angle2)).ToIntVec3(); IntVec3 centerH = mapCenter + ((mapSize * 0.2f) * Vector3Utility.FromAngleFlat(angle2)).ToIntVec3(); IntVec3 centerI = mapCenter + ((mapSize * 0.3f) * Vector3Utility.FromAngleFlat(angle2)).ToIntVec3(); IntVec3 centerJ = mapCenter + ((mapSize * 0.4f) * Vector3Utility.FromAngleFlat(angle2)).ToIntVec3(); IntVec3 centerK = mapCenter + ((mapSize * 0.5f) * Vector3Utility.FromAngleFlat(angle2)).ToIntVec3(); ModuleBase noiseA = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High); ModuleBase noiseB = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High); float noisinessCenter = Rand.Range(5f, 5f); float noisinessEdges = Rand.Range(2f, 2f); float size = Rand.Range(6f, 8f); foreach (IntVec3 cell in map.AllCells) { Elevation[cell] = 4f * (noiseA.GetValue(cell) + 0.5f); float distCenter = (float)Math.Sqrt(Math.Pow(cell.x - mapCenter.x, 2) + Math.Pow(cell.z - mapCenter.z, 2)); float distA = (float)Math.Sqrt(Math.Pow(cell.x - centerA.x, 2) + Math.Pow(cell.z - centerA.z, 2)); float distB = (float)Math.Sqrt(Math.Pow(cell.x - centerB.x, 2) + Math.Pow(cell.z - centerB.z, 2)); float distC = (float)Math.Sqrt(Math.Pow(cell.x - centerC.x, 2) + Math.Pow(cell.z - centerC.z, 2)); float distD = (float)Math.Sqrt(Math.Pow(cell.x - centerD.x, 2) + Math.Pow(cell.z - centerD.z, 2)); float distE = (float)Math.Sqrt(Math.Pow(cell.x - centerE.x, 2) + Math.Pow(cell.z - centerE.z, 2)); float distF = (float)Math.Sqrt(Math.Pow(cell.x - centerF.x, 2) + Math.Pow(cell.z - centerF.z, 2)); float distG = (float)Math.Sqrt(Math.Pow(cell.x - centerG.x, 2) + Math.Pow(cell.z - centerA.z, 2)); float distH = (float)Math.Sqrt(Math.Pow(cell.x - centerH.x, 2) + Math.Pow(cell.z - centerB.z, 2)); float distI = (float)Math.Sqrt(Math.Pow(cell.x - centerI.x, 2) + Math.Pow(cell.z - centerC.z, 2)); float distJ = (float)Math.Sqrt(Math.Pow(cell.x - centerJ.x, 2) + Math.Pow(cell.z - centerD.z, 2)); float distK = (float)Math.Sqrt(Math.Pow(cell.x - centerK.x, 2) + Math.Pow(cell.z - centerE.z, 2)); float valleysection = 0; valleysection += Math.Max(0, 20 * (1f - (size * distCenter / mapSize)) + noisinessCenter * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distA / mapSize)) + noisinessCenter * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distB / mapSize)) + noisinessCenter * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distC / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distD / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distE / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distF / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distG / mapSize)) + noisinessCenter * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distH / mapSize)) + noisinessCenter * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distI / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distJ / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); valleysection += Math.Max(0, 20 * (1f - (size * distK / mapSize)) + noisinessEdges * noiseB.GetValue(cell)); Elevation[cell] -= valleysection; } }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vect = start.ToVector3Shifted(); IntVec3 intVec = start; float num = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; bool flag = false; bool flag2 = false; if (visited == null) { visited = new HashSet <IntVec3>(); } tmpGroupSet.Clear(); tmpGroupSet.AddRange(group); int num2 = 0; while (true) { if (closed) { int num3 = GenRadial.NumCellsInRadius(width / 2f + 1.5f); for (int i = 0; i < num3; i++) { IntVec3 intVec2 = intVec + GenRadial.RadialPattern[i]; if (!visited.Contains(intVec2) && (!tmpGroupSet.Contains(intVec2) || caves[intVec2] > 0f)) { return; } } } if (num2 >= AllowBranchingAfterThisManyCells && width > MinTunnelWidth + BranchedTunnelWidthOffset.max) { if (!flag && Rand.Chance(BranchChance)) { DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(BranchChance)) { DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } } SetCaveAround(intVec, width, map, visited, out bool hitAnotherTunnel); if (hitAnotherTunnel) { break; } while (vect.ToIntVec3() == intVec) { vect += Vector3Utility.FromAngleFlat(dir) * 0.5f; num += 0.5f; } if (!tmpGroupSet.Contains(vect.ToIntVec3())) { break; } IntVec3 intVec3 = new IntVec3(intVec.x, 0, vect.ToIntVec3().z); if (IsRock(intVec3, elevation, map)) { caves[intVec3] = Mathf.Max(caves[intVec3], width); visited.Add(intVec3); } intVec = vect.ToIntVec3(); dir += (float)directionNoise.GetValue(num * 60f, (float)start.x * 200f, (float)start.z * 200f) * DirectionChangeSpeed; width -= WidthOffsetPerCell; if (!(width < MinTunnelWidth)) { num2++; continue; } break; } }
public override void Generate(Map map, GenStepParams parms) { IntVec3 mapCenter = map.Center; MapGenFloatGrid fertility = MapGenerator.Fertility; float mapSize = map.Size.x; IntRange distRange = new IntRange(3, 10); distRange.min = (int)(0.18 * map.Size.x); distRange.max = (int)(0.30 * map.Size.x); float angleA = Rand.Range(10f, 120f); float angleB = angleA + Rand.Range(60f, 120f); float angleC = angleB + Rand.Range(60f, 120f); float angleD = angleC + Rand.Range(60f, 120); float angleE = angleD + Rand.Range(60f, 120); float angleF = angleE + Rand.Range(60f, 120); IntVec3 centerA = mapCenter + (distRange.RandomInRange * Vector3Utility.FromAngleFlat(angleA)).ToIntVec3(); IntVec3 centerB = mapCenter + (distRange.RandomInRange * 0.2f * Vector3Utility.FromAngleFlat(angleB)).ToIntVec3(); IntVec3 centerC = mapCenter + (distRange.RandomInRange * 0.8f * Vector3Utility.FromAngleFlat(angleC)).ToIntVec3(); IntVec3 centerD = mapCenter + (distRange.RandomInRange * Vector3Utility.FromAngleFlat(angleD)).ToIntVec3(); IntVec3 centerE = mapCenter + (distRange.RandomInRange * 0.2f * Vector3Utility.FromAngleFlat(angleE)).ToIntVec3(); IntVec3 centerF = mapCenter + (distRange.RandomInRange * 1f * Vector3Utility.FromAngleFlat(angleF)).ToIntVec3(); ModuleBase noiseA = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High); ModuleBase noiseB = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High); float noisiness = Rand.Range(25f, 35f); // original size = 4f float sizeA = Rand.Range(7.5f, 0.5f); // smaller on average float sizeB = Rand.Range(5f, 7f); // bigger on average int islandNumber = Rand.Range(4, 6); foreach (IntVec3 current in map.AllCells) { float distA = (float)Math.Sqrt(Math.Pow(current.x - centerA.x, 2) + Math.Pow(current.z - centerA.z, 2)); float distB = (float)Math.Sqrt(Math.Pow(current.x - centerB.x, 2) + Math.Pow(current.z - centerB.z, 2)); float distC = (float)Math.Sqrt(Math.Pow(current.x - centerC.x, 2) + Math.Pow(current.z - centerC.z, 2)); float distD = (float)Math.Sqrt(Math.Pow(current.x - centerD.x, 2) + Math.Pow(current.z - centerD.z, 2)); float distE = (float)Math.Sqrt(Math.Pow(current.x - centerE.x, 2) + Math.Pow(current.z - centerE.z, 2)); float distF = (float)Math.Sqrt(Math.Pow(current.x - centerF.x, 2) + Math.Pow(current.z - centerF.z, 2)); // island A float addition = Math.Max(0, 20 * (1f - (sizeA * distA / mapSize)) + noisiness * noiseA.GetValue(current)); // island B addition += Math.Max(0, 20 * (1f - (sizeB * distB / mapSize)) + noisiness * noiseA.GetValue(current)); // island C addition += Math.Max(0, 20 * (1f - (sizeB * distC / mapSize)) + noisiness * noiseB.GetValue(current)); // island D addition += Math.Max(0, 20 * (1f - (sizeA * distD / mapSize)) + noisiness * noiseB.GetValue(current)); switch (islandNumber) { case int temp when temp >= 5: addition += Math.Max(0, 20 * (1f - (sizeA * distE / mapSize)) + noisiness * noiseB.GetValue(current)); break; case 5: addition += Math.Max(0, 20 * (1f - (sizeB * distF / mapSize)) + noisiness * noiseB.GetValue(current)); break; } fertility[current] += addition; } }