- consolidation of Blood rotation code.

24x the same pattern merged into a subfunction.
This commit is contained in:
Christoph Oelckers 2022-09-03 11:54:01 +02:00
parent b5c679f228
commit 39109de22f
10 changed files with 159 additions and 268 deletions

View file

@ -241,4 +241,5 @@ void actBuildMissile(DBloodActor* spawned, DBloodActor* actor);
extern const int16_t DudeDifficulty[]; extern const int16_t DudeDifficulty[];
END_BLD_NS END_BLD_NS

View file

@ -319,18 +319,13 @@ static void batMoveForward(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if ((unsigned int)Random(64) < 32 && nDist <= 0x200) if ((unsigned int)Random(64) < 32 && nDist <= 0x200)
return; return;
int nCos = Cos(actor->int_ang());
int nSin = Sin(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int vx = actor->int_vel().X; if (actor->GetTarget() == nullptr)
int vy = actor->int_vel().Y; t1 += FixedToFloat(nAccel);
int t1 = DMulScale(vx, nCos, vy, nSin, 30); else
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); t1 += FixedToFloat(nAccel * 0.5);
if (actor->GetTarget() == nullptr) });
t1 += nAccel;
else
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void batMoveSwoop(DBloodActor* actor) static void batMoveSwoop(DBloodActor* actor)
@ -350,15 +345,10 @@ static void batMoveSwoop(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x600) && nDist <= 0x200) if (Chance(0x600) && nDist <= 0x200)
return; return;
int nCos = Cos(actor->int_ang());
int nSin = Sin(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel) * 0.5;
int vy = actor->int_vel().Y; });
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(0x44444); actor->set_int_bvel_z(0x44444);
} }
@ -379,15 +369,9 @@ static void batMoveFly(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x4000) && nDist <= 0x200) if (Chance(0x4000) && nDist <= 0x200)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel) * 0.5;
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(-0x2d555); actor->set_int_bvel_z(-0x2d555);
} }

View file

@ -422,18 +422,12 @@ static void sub_628A0(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Random(64) < 32 && nDist <= 0x400) if (Random(64) < 32 && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.25);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 2;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void sub_62AE0(DBloodActor* actor) static void sub_62AE0(DBloodActor* actor)
@ -458,15 +452,10 @@ static void sub_62AE0(DBloodActor* actor)
int dz = z2 - z; int dz = z2 - z;
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(-dz); actor->set_int_bvel_z(-dz);
} }
@ -492,15 +481,10 @@ static void sub_62D7C(DBloodActor* actor)
int dz = (z2 - z) << 3; int dz = (z2 - z) << 3;
if (Chance(0x4000) && nDist <= 0x400) if (Chance(0x4000) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(dz); actor->set_int_bvel_z(dz);
} }

View file

@ -331,18 +331,13 @@ static void eelMoveForward(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (nDist <= 0x399) if (nDist <= 0x399)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.5);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void eelMoveSwoop(DBloodActor* actor) static void eelMoveSwoop(DBloodActor* actor)
@ -359,15 +354,10 @@ static void eelMoveSwoop(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x8000) && nDist <= 0x399) if (Chance(0x8000) && nDist <= 0x399)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(0x22222); actor->set_int_bvel_z(0x22222);
} }
@ -385,15 +375,10 @@ static void eelMoveAscend(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x4000) && nDist <= 0x399) if (Chance(0x4000) && nDist <= 0x399)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(-0x8000); actor->set_int_bvel_z(-0x8000);
} }

View file

@ -290,18 +290,13 @@ static void sub_65D04(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Random(64) < 32 && nDist <= 0x400) if (Random(64) < 32 && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.25);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 2;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void sub_65F44(DBloodActor* actor) static void sub_65F44(DBloodActor* actor)
@ -327,15 +322,10 @@ static void sub_65F44(DBloodActor* actor)
int dz = z2 - z; int dz = z2 - z;
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(-dz); actor->set_int_bvel_z(-dz);
} }
@ -362,15 +352,10 @@ static void sub_661E0(DBloodActor* actor)
int dz = (z2 - z) << 3; int dz = (z2 - z) << 3;
if (Chance(0x4000) && nDist <= 0x400) if (Chance(0x4000) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(dz); actor->set_int_bvel_z(dz);
} }

View file

@ -532,18 +532,13 @@ static void gargMoveForward(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if ((unsigned int)Random(64) < 32 && nDist <= 0x400) if ((unsigned int)Random(64) < 32 && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.5);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void gargMoveSlow(DBloodActor* actor) static void gargMoveSlow(DBloodActor* actor)
@ -566,16 +561,11 @@ static void gargMoveSlow(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; t2 *= 0.5;
int vy = actor->int_vel().Y; });
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 = nAccel >> 1;
t2 >>= 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
switch (actor->spr.type) { switch (actor->spr.type) {
case kDudeGargoyleFlesh: case kDudeGargoyleFlesh:
actor->set_int_bvel_z(0x44444); actor->set_int_bvel_z(0x44444);
@ -606,23 +596,19 @@ static void gargMoveSwoop(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang());
int nSin = Sin(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel * 0.5);
int vy = actor->int_vel().Y; switch (actor->spr.type) {
int t1 = DMulScale(vx, nCos, vy, nSin, 30); case kDudeGargoyleFlesh:
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); actor->vel.Z = t1;
t1 += nAccel >> 1; break;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30)); case kDudeGargoyleStone:
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30)); actor->vel.Z = t1;
switch (actor->spr.type) { break;
case kDudeGargoyleFlesh: }
actor->set_int_bvel_z(t1); });
break;
case kDudeGargoyleStone:
actor->set_int_bvel_z(t1);
break;
}
} }
static void gargMoveFly(DBloodActor* actor) static void gargMoveFly(DBloodActor* actor)
@ -645,23 +631,19 @@ static void gargMoveFly(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x4000) && nDist <= 0x400) if (Chance(0x4000) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang());
int nSin = Sin(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel * 0.5);
int vy = actor->int_vel().Y; switch (actor->spr.type) {
int t1 = DMulScale(vx, nCos, vy, nSin, 30); case kDudeGargoyleFlesh:
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); actor->vel.Z = -t1;
t1 += nAccel >> 1; break;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30)); case kDudeGargoyleStone:
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30)); actor->vel.Z = -t1;
switch (actor->spr.type) { break;
case kDudeGargoyleFlesh: }
actor->set_int_bvel_z(-t1); });
break;
case kDudeGargoyleStone:
actor->set_int_bvel_z(-t1);
break;
}
} }
END_BLD_NS END_BLD_NS

View file

@ -428,18 +428,12 @@ static void ghostMoveForward(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if ((unsigned int)Random(64) < 32 && nDist <= 0x400) if ((unsigned int)Random(64) < 32 && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.5);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void ghostMoveSlow(DBloodActor* actor) static void ghostMoveSlow(DBloodActor* actor)
@ -462,16 +456,10 @@ static void ghostMoveSlow(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; t2 *= 0.5;
int vy = actor->int_vel().Y; });
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 = nAccel >> 1;
t2 >>= 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
switch (actor->spr.type) { switch (actor->spr.type) {
case kDudePhantasm: case kDudePhantasm:
actor->set_int_bvel_z(0x44444); actor->set_int_bvel_z(0x44444);
@ -499,20 +487,14 @@ static void ghostMoveSwoop(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; switch (actor->spr.type) {
int vy = actor->int_vel().Y; case kDudePhantasm:
int t1 = DMulScale(vx, nCos, vy, nSin, 30); actor->vel.Z = t1;
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); break;
t1 += nAccel >> 1; }
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30)); });
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
switch (actor->spr.type) {
case kDudePhantasm:
actor->set_int_bvel_z(t1);
break;
}
} }
static void ghostMoveFly(DBloodActor* actor) static void ghostMoveFly(DBloodActor* actor)
@ -535,20 +517,14 @@ static void ghostMoveFly(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Chance(0x4000) && nDist <= 0x400) if (Chance(0x4000) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; switch (actor->spr.type) {
int vy = actor->int_vel().Y; case kDudePhantasm:
int t1 = DMulScale(vx, nCos, vy, nSin, 30); actor->vel.Z = -t1;
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); break;
t1 += nAccel >> 1; }
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30)); });
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
switch (actor->spr.type) {
case kDudePhantasm:
actor->set_int_bvel_z(-t1);
break;
}
} }
END_BLD_NS END_BLD_NS

View file

@ -277,18 +277,13 @@ static void sub_6CB00(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if (Random(64) < 32 && nDist <= 0x400) if (Random(64) < 32 && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.25);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 2;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
static void sub_6CD74(DBloodActor* actor) static void sub_6CD74(DBloodActor* actor)
@ -313,15 +308,10 @@ static void sub_6CD74(DBloodActor* actor)
int dz = z2 - z; int dz = z2 - z;
if (Chance(0x600) && nDist <= 0x400) if (Chance(0x600) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(-dz); actor->set_int_bvel_z(-dz);
} }
@ -347,15 +337,10 @@ static void sub_6D03C(DBloodActor* actor)
int dz = (z2 - z) << 3; int dz = (z2 - z) << 3;
if (Chance(0x4000) && nDist <= 0x400) if (Chance(0x4000) && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); t1 += FixedToFloat(nAccel * 0.5);
int vx = actor->int_vel().X; });
int vy = actor->int_vel().Y;
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
actor->set_int_bvel_z(dz); actor->set_int_bvel_z(dz);
} }

View file

@ -1126,18 +1126,13 @@ void aiGenDudeMoveForward(DBloodActor* actor)
int nDist = approxDist(dvec); int nDist = approxDist(dvec);
if ((unsigned int)Random(64) < 32 && nDist <= 0x400) if ((unsigned int)Random(64) < 32 && nDist <= 0x400)
return; return;
int nCos = Cos(actor->int_ang()); AdjustVelocity(actor, ADJUSTER{
int nSin = Sin(actor->int_ang()); if (actor->GetTarget() == nullptr)
int vx = actor->int_vel().X; t1 += FixedToFloat(nAccel);
int vy = actor->int_vel().Y; else
int t1 = DMulScale(vx, nCos, vy, nSin, 30); t1 += FixedToFloat(nAccel * 0.5);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30); });
if (actor->GetTarget() == nullptr)
t1 += nAccel;
else
t1 += nAccel >> 1;
actor->set_int_bvel_x(DMulScale(t1, nCos, t2, nSin, 30));
actor->set_int_bvel_y(DMulScale(t1, nSin, -t2, nCos, 30));
} }
else else
{ {

View file

@ -174,5 +174,19 @@ inline bool IsTargetTeammate(DBloodActor* pSource, DBloodActor* pTarget)
return IsTargetTeammate(pSourcePlayer, pTarget); return IsTargetTeammate(pSourcePlayer, pTarget);
} }
template<typename T>
void AdjustVelocity(DBloodActor *actor, T adjuster)
{
double nCos = actor->spr.angle.Cos();
double nSin = actor->spr.angle.Sin();
double t1 = actor->vel.X * nCos + actor->vel.Y * nSin;
double t2 = actor->vel.X * nSin - actor->vel.Y * nCos;
adjuster(actor, t1, t2);
actor->vel.X = t1 * nCos + t2 * nSin;
actor->vel.Y = t1 * nSin - t2 * nCos;
}
// just so we don't have to type this out several dozen times
#define ADJUSTER [=](DBloodActor* actor, double& t1, double& t2)
END_BLD_NS END_BLD_NS