From 67472623fe10d0c95400d791dd791e9c5fd7ec3b Mon Sep 17 00:00:00 2001 From: CommonLoon102 <321850+CommonLoon102@users.noreply.github.com> Date: Sun, 22 Sep 2019 07:53:42 +0000 Subject: [PATCH] Friendly fire related fixes (#184) --- source/blood/src/actor.cpp | 15 ++++----------- source/blood/src/player.cpp | 2 ++ source/blood/src/player.h | 30 ++++++++++++++++++++++++++++++ source/blood/src/weapon.cpp | 8 ++++++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/source/blood/src/actor.cpp b/source/blood/src/actor.cpp index d7f4cd6b0..dfbd9b580 100644 --- a/source/blood/src/actor.cpp +++ b/source/blood/src/actor.cpp @@ -3716,17 +3716,8 @@ int actDamageSprite(int nSource, spritetype *pSprite, DAMAGE_TYPE damageType, in PLAYER *pSourcePlayer = NULL; if (IsPlayerSprite(&sprite[nSource])) pSourcePlayer = &gPlayer[sprite[nSource].type-kDudePlayer1]; - if (!gGameOptions.bFriendlyFire && pSourcePlayer != NULL && (gGameOptions.nGameType == 1 || gGameOptions.nGameType == 3) && IsPlayerSprite(pSprite)) - { - PLAYER *pTargetPlayer = &gPlayer[pSprite->type-kDudePlayer1]; - if (pSourcePlayer != pTargetPlayer) - { - if (gGameOptions.nGameType == 1) - return 0; - if (gGameOptions.nGameType == 3 && (pSourcePlayer->at2ea&3) == (pTargetPlayer->at2ea&3)) - return 0; - } - } + if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pSourcePlayer, pSprite)) + return 0; switch (pSprite->statnum) { case 6: @@ -6935,6 +6926,8 @@ void actFireVector(spritetype *pShooter, int a2, int a3, int a4, int a5, int a6, int nSprite = gHitInfo.hitsprite; dassert(nSprite >= 0 && nSprite < kMaxSprites); spritetype *pSprite = &sprite[nSprite]; + if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pShooter, pSprite)) + return; if (IsPlayerSprite(pSprite)) { PLAYER *pPlayer = &gPlayer[pSprite->type-kDudePlayer1]; diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index a34b9ddf2..298e8afc2 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -2348,6 +2348,8 @@ void playerLandingSound(PLAYER *pPlayer) SPRITEHIT *pHit = &gSpriteHit[pSprite->extra]; if (pHit->florhit) { + if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, &sprite[pHit->florhit & 0x3fff])) + return; char nSurf = tileGetSurfType(pHit->florhit); if (nSurf) sfxPlay3DSound(pSprite, surfaceSound[nSurf], -1, 0); diff --git a/source/blood/src/player.h b/source/blood/src/player.h index 253382d63..1f3952516 100644 --- a/source/blood/src/player.h +++ b/source/blood/src/player.h @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "controls.h" #include "db.h" #include "dude.h" +#include "levels.h" BEGIN_BLD_NS @@ -208,6 +209,35 @@ extern ClockTicks dword_21EFD0[kMaxPlayers]; extern AMMOINFO gAmmoInfo[]; extern POWERUPINFO gPowerUpInfo[kMaxPowerUps]; +inline bool IsTargetTeammate(PLAYER* pSourcePlayer, spritetype* pTargetSprite) +{ + if (pSourcePlayer == NULL) + return false; + if (!IsPlayerSprite(pTargetSprite)) + return false; + if (gGameOptions.nGameType == 1 || gGameOptions.nGameType == 3) + { + PLAYER* pTargetPlayer = &gPlayer[pTargetSprite->type - kDudePlayer1]; + if (pSourcePlayer != pTargetPlayer) + { + if (gGameOptions.nGameType == 1) + return true; + if (gGameOptions.nGameType == 3 && (pSourcePlayer->at2ea & 3) == (pTargetPlayer->at2ea & 3)) + return true; + } + } + + return false; +} + +inline bool IsTargetTeammate(spritetype* pSourceSprite, spritetype* pTargetSprite) +{ + if (!IsPlayerSprite(pSourceSprite)) + return false; + PLAYER* pSourcePlayer = &gPlayer[pSourceSprite->type - kDudePlayer1]; + return IsTargetTeammate(pSourcePlayer, pTargetSprite); +} + int powerupCheck(PLAYER *pPlayer, int nPowerUp); char powerupActivate(PLAYER *pPlayer, int nPowerUp); void powerupDeactivate(PLAYER *pPlayer, int nPowerUp); diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 702619766..f543d319e 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -1340,6 +1340,8 @@ void FireVoodoo(int nTrigger, PLAYER *pPlayer) } dassert(pPlayer->voodooTarget >= 0); spritetype *pTarget = &sprite[pPlayer->voodooTarget]; + if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, pTarget)) + return; switch (nTrigger) { case 0: @@ -1386,7 +1388,6 @@ void FireVoodoo(int nTrigger, PLAYER *pPlayer) void AltFireVoodoo(int nTrigger, PLAYER *pPlayer) { - if (nTrigger == 2) { // by NoOne: trying to simulate v1.0x voodoo here. @@ -1399,7 +1400,8 @@ void AltFireVoodoo(int nTrigger, PLAYER *pPlayer) { int nTarget = pPlayer->at1de[i]; spritetype* pTarget = &sprite[nTarget]; - + if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, pTarget)) + continue; int nDist = approxDist(pTarget->x - pPlayer->pSprite->x, pTarget->y - pPlayer->pSprite->y); if (nDist > 0 && nDist < 51200) { @@ -1434,6 +1436,8 @@ void AltFireVoodoo(int nTrigger, PLAYER *pPlayer) { int nTarget = pPlayer->at1de[i]; spritetype* pTarget = &sprite[nTarget]; + if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, pTarget)) + continue; if (v4 > 0) v4--; int nDist = approxDist(pTarget->x - pPlayer->pSprite->x, pTarget->y - pPlayer->pSprite->y);