diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 8b392b30..fcdc566b 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -13949,3 +13949,19 @@ BOOLEAN HasItemFlag( UINT16 usItem, UINT32 aFlag ) { return( (Item[usItem].usItemFlag & aFlag) != 0 ); } + +// Flugente: get first item number that has this flag. Use with caution, as we search in all items +BOOLEAN GetFirstItemWithFlag( UINT16* pusItem, UINT32 aFlag ) +{ + register UINT16 i; + for (i = 1; i < MAXITEMS; ++i) + { + if ( HasItemFlag(i, aFlag) ) + { + (*pusItem) = i; + return( TRUE ); + } + } + + return( FALSE ); +} diff --git a/Tactical/Items.h b/Tactical/Items.h index e4f07df2..c7bdc422 100644 --- a/Tactical/Items.h +++ b/Tactical/Items.h @@ -465,4 +465,7 @@ void CheckBombSpecifics( OBJECTTYPE * pObj, INT8* detonatortype, INT8* setting, // Flugente: check for specific flags BOOLEAN HasItemFlag( UINT16 usItem, UINT32 aFlag ); +// Flugente: get first item number that has this flag. Use with caution, as we search in all items +BOOLEAN GetFirstItemWithFlag( UINT16* pusItem, UINT32 aFlag ); + #endif diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index 089ac1bb..d44459f5 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -14424,6 +14424,8 @@ extern UINT8 NumEnemiesInAnySector( INT16 sSectorX, INT16 sSectorY, INT16 sSecto void SOLDIERTYPE::EVENT_SoldierBuildStructure( INT32 sGridNo, UINT8 ubDirection ) { + // a static variable that is the item number of sandbags. Hardcoding item numbers is bad, that's why we will search for it. + static UINT16 fullsandbagnr = 1541; BOOLEAN fSuccess = FALSE; // if specified by the ini, building/disassembling stuff is disabled while enemies are around @@ -14483,9 +14485,8 @@ void SOLDIERTYPE::EVENT_SoldierBuildStructure( INT32 sGridNo, UINT8 ubDirection if ( pShovelObj && pShovelObj->exists() && HasItemFlag(this->inv[ SECONDHANDPOS ].usItem, (SHOVEL)) ) { - // test: does there an item that is a filled sandbag exist? (xmls might have changed) - UINT16 fullsandbagnr = 1541; - if ( HasItemFlag(fullsandbagnr, FULL_SANDBAG) ) + // eventually search for the number of a sandbag item + if ( HasItemFlag(fullsandbagnr, FULL_SANDBAG) || GetFirstItemWithFlag(&fullsandbagnr, FULL_SANDBAG) ) { // Erase 'material' item from our hand - we 'used' it to build the structure INT8 bObjSlot = HANDPOS; @@ -14502,27 +14503,6 @@ void SOLDIERTYPE::EVENT_SoldierBuildStructure( INT32 sGridNo, UINT8 ubDirection fSuccess = TRUE; } - else - { - fullsandbagnr = 2824; - if ( HasItemFlag(fullsandbagnr, FULL_SANDBAG) ) - { - // Erase 'material' item from our hand - we 'used' it to build the structure - INT8 bObjSlot = HANDPOS; - - CreateItem( fullsandbagnr, 100, &gTempObject ); - - SwapObjs( this, bObjSlot, &gTempObject, TRUE ); - - // we gain a bit of experience... - StatChange( this, STRAMT, 1, TRUE ); - StatChange( this, HEALTHAMT, 1, TRUE ); - - DeductPoints( this, restAPs, 0, AFTERACTION_INTERRUPT ); - - fSuccess = TRUE; - } - } } } } @@ -14531,9 +14511,8 @@ void SOLDIERTYPE::EVENT_SoldierBuildStructure( INT32 sGridNo, UINT8 ubDirection // Build the thing if ( RemoveFortification( sGridNo ) ) { - // test: does there an item that is a filled sandbag exist? (xmls might have changed) - UINT16 fullsandbagnr = 1541; - if ( HasItemFlag(fullsandbagnr, FULL_SANDBAG) ) + // eventually search for the number of a sandbag item + if ( HasItemFlag(fullsandbagnr, FULL_SANDBAG) || GetFirstItemWithFlag(&fullsandbagnr, FULL_SANDBAG) ) { // Erase 'material' item from our hand - we 'used' it to build the structure INT8 bObjSlot = HANDPOS; @@ -14551,28 +14530,6 @@ void SOLDIERTYPE::EVENT_SoldierBuildStructure( INT32 sGridNo, UINT8 ubDirection fSuccess = TRUE; } - else - { - fullsandbagnr = 2824; - if ( HasItemFlag(fullsandbagnr, FULL_SANDBAG) ) - { - // Erase 'material' item from our hand - we 'used' it to build the structure - INT8 bObjSlot = HANDPOS; - - CreateItem( fullsandbagnr, 100, &gTempObject ); - - // now add a tripwire item to the floor, simulating that activating tripwire deactivates it - AddItemToPool( sGridNo, &gTempObject, 1, 0, 0, -1 ); - - // we gain a bit of experience... - StatChange( this, STRAMT, 3, TRUE ); - StatChange( this, HEALTHAMT, 2, TRUE ); - - DeductPoints( this, restAPs, 0, AFTERACTION_INTERRUPT ); - - fSuccess = TRUE; - } - } } } }