diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 2226681c..b926cb20 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -12827,6 +12827,55 @@ UINT16 GetFirstExplosiveOfType(UINT16 expType) return 0; } +// sevenfm: same as GetFirstExplosiveOfType, but check only hand grenades +UINT16 GetFirstHandGrenadeOfType(UINT16 expType) +{ + for (UINT16 i = 0; i < gMAXITEMS_READ; i++) + { + if (ItemIsHandGrenade(i) && + Item[i].ubCoolness > 0 && + Explosive[Item[i].ubClassIndex].ubType == expType) + return i; + } + + return 0; +} + +// sevenfm: use to substitute default item with first matching if needed +UINT16 GetHandGrenadeOfType(UINT16 usDefaultItem, UINT16 usType) +{ + UINT16 usSmokeItem = usDefaultItem; + + if (usSmokeItem > 0 && + ItemIsHandGrenade(usSmokeItem) && + Item[usSmokeItem].ubCoolness > 0 && + Explosive[Item[usSmokeItem].ubClassIndex].ubType == usType) + return usSmokeItem; + + usSmokeItem = GetFirstHandGrenadeOfType(EXPLOSV_SMOKE); + + if (usSmokeItem > 0 && + ItemIsHandGrenade(usSmokeItem) && + Item[usSmokeItem].ubCoolness > 0 && + Explosive[Item[usSmokeItem].ubClassIndex].ubType == usType) + return usSmokeItem; + + return 0; +} + +// sevenfm: check if item is valid hand grenade +BOOLEAN ItemIsHandGrenade(UINT16 usItem) +{ + if (usItem > 0 && + Item[usItem].usItemClass == IC_GRENADE && + Item[usItem].ubCursor == TOSSCURS) + { + return TRUE; + } + + return FALSE; +} + // WDS - Smart goggle switching OBJECTTYPE* FindSunGogglesInInv( SOLDIERTYPE * pSoldier, INT8 * bSlot, BOOLEAN * isAttach, BOOLEAN searchAllInventory ) { diff --git a/Tactical/Items.h b/Tactical/Items.h index 29271e66..264d6acc 100644 --- a/Tactical/Items.h +++ b/Tactical/Items.h @@ -430,6 +430,10 @@ INT16 GetGearAPBonus( SOLDIERTYPE * pSoldier ); INT16 GetAPBonus( OBJECTTYPE * pObj ); UINT16 GetFirstExplosiveOfType(UINT16 expType); +UINT16 GetFirstHandGrenadeOfType(UINT16 expType); +UINT16 GetHandGrenadeOfType(UINT16 usDefaultItem, UINT16 usType); + +BOOLEAN ItemIsHandGrenade(UINT16 usItem); OBJECTTYPE* FindSunGogglesInInv( SOLDIERTYPE * pSoldier, INT8 * bSlot, BOOLEAN * isAttach, BOOLEAN searchAllInventory = FALSE ); OBJECTTYPE* FindNightGogglesInInv( SOLDIERTYPE * pSoldier, INT8 * bSlot, BOOLEAN * isAttach, BOOLEAN searchAllInventory = FALSE ); diff --git a/TileEngine/Explosion Control.cpp b/TileEngine/Explosion Control.cpp index 2d26a07c..28a4767d 100644 --- a/TileEngine/Explosion Control.cpp +++ b/TileEngine/Explosion Control.cpp @@ -379,11 +379,14 @@ void InternalIgniteExplosion( UINT8 ubOwner, INT16 sX, INT16 sY, INT16 sZ, INT32 Item[usItem].usBuddyItem == 0 && Explosive[Item[usItem].ubClassIndex].ubDamage > 20) { - UINT16 usSmokeItem = SMOKE_GRENADE; - if (HasItemFlag(usItem, JUMP_GRENADE)) - NewSmokeEffect(sGridNo, usSmokeItem, bLevel, ubOwner, 0, 1, 0); - else - NewSmokeEffect(sGridNo, usSmokeItem, bLevel, ubOwner, 0, 2, 1); + UINT16 usSmokeItem = GetHandGrenadeOfType(SMOKE_GRENADE, EXPLOSV_SMOKE); + if (usSmokeItem) + { + if (HasItemFlag(usItem, JUMP_GRENADE)) + NewSmokeEffect(sGridNo, usSmokeItem, bLevel, ubOwner, 0, 1, 0); + else + NewSmokeEffect(sGridNo, usSmokeItem, bLevel, ubOwner, 0, 2, 1); + } } }