summaryrefslogtreecommitdiffstats
path: root/source/BlockID.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-01 20:46:45 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-01 20:46:45 +0200
commit37f6c78404aeb92a40c1a96c856e69225788c3db (patch)
treea0fc1be5a64a00b46c6a01db21a936d6f56ab9c3 /source/BlockID.cpp
parentFixed burn / fire damage in each game tick. (diff)
downloadcuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.tar
cuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.tar.gz
cuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.tar.bz2
cuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.tar.lz
cuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.tar.xz
cuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.tar.zst
cuberite-37f6c78404aeb92a40c1a96c856e69225788c3db.zip
Diffstat (limited to 'source/BlockID.cpp')
-rw-r--r--source/BlockID.cpp102
1 files changed, 101 insertions, 1 deletions
diff --git a/source/BlockID.cpp b/source/BlockID.cpp
index a3bb75cf4..f89178c73 100644
--- a/source/BlockID.cpp
+++ b/source/BlockID.cpp
@@ -323,6 +323,7 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
eDimension StringToDimension(const AString & a_DimensionString)
{
+ // First try decoding as a number
int res = atoi(a_DimensionString.c_str());
if ((res != 0) || (a_DimensionString == "0"))
{
@@ -330,7 +331,7 @@ eDimension StringToDimension(const AString & a_DimensionString)
return (eDimension)res;
}
- // Convert using a built-in map:
+ // Decode using a built-in map:
static struct
{
eDimension m_Dimension;
@@ -361,6 +362,105 @@ eDimension StringToDimension(const AString & a_DimensionString)
+/// Translates damage type constant to a string representation (built-in).
+AString DamageTypeToString(eDamageType a_DamageType)
+{
+ switch (a_DamageType)
+ {
+ case dtAttack: return "dtAttack";
+ case dtLightning: return "dtLightning";
+ case dtFalling: return "dtFalling";
+ case dtDrowning: return "dtDrowning";
+ case dtSuffocating: return "dtSuffocation";
+ case dtStarving: return "dtStarving";
+ case dtCactusContact: return "dtCactusContact";
+ case dtLavaContact: return "dtLavaContact";
+ case dtPoisoning: return "dtPoisoning";
+ case dtOnFire: return "dtOnFire";
+ case dtFireContact: return "dtFireContact";
+ case dtInVoid: return "dtInVoid";
+ case dtPotionOfHarming: return "dtPotionOfHarming";
+ case dtAdmin: return "dtAdmin";
+ }
+
+ // Unknown damage type:
+ ASSERT(!"Unknown DamageType");
+ return Printf("dtUnknown_%d", (int)a_DamageType);
+}
+
+
+
+
+
+/// Translates a damage type string to damage type. Takes either a number or a damage type alias (built-in). Returns -1 on failure
+eDamageType StringToDamageType(const AString & a_DamageTypeString)
+{
+ // First try decoding as a number:
+ int res = atoi(a_DamageTypeString.c_str());
+ if ((res != 0) || (a_DamageTypeString == "0"))
+ {
+ // It was a valid number
+ return (eDamageType)res;
+ }
+
+ // Decode using a built-in map:
+ static struct
+ {
+ eDamageType m_DamageType;
+ const char * m_String;
+ } DamageTypeMap [] =
+ {
+ // Cannonical names:
+ { dtAttack, "dtAttack"},
+ { dtLightning, "dtLightning"},
+ { dtFalling, "dtFalling"},
+ { dtDrowning, "dtDrowning"},
+ { dtSuffocating, "dtSuffocation"},
+ { dtStarving, "dtStarving"},
+ { dtCactusContact, "dtCactusContact"},
+ { dtLavaContact, "dtLavaContact"},
+ { dtPoisoning, "dtPoisoning"},
+ { dtOnFire, "dtOnFire"},
+ { dtFireContact, "dtFireContact"},
+ { dtInVoid, "dtInVoid"},
+ { dtPotionOfHarming, "dtPotionOfHarming"},
+ { dtAdmin, "dtAdmin"},
+
+ // Common synonyms:
+ { dtPawnAttack, "dtAttack"},
+ { dtEntityAttack, "dtAttack"},
+ { dtMob, "dtAttack"},
+ { dtMobAttack, "dtAttack"},
+ { dtFall, "dtFalling"},
+ { dtDrown, "dtDrowning"},
+ { dtSuffocation, "dtSuffocating"},
+ { dtStarvation, "dtStarving"},
+ { dtHunger, "dtStarving"},
+ { dtCactus, "dtCactusContact"},
+ { dtCactuses, "dtCactusContact"},
+ { dtCacti, "dtCactusContact"},
+ { dtLava, "dtLavaContact"},
+ { dtPoison, "dtPoisoning"},
+ { dtBurning, "dtOnFire"},
+ { dtInFire, "dtFireContact"},
+ { dtPlugin, "dtAdmin"},
+ } ;
+ for (int i = 0; i < ARRAYCOUNT(DamageTypeMap); i++)
+ {
+ if (NoCaseCompare(DamageTypeMap[i].m_String, a_DamageTypeString) == 0)
+ {
+ return DamageTypeMap[i].m_DamageType;
+ }
+ } // for i - DamageTypeMap[]
+
+ // Not found:
+ return (eDamageType)-1;
+}
+
+
+
+
+
// This is actually just some code that needs to run at program startup, so it is wrapped into a global var's constructor:
class cBlockPropertiesInitializer
{