DungeonRooms: Added a height probability distribution function.
This commit is contained in:
parent
c6beb9760b
commit
62e1c45ca5
@ -349,7 +349,8 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
|
|||||||
int GridSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsGridSize", 48);
|
int GridSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsGridSize", 48);
|
||||||
int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7);
|
int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7);
|
||||||
int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5);
|
int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5);
|
||||||
m_FinishGens.push_back(new cDungeonRoomsFinisher(*m_HeightGen, Seed, GridSize, MaxSize, MinSize));
|
AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1");
|
||||||
|
m_FinishGens.push_back(new cDungeonRoomsFinisher(*m_HeightGen, Seed, GridSize, MaxSize, MinSize, HeightDistrib));
|
||||||
}
|
}
|
||||||
else if (NoCaseCompare(*itr, "Ice") == 0)
|
else if (NoCaseCompare(*itr, "Ice") == 0)
|
||||||
{
|
{
|
||||||
|
@ -230,12 +230,16 @@ protected:
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// cDungeonRoomsFinisher:
|
// cDungeonRoomsFinisher:
|
||||||
|
|
||||||
cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainHeightGen & a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize) :
|
cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainHeightGen & a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) :
|
||||||
super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024),
|
super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024),
|
||||||
m_HeightGen(a_HeightGen),
|
m_HeightGen(a_HeightGen),
|
||||||
m_MaxHalfSize((a_MaxSize + 1) / 2),
|
m_MaxHalfSize((a_MaxSize + 1) / 2),
|
||||||
m_MinHalfSize((a_MinSize + 1) / 2)
|
m_MinHalfSize((a_MinSize + 1) / 2),
|
||||||
|
m_HeightProbability(cChunkDef::Height)
|
||||||
{
|
{
|
||||||
|
// Initialize the height probability distribution:
|
||||||
|
m_HeightProbability.SetDefString(a_HeightDistrib);
|
||||||
|
|
||||||
// Normalize the min and max size:
|
// Normalize the min and max size:
|
||||||
if (m_MinHalfSize > m_MaxHalfSize)
|
if (m_MinHalfSize > m_MaxHalfSize)
|
||||||
{
|
{
|
||||||
@ -264,7 +268,7 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int
|
|||||||
cChunkDef::HeightMap HeightMap;
|
cChunkDef::HeightMap HeightMap;
|
||||||
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, HeightMap);
|
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, HeightMap);
|
||||||
int Height = cChunkDef::GetHeight(HeightMap, RelX, RelZ); // Max room height at {a_OriginX, a_OriginZ}
|
int Height = cChunkDef::GetHeight(HeightMap, RelX, RelZ); // Max room height at {a_OriginX, a_OriginZ}
|
||||||
Height = 10 + (rnd % std::max(1, (Height - 14)));
|
Height = Clamp(m_HeightProbability.MapValue(rnd % m_HeightProbability.GetSum()), 10, Height - 5);
|
||||||
|
|
||||||
// Create the dungeon room descriptor:
|
// Create the dungeon room descriptor:
|
||||||
return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, Height, m_Noise));
|
return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, Height, m_Noise));
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GridStructGen.h"
|
#include "GridStructGen.h"
|
||||||
|
#include "../ProbabDistrib.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -23,8 +24,9 @@ class cDungeonRoomsFinisher :
|
|||||||
public:
|
public:
|
||||||
/** Creates a new dungeon room finisher.
|
/** Creates a new dungeon room finisher.
|
||||||
a_HeightGen is the underlying height generator, so that the rooms can always be placed under the terrain.
|
a_HeightGen is the underlying height generator, so that the rooms can always be placed under the terrain.
|
||||||
a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across. */
|
a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across.
|
||||||
cDungeonRoomsFinisher(cTerrainHeightGen & a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize);
|
a_HeightDistrib is the string defining the height distribution for the rooms (cProbabDistrib format). */
|
||||||
|
cDungeonRoomsFinisher(cTerrainHeightGen & a_HeightGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -37,6 +39,9 @@ protected:
|
|||||||
/** Minimum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 2 (vanilla). */
|
/** Minimum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 2 (vanilla). */
|
||||||
int m_MinHalfSize;
|
int m_MinHalfSize;
|
||||||
|
|
||||||
|
/** The height probability distribution to make the spawners more common in layers 10 - 40, less common outside this range. */
|
||||||
|
cProbabDistrib m_HeightProbability;
|
||||||
|
|
||||||
|
|
||||||
// cGridStructGen overrides:
|
// cGridStructGen overrides:
|
||||||
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override;
|
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user