1
0
Fork 0

Added BiomeToString() API function.

This commit is contained in:
madmaxoft 2014-04-29 15:36:05 +02:00
parent 709ae320e0
commit 015bf244b5
2 changed files with 106 additions and 81 deletions

View File

@ -7,6 +7,88 @@
#include "BiomeDef.h"
// The "map" used for biome <-> string conversions:
static struct {
EMCSBiome m_Biome;
const char * m_String;
} g_BiomeMap[] =
{
{biOcean, "Ocean"} ,
{biPlains, "Plains"},
{biDesert, "Desert"},
{biExtremeHills, "ExtremeHills"},
{biForest, "Forest"},
{biTaiga, "Taiga"},
{biSwampland, "Swampland"},
{biRiver, "River"},
{biNether, "Hell"},
{biNether, "Nether"},
{biEnd, "Sky"},
{biEnd, "End"},
{biFrozenOcean, "FrozenOcean"},
{biFrozenRiver, "FrozenRiver"},
{biIcePlains, "IcePlains"},
{biIcePlains, "Tundra"},
{biIceMountains, "IceMountains"},
{biMushroomIsland, "MushroomIsland"},
{biMushroomShore, "MushroomShore"},
{biBeach, "Beach"},
{biDesertHills, "DesertHills"},
{biForestHills, "ForestHills"},
{biTaigaHills, "TaigaHills"},
{biExtremeHillsEdge, "ExtremeHillsEdge"},
{biJungle, "Jungle"},
{biJungleHills, "JungleHills"},
// Release 1.7 biomes:
{biJungleEdge, "JungleEdge"},
{biDeepOcean, "DeepOcean"},
{biStoneBeach, "StoneBeach"},
{biColdBeach, "ColdBeach"},
{biBirchForest, "BirchForest"},
{biBirchForestHills, "BirchForestHills"},
{biRoofedForest, "RoofedForest"},
{biColdTaiga, "ColdTaiga"},
{biColdTaigaHills, "ColdTaigaHills"},
{biMegaTaiga, "MegaTaiga"},
{biMegaTaigaHills, "MegaTaigaHills"},
{biExtremeHillsPlus, "ExtremeHillsPlus"},
{biSavanna, "Savanna"},
{biSavannaPlateau, "SavannaPlateau"},
{biMesa, "Mesa"},
{biMesaPlateauF, "MesaPlateauF"},
{biMesaPlateau, "MesaPlateau"},
// Release 1.7 variants:
{biSunflowerPlains, "SunflowerPlains"},
{biDesertM, "DesertM"},
{biExtremeHillsM, "ExtremeHillsM"},
{biFlowerForest, "FlowerForest"},
{biTaigaM, "TaigaM"},
{biSwamplandM, "SwamplandM"},
{biIcePlainsSpikes, "IcePlainsSpikes"},
{biJungleM, "JungleM"},
{biJungleEdgeM, "JungleEdgeM"},
{biBirchForestM, "BirchForestM"},
{biBirchForestHillsM, "BirchForestHillsM"},
{biRoofedForestM, "RoofedForestM"},
{biColdTaigaM, "ColdTaigaM"},
{biMegaSpruceTaiga, "MegaSpruceTaiga"},
{biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"},
{biExtremeHillsPlusM, "ExtremeHillsPlusM"},
{biSavannaM, "SavannaM"},
{biSavannaPlateauM, "SavannaPlateauM"},
{biMesaBryce, "MesaBryce"},
{biMesaPlateauFM, "MesaPlateauFM"},
{biMesaPlateauM, "MesaPlateauM"},
} ;
EMCSBiome StringToBiome(const AString & a_BiomeString)
{
// If it is a number, return it:
@ -25,87 +107,11 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
return biInvalidBiome;
}
// Convert using the built-in map:
static struct {
EMCSBiome m_Biome;
const char * m_String;
} BiomeMap[] =
for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
{
{biOcean, "Ocean"} ,
{biPlains, "Plains"},
{biDesert, "Desert"},
{biExtremeHills, "ExtremeHills"},
{biForest, "Forest"},
{biTaiga, "Taiga"},
{biSwampland, "Swampland"},
{biRiver, "River"},
{biNether, "Hell"},
{biNether, "Nether"},
{biEnd, "Sky"},
{biEnd, "End"},
{biFrozenOcean, "FrozenOcean"},
{biFrozenRiver, "FrozenRiver"},
{biIcePlains, "IcePlains"},
{biIcePlains, "Tundra"},
{biIceMountains, "IceMountains"},
{biMushroomIsland, "MushroomIsland"},
{biMushroomShore, "MushroomShore"},
{biBeach, "Beach"},
{biDesertHills, "DesertHills"},
{biForestHills, "ForestHills"},
{biTaigaHills, "TaigaHills"},
{biExtremeHillsEdge, "ExtremeHillsEdge"},
{biJungle, "Jungle"},
{biJungleHills, "JungleHills"},
// Release 1.7 biomes:
{biJungleEdge, "JungleEdge"},
{biDeepOcean, "DeepOcean"},
{biStoneBeach, "StoneBeach"},
{biColdBeach, "ColdBeach"},
{biBirchForest, "BirchForest"},
{biBirchForestHills, "BirchForestHills"},
{biRoofedForest, "RoofedForest"},
{biColdTaiga, "ColdTaiga"},
{biColdTaigaHills, "ColdTaigaHills"},
{biMegaTaiga, "MegaTaiga"},
{biMegaTaigaHills, "MegaTaigaHills"},
{biExtremeHillsPlus, "ExtremeHillsPlus"},
{biSavanna, "Savanna"},
{biSavannaPlateau, "SavannaPlateau"},
{biMesa, "Mesa"},
{biMesaPlateauF, "MesaPlateauF"},
{biMesaPlateau, "MesaPlateau"},
// Release 1.7 variants:
{biSunflowerPlains, "SunflowerPlains"},
{biDesertM, "DesertM"},
{biExtremeHillsM, "ExtremeHillsM"},
{biFlowerForest, "FlowerForest"},
{biTaigaM, "TaigaM"},
{biSwamplandM, "SwamplandM"},
{biIcePlainsSpikes, "IcePlainsSpikes"},
{biJungleM, "JungleM"},
{biJungleEdgeM, "JungleEdgeM"},
{biBirchForestM, "BirchForestM"},
{biBirchForestHillsM, "BirchForestHillsM"},
{biRoofedForestM, "RoofedForestM"},
{biColdTaigaM, "ColdTaigaM"},
{biMegaSpruceTaiga, "MegaSpruceTaiga"},
{biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"},
{biExtremeHillsPlusM, "ExtremeHillsPlusM"},
{biSavannaM, "SavannaM"},
{biSavannaPlateauM, "SavannaPlateauM"},
{biMesaBryce, "MesaBryce"},
{biMesaPlateauFM, "MesaPlateauFM"},
{biMesaPlateauM, "MesaPlateauM"},
} ;
for (size_t i = 0; i < ARRAYCOUNT(BiomeMap); i++)
{
if (NoCaseCompare(BiomeMap[i].m_String, a_BiomeString) == 0)
if (NoCaseCompare(g_BiomeMap[i].m_String, a_BiomeString) == 0)
{
return BiomeMap[i].m_Biome;
return g_BiomeMap[i].m_Biome;
}
} // for i - BiomeMap[]
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)
{
switch (a_Biome)

View File

@ -104,10 +104,13 @@ enum EMCSBiome
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);
/// 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);