Slight cleanup in the cInventory / cItemGrid API

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1504 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2013-05-24 09:16:09 +00:00
parent cf87169737
commit 90e0656c75
6 changed files with 239 additions and 41 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 05/24/13 09:11:00.
** Generated automatically by tolua++-1.0.92 on 05/24/13 11:00:52.
*/
#ifndef __cplusplus
@ -4327,6 +4327,38 @@ static int tolua_AllToLua_cEntity_GetHeadYaw00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetHeight of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_GetHeight00
static int tolua_AllToLua_cEntity_GetHeight00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cEntity",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cEntity* self = (const cEntity*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHeight'", NULL);
#endif
{
double tolua_ret = (double) self->GetHeight();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetHeight'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetMass of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_GetMass00
static int tolua_AllToLua_cEntity_GetMass00(lua_State* tolua_S)
@ -4785,6 +4817,38 @@ static int tolua_AllToLua_cEntity_GetSpeedZ00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetWidth of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_GetWidth00
static int tolua_AllToLua_cEntity_GetWidth00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cEntity",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cEntity* self = (const cEntity*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWidth'", NULL);
#endif
{
double tolua_ret = (double) self->GetWidth();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetWidth'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetChunkX of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_GetChunkX00
static int tolua_AllToLua_cEntity_GetChunkX00(lua_State* tolua_S)
@ -4882,6 +4946,39 @@ static int tolua_AllToLua_cEntity_SetHeadYaw00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetHeight of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_SetHeight00
static int tolua_AllToLua_cEntity_SetHeight00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cEntity",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cEntity* self = (cEntity*) tolua_tousertype(tolua_S,1,0);
double a_Height = ((double) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetHeight'", NULL);
#endif
{
self->SetHeight(a_Height);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SetHeight'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetMass of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_SetMass00
static int tolua_AllToLua_cEntity_SetMass00(lua_State* tolua_S)
@ -5375,6 +5472,39 @@ static int tolua_AllToLua_cEntity_SetSpeedZ00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetWidth of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_SetWidth00
static int tolua_AllToLua_cEntity_SetWidth00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cEntity",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cEntity* self = (cEntity*) tolua_tousertype(tolua_S,1,0);
double a_Width = ((double) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetWidth'", NULL);
#endif
{
self->SetWidth(a_Width);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SetWidth'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: AddPosX of class cEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cEntity_AddPosX00
static int tolua_AllToLua_cEntity_AddPosX00(lua_State* tolua_S)
@ -13562,39 +13692,6 @@ static int tolua_AllToLua_cInventory_GetEquippedBoots00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: SendSlot of class cInventory */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_SendSlot00
static int tolua_AllToLua_cInventory_SendSlot00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cInventory",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cInventory* self = (cInventory*) tolua_tousertype(tolua_S,1,0);
int a_SlotNum = ((int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SendSlot'", NULL);
#endif
{
self->SendSlot(a_SlotNum);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'SendSlot'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: new of class cItem */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_new00
static int tolua_AllToLua_cItem_new00(lua_State* tolua_S)
@ -15071,6 +15168,39 @@ static int tolua_AllToLua_cItemGrid_ChangeSlotCount00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: ChangeSlotCount of class cItemGrid */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_ChangeSlotCount01
static int tolua_AllToLua_cItemGrid_ChangeSlotCount01(lua_State* tolua_S)
{
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
)
goto tolua_lerror;
else
{
cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0);
int a_X = ((int) tolua_tonumber(tolua_S,2,0));
int a_Y = ((int) tolua_tonumber(tolua_S,3,0));
int a_AddToCount = ((int) tolua_tonumber(tolua_S,4,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ChangeSlotCount'", NULL);
#endif
{
int tolua_ret = (int) self->ChangeSlotCount(a_X,a_Y,a_AddToCount);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
tolua_lerror:
return tolua_AllToLua_cItemGrid_ChangeSlotCount00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE
/* method: HowManyItems of class cItemGrid */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_HowManyItems00
static int tolua_AllToLua_cItemGrid_HowManyItems00(lua_State* tolua_S)
@ -15306,6 +15436,39 @@ static int tolua_AllToLua_cItemGrid_DamageItem00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: DamageItem of class cItemGrid */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cItemGrid_DamageItem01
static int tolua_AllToLua_cItemGrid_DamageItem01(lua_State* tolua_S)
{
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
)
goto tolua_lerror;
else
{
cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0);
int a_X = ((int) tolua_tonumber(tolua_S,2,0));
int a_Y = ((int) tolua_tonumber(tolua_S,3,0));
short a_Amount = ((short) tolua_tonumber(tolua_S,4,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DamageItem'", NULL);
#endif
{
bool tolua_ret = (bool) self->DamageItem(a_X,a_Y,a_Amount);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
tolua_lerror:
return tolua_AllToLua_cItemGrid_DamageItem00(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE
/* method: new of class cChestEntity */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_new00
static int tolua_AllToLua_cChestEntity_new00(lua_State* tolua_S)
@ -25523,6 +25686,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetParentClass",tolua_AllToLua_cEntity_GetParentClass00);
tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cEntity_GetWorld00);
tolua_function(tolua_S,"GetHeadYaw",tolua_AllToLua_cEntity_GetHeadYaw00);
tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cEntity_GetHeight00);
tolua_function(tolua_S,"GetMass",tolua_AllToLua_cEntity_GetMass00);
tolua_function(tolua_S,"GetPosition",tolua_AllToLua_cEntity_GetPosition00);
tolua_function(tolua_S,"GetPosX",tolua_AllToLua_cEntity_GetPosX00);
@ -25537,9 +25701,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetSpeedX",tolua_AllToLua_cEntity_GetSpeedX00);
tolua_function(tolua_S,"GetSpeedY",tolua_AllToLua_cEntity_GetSpeedY00);
tolua_function(tolua_S,"GetSpeedZ",tolua_AllToLua_cEntity_GetSpeedZ00);
tolua_function(tolua_S,"GetWidth",tolua_AllToLua_cEntity_GetWidth00);
tolua_function(tolua_S,"GetChunkX",tolua_AllToLua_cEntity_GetChunkX00);
tolua_function(tolua_S,"GetChunkZ",tolua_AllToLua_cEntity_GetChunkZ00);
tolua_function(tolua_S,"SetHeadYaw",tolua_AllToLua_cEntity_SetHeadYaw00);
tolua_function(tolua_S,"SetHeight",tolua_AllToLua_cEntity_SetHeight00);
tolua_function(tolua_S,"SetMass",tolua_AllToLua_cEntity_SetMass00);
tolua_function(tolua_S,"SetPosX",tolua_AllToLua_cEntity_SetPosX00);
tolua_function(tolua_S,"SetPosY",tolua_AllToLua_cEntity_SetPosY00);
@ -25555,6 +25721,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"SetSpeedX",tolua_AllToLua_cEntity_SetSpeedX00);
tolua_function(tolua_S,"SetSpeedY",tolua_AllToLua_cEntity_SetSpeedY00);
tolua_function(tolua_S,"SetSpeedZ",tolua_AllToLua_cEntity_SetSpeedZ00);
tolua_function(tolua_S,"SetWidth",tolua_AllToLua_cEntity_SetWidth00);
tolua_function(tolua_S,"AddPosX",tolua_AllToLua_cEntity_AddPosX00);
tolua_function(tolua_S,"AddPosY",tolua_AllToLua_cEntity_AddPosY00);
tolua_function(tolua_S,"AddPosZ",tolua_AllToLua_cEntity_AddPosZ00);
@ -25891,7 +26058,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetEquippedChestplate",tolua_AllToLua_cInventory_GetEquippedChestplate00);
tolua_function(tolua_S,"GetEquippedLeggings",tolua_AllToLua_cInventory_GetEquippedLeggings00);
tolua_function(tolua_S,"GetEquippedBoots",tolua_AllToLua_cInventory_GetEquippedBoots00);
tolua_function(tolua_S,"SendSlot",tolua_AllToLua_cInventory_SendSlot00);
tolua_endmodule(tolua_S);
#ifdef __cplusplus
tolua_cclass(tolua_S,"cItem","cItem","",tolua_collect_cItem);
@ -25956,6 +26122,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"AddItem",tolua_AllToLua_cItemGrid_AddItem00);
tolua_function(tolua_S,"AddItems",tolua_AllToLua_cItemGrid_AddItems00);
tolua_function(tolua_S,"ChangeSlotCount",tolua_AllToLua_cItemGrid_ChangeSlotCount00);
tolua_function(tolua_S,"ChangeSlotCount",tolua_AllToLua_cItemGrid_ChangeSlotCount01);
tolua_function(tolua_S,"HowManyItems",tolua_AllToLua_cItemGrid_HowManyItems00);
tolua_function(tolua_S,"HasItems",tolua_AllToLua_cItemGrid_HasItems00);
tolua_function(tolua_S,"GetFirstEmptySlot",tolua_AllToLua_cItemGrid_GetFirstEmptySlot00);
@ -25963,6 +26130,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetNextEmptySlot",tolua_AllToLua_cItemGrid_GetNextEmptySlot00);
tolua_function(tolua_S,"CopyToItems",tolua_AllToLua_cItemGrid_CopyToItems00);
tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItemGrid_DamageItem00);
tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItemGrid_DamageItem01);
tolua_endmodule(tolua_S);
#ifdef __cplusplus
tolua_cclass(tolua_S,"cChestEntity","cChestEntity","cBlockEntity",tolua_collect_cChestEntity);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 05/24/13 09:11:00.
** Generated automatically by tolua++-1.0.92 on 05/24/13 11:00:53.
*/
/* Exported function */

View File

@ -135,11 +135,11 @@ public:
const cItem & GetEquippedLeggings (void) const { return m_ArmorSlots.GetSlot(2); }
const cItem & GetEquippedBoots (void) const { return m_ArmorSlots.GetSlot(3); }
// tolua_end
/// Sends the slot contents to the owner
void SendSlot(int a_SlotNum);
// tolua_end
/// Converts an armor slot number into the ID for the EntityEquipment packet
static int ArmorSlotNumToEntityEquipmentID(short a_ArmorSlotNum);

View File

@ -346,6 +346,15 @@ int cItemGrid::ChangeSlotCount(int a_SlotNum, int a_AddToCount)
int cItemGrid::ChangeSlotCount(int a_X, int a_Y, int a_AddToCount)
{
return ChangeSlotCount(GetSlotNum(a_X, a_Y), a_AddToCount);
}
int cItemGrid::HowManyItems(const cItem & a_Item)
{
int res = 0;
@ -443,6 +452,15 @@ bool cItemGrid::DamageItem(int a_SlotNum, short a_Amount)
bool cItemGrid::DamageItem(int a_X, int a_Y, short a_Amount)
{
return DamageItem(GetSlotNum(a_X, a_Y), a_Amount);
}
void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, int a_CountLootProbabs, int a_NumSlots, int a_Seed)
{
// Calculate the total weight:

View File

@ -42,15 +42,18 @@ public:
int GetSlotNum(int a_X, int a_Y) const;
// tolua_end
/// Converts slot number into XY coords; sets coords to -1 on invalid slot number. Exported in ManualBindings.cpp
void GetSlotCoords(int a_SlotNum, int & a_X, int & a_Y) const;
cItem & GetSlot(int a_X, int a_Y); // TODO: This will be removed!
cItem & GetSlot(int a_SlotNum); // TODO: This will be removed!
// tolua_begin
// Retrieve slots by coords or slot number; Logs warning and returns the first slot on invalid coords / slotnum
const cItem & GetSlot(int a_X, int a_Y) const;
cItem & GetSlot(int a_X, int a_Y);
const cItem & GetSlot(int a_SlotNum) const;
cItem & GetSlot(int a_SlotNum);
// Set slot by coords or slot number; Logs warning and doesn't set on invalid coords / slotnum
void SetSlot(int a_X, int a_Y, const cItem & a_Item);
@ -89,6 +92,12 @@ public:
*/
int ChangeSlotCount(int a_SlotNum, int a_AddToCount);
/** Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
If the slot is empty, ignores the call.
Returns the new count.
*/
int ChangeSlotCount(int a_X, int a_Y, int a_AddToCount);
/// Returns the number of items of type a_Item that are stored
int HowManyItems(const cItem & a_Item);
@ -110,6 +119,9 @@ public:
/// Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact)
bool DamageItem(int a_SlotNum, short a_Amount);
/// Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact)
bool DamageItem(int a_X, int a_Y, short a_Amount);
// tolua_end

View File

@ -1127,7 +1127,7 @@ static int Lua_ItemGrid_GetSlotCoords(lua_State * L)
}
tolua_lerror:
tolua_error(L, "#ferror in function 'FindKey'.", &tolua_err);
tolua_error(L, "#ferror in function 'cItemGrid:GetSlotCoords'.", &tolua_err);
return 0;
}