summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Bindings.cpp125
-rw-r--r--source/Bindings.h2
-rw-r--r--source/BlockID.cpp102
-rw-r--r--source/BlockID.h48
-rw-r--r--source/Entity.h42
5 files changed, 243 insertions, 76 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 9e6e69005..63d414194 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 07/01/13 09:49:28.
+** Generated automatically by tolua++-1.0.92 on 07/01/13 20:42:05.
*/
#ifndef __cplusplus
@@ -2590,6 +2590,65 @@ static int tolua_AllToLua_StringToDimension00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* function: DamageTypeToString */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_DamageTypeToString00
+static int tolua_AllToLua_DamageTypeToString00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ eDamageType a_DamageType = ((eDamageType) (int) tolua_tonumber(tolua_S,1,0));
+ {
+ AString tolua_ret = (AString) DamageTypeToString(a_DamageType);
+ tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'DamageTypeToString'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* function: StringToDamageType */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_StringToDamageType00
+static int tolua_AllToLua_StringToDamageType00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_iscppstring(tolua_S,1,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_DamageString = ((const AString) tolua_tocppstring(tolua_S,1,0));
+ {
+ eDamageType tolua_ret = (eDamageType) StringToDamageType(a_DamageString);
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_DamageString);
+ }
+ }
+ return 2;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'StringToDamageType'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* get function: g_BlockLightValue */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue
static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
@@ -27784,6 +27843,37 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"dimNether",dimNether);
tolua_constant(tolua_S,"dimOverworld",dimOverworld);
tolua_constant(tolua_S,"dimEnd",dimEnd);
+ tolua_constant(tolua_S,"dtAttack",dtAttack);
+ tolua_constant(tolua_S,"dtLightning",dtLightning);
+ tolua_constant(tolua_S,"dtFalling",dtFalling);
+ tolua_constant(tolua_S,"dtDrowning",dtDrowning);
+ tolua_constant(tolua_S,"dtSuffocating",dtSuffocating);
+ tolua_constant(tolua_S,"dtStarving",dtStarving);
+ tolua_constant(tolua_S,"dtCactusContact",dtCactusContact);
+ tolua_constant(tolua_S,"dtLavaContact",dtLavaContact);
+ tolua_constant(tolua_S,"dtPoisoning",dtPoisoning);
+ tolua_constant(tolua_S,"dtOnFire",dtOnFire);
+ tolua_constant(tolua_S,"dtFireContact",dtFireContact);
+ tolua_constant(tolua_S,"dtInVoid",dtInVoid);
+ tolua_constant(tolua_S,"dtPotionOfHarming",dtPotionOfHarming);
+ tolua_constant(tolua_S,"dtAdmin",dtAdmin);
+ tolua_constant(tolua_S,"dtPawnAttack",dtPawnAttack);
+ tolua_constant(tolua_S,"dtEntityAttack",dtEntityAttack);
+ tolua_constant(tolua_S,"dtMob",dtMob);
+ tolua_constant(tolua_S,"dtMobAttack",dtMobAttack);
+ tolua_constant(tolua_S,"dtFall",dtFall);
+ tolua_constant(tolua_S,"dtDrown",dtDrown);
+ tolua_constant(tolua_S,"dtSuffocation",dtSuffocation);
+ tolua_constant(tolua_S,"dtStarvation",dtStarvation);
+ tolua_constant(tolua_S,"dtHunger",dtHunger);
+ tolua_constant(tolua_S,"dtCactus",dtCactus);
+ tolua_constant(tolua_S,"dtCactuses",dtCactuses);
+ tolua_constant(tolua_S,"dtCacti",dtCacti);
+ tolua_constant(tolua_S,"dtLava",dtLava);
+ tolua_constant(tolua_S,"dtPoison",dtPoison);
+ tolua_constant(tolua_S,"dtBurning",dtBurning);
+ tolua_constant(tolua_S,"dtInFire",dtInFire);
+ tolua_constant(tolua_S,"dtPlugin",dtPlugin);
tolua_function(tolua_S,"BlockStringToType",tolua_AllToLua_BlockStringToType00);
tolua_function(tolua_S,"StringToItem",tolua_AllToLua_StringToItem00);
tolua_function(tolua_S,"ItemToString",tolua_AllToLua_ItemToString00);
@@ -27791,6 +27881,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"ItemToFullString",tolua_AllToLua_ItemToFullString00);
tolua_function(tolua_S,"StringToBiome",tolua_AllToLua_StringToBiome00);
tolua_function(tolua_S,"StringToDimension",tolua_AllToLua_StringToDimension00);
+ tolua_function(tolua_S,"DamageTypeToString",tolua_AllToLua_DamageTypeToString00);
+ tolua_function(tolua_S,"StringToDamageType",tolua_AllToLua_StringToDamageType00);
tolua_array(tolua_S,"g_BlockLightValue",tolua_get_AllToLua_g_BlockLightValue,tolua_set_AllToLua_g_BlockLightValue);
tolua_array(tolua_S,"g_BlockSpreadLightFalloff",tolua_get_AllToLua_g_BlockSpreadLightFalloff,tolua_set_AllToLua_g_BlockSpreadLightFalloff);
tolua_array(tolua_S,"g_BlockTransparent",tolua_get_AllToLua_g_BlockTransparent,tolua_set_AllToLua_g_BlockTransparent);
@@ -27916,37 +28008,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetViewDistance",tolua_AllToLua_cClientHandle_GetViewDistance00);
tolua_function(tolua_S,"GetUniqueID",tolua_AllToLua_cClientHandle_GetUniqueID00);
tolua_endmodule(tolua_S);
- tolua_constant(tolua_S,"dtAttack",dtAttack);
- tolua_constant(tolua_S,"dtLightning",dtLightning);
- tolua_constant(tolua_S,"dtFalling",dtFalling);
- tolua_constant(tolua_S,"dtDrowning",dtDrowning);
- tolua_constant(tolua_S,"dtSuffocating",dtSuffocating);
- tolua_constant(tolua_S,"dtStarving",dtStarving);
- tolua_constant(tolua_S,"dtCactusContact",dtCactusContact);
- tolua_constant(tolua_S,"dtLavaContact",dtLavaContact);
- tolua_constant(tolua_S,"dtPoisoning",dtPoisoning);
- tolua_constant(tolua_S,"dtOnFire",dtOnFire);
- tolua_constant(tolua_S,"dtFireContact",dtFireContact);
- tolua_constant(tolua_S,"dtInVoid",dtInVoid);
- tolua_constant(tolua_S,"dtPotionOfHarming",dtPotionOfHarming);
- tolua_constant(tolua_S,"dtAdmin",dtAdmin);
- tolua_constant(tolua_S,"dtPawnAttack",dtPawnAttack);
- tolua_constant(tolua_S,"dtEntityAttack",dtEntityAttack);
- tolua_constant(tolua_S,"dtMob",dtMob);
- tolua_constant(tolua_S,"dtMobAttack",dtMobAttack);
- tolua_constant(tolua_S,"dtFall",dtFall);
- tolua_constant(tolua_S,"dtDrown",dtDrown);
- tolua_constant(tolua_S,"dtSuffocation",dtSuffocation);
- tolua_constant(tolua_S,"dtStarvation",dtStarvation);
- tolua_constant(tolua_S,"dtHunger",dtHunger);
- tolua_constant(tolua_S,"dtCactus",dtCactus);
- tolua_constant(tolua_S,"dtCactuses",dtCactuses);
- tolua_constant(tolua_S,"dtCacti",dtCacti);
- tolua_constant(tolua_S,"dtLava",dtLava);
- tolua_constant(tolua_S,"dtPoison",dtPoison);
- tolua_constant(tolua_S,"dtBurning",dtBurning);
- tolua_constant(tolua_S,"dtInFire",dtInFire);
- tolua_constant(tolua_S,"dtPlugin",dtPlugin);
tolua_cclass(tolua_S,"TakeDamageInfo","TakeDamageInfo","",NULL);
tolua_beginmodule(tolua_S,"TakeDamageInfo");
tolua_variable(tolua_S,"DamageType",tolua_get_TakeDamageInfo_DamageType,tolua_set_TakeDamageInfo_DamageType);
diff --git a/source/Bindings.h b/source/Bindings.h
index f1ebbac51..1b2c12dad 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 07/01/13 09:49:29.
+** Generated automatically by tolua++-1.0.92 on 07/01/13 20:42:05.
*/
/* Exported function */
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
{
diff --git a/source/BlockID.h b/source/BlockID.h
index 7e03388d3..9b2a104f3 100644
--- a/source/BlockID.h
+++ b/source/BlockID.h
@@ -614,6 +614,48 @@ enum eDimension
} ;
+
+
+
+/// Damage type, used in the TakeDamageInfo structure and related functions
+enum eDamageType
+{
+ // Canonical names for the types (as documented in the plugin wiki):
+ dtAttack, // Being attacked by a mob
+ dtLightning, // Hit by a lightning strike
+ dtFalling, // Falling down; dealt when hitting the ground
+ dtDrowning, // Drowning in water / lava
+ dtSuffocating, // Suffocating inside a block
+ dtStarving, // Hunger
+ dtCactusContact, // Contact with a cactus block
+ dtLavaContact, // Contact with a lava block
+ dtPoisoning, // Having the poison effect
+ dtOnFire, // Being on fire
+ dtFireContact, // Standing inside a fire block
+ dtInVoid, // Falling into the Void (Y < 0)
+ dtPotionOfHarming,
+ dtAdmin, // Damage applied by an admin command
+
+ // Some 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,
+} ;
+
// tolua_end
@@ -649,6 +691,12 @@ extern EMCSBiome StringToBiome(const AString & a_BiomeString);
/// Translates a dimension string to dimension enum. Takes either a number or a dimension alias (built-in). Returns -1000 on failure
extern eDimension StringToDimension(const AString & a_DimensionString);
+/// Translates damage type constant to a string representation (built-in).
+extern AString DamageTypeToString(eDamageType 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
+extern eDamageType StringToDamageType(const AString & a_DamageString);
+
// tolua_end
diff --git a/source/Entity.h b/source/Entity.h
index 775b95253..0faa10830 100644
--- a/source/Entity.h
+++ b/source/Entity.h
@@ -43,48 +43,6 @@ class cChunk;
// tolua_begin
-enum eDamageType
-{
- // Canonical names for the types (as documented in the plugin wiki):
- dtAttack, // Being attacked by a mob
- dtLightning, // Hit by a lightning strike
- dtFalling, // Falling down; dealt when hitting the ground
- dtDrowning, // Drowning in water / lava
- dtSuffocating, // Suffocating inside a block
- dtStarving, // Hunger
- dtCactusContact, // Contact with a cactus block
- dtLavaContact, // Contact with a lava block
- dtPoisoning, // Having the poison effect
- dtOnFire, // Being on fire
- dtFireContact, // Standing inside a fire block
- dtInVoid, // Falling into the Void (Y < 0)
- dtPotionOfHarming,
- dtAdmin, // Damage applied by an admin command
-
- // Some 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,
-} ;
-
-
-
-
-
struct TakeDamageInfo
{
eDamageType DamageType; // Where does the damage come from? Being hit / on fire / contact with cactus / ...