Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
TerrainContentsGeneratorFlat.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
6
8
10
12
14
16
18
19 public float[] m_shoreRoughnessOffset = new float[4];
20
21 public int OceanLevel => m_worldSettings.TerrainLevel + m_worldSettings.SeaLevelOffset;
22
24 m_subsystemTerrain = subsystemTerrain;
25 SubsystemGameInfo subsystemGameInfo = subsystemTerrain.Project.FindSubsystem<SubsystemGameInfo>(true);
26 m_worldSettings = subsystemGameInfo.WorldSettings;
27 m_oceanCorner = string.CompareOrdinal(subsystemGameInfo.WorldSettings.OriginalSerializationVersion, "2.1") < 0
28 ? m_oceanCorner = new Vector2(2001f, 2001f)
29 : m_oceanCorner = new Vector2(-199f, -199f);
30 m_islandSize = m_worldSettings.TerrainGenerationMode == TerrainGenerationMode.FlatIsland
31 ? new Vector2?(m_worldSettings.IslandSize)
32 : null;
33 m_shoreRoughnessAmplitude.X = MathF.Pow(m_worldSettings.ShoreRoughness, 2f)
34 * (m_islandSize.HasValue ? Math.Min(4f * m_islandSize.Value.X, 400f) : 400f);
35 m_shoreRoughnessAmplitude.Y = MathF.Pow(m_worldSettings.ShoreRoughness, 2f)
36 * (m_islandSize.HasValue ? Math.Min(4f * m_islandSize.Value.Y, 400f) : 400f);
38 m_shoreRoughnessOctaves.X = (int)Math.Clamp(MathF.Log(1f / m_shoreRoughnessFrequency.X) / MathF.Log(2f) - 1f, 1f, 7f);
39 m_shoreRoughnessOctaves.Y = (int)Math.Clamp(MathF.Log(1f / m_shoreRoughnessFrequency.Y) / MathF.Log(2f) - 1f, 1f, 7f);
40 Random random = new(subsystemGameInfo.WorldSeed);
41 m_shoreRoughnessOffset[0] = random.Float(-2000f, 2000f);
42 m_shoreRoughnessOffset[1] = random.Float(-2000f, 2000f);
43 m_shoreRoughnessOffset[2] = random.Float(-2000f, 2000f);
44 m_shoreRoughnessOffset[3] = random.Float(-2000f, 2000f);
45 }
46
48 for (int i = -400; i <= 400; i += 10) {
49 for (int j = -400; j <= 400; j += 10) {
50 Vector2 vector = m_oceanCorner + new Vector2(i, j);
51 float num = CalculateOceanShoreDistance(vector.X, vector.Y);
52 if (num >= 1f
53 && num <= 20f) {
54 return new Vector3(vector.X, CalculateHeight(vector.X, vector.Y), vector.Y);
55 }
56 }
57 }
59 }
60
62 for (int i = 0; i < TerrainChunk.Size; i++) {
63 for (int j = 0; j < TerrainChunk.Size; j++) {
64 int num = i + chunk.Origin.X;
65 int num2 = j + chunk.Origin.Y;
66 chunk.SetTemperatureFast(i, j, CalculateTemperature(num, num2));
67 chunk.SetHumidityFast(i, j, CalculateHumidity(num, num2));
68 bool flag = CalculateOceanShoreDistance(num, num2) >= 0f;
69 int num3 = TerrainChunk.CalculateCellIndex(i, 0, j);
70 for (int k = 0; k < TerrainChunk.Height; k++) {
71 int value = Terrain.MakeBlockValue(0);
72 if (flag) {
73 if (k < 2
74 && m_worldSettings.TerrainLevel > 0) {
75 value = Terrain.MakeBlockValue(1);
76 }
77 else if (k < m_worldSettings.TerrainLevel) {
78 value = Terrain.MakeBlockValue(m_worldSettings.TerrainBlockIndex == 8 ? 2 : m_worldSettings.TerrainBlockIndex);
79 }
80 else if (k == m_worldSettings.TerrainLevel) {
81 value = Terrain.MakeBlockValue(m_worldSettings.TerrainBlockIndex);
82 }
83 else if (k <= OceanLevel) {
84 value = Terrain.MakeBlockValue(m_worldSettings.TerrainOceanBlockIndex);
85 }
86 }
87 else if (k < 2
88 && m_worldSettings.TerrainLevel > 0) {
89 value = Terrain.MakeBlockValue(1);
90 }
91 else if (k <= OceanLevel) {
92 value = Terrain.MakeBlockValue(m_worldSettings.TerrainOceanBlockIndex);
93 }
94 chunk.SetCellValueFast(num3 + k, value);
95 }
96 }
97 }
98 }
99
101 UpdateFluidIsTop(chunk);
102 }
103
105
107
108 public float CalculateOceanShoreDistance(float x, float z) {
109 float x2 = 0f;
110 float x3 = 0f;
111 float y = 0f;
112 float y2 = 0f;
113 if (m_shoreRoughnessAmplitude.X > 0f) {
114 x2 = m_shoreRoughnessAmplitude.X
116 x3 = m_shoreRoughnessAmplitude.X
118 }
119 if (m_shoreRoughnessAmplitude.Y > 0f) {
120 y = m_shoreRoughnessAmplitude.Y
122 y2 = m_shoreRoughnessAmplitude.Y
124 }
125 Vector2 vector = m_oceanCorner + new Vector2(x2, y);
126 Vector2 vector2 = m_oceanCorner + (m_islandSize ?? new Vector2(3.40282347E+38f)) + new Vector2(x3, y2);
127 return MathUtils.Min(x - vector.X, vector2.X - x, z - vector.Y, vector2.Y - z);
128 }
129
130 public float CalculateHeight(float x, float z) => m_worldSettings.TerrainLevel;
131
132 public int CalculateTemperature(float x, float z) => Math.Clamp(12 + (int)m_worldSettings.TemperatureOffset, 0, 15);
133
134 public int CalculateHumidity(float x, float z) => Math.Clamp(12 + (int)m_worldSettings.HumidityOffset, 0, 15);
135
136 public float CalculateMountainRangeFactor(float x, float z) => 0f;
137
138 public virtual void UpdateFluidIsTop(TerrainChunk chunk) {
139 _ = m_subsystemTerrain.Terrain;
140 for (int i = 0; i < TerrainChunk.Size; i++) {
141 for (int j = 0; j < TerrainChunk.Size; j++) {
143 int num2 = 0;
144 int num3 = TerrainChunk.HeightMinusOne;
145 while (num3 >= 0) {
146 int cellValueFast = chunk.GetCellValueFast(num);
147 int num4 = Terrain.ExtractContents(cellValueFast);
148 if (num4 != 0
149 && num4 != num2
150 && BlocksManager.Blocks[num4] is FluidBlock) {
151 int data = Terrain.ExtractData(cellValueFast);
152 chunk.SetCellValueFast(num, Terrain.MakeBlockValue(num4, 0, FluidBlock.SetIsTop(data, true)));
153 }
154 num2 = num4;
155 num3--;
156 num--;
157 }
158 }
159 }
160 }
161 }
162}
Engine.Vector3 Vector3
static int Min(int x1, int x2)
static float Lerp(float x1, float x2, float f)
static int SetIsTop(int data, bool isTop)
float Float()
static float OctavedNoise(float x, float frequency, int octaves, float frequencyStep, float amplitudeStep, bool ridged=false)
static int CalculateCellIndex(int x, int y, int z)
virtual int GetCellValueFast(int index)
virtual void SetCellValueFast(int x, int y, int z, int value)
virtual void SetHumidityFast(int x, int z, int humidity)
virtual void SetTemperatureFast(int x, int z, int temperature)
TerrainContentsGeneratorFlat(SubsystemTerrain subsystemTerrain)
static int ExtractContents(int value)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
virtual Subsystem FindSubsystem(Type type, string name, bool throwOnError)