Skip to content

Commit

Permalink
- playGenDudeSound.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Oct 12, 2021
1 parent ea63229 commit 75258c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
8 changes: 4 additions & 4 deletions source/games/blood/src/actor.cpp
Expand Up @@ -2997,7 +2997,7 @@ static bool actKillModernDude(DBloodActor* actor, DAMAGE_TYPE damageType)
pSprite->flags &= ~kPhysMove;
actor->xvel() = actor->yvel() = 0;

playGenDudeSound(pSprite, kGenDudeSndTransforming);
playGenDudeSound(actor, kGenDudeSndTransforming);
int seqId = pXSprite->data2 + kGenDudeSeqTransform;
if (getSequence(seqId)) seqSpawn(seqId, actor, -1);
else
Expand Down Expand Up @@ -3194,7 +3194,7 @@ static int checkDamageType(DBloodActor* actor, DAMAGE_TYPE damageType)
case kDudeModernCustom:
case kDudeModernCustomBurning:
{
playGenDudeSound(pSprite, kGenDudeSndDeathExplode);
playGenDudeSound(actor, kGenDudeSndDeathExplode);
GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
if (!pExtra->availDeaths[damageType])
{
Expand Down Expand Up @@ -3339,7 +3339,7 @@ static void modernCustomDudeDeath(DBloodActor* actor, int nSeq, int damageType)
auto pSprite = &actor->s();
auto pXSprite = &actor->x();

playGenDudeSound(pSprite, kGenDudeSndDeathNormal);
playGenDudeSound(actor, kGenDudeSndDeathNormal);
int dudeToGib = (actCheckRespawn(actor)) ? -1 : ((nSeq == 3) ? nDudeToGibClient2 : nDudeToGibClient1);
if (nSeq == 3)
{
Expand Down Expand Up @@ -3367,7 +3367,7 @@ static void modernCustomDudeBurningDeath(DBloodActor* actor, int nSeq)
{
auto pSprite = &actor->s();

playGenDudeSound(pSprite, kGenDudeSndDeathExplode);
playGenDudeSound(actor, kGenDudeSndDeathExplode);
int dudeToGib = (actCheckRespawn(actor)) ? -1 : nDudeToGibClient1;

if (Chance(0x4000)) spawnGibs(actor, GIBTYPE_27, -0xccccc);
Expand Down
12 changes: 6 additions & 6 deletions source/games/blood/src/ai.cpp
Expand Up @@ -456,7 +456,7 @@ void aiActivateDude(DBloodActor* actor)
}
else
{
if (Chance(0x4000)) playGenDudeSound(pSprite, kGenDudeSndTargetSpot);
if (Chance(0x4000)) playGenDudeSound(actor,kGenDudeSndTargetSpot);
if (spriteIsUnderwater(pSprite, false)) aiGenDudeNewState(actor, &genDudeChaseW);
else aiGenDudeNewState(actor, &genDudeChaseL);
}
Expand Down Expand Up @@ -1033,7 +1033,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
if (pSprite->type == kDudeModernCustomBurning)
{
if (Chance(0x2000) && actor->dudeExtra.time < PlayClock) {
playGenDudeSound(pSprite, kGenDudeSndBurning);
playGenDudeSound(actor,kGenDudeSndBurning);
actor->dudeExtra.time = PlayClock + 360;
}

Expand Down Expand Up @@ -1075,7 +1075,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
if (pExtra->canBurn && pExtra->availDeaths[kDamageBurn] > 0) {

aiPlay3DSound(actor, 361, AI_SFX_PRIORITY_0, -1);
playGenDudeSound(pSprite, kGenDudeSndBurning);
playGenDudeSound(actor,kGenDudeSndBurning);
pSprite->type = kDudeModernCustomBurning;

if (pXSprite->data2 == kGenDudeDefaultSeq) // don't inherit palette for burning if using default animation
Expand Down Expand Up @@ -1105,7 +1105,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
else aiGenDudeNewState(actor, &genDudeDodgeShortD);

if (Chance(0x0200))
playGenDudeSound(pSprite, kGenDudeSndGotHit);
playGenDudeSound(actor,kGenDudeSndGotHit);

}
else if (dudeIsPlayingSeq(actor, 13))
Expand All @@ -1116,7 +1116,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
}
else if (Chance(0x0200))
{
playGenDudeSound(pSprite, kGenDudeSndGotHit);
playGenDudeSound(actor,kGenDudeSndGotHit);
}
}
return nDamage;
Expand Down Expand Up @@ -1315,7 +1315,7 @@ void RecoilDude(DBloodActor* actor)
else if (rState == 2) pXSprite->aiState->nextState = &genDudeChaseD;
else pXSprite->aiState->nextState = &genDudeChaseW;

playGenDudeSound(pSprite, kGenDudeSndGotHit);
playGenDudeSound(actor,kGenDudeSndGotHit);

}

Expand Down
47 changes: 28 additions & 19 deletions source/games/blood/src/aiunicult.cpp
Expand Up @@ -217,7 +217,7 @@ void punchCallback(int, DBloodActor* actor)
int dy = SinScale16(pSprite->ang);
int dz = nZOffset1 - nZOffset2;

if (!playGenDudeSound(pSprite, kGenDudeSndAttackMelee))
if (!playGenDudeSound(actor, kGenDudeSndAttackMelee))
sfxPlay3DSound(actor, 530, 1, 0);

actFireVector(actor, 0, 0, dx, dy, dz,kVectorGenDudePunch);
Expand Down Expand Up @@ -255,7 +255,7 @@ void genDudeAttack1(int, DBloodActor* actor)
}

