- turned TurnRange calculation into a subfunction.

This formula was used in 36 places
This commit is contained in:
Christoph Oelckers 2022-09-27 00:20:44 +02:00
parent e309d05161
commit 8b96a93e80
10 changed files with 41 additions and 36 deletions

View file

@ -300,7 +300,7 @@ void aiMoveForward(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (abs(nAng) > DAngle60)
return;
@ -318,7 +318,7 @@ void aiMoveTurn(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
}
@ -333,7 +333,7 @@ void aiMoveDodge(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (actor->xspr.dodgeDir)
{

View file

@ -201,7 +201,7 @@ static void batMoveDodgeUp(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
AdjustVelocity(actor, ADJUSTER{
if (actor->xspr.dodgeDir > 0)
@ -218,7 +218,7 @@ static void batMoveDodgeDown(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (actor->xspr.dodgeDir == 0)
return;
@ -299,7 +299,7 @@ static void batMoveForward(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -324,7 +324,7 @@ static void batMoveSwoop(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -348,7 +348,7 @@ static void batMoveFly(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)

View file

@ -394,7 +394,7 @@ static void beastMoveForward(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (abs(nAng) > DAngle60)
return;
@ -410,7 +410,7 @@ static void sub_628A0(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -438,7 +438,7 @@ static void sub_62AE0(DBloodActor* actor)
int z = actor->int_pos().Z + getDudeInfo(actor->spr.type)->eyeHeight;
int z2 = target->int_pos().Z + getDudeInfo(target->spr.type)->eyeHeight;
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -467,7 +467,7 @@ static void sub_62D7C(DBloodActor* actor)
int z = actor->int_pos().Z + getDudeInfo(actor->spr.type)->eyeHeight;
int z2 = target->int_pos().Z + getDudeInfo(target->spr.type)->eyeHeight;
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)

View file

@ -216,7 +216,7 @@ static void eelMoveDodgeUp(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
AdjustVelocity(actor, ADJUSTER{
if (actor->xspr.dodgeDir > 0)
@ -233,7 +233,7 @@ static void eelMoveDodgeDown(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (actor->xspr.dodgeDir == 0)
return;
@ -308,7 +308,7 @@ static void eelMoveForward(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 26) / 120) / 120) << 2;
if (abs(nAng) > DAngle60)
@ -333,7 +333,7 @@ static void eelMoveSwoop(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 26) / 120) / 120) << 2;
if (abs(nAng) > DAngle60)
@ -354,7 +354,7 @@ static void eelMoveAscend(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 26) / 120) / 120) << 2;
if (abs(nAng) > DAngle60)

View file

@ -279,7 +279,7 @@ static void sub_65D04(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -309,7 +309,7 @@ static void sub_65F44(DBloodActor* actor)
int z = actor->int_pos().Z + getDudeInfo(actor->spr.type)->eyeHeight;
int z2 = target->int_pos().Z + getDudeInfo(target->spr.type)->eyeHeight;
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -339,7 +339,7 @@ static void sub_661E0(DBloodActor* actor)
int z = actor->int_pos().Z + getDudeInfo(actor->spr.type)->eyeHeight;
int z2 = target->int_pos().Z + getDudeInfo(target->spr.type)->eyeHeight;
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)

View file

@ -277,7 +277,7 @@ static void gargMoveDodgeUp(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
AdjustVelocity(actor, ADJUSTER{
if (actor->xspr.dodgeDir > 0)
@ -297,7 +297,7 @@ static void gargMoveDodgeDown(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (actor->xspr.dodgeDir == 0)
return;
@ -512,7 +512,7 @@ static void gargMoveForward(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -540,7 +540,7 @@ static void gargMoveSlow(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -575,7 +575,7 @@ static void gargMoveSwoop(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -610,7 +610,7 @@ static void gargMoveFly(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)

View file

@ -256,7 +256,7 @@ static void ghostMoveDodgeUp(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
AdjustVelocity(actor, ADJUSTER{
if (actor->xspr.dodgeDir > 0)
@ -276,7 +276,7 @@ static void ghostMoveDodgeDown(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
if (actor->xspr.dodgeDir == 0)
return;
@ -407,7 +407,7 @@ static void ghostMoveForward(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -434,7 +434,7 @@ static void ghostMoveSlow(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -465,7 +465,7 @@ static void ghostMoveSwoop(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)
@ -495,7 +495,7 @@ static void ghostMoveFly(DBloodActor* actor)
}
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)

View file

@ -266,7 +266,7 @@ static void sub_6CB00(DBloodActor* actor)
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 27) / 120) / 120) << 2;
if (abs(nAng) > DAngle60)
@ -295,7 +295,7 @@ static void sub_6CD74(DBloodActor* actor)
int z = actor->int_pos().Z + getDudeInfo(actor->spr.type)->eyeHeight;
int z2 = target->int_pos().Z + getDudeInfo(target->spr.type)->eyeHeight;
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 27) / 120) / 120) << 2;
if (abs(nAng) > DAngle60)
@ -324,7 +324,7 @@ static void sub_6D03C(DBloodActor* actor)
int z = actor->int_pos().Z + getDudeInfo(actor->spr.type)->eyeHeight;
int z2 = target->int_pos().Z + getDudeInfo(target->spr.type)->eyeHeight;
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 27) / 120) / 120) << 2;
if (abs(nAng) > DAngle60)

View file

@ -1114,7 +1114,7 @@ void aiGenDudeMoveForward(DBloodActor* actor)
if (pExtra->canFly)
{
auto nAng = deltaangle(actor->spr.angle, actor->xspr.goalAng);
auto nTurnRange = DAngle::fromQ16(pDudeInfo->angSpeed << 3);
auto nTurnRange = pDudeInfo->TurnRange();
actor->spr.angle += clamp(nAng, -nTurnRange, nTurnRange);
int nAccel = pDudeInfo->frontSpeed << 2;
if (abs(nAng) > DAngle60)

View file

@ -73,6 +73,11 @@ struct DUDEINFO {
{
return FixedToFloat(frontSpeed);
}
inline DAngle TurnRange() const
{
return DAngle::fromQ16(angSpeed << 3);
}
};
extern DUDEINFO dudeInfo[kDudeMax - kDudeBase];