9 #include "../BlockInfo.h"
26 int a_Seed,
size_t a_Size,
27 float a_CenterWidth,
float a_Roughness,
28 float a_FloorHeightEdge1,
float a_FloorHeightEdge2,
float a_FloorHeightCenter,
29 float a_CeilingHeightEdge1,
float a_CeilingHeightEdge2,
float a_CeilingHeightCenter,
30 int a_GridX,
int a_GridZ,
int a_OriginX,
int a_OriginZ
32 Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
38 size_t Max = 2 * a_Size;
42 float Len =
static_cast<float>(a_Size);
43 float Angle =
static_cast<float>(rnd);
44 float OfsX = sinf(Angle) * Len;
45 float OfsZ = cosf(Angle) * Len;
46 m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, a_CeilingHeightEdge1, a_FloorHeightEdge1);
47 m_DefPoints[
Half].Set(
static_cast<float>(a_OriginX),
static_cast<float>(a_OriginZ), a_CenterWidth, a_CeilingHeightCenter, a_FloorHeightCenter);
48 m_DefPoints[Max].Set (a_OriginX + OfsX, a_OriginZ + OfsZ, 1, a_CeilingHeightEdge2, a_FloorHeightEdge2);
67 void Set(
float a_X,
float a_Z,
float a_Radius,
float a_Top,
float a_Bottom)
100 float MidX = (p1.
m_X + p2.
m_X) / 2;
101 float MidZ = (p1.
m_Z + p2.
m_Z) / 2;
107 float dx = p2.
m_X - p1.
m_X;
108 float dz = p2.
m_Z - p1.
m_Z;
119 size_t MidIdx = (a_Idx1 + a_Idx2) / 2;
120 m_DefPoints[MidIdx].Set(MidX, MidZ, MidR, MidT, MidB);
123 if (MidIdx - a_Idx1 > 1)
127 if (a_Idx2 - MidIdx > 1)
141 int NumBlocks = (rnd % 3) + 2;
143 float Val =
static_cast<float>(rnd % 256) / 128.0f - 1.0f;
148 for (
int i = 0; i < NumBlocks; i++)
163 for (sRavineDefPoints::const_iterator itr =
m_DefPoints.begin(), end =
m_DefPoints.end(); itr != end; ++itr)
166 (ceilf (itr->m_X + itr->m_Radius + 2) < BlockStartX) ||
167 (floorf(itr->m_X - itr->m_Radius - 2) > BlockEndX) ||
168 (ceilf (itr->m_Z + itr->m_Radius + 2) < BlockStartZ) ||
169 (floorf(itr->m_Z - itr->m_Radius - 2) > BlockEndZ)
179 float RadiusSq = (itr->m_Radius + 2) * (itr->m_Radius + 2);
180 float DifX = BlockStartX - itr->m_X;
181 float DifZ = BlockStartZ - itr->m_Z;
193 float DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z);
194 if (DistSq > RadiusSq)
200 for (
int y = std::max(
FloorC(itr->m_Bottom), 1); y <= Top; y++)
226 int a_MaxSize,
int a_MinSize,
227 float a_MaxCenterWidth,
float a_MinCenterWidth,
228 float a_MaxRoughness,
float a_MinRoughness,
229 float a_MaxFloorHeightEdge,
float a_MinFloorHeightEdge,
230 float a_MaxFloorHeightCenter,
float a_MinFloorHeightCenter,
231 float a_MaxCeilingHeightEdge,
float a_MinCeilingHeightEdge,
232 float a_MaxCeilingHeightCenter,
float a_MinCeilingHeightCenter,
233 int a_GridSize,
int a_MaxOffset
235 Super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 64),
236 m_MaxSize(a_MaxSize),
237 m_MinSize(a_MinSize),
238 m_MaxCenterWidth(a_MaxCenterWidth),
239 m_MinCenterWidth(a_MinCenterWidth),
240 m_MaxRoughness(a_MaxRoughness),
241 m_MinRoughness(a_MinRoughness),
242 m_MaxFloorHeightEdge(a_MaxFloorHeightEdge),
243 m_MinFloorHeightEdge(a_MinFloorHeightEdge),
244 m_MaxFloorHeightCenter(a_MaxFloorHeightCenter),
245 m_MinFloorHeightCenter(a_MinFloorHeightCenter),
246 m_MaxCeilingHeightEdge(a_MaxCeilingHeightEdge),
247 m_MinCeilingHeightEdge(a_MinCeilingHeightEdge),
248 m_MaxCeilingHeightCenter(a_MaxCeilingHeightCenter),
249 m_MinCeilingHeightCenter(a_MinCeilingHeightCenter)
254 std::swap(a_MinSize, a_MaxSize);
259 LOGWARNING(
"RoughRavines: MaxSize too small, adjusting request from %d to %d", a_MaxSize,
m_MaxSize);
264 LOGWARNING(
"RoughRavines: MinSize too small, adjusting request from %d to %d", a_MinSize,
m_MinSize);
292 Size, CenterWidth, Roughness,
293 FloorHeightEdge1, FloorHeightEdge2, FloorHeightCenter,
294 CeilingHeightEdge1, CeilingHeightEdge2, CeilingHeightCenter,
295 a_GridX, a_GridZ, a_OriginX, a_OriginZ
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
void LOGWARNING(std::string_view a_Format, const Args &... args)
static bool CanBeTerraformed(BLOCKTYPE Block)
Can a finisher change it?
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
int m_Seed
Seed for generating grid offsets and also available for descendants.
cNoise m_Noise
The noise used for generating grid offsets.
Represents a single structure that occupies the grid point.
float m_PerHeightRadius[cChunkDef::Height]
Number to add to the radius based on the height.
sRavineDefPoints m_DefPoints
void InitPerHeightRadius(int a_GridX, int a_GridZ)
void SubdivideLine(size_t a_Idx1, size_t a_Idx2)
Recursively subdivides the line between the points of the specified index.
cRoughRavine(int a_Seed, size_t a_Size, float a_CenterWidth, float a_Roughness, float a_FloorHeightEdge1, float a_FloorHeightEdge2, float a_FloorHeightCenter, float a_CeilingHeightEdge1, float a_CeilingHeightEdge2, float a_CeilingHeightCenter, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ)
virtual void DrawIntoChunk(cChunkDesc &a_ChunkDesc) override
Draws self into the specified chunk.
std::vector< sRavineDefPoint > sRavineDefPoints
void Set(float a_X, float a_Z, float a_Radius, float a_Top, float a_Bottom)
float m_MaxCeilingHeightCenter
Maximum ceiling height at the ravine's center.
cRoughRavines(int a_Seed, int a_MaxSize, int a_MinSize, float a_MaxCenterWidth, float a_MinCenterWidth, float a_MaxRoughness, float a_MinRoughness, float a_MaxFloorHeightEdge, float a_MinFloorHeightEdge, float a_MaxFloorHeightCenter, float a_MinFloorHeightCenter, float a_MaxCeilingHeightEdge, float a_MinCeilingHeightEdge, float a_MaxCeilingHeightCenter, float a_MinCeilingHeightCenter, int a_GridSize, int a_MaxOffset)
float m_MaxFloorHeightEdge
Maximum floor height at the ravine's edge.
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override
Create a new structure at the specified gridpoint.
float m_MinCeilingHeightEdge
Minimum ceiling height at the ravine's edge.
float m_MinCeilingHeightCenter
Minimum ceiling height at the ravine's center.
float m_MaxCenterWidth
Maximum width of the ravine's center, in blocks.
float m_MinFloorHeightEdge
Minimum floor height at the ravine's edge.
float m_MaxFloorHeightCenter
Maximum floor height at the ravine's center.
int m_MaxSize
Maximum size of the ravine, in each of the X / Z axis.
int m_MinSize
Minimum size of the ravine.
float m_MaxRoughness
Maximum roughness of the ravine.
float m_MinRoughness
Minimum roughness of the ravine.
float m_MinFloorHeightCenter
Minimum floor height at the ravine's center.
float m_MaxCeilingHeightEdge
Maximum ceiling height at the ravine's edge.
float m_MinCenterWidth
Minimum width of the ravine's center, in blocks.
int IntNoise2DInt(int a_X, int a_Y) const
NOISE_DATATYPE IntNoise2DInRange(int a_X, int a_Y, float a_Min, float a_Max) const