1
0

OrePockets finisher is now configurable.

This commit is contained in:
Mattes D 2015-11-25 15:06:32 +01:00
parent f2a8d5c047
commit 326f5e04f7
4 changed files with 126 additions and 25 deletions

View File

@ -332,7 +332,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
} }
else if (NoCaseCompare(*itr, "DirtPockets") == 0) else if (NoCaseCompare(*itr, "DirtPockets") == 0)
{ {
m_FinishGens.push_back(std::make_shared<cFinishGenOrePockets>(Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches())); auto gen = std::make_shared<cFinishGenOrePockets>(Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches());
if (gen->Initialize(a_IniFile, "DirtPockets"))
{
m_FinishGens.push_back(gen);
}
} }
else if (NoCaseCompare(*itr, "DistortedMembraneOverhangs") == 0) else if (NoCaseCompare(*itr, "DistortedMembraneOverhangs") == 0)
{ {
@ -425,7 +429,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
else if (NoCaseCompare(*itr, "OrePockets") == 0) else if (NoCaseCompare(*itr, "OrePockets") == 0)
{ {
auto gen = std::make_shared<cFinishGenOrePockets>(Seed + 2, cFinishGenOrePockets::DefaultOverworldOres()); auto gen = std::make_shared<cFinishGenOrePockets>(Seed + 2, cFinishGenOrePockets::DefaultOverworldOres());
if (gen->Initialize(a_IniFile)) if (gen->Initialize(a_IniFile, "OrePockets"))
{ {
m_FinishGens.push_back(gen); m_FinishGens.push_back(gen);
} }

View File

@ -1441,13 +1441,11 @@ const cFinishGenOres::OreInfos & cFinishGenOres::DefaultOverworldOres(void)
const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNetherOres(void) const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNetherOres(void)
{ {
static OreInfos res; static OreInfos res
if (res.empty())
{ {
// Hasn't been initialized yet, emplace the defaults: // OreType, OreMeta, MaxHeight, NumNests, NestSize
// OreType, OreMeta, MaxHeight, NumNests, NestSize {E_BLOCK_NETHER_QUARTZ_ORE, 0, 127, 20, 8},
res.emplace_back(E_BLOCK_NETHER_QUARTZ_ORE, 0, 127, 20, 8); };
}
return res; return res;
} }
@ -1457,17 +1455,15 @@ const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNetherOres(void)
const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNaturalPatches(void) const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNaturalPatches(void)
{ {
static OreInfos res; static OreInfos res
if (res.empty())
{ {
// Hasn't been initialized yet, emplace the defaults: // OreType, OreMeta, MaxHeight, NumNests, NestSize
// OreType, OreMeta, MaxHeight, NumNests, NestSize {E_BLOCK_DIRT, 0, 127, 20, 32},
res.emplace_back(E_BLOCK_DIRT, 0, 127, 20, 32); {E_BLOCK_GRAVEL, 0, 127, 10, 32},
res.emplace_back(E_BLOCK_GRAVEL, 0, 127, 10, 32); {E_BLOCK_STONE, E_META_STONE_GRANITE, 127, 20, 32},
res.emplace_back(E_BLOCK_STONE, E_META_STONE_GRANITE, 127, 20, 32); {E_BLOCK_STONE, E_META_STONE_DIORITE, 127, 20, 32},
res.emplace_back(E_BLOCK_STONE, E_META_STONE_DIORITE, 127, 20, 32); {E_BLOCK_STONE, E_META_STONE_ANDESITE, 127, 20, 32},
res.emplace_back(E_BLOCK_STONE, E_META_STONE_ANDESITE, 127, 20, 32); };
}
return res; return res;
} }
@ -1475,6 +1471,80 @@ const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNaturalPatches(void)
cFinishGenOres::OreInfos cFinishGenOres::OreInfosFromString(const AString & a_OreInfosString)
{
// The string is expected to be formatted as "<OreInfo1> | <OreInfo2> | <OreInfo3> | ..."
// Each OreInfo is expected to be formatted as "<OreType> : <OreMeta> : <MaxHeight> : <NumNests> : <NestSize>"
OreInfos res;
auto ores = StringSplitAndTrim(a_OreInfosString, "|");
for (const auto & ore: ores)
{
auto parts = StringSplitAndTrim(ore, ":");
if (parts.size() != 5)
{
LOGWARNING("Cannot parse ore information from string, not enough OreInfo members (exp 5, got %d). Offending item: \"%s\".",
static_cast<unsigned>(parts.size()), ore.c_str()
);
continue;
}
auto oreType = BlockStringToType(parts[0]);
if (oreType < 0)
{
LOGWARNING("Cannot parse ore information from string, invalid OreType: \"%s\".", parts[0].c_str());
continue;
}
NIBBLETYPE oreMeta;
int maxHeight, numNests, nestSize;
if (
!StringToInteger(parts[1], oreMeta) ||
!StringToInteger(parts[2], maxHeight) ||
!StringToInteger(parts[3], numNests) ||
!StringToInteger(parts[4], nestSize)
)
{
LOGWARNING("Cannot parse ore information from string, invalid number in OreInfo \"%s\".", ore.c_str());
continue;
}
res.emplace_back(oreType, oreMeta, maxHeight, numNests, nestSize);
} // for i - split[]
return res;
}
AString cFinishGenOres::OreInfosToString(const cFinishGenOres::OreInfos & a_OreInfos)
{
AString res;
for (const auto & ore: a_OreInfos)
{
if (!res.empty())
{
res.append(" | ");
}
AppendPrintf(res, "%s:%d:%d:%d:%d",
ItemTypeToString(ore.m_BlockType).c_str(), ore.m_BlockMeta,
ore.m_MaxHeight, ore.m_NumNests, ore.m_NestSize
);
} // for ore - a_OreInfos[]
return res;
}
void cFinishGenOres::SetSeed(int a_Seed)
{
m_Noise.SetSeed(a_Seed);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cFinishGenOreNests: // cFinishGenOreNests:
@ -1576,9 +1646,25 @@ void cFinishGenOreNests::GenerateOre(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cFinishGenOrePockets: // cFinishGenOrePockets:
bool cFinishGenOrePockets::Initialize(cIniFile & a_IniFile) bool cFinishGenOrePockets::Initialize(cIniFile & a_IniFile, const AString & a_GenName)
{ {
// TODO // Read the OreInfos configuration:
auto valueName = a_GenName + "_blocks";
auto pocketCfg = a_IniFile.GetValue("Generator", valueName, "");
if (pocketCfg.empty())
{
// There's no config currently stored in the INI file. Store the defaults as the config:
a_IniFile.SetValue("Generator", valueName, OreInfosToString(m_OreInfos));
}
else
{
m_OreInfos = OreInfosFromString(pocketCfg);
}
// Read the optional seed configuration (but do not store the default):
valueName = a_GenName + "_seed";
SetSeed(a_IniFile.GetValueI("Generator", valueName, m_Noise.GetSeed()));
return true; return true;
} }

View File

@ -440,7 +440,6 @@ public:
cFinishGenOres(int a_Seed, const OreInfos & a_OreInfos): cFinishGenOres(int a_Seed, const OreInfos & a_OreInfos):
m_Noise(a_Seed), m_Noise(a_Seed),
m_Seed(a_Seed),
m_OreInfos(a_OreInfos) m_OreInfos(a_OreInfos)
{ {
} }
@ -457,13 +456,23 @@ public:
/** Returns a vector of OreInfo structures describing the default Overworld non-ore pockets (dirt, diorite etc), usable in the constructor. */ /** Returns a vector of OreInfo structures describing the default Overworld non-ore pockets (dirt, diorite etc), usable in the constructor. */
static const OreInfos & DefaultNaturalPatches(void); static const OreInfos & DefaultNaturalPatches(void);
/** Parses the parameter string into OreInfos array.
See OreInfosToString() for the complementary function.
Used for loading configuration from INI files. */
static OreInfos OreInfosFromString(const AString & a_OreInfosString);
/** Returns a string that represents the OreInfos given as the parameter.
See OreInfosFromString() for the complementary function.
Used for storing defaults in the INI file. */
static AString OreInfosToString(const OreInfos & a_OreInfos);
/** (Re-)sets the seed used by the internal generating mechanisms. */
void SetSeed(int a_Seed);
protected: protected:
/** The noise used for generating. */ /** The noise used for generating. */
cNoise m_Noise; cNoise m_Noise;
/** The seed for the generating noise. */
int m_Seed;
/** All the ores enabled in this generator. */ /** All the ores enabled in this generator. */
OreInfos m_OreInfos; OreInfos m_OreInfos;
@ -520,8 +529,9 @@ public:
{} {}
/** Reads the configuration from the specified INI file. /** Reads the configuration from the specified INI file.
a_GenName is the name of the generator (this class may be used for OrePockets and DirtPockets, each has a different default).
Returns true on success, false and logs errors to console on failure. */ Returns true on success, false and logs errors to console on failure. */
bool Initialize(cIniFile & a_IniFile); bool Initialize(cIniFile & a_IniFile, const AString & a_GenName);
protected: protected:

View File

@ -49,6 +49,7 @@ public:
NOISE_DATATYPE CubicNoise3D (NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const; NOISE_DATATYPE CubicNoise3D (NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const;
void SetSeed(int a_Seed) { m_Seed = a_Seed; } void SetSeed(int a_Seed) { m_Seed = a_Seed; }
int GetSeed(void) const { return m_Seed; }
inline static NOISE_DATATYPE CubicInterpolate (NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_C, NOISE_DATATYPE a_D, NOISE_DATATYPE a_Pct); inline static NOISE_DATATYPE CubicInterpolate (NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_C, NOISE_DATATYPE a_D, NOISE_DATATYPE a_Pct);
inline static NOISE_DATATYPE CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct); inline static NOISE_DATATYPE CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct);