mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Added lua function for finding/creating/destroying items in a soldier's inventory
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9132 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -837,6 +837,10 @@ static int l_TalkingMenuDialogue (lua_State *L);
|
||||
static int l_StartDialogueMessageBox (lua_State *L);
|
||||
|
||||
static int l_CreateItemInv (lua_State *L);
|
||||
static int l_CreateItemInvOrFloor ( lua_State *L );
|
||||
static int l_DestroyOneItemInInventory( lua_State *L );
|
||||
static int l_HasItemInInventory( lua_State *L );
|
||||
|
||||
static int l_MercSalary(lua_State *L);
|
||||
static int l_PlayerTeamFull (lua_State *L);
|
||||
|
||||
@@ -1165,6 +1169,9 @@ void IniFunction(lua_State *L, BOOLEAN bQuests )
|
||||
lua_register(L, "SoldierGiveItem", l_SoldierGiveItem);
|
||||
lua_register(L, "ProfilGiveItem", l_SoldierGiveItem);
|
||||
lua_register(L, "AddItemToInventory", l_CreateItemInv);
|
||||
lua_register(L, "CreateItemInvOrFloor", l_CreateItemInvOrFloor );
|
||||
lua_register(L, "DestroyOneItemInInventory", l_DestroyOneItemInInventory );
|
||||
lua_register(L, "HasItemInInventory", l_HasItemInInventory );
|
||||
lua_register(L, "TacticalCharacterDialogueWithSpecialEvent", l_TacticalCharacterDialogueWithSpecialEvent);
|
||||
lua_register(L, "SetSalary", l_MercSalary);
|
||||
lua_register(L, "SetProfileStrategicInsertionData", l_ProfilesStrategicInsertionData);
|
||||
@@ -8452,6 +8459,67 @@ static int l_CreateItemInv(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_CreateItemInvOrFloor( lua_State *L )
|
||||
{
|
||||
if ( lua_gettop( L ) >= 2 )
|
||||
{
|
||||
UINT16 ubID = lua_tointeger( L, 1 );
|
||||
UINT16 usItem = lua_tointeger( L, 2 );
|
||||
|
||||
if ( ubID < TOTAL_SOLDIERS )
|
||||
{
|
||||
SOLDIERTYPE* pSoldier = MercPtrs[ubID];
|
||||
if ( pSoldier )
|
||||
{
|
||||
CreateItem( usItem, 100, &gTempObject );
|
||||
|
||||
if ( !AutoPlaceObject( pSoldier, &gTempObject, TRUE ) )
|
||||
{
|
||||
AddItemToPool( pSoldier->sGridNo, &gTempObject, 1, pSoldier->pathing.bLevel, 0, -1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_DestroyOneItemInInventory( lua_State *L )
|
||||
{
|
||||
if ( lua_gettop( L ) >= 2 )
|
||||
{
|
||||
UINT16 ubID = lua_tointeger( L, 1 );
|
||||
UINT16 usItem = lua_tointeger( L, 2 );
|
||||
|
||||
if ( ubID < TOTAL_SOLDIERS )
|
||||
{
|
||||
MercPtrs[ubID]->DestroyOneItemInInventory( usItem );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_HasItemInInventory( lua_State *L )
|
||||
{
|
||||
bool Bool = FALSE;
|
||||
|
||||
if ( lua_gettop( L ) >= 2 )
|
||||
{
|
||||
UINT16 ubID = lua_tointeger( L, 1 );
|
||||
UINT16 usItem = lua_tointeger( L, 2 );
|
||||
|
||||
if ( ubID < TOTAL_SOLDIERS )
|
||||
{
|
||||
Bool = MercPtrs[ubID]->HasItemInInventory( usItem );
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushboolean( L, Bool );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_CreateKeyProfInvAndAddItemToPool(lua_State *L)
|
||||
{
|
||||
UINT8 n = lua_gettop(L);
|
||||
|
||||
@@ -21188,7 +21188,7 @@ OBJECTTYPE* SOLDIERTYPE::GetObjectWithItemFlag( UINT64 aFlag )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SOLDIERTYPE::DestroyOneObjectWithItemFlag( UINT64 aFlag )
|
||||
bool SOLDIERTYPE::DestroyOneObjectWithItemFlag( UINT64 aFlag )
|
||||
{
|
||||
for ( INT8 bLoop = 0, invsize = (INT8)inv.size(); bLoop < invsize; ++bLoop )
|
||||
{
|
||||
@@ -21204,9 +21204,56 @@ void SOLDIERTYPE::DestroyOneObjectWithItemFlag( UINT64 aFlag )
|
||||
{
|
||||
DeleteObj( pObj );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SOLDIERTYPE::DestroyOneItemInInventory( UINT16 ausItem )
|
||||
{
|
||||
for ( INT8 bLoop = 0, invsize = (INT8)inv.size(); bLoop < invsize; ++bLoop )
|
||||
{
|
||||
if ( inv[bLoop].exists() )
|
||||
{
|
||||
OBJECTTYPE* pObj = &( inv[bLoop] );
|
||||
|
||||
if ( pObj && pObj->usItem == ausItem )
|
||||
{
|
||||
pObj->RemoveObjectsFromStack( 1 );
|
||||
|
||||
if ( pObj->ubNumberOfObjects <= 0 )
|
||||
{
|
||||
DeleteObj( pObj );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SOLDIERTYPE::HasItemInInventory( UINT16 ausItem )
|
||||
{
|
||||
for ( INT8 bLoop = 0, invsize = (INT8)inv.size(); bLoop < invsize; ++bLoop )
|
||||
{
|
||||
if ( inv[bLoop].exists() )
|
||||
{
|
||||
OBJECTTYPE* pObj = &( inv[bLoop] );
|
||||
|
||||
if ( pObj && pObj->usItem == ausItem )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#define BLOODDONATION_AMOUNT 10
|
||||
|
||||
@@ -2053,7 +2053,9 @@ public:
|
||||
void DrugAutoUse();
|
||||
|
||||
OBJECTTYPE* GetObjectWithItemFlag( UINT64 aFlag );
|
||||
void DestroyOneObjectWithItemFlag( UINT64 aFlag );
|
||||
bool DestroyOneObjectWithItemFlag( UINT64 aFlag );
|
||||
bool DestroyOneItemInInventory( UINT16 ausItem );
|
||||
bool HasItemInInventory( UINT16 ausItem );
|
||||
|
||||
// Flugente: can we fill a blood bag from this guy ?
|
||||
BOOLEAN IsValidBloodDonor();
|
||||
|
||||
Reference in New Issue
Block a user