1
0

Fixed a bit of coding style and function names in cItem

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1384 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-04-11 10:05:53 +00:00
parent dc878898f3
commit 58fb05980d
4 changed files with 80 additions and 67 deletions

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 04/10/13 23:35:42. ** Generated automatically by tolua++-1.0.92 on 04/11/13 11:57:58.
*/ */
#ifndef __cplusplus #ifndef __cplusplus
@ -13106,9 +13106,9 @@ static int tolua_AllToLua_cItem_CopyOne00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: GetMaxDuration of class cItem */ /* method: GetMaxDamage of class cItem */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetMaxDuration00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetMaxDamage00
static int tolua_AllToLua_cItem_GetMaxDuration00(lua_State* tolua_S) static int tolua_AllToLua_cItem_GetMaxDamage00(lua_State* tolua_S)
{ {
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_Error tolua_err; tolua_Error tolua_err;
@ -13122,17 +13122,17 @@ static int tolua_AllToLua_cItem_GetMaxDuration00(lua_State* tolua_S)
{ {
const cItem* self = (const cItem*) tolua_tousertype(tolua_S,1,0); const cItem* self = (const cItem*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxDuration'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxDamage'", NULL);
#endif #endif
{ {
int tolua_ret = (int) self->GetMaxDuration(); short tolua_ret = (short) self->GetMaxDamage();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
} }
} }
return 1; return 1;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetMaxDuration'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'GetMaxDamage'.",&tolua_err);
return 0; return 0;
#endif #endif
} }
@ -13170,33 +13170,33 @@ static int tolua_AllToLua_cItem_DamageItem00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: HasDuration of class cItem */ /* method: IsDamageable of class cItem */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_HasDuration00 #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_IsDamageable00
static int tolua_AllToLua_cItem_HasDuration00(lua_State* tolua_S) static int tolua_AllToLua_cItem_IsDamageable00(lua_State* tolua_S)
{ {
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_Error tolua_err; tolua_Error tolua_err;
if ( if (
!tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) || !tolua_isusertype(tolua_S,1,"const cItem",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err) !tolua_isnoobj(tolua_S,2,&tolua_err)
) )
goto tolua_lerror; goto tolua_lerror;
else else
#endif #endif
{ {
cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0); const cItem* self = (const cItem*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HasDuration'", NULL); if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsDamageable'", NULL);
#endif #endif
{ {
bool tolua_ret = (bool) self->HasDuration(); bool tolua_ret = (bool) self->IsDamageable();
tolua_pushboolean(tolua_S,(bool)tolua_ret); tolua_pushboolean(tolua_S,(bool)tolua_ret);
} }
} }
return 1; return 1;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'HasDuration'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'IsDamageable'.",&tolua_err);
return 0; return 0;
#endif #endif
} }
@ -24812,9 +24812,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"IsEqual",tolua_AllToLua_cItem_IsEqual00); tolua_function(tolua_S,"IsEqual",tolua_AllToLua_cItem_IsEqual00);
tolua_function(tolua_S,"IsSameType",tolua_AllToLua_cItem_IsSameType00); tolua_function(tolua_S,"IsSameType",tolua_AllToLua_cItem_IsSameType00);
tolua_function(tolua_S,"CopyOne",tolua_AllToLua_cItem_CopyOne00); tolua_function(tolua_S,"CopyOne",tolua_AllToLua_cItem_CopyOne00);
tolua_function(tolua_S,"GetMaxDuration",tolua_AllToLua_cItem_GetMaxDuration00); tolua_function(tolua_S,"GetMaxDamage",tolua_AllToLua_cItem_GetMaxDamage00);
tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItem_DamageItem00); tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItem_DamageItem00);
tolua_function(tolua_S,"HasDuration",tolua_AllToLua_cItem_HasDuration00); tolua_function(tolua_S,"IsDamageable",tolua_AllToLua_cItem_IsDamageable00);
tolua_function(tolua_S,"IsStackableWith",tolua_AllToLua_cItem_IsStackableWith00); tolua_function(tolua_S,"IsStackableWith",tolua_AllToLua_cItem_IsStackableWith00);
tolua_function(tolua_S,"IsEnchantable",tolua_AllToLua_cItem_IsEnchantable00); tolua_function(tolua_S,"IsEnchantable",tolua_AllToLua_cItem_IsEnchantable00);
tolua_variable(tolua_S,"m_ItemType",tolua_get_cItem_m_ItemType,tolua_set_cItem_m_ItemType); tolua_variable(tolua_S,"m_ItemType",tolua_get_cItem_m_ItemType,tolua_set_cItem_m_ItemType);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 04/10/13 23:35:43. ** Generated automatically by tolua++-1.0.92 on 04/11/13 11:57:59.
*/ */
/* Exported function */ /* Exported function */

View File

@ -19,6 +19,62 @@ cItem cItem::CopyOne(void) const
short cItem::GetMaxDamage(void) const
{
switch (m_ItemType)
{
case E_ITEM_DIAMOND_AXE: return 1563;
case E_ITEM_DIAMOND_HOE: return 1563;
case E_ITEM_DIAMOND_PICKAXE: return 1563;
case E_ITEM_DIAMOND_SHOVEL: return 1563;
case E_ITEM_DIAMOND_SWORD: return 1563;
case E_ITEM_FLINT_AND_STEEL: return 65;
case E_ITEM_GOLD_AXE: return 32;
case E_ITEM_GOLD_HOE: return 32;
case E_ITEM_GOLD_PICKAXE: return 32;
case E_ITEM_GOLD_SHOVEL: return 32;
case E_ITEM_GOLD_SWORD: return 32;
case E_ITEM_IRON_AXE: return 251;
case E_ITEM_IRON_HOE: return 251;
case E_ITEM_IRON_PICKAXE: return 251;
case E_ITEM_IRON_SHOVEL: return 251;
case E_ITEM_IRON_SWORD: return 251;
case E_ITEM_SHEARS: return 251;
case E_ITEM_STONE_AXE: return 132;
case E_ITEM_STONE_HOE: return 132;
case E_ITEM_STONE_PICKAXE: return 132;
case E_ITEM_STONE_SHOVEL: return 132;
case E_ITEM_STONE_SWORD: return 132;
case E_ITEM_WOODEN_AXE: return 60;
case E_ITEM_WOODEN_HOE: return 60;
case E_ITEM_WOODEN_PICKAXE: return 60;
case E_ITEM_WOODEN_SHOVEL: return 60;
case E_ITEM_WOODEN_SWORD: return 60;
}
return 0;
}
bool cItem::DamageItem(void)
{
short MaxDamage = GetMaxDamage();
if (MaxDamage == 0)
{
// Item doesn't have damage
return false;
}
m_ItemDamage++;
return (m_ItemDamage >= MaxDamage);
}
bool cItem::IsStackableWith(const cItem & a_OtherStack) bool cItem::IsStackableWith(const cItem & a_OtherStack)
{ {
if (a_OtherStack.m_ItemType != m_ItemType) if (a_OtherStack.m_ItemType != m_ItemType)

View File

@ -65,56 +65,13 @@ public:
/// Returns a copy of this item with m_ItemCount set to 1. Useful to preserve enchantments etc. on stacked items /// Returns a copy of this item with m_ItemCount set to 1. Useful to preserve enchantments etc. on stacked items
cItem CopyOne(void) const; cItem CopyOne(void) const;
// TODO Sorry for writing the functions in the header. But somehow it doesn´t worked when I put them into the cpp File :s /// Returns the maximum damage value that this item can have; zero if damage is not applied
short GetMaxDamage(void) const;
/// Damages a weapon / tool. Returns true when damage reaches max value and the item should be destroyed
bool DamageItem(void);
inline int GetMaxDuration(void) const inline bool IsDamageable(void) const { return (GetMaxDamage() > 0); }
{
switch (m_ItemType)
{
case 256: return 251;
case 257: return 251;
case 258: return 251;
case 259: return 65; //Lighter / Flint and Steel
case 267: return 251;
case 268: return 60;
case 269: return 60;
case 270: return 60;
case 271: return 60;
case 272: return 132;
case 273: return 132;
case 274: return 132;
case 275: return 132;
case 276: return 1563;
case 277: return 1563;
case 278: return 1563;
case 279: return 1563;
case 283: return 32;
case 284: return 32;
case 285: return 32;
case 286: return 32;
case 290: return 60;
case 291: return 132;
case 292: return 251;
case 293: return 1563;
case 294: return 32;
case 359: return 251;
default: return 0;
}
}
/// Damages a weapon / tool. Returns true when destroyed
inline bool DamageItem()
{
if (HasDuration())
{
m_ItemDamage++;
if (m_ItemDamage >= GetMaxDuration())
return true;
}
return false;
}
inline bool HasDuration() { return GetMaxDuration() > 0; }
/// Returns true if this itemstack can stack with the specified stack (types match, enchantments etc.) ItemCounts are ignored! /// Returns true if this itemstack can stack with the specified stack (types match, enchantments etc.) ItemCounts are ignored!
bool IsStackableWith(const cItem & a_OtherStack); bool IsStackableWith(const cItem & a_OtherStack);