26 cRavDefPoint(
int a_BlockX,
int a_BlockZ,
int a_Radius,
int a_Top,
int a_Bottom) :
64 cRavine(
int a_GridX,
int a_GridZ,
int a_OriginX,
int a_OriginZ,
int a_Size,
cNoise & a_Noise);
84 Super(a_Seed, a_Size, a_Size, a_Size, a_Size, a_Size * 2, a_Size * 2, 100),
106 Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ)
126 a_Size = (512 + ((a_Noise.
IntNoise3DInt(19 * a_BlockX, 11 * a_BlockZ, a_BlockX + a_BlockZ) / 17) % 512)) * a_Size / 1024;
129 int OffsetX = (((a_Noise.
IntNoise3DInt(50 * a_BlockX, 30 * a_BlockZ, 0) / 9) % (2 * a_Size)) + ((a_Noise.
IntNoise3DInt(30 * a_BlockX, 50 * a_BlockZ, 1000) / 7) % (2 * a_Size)) - 2 * a_Size) / 2;
130 int OffsetZ = (((a_Noise.
IntNoise3DInt(50 * a_BlockX, 30 * a_BlockZ, 2000) / 7) % (2 * a_Size)) + ((a_Noise.
IntNoise3DInt(30 * a_BlockX, 50 * a_BlockZ, 3000) / 9) % (2 * a_Size)) - 2 * a_Size) / 2;
131 int CenterX = a_BlockX + OffsetX;
132 int CenterZ = a_BlockZ + OffsetZ;
135 float Angle =
static_cast<float>((
static_cast<float>((a_Noise.
IntNoise3DInt(20 * a_BlockX, 70 * a_BlockZ, 6000) / 9) % 16384)) / 16384.0 * M_PI);
136 float xc = sinf(Angle);
137 float zc = cosf(Angle);
140 int MaxRadius =
static_cast<int>(sqrt(12.0 + ((a_Noise.
IntNoise2DInt(61 * a_BlockX, 97 * a_BlockZ) / 13) % a_Size) / 16));
141 int Top = 32 + ((a_Noise.
IntNoise2DInt(13 * a_BlockX, 17 * a_BlockZ) / 23) % 32);
143 int Mid = (Top +
Bottom) / 2;
144 int DefinitionPointX = CenterX -
static_cast<int>(xc * a_Size / 2);
145 int DefinitionPointZ = CenterZ -
static_cast<int>(zc * a_Size / 2);
146 m_Points.emplace_back(DefinitionPointX, DefinitionPointZ, 0, (Mid + Top) / 2, (Mid +
Bottom) / 2);
152 int Amplitude = (a_Noise.
IntNoise3DInt(70 * a_BlockX, 20 * a_BlockZ + 31 * i, 10000 * i) / 9) % a_Size;
153 Amplitude = Amplitude / 4 - a_Size / 8;
154 int PointX = LineX +
static_cast<int>(zc * Amplitude);
155 int PointZ = LineZ -
static_cast<int>(xc * Amplitude);
157 int ThisTop = Top + ((a_Noise.
IntNoise3DInt(7 * a_BlockX, 19 * a_BlockZ, i * 31) / 13) % 8) - 4;
158 int ThisBottom =
Bottom + ((a_Noise.
IntNoise3DInt(19 * a_BlockX, 7 * a_BlockZ, i * 31) / 13) % 8) - 4;
159 m_Points.emplace_back(PointX, PointZ, Radius, ThisTop, ThisBottom);
161 DefinitionPointX = CenterX +
static_cast<int>(xc * a_Size / 2);
162 DefinitionPointZ = CenterZ +
static_cast<int>(zc * a_Size / 2);
163 m_Points.emplace_back(DefinitionPointX, DefinitionPointZ, 0, Mid, Mid);
172 if (a_Src.size() < 2)
179 size_t Num = a_Src.size() - 2;
181 a_Dst.reserve(Num * 2 + 2);
182 cRavDefPoints::const_iterator itr = a_Src.begin() + 1;
184 a_Dst.push_back(Source);
188 int PrevT = Source.
m_Top;
190 for (
size_t i = 0; i <= Num; ++i, ++itr)
192 int dx = itr->m_BlockX - PrevX;
193 int dz = itr->m_BlockZ - PrevZ;
194 if (abs(dx) + abs(dz) < 4)
199 int dr = itr->m_Radius - PrevR;
200 int dt = itr->m_Top - PrevT;
201 int db = itr->m_Bottom - PrevB;
202 int Rad1 = std::max(PrevR + 1 * dr / 4, 1);
203 int Rad2 = std::max(PrevR + 3 * dr / 4, 1);
204 a_Dst.emplace_back(PrevX + 1 * dx / 4, PrevZ + 1 * dz / 4, Rad1, PrevT + 1 * dt / 4, PrevB + 1 * db / 4);
205 a_Dst.emplace_back(PrevX + 3 * dx / 4, PrevZ + 3 * dz / 4, Rad2, PrevT + 3 * dt / 4, PrevB + 3 * db / 4);
206 PrevX = itr->m_BlockX;
207 PrevZ = itr->m_BlockZ;
208 PrevR = itr->m_Radius;
210 PrevB = itr->m_Bottom;
212 a_Dst.push_back(a_Src.back());
222 RefineDefPoints(m_Points, Pts);
223 RefineDefPoints(Pts, m_Points);
237 std::swap(Pts, m_Points);
239 m_Points.reserve(Pts.size() * 3);
240 int PrevX = Pts.front().m_BlockX;
241 int PrevZ = Pts.front().m_BlockZ;
242 for (cRavDefPoints::const_iterator itr = Pts.begin() + 1, end = Pts.end(); itr != end; ++itr)
244 int x1 = itr->m_BlockX;
245 int z1 = itr->m_BlockZ;
246 int dx = abs(x1 - PrevX);
247 int dz = abs(z1 - PrevZ);
248 int sx = (PrevX < x1) ? 1 : -1;
249 int sz = (PrevZ < z1) ? 1 : -1;
251 int R = itr->m_Radius;
253 int B = itr->m_Bottom;
256 m_Points.emplace_back(PrevX, PrevZ, R, T, B);
257 if ((PrevX == x1) && (PrevZ == z1))
283 auto SVG = fmt::format(FMT_STRING(
"<path style=\"fill:none;stroke:#{:06x};stroke-width:1px;\"\nd=\""), a_Color);
285 for (cRavDefPoints::const_iterator itr = m_Points.begin(); itr != m_Points.end(); ++itr)
287 SVG.append(fmt::format(FMT_STRING(
"{} {}, {} "), Prefix, a_OffsetX + itr->m_BlockX, a_OffsetZ + itr->m_BlockZ));
290 SVG.append(
"\"/>\n");
293 SVG.append(fmt::format(FMT_STRING(
"<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"),
294 a_OffsetX + m_OriginX - 5, a_OffsetZ + m_OriginZ, a_OffsetX + m_OriginX + 5, a_OffsetZ + m_OriginZ
296 SVG.append(fmt::format(FMT_STRING(
"<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"),
297 a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ - 5, a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ + 5
301 SVG.append(fmt::format(FMT_STRING(
"<path style=\"fill:none;stroke:#cfcfcf;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"),
302 a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ, a_OffsetX + m_Points.front().m_BlockX, a_OffsetZ + m_Points.front().m_BlockZ
308 SVG.append(fmt::format(FMT_STRING(
"<path style=\"fill:none;stroke:#0000ff;stroke-width:1px;\"\nd=\"M {}, 0 L {}, 1024\"/>\n"),
314 SVG.append(fmt::format(FMT_STRING(
"<path style=\"fill:none;stroke:#0000ff;stroke-width:1px;\"\nd=\"M 0, {} L 1024, {}\"/>\n"),
332 for (cRavDefPoints::const_iterator itr = m_Points.begin(), end = m_Points.end(); itr != end; ++itr)
335 (itr->m_BlockX + itr->m_Radius < BlockStartX) ||
336 (itr->m_BlockX - itr->m_Radius > BlockEndX) ||
337 (itr->m_BlockZ + itr->m_Radius < BlockStartZ) ||
338 (itr->m_BlockZ - itr->m_Radius > BlockEndZ)
346 int RadiusSq = itr->m_Radius * itr->m_Radius;
347 int DifX = BlockStartX - itr->m_BlockX;
348 int DifZ = BlockStartZ - itr->m_BlockZ;
353 if ((DifX + x == 0) && (DifZ + z == 0))
359 int DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z);
360 if (DistSq <= RadiusSq)
363 for (
int y = std::max(itr->m_Bottom, 1); y <= Top; y++)
@ E_BLOCK_REDSTONE_ORE_GLOWING
static const int NUM_RAVINE_POINTS
std::vector< cRavDefPoint > cRavDefPoints
bool Bottom(const BlockState Block)
void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
Generates structures in a semi-random grid.
std::shared_ptr< cStructure > cStructurePtr
cNoise m_Noise
The noise used for generating grid offsets.
Represents a single structure that occupies the grid point.
cRavDefPoint(int a_BlockX, int a_BlockZ, int a_Radius, int a_Top, int a_Bottom)
void Smooth(void)
Does one round of smoothing, two passes of RefineDefPoints()
AString ExportAsSVG(int a_Color, int a_OffsetX=0, int a_OffsetZ=0) const
Exports itself as a SVG line definition.
void GenerateBaseDefPoints(int a_BlockX, int a_BlockZ, int a_Size, cNoise &a_Noise)
Generates the shaping defpoints for the ravine, based on the ravine block coords and noise.
void FinishLinear(void)
Linearly interpolates the points so that the maximum distance between two neighbors is max 1 block.
void RefineDefPoints(const cRavDefPoints &a_Src, cRavDefPoints &a_Dst)
Refines (adds and smooths) defpoints from a_Src into a_Dst.
virtual void DrawIntoChunk(cChunkDesc &a_ChunkDesc) override
Draws self into the specified chunk.
cRavine(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_Size, cNoise &a_Noise)
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override
Create a new structure at the specified gridpoint.
cStructGenRavines(int a_Seed, int a_Size)
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const
int IntNoise2DInt(int a_X, int a_Y) const