Friendly fire related fixes (#184)

This commit is contained in:
CommonLoon102 2019-09-22 07:53:42 +00:00 committed by Christoph Oelckers
parent d19e74b31a
commit 67472623fe
4 changed files with 42 additions and 13 deletions

View file

@ -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];

View file

@ -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);

View file

@ -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);

View file

@ -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);