Added BiomeToString() API function.
This commit is contained in:
parent
e39f2a21d5
commit
5d33ce226f
@ -7,29 +7,13 @@
|
|||||||
#include "BiomeDef.h"
|
#include "BiomeDef.h"
|
||||||
|
|
||||||
|
|
||||||
EMCSBiome StringToBiome(const AString & a_BiomeString)
|
|
||||||
{
|
|
||||||
// If it is a number, return it:
|
|
||||||
int res = atoi(a_BiomeString.c_str());
|
|
||||||
if ((res != 0) || (a_BiomeString.compare("0") == 0))
|
|
||||||
{
|
|
||||||
if ((res >= biFirstBiome) && (res < biNumBiomes))
|
|
||||||
{
|
|
||||||
return (EMCSBiome)res;
|
|
||||||
}
|
|
||||||
else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes))
|
|
||||||
{
|
|
||||||
return (EMCSBiome)res;
|
|
||||||
}
|
|
||||||
// It was an invalid number
|
|
||||||
return biInvalidBiome;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert using the built-in map:
|
|
||||||
|
// The "map" used for biome <-> string conversions:
|
||||||
static struct {
|
static struct {
|
||||||
EMCSBiome m_Biome;
|
EMCSBiome m_Biome;
|
||||||
const char * m_String;
|
const char * m_String;
|
||||||
} BiomeMap[] =
|
} g_BiomeMap[] =
|
||||||
{
|
{
|
||||||
{biOcean, "Ocean"} ,
|
{biOcean, "Ocean"} ,
|
||||||
{biPlains, "Plains"},
|
{biPlains, "Plains"},
|
||||||
@ -101,11 +85,33 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
|
|||||||
{biMesaPlateauM, "MesaPlateauM"},
|
{biMesaPlateauM, "MesaPlateauM"},
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
for (size_t i = 0; i < ARRAYCOUNT(BiomeMap); i++)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EMCSBiome StringToBiome(const AString & a_BiomeString)
|
||||||
{
|
{
|
||||||
if (NoCaseCompare(BiomeMap[i].m_String, a_BiomeString) == 0)
|
// If it is a number, return it:
|
||||||
|
int res = atoi(a_BiomeString.c_str());
|
||||||
|
if ((res != 0) || (a_BiomeString.compare("0") == 0))
|
||||||
{
|
{
|
||||||
return BiomeMap[i].m_Biome;
|
if ((res >= biFirstBiome) && (res < biNumBiomes))
|
||||||
|
{
|
||||||
|
return (EMCSBiome)res;
|
||||||
|
}
|
||||||
|
else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes))
|
||||||
|
{
|
||||||
|
return (EMCSBiome)res;
|
||||||
|
}
|
||||||
|
// It was an invalid number
|
||||||
|
return biInvalidBiome;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
|
||||||
|
{
|
||||||
|
if (NoCaseCompare(g_BiomeMap[i].m_String, a_BiomeString) == 0)
|
||||||
|
{
|
||||||
|
return g_BiomeMap[i].m_Biome;
|
||||||
}
|
}
|
||||||
} // for i - BiomeMap[]
|
} // for i - BiomeMap[]
|
||||||
return biInvalidBiome;
|
return biInvalidBiome;
|
||||||
@ -115,6 +121,22 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AString BiomeToString(int a_Biome)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
|
||||||
|
{
|
||||||
|
if (g_BiomeMap[i].m_Biome == a_Biome)
|
||||||
|
{
|
||||||
|
return g_BiomeMap[i].m_String;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool IsBiomeNoDownfall(EMCSBiome a_Biome)
|
bool IsBiomeNoDownfall(EMCSBiome a_Biome)
|
||||||
{
|
{
|
||||||
switch (a_Biome)
|
switch (a_Biome)
|
||||||
|
@ -104,10 +104,13 @@ enum EMCSBiome
|
|||||||
biMaxVariantBiome = biNumVariantBiomes - 1, // The maximum biome value
|
biMaxVariantBiome = biNumVariantBiomes - 1, // The maximum biome value
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure.
|
/** Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. */
|
||||||
extern EMCSBiome StringToBiome(const AString & a_BiomeString);
|
extern EMCSBiome StringToBiome(const AString & a_BiomeString);
|
||||||
|
|
||||||
/// Returns true if the biome has no downfall - deserts and savannas
|
/** Translates biome enum into biome string. Returns empty string on failure (unknown biome). */
|
||||||
|
extern AString BiomeToString(int a_Biome);
|
||||||
|
|
||||||
|
/** Returns true if the biome has no downfall - deserts and savannas */
|
||||||
extern bool IsBiomeNoDownfall(EMCSBiome a_Biome);
|
extern bool IsBiomeNoDownfall(EMCSBiome a_Biome);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user