actFireVector(actor, 0, 0, dx, dy, dz,(VECTOR_TYPE)pExtra->curWeapon);
if (!playGenDudeSound(pSprite, kGenDudeSndAttackNormal))
if (!playGenDudeSound(actor, kGenDudeSndAttackNormal))
sfxPlayVectorSound(pSprite, pExtra->curWeapon);
}
else if (pExtra->weaponType == kGenDudeWeaponSummon)
Expand All @@ -278,7 +278,7 @@ void genDudeAttack1(int, DBloodActor* actor)

gKillMgr.AddNewKill(1);
pExtra->slave[pExtra->slaveCount++] = pSpawned->index;
if (!playGenDudeSound(pSprite, kGenDudeSndAttackNormal))
if (!playGenDudeSound(actor, kGenDudeSndAttackNormal))
sfxPlay3DSoundCP(actor, 379, 1, 0, 0x10000 - Random3(0x3000));
}
}
Expand All @@ -291,7 +291,7 @@ void genDudeAttack1(int, DBloodActor* actor)
dx += Random3(dispersion); dy += Random3(dispersion); dz += Random3(dispersion >> 1);

actFireMissile(actor, 0, 0, dx, dy, dz, pExtra->curWeapon);
if (!playGenDudeSound(pSprite, kGenDudeSndAttackNormal))
if (!playGenDudeSound(actor, kGenDudeSndAttackNormal))
sfxPlayMissileSound(pSprite, pExtra->curWeapon);
}
}
Expand Down Expand Up @@ -330,7 +330,7 @@ static void ThrowThing(DBloodActor* actor, bool impact)

const THINGINFO* pThinkInfo = &thingInfo[curWeapon - kThingBase];
if (!gThingInfoExtra[curWeapon - kThingBase].allowThrow) return;
else if (!playGenDudeSound(pSprite, kGenDudeSndAttackThrow))
else if (!playGenDudeSound(actor, kGenDudeSndAttackThrow))
sfxPlay3DSound(actor, 455, -1, 0);

int zThrow = 14500;
Expand Down Expand Up @@ -502,7 +502,7 @@ static void unicultThinkChase(DBloodActor* actor)
PLAYER* pPlayer = NULL;
if ((!IsPlayerSprite(pTarget)) || ((pPlayer = getPlayerById(pTarget->type)) != NULL && pPlayer->fraggerId == pSprite->index))
{
playGenDudeSound(pSprite, kGenDudeSndTargetDead);
playGenDudeSound(actor, kGenDudeSndTargetDead);
if (spriteIsUnderwater(pSprite, false)) aiGenDudeNewState(actor, &genDudeSearchShortW);
else aiGenDudeNewState(actor, &genDudeSearchShortL);
}
Expand Down Expand Up @@ -565,7 +565,7 @@ static void unicultThinkChase(DBloodActor* actor)
if (dist < pDudeInfo->seeDist && abs(losAngle) <= pDudeInfo->periphery) {

if ((PlayClock & 64) == 0 && Chance(0x3000) && !spriteIsUnderwater(pSprite, false))
playGenDudeSound(pSprite, kGenDudeSndChasing);
playGenDudeSound(actor, kGenDudeSndChasing);

actor->dudeSlope = DivScale(pTarget->z - pSprite->z, dist, 10);

Expand Down Expand Up @@ -636,7 +636,7 @@ static void unicultThinkChase(DBloodActor* actor)
return;
case kModernThingThrowableRock:
if (Chance(0x4000)) aiGenDudeNewState(actor, &genDudeThrow2);
else playGenDudeSound(pSprite, kGenDudeSndTargetSpot);
else playGenDudeSound(actor, kGenDudeSndTargetSpot);
return;
default:
aiGenDudeNewState(actor, &genDudeThrow2);
Expand Down Expand Up @@ -1324,12 +1324,14 @@ void aiGenDudeNewState(DBloodActor* actor, AISTATE* pAIState)
//
//---------------------------------------------------------------------------

bool playGenDudeSound(spritetype* pSprite, int mode) {

bool playGenDudeSound(DBloodActor* actor, int mode)
{
auto const pSprite = &actor->s();
auto const pXSprite = &actor->x();
if (mode < kGenDudeSndTargetSpot || mode >= kGenDudeSndMax) return false;
auto actor = &bloodActors[pSprite->index];
const GENDUDESND* sndInfo =& gCustomDudeSnd[mode]; bool gotSnd = false;
short sndStartId = xsprite[pSprite->extra].sysData1; int rand = sndInfo->randomRange;
const GENDUDESND* sndInfo = &gCustomDudeSnd[mode]; bool gotSnd = false;
short sndStartId = pXSprite->sysData1;
int rand = sndInfo->randomRange;
int sndId = (sndStartId <= 0) ? sndInfo->defaultSndId : sndStartId + sndInfo->sndIdOffset;
GENDUDEEXTRA* pExtra = &actor->genDudeExtra();

Expand Down Expand Up @@ -1357,8 +1359,8 @@ bool playGenDudeSound(spritetype* pSprite, int mode) {

if (sndId < 0) return false;
else if (sndStartId <= 0) { sndId += Random(rand); gotSnd = true; }
else {

else
{
// Let's try to get random snd
int maxRetries = 5;
while (maxRetries-- > 0) {
Expand All @@ -1370,9 +1372,11 @@ bool playGenDudeSound(spritetype* pSprite, int mode) {
}

// If no success in getting random snd, get first existing one
if (gotSnd == false) {
if (gotSnd == false)
{
int maxSndId = sndId + rand;
while (sndId++ < maxSndId) {
while (sndId++ < maxSndId)
{
if (!soundEngine->FindSoundByResID(sndId)) continue;
gotSnd = true;
break;
Expand All @@ -1383,13 +1387,18 @@ bool playGenDudeSound(spritetype* pSprite, int mode) {

if (gotSnd == false) return false;
else if (sndInfo->aiPlaySound) aiPlay3DSound(actor, sndId, AI_SFX_PRIORITY_2, -1);
else sfxPlay3DSound(pSprite, sndId, -1, 0);
else sfxPlay3DSound(actor, sndId, -1, 0);

pExtra->sndPlaying = true;
return true;
}


//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

bool spriteIsUnderwater(spritetype* pSprite, bool oldWay) {
return ((sector[pSprite->sectnum].extra >= 0 && xsector[sector[pSprite->sectnum].extra].Underwater)
|| (oldWay && (xsprite[pSprite->extra].medium == kMediumWater || xsprite[pSprite->extra].medium == kMediumGoo)));
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/aiunicult.h
Expand Up @@ -201,7 +201,7 @@ void removeLeech(spritetype* pLeech, bool delSprite = true);
void removeDudeStuff(spritetype* pSprite);
spritetype* leechIsDropped(spritetype* pSprite);
bool spriteIsUnderwater(spritetype* pSprite, bool oldWay = false);
bool playGenDudeSound(spritetype* pSprite, int mode);
bool playGenDudeSound(DBloodActor* actor, int mode);
void aiGenDudeMoveForward(DBloodActor* actor);
void aiGenDudeChooseDirection(DBloodActor* actor, int a3, int aXvel = -1, int aYvel = -1);
void aiGenDudeNewState(DBloodActor* actor, AISTATE* pAIState);
Expand Down

0 comments on commit 75258c8

Please sign in to comment.