Skip to content

Commit 47442a5

Browse files
committed
feat: add additional parameters to strafe tool
1 parent 352b019 commit 47442a5

File tree

2 files changed

+50
-14
lines changed

2 files changed

+50
-14
lines changed

src/Features/Tas/TasTools/StrafeTool.cpp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ void AutoStrafeTool::Apply(TasFramebulk &fb, const TasPlayerInfo &pInfo) {
5757
this->updated = false;
5858
}
5959

60-
bool shouldStrafe = true;
60+
bool reachedTargetValues = false;
6161
FOR_TAS_SCRIPT_VERSIONS_SINCE(8) {
62-
shouldStrafe = !TryReachTargetValues(fb, fakePlayerInfo);
62+
reachedTargetValues = TryReachTargetValues(fb, fakePlayerInfo);
6363
}
64-
if (shouldStrafe) {
64+
if (!reachedTargetValues) {
6565
ApplyStrafe(fb, fakePlayerInfo);
6666
}
6767

@@ -133,8 +133,8 @@ bool AutoStrafeTool::TryReachTargetValues(TasFramebulk &bulk, const TasPlayerInf
133133

134134
float playerYawRad = DEG2RAD(pInfo.angles.y);
135135
float wishDirAngleRad = absoluteWishDirAngleRad - playerYawRad;
136-
float forwardMove = cosf(wishDirAngleRad);
137-
float sideMove = -sinf(wishDirAngleRad);
136+
float forwardMove = cosf(wishDirAngleRad) * params.force;
137+
float sideMove = -sinf(wishDirAngleRad) * params.force;
138138

139139
Vector velocityAfterMove = GetVelocityAfterMove(pInfo, forwardMove, sideMove);
140140
Vector afterMoveDelta = velocityAfterMove - velocity;
@@ -172,7 +172,7 @@ void AutoStrafeTool::ApplyStrafe(TasFramebulk &fb, const TasPlayerInfo &pInfo) {
172172
}
173173
}
174174

175-
float angle = velAngle + RAD2DEG(this->GetStrafeAngle(pInfo, params));
175+
float angle = velAngle + RAD2DEG(this->GetStrafeAngle(pInfo, params)) * params.turnRate;
176176

177177
FOR_TAS_SCRIPT_VERSIONS_SINCE(8) {
178178
// Deal with airlock: we're strafing, so always try to maximize how much
@@ -225,6 +225,8 @@ void AutoStrafeTool::ApplyStrafe(TasFramebulk &fb, const TasPlayerInfo &pInfo) {
225225
QAngle newAngle = {0, angle + lookAngle, 0};
226226
fb.viewAnalog.x -= newAngle.y - pInfo.angles.y;
227227
}
228+
229+
fb.moveAnalog *= params.force;
228230
}
229231

230232
// returns player's velocity after its been affected by ground friction
@@ -366,7 +368,7 @@ float AutoStrafeTool::GetFastestStrafeAngle(const TasPlayerInfo &player) {
366368

367369
if (velocity.Length2D() == 0) return 0;
368370

369-
Vector wishDir(0, 1);
371+
Vector wishDir = Vector(0, 1) * params.force;
370372
float maxSpeed = GetMaxSpeed(player, wishDir);
371373
float maxAccel = GetMaxAccel(player, wishDir);
372374

@@ -385,7 +387,8 @@ float AutoStrafeTool::GetTargetStrafeAngle(const TasPlayerInfo &player, float ta
385387
float currentSpeed = vel.Length2D();
386388
if (currentSpeed == 0) return 0;
387389

388-
float maxAccel = GetMaxAccel(player, {0, 1});
390+
Vector wishDir = Vector(0, 1) * params.force;
391+
float maxAccel = GetMaxAccel(player, wishDir);
389392

390393
// Assuming that it is possible to achieve a velocity of a given length,
391394
// I'm using a law of cosines to get the right angle for acceleration.
@@ -425,7 +428,7 @@ float AutoStrafeTool::GetTurningStrafeAngle(const TasPlayerInfo &player) {
425428

426429
if (velocity.Length2D() == 0) return 0;
427430

428-
Vector wishDir(0, 1);
431+
Vector wishDir = Vector(0, 1) * params.force;
429432
float maxAccel = GetMaxAccel(player, wishDir);
430433

431434
// In order to maximize the angle between old and new velocity, the angle between
@@ -480,6 +483,9 @@ float AutoStrafeTool::GetStrafeAngle(const TasPlayerInfo &player, AutoStrafePara
480483
sidemove = sinOld(ang);
481484
}
482485

486+
forwardmove *= params.force;
487+
sidemove *= params.force;
488+
483489
float predictedVel = GetVelocityAfterMove(player, forwardmove, sidemove).Length2D();
484490
if ((speedDiff > 0 && predictedVel > params.strafeSpeed.speed) || (speedDiff < 0 && predictedVel < params.strafeSpeed.speed)) {
485491
passedTargetSpeed = true;
@@ -522,7 +528,7 @@ int AutoStrafeTool::GetTurningDirection(const TasPlayerInfo &pInfo, float desAng
522528
// using the math from max angle change strafing to determine whether
523529
// line following is too "wobbly"
524530
Vector velocity = GetGroundFrictionVelocity(pInfo);
525-
float maxAccel = GetMaxAccel(pInfo, Vector(0, 1));
531+
float maxAccel = GetMaxAccel(pInfo, Vector(0, 1) * params.force);
526532
float maxRotAng = RAD2DEG(asinf(maxAccel / velocity.Length2D()));
527533

528534
// scale maxRotAng by surfaceFriction and make it slightly bigger, as the range
@@ -585,7 +591,7 @@ int AutoStrafeTool::GetTurningDirection(const TasPlayerInfo &pInfo, float desAng
585591
}
586592

587593
if (shouldPreventSpeedLock) {
588-
Vector wishDir(0, 1);
594+
Vector wishDir = Vector(0, 1) * params.force;
589595
float maxSpeed = GetMaxSpeed(pInfo, wishDir);
590596
float maxAccel = GetMaxAccel(pInfo, wishDir);
591597

@@ -632,6 +638,8 @@ std::shared_ptr<TasToolParams> AutoStrafeTool::ParseParams(std::vector<std::stri
632638
AutoStrafeSpeed speed = {SPECIFIED, maxSpeed};
633639
bool noPitchLock = false;
634640
bool antiSpeedLock = true;
641+
float turnRate = 1.0f;
642+
float force = 1.0f;
635643

636644
if (vp.size() == 0) {
637645
return std::make_shared<AutoStrafeParams>();
@@ -658,6 +666,9 @@ std::shared_ptr<TasToolParams> AutoStrafeTool::ParseParams(std::vector<std::stri
658666
} else if (param.size() > 3 && param.substr(param.size() - 3, 3) == "ups") {
659667
speed.type = SPECIFIED;
660668
speed.speed = TasParser::toFloat(param.substr(0, param.size() - 3));
669+
} else if (param == "min") {
670+
speed.type = SPECIFIED;
671+
speed.speed = 0.0f;
661672
}
662673

663674
//dir (using large numbers for left and right because angle is clamped to range -180 and 180)
@@ -686,10 +697,31 @@ std::shared_ptr<TasToolParams> AutoStrafeTool::ParseParams(std::vector<std::stri
686697
antiSpeedLock = false;
687698
}
688699

700+
//named value parameters
701+
else if (param.find('=') != std::string::npos) {
702+
size_t eqPos = param.find('=');
703+
std::string key = param.substr(0, eqPos);
704+
std::string value = param.substr(eqPos + 1);
705+
706+
if (key == "turnrate") {
707+
turnRate = TasParser::toFloat(value);
708+
} else if (key == "force") {
709+
force = TasParser::toFloat(value);
710+
} else if (key == "velocity" || key == "vel") {
711+
speed.type = SPECIFIED;
712+
speed.speed = TasParser::toFloat(value);
713+
} else if (key == "angle" || key == "ang") {
714+
dir.angle = SPECIFIED;
715+
dir.angle = TasParser::toFloat(value);
716+
} else {
717+
throw TasParserException(Utils::ssprintf("Unknown named parameter for tool %s: %s", this->GetName(), key.c_str()));
718+
}
719+
}
720+
689721
//unknown parameter...
690722
else
691723
throw TasParserException(Utils::ssprintf("Bad parameter for tool %s: %s", this->GetName(), param.c_str()));
692724
}
693725

694-
return std::make_shared<AutoStrafeParams>(type, dir, speed, noPitchLock, antiSpeedLock);
726+
return std::make_shared<AutoStrafeParams>(type, dir, speed, noPitchLock, antiSpeedLock, turnRate, force);
695727
}

src/Features/Tas/TasTools/StrafeTool.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,21 @@ struct AutoStrafeParams : public TasToolParams {
3939
AutoStrafeSpeed strafeSpeed = {CURRENT};
4040
bool noPitchLock = false;
4141
bool antiSpeedLock = true;
42+
float turnRate = 1.0f;
43+
float force = 1.0f;
4244

4345
AutoStrafeParams()
4446
: TasToolParams() {}
4547

46-
AutoStrafeParams(AutoStrafeType type, AutoStrafeDirection dir, AutoStrafeSpeed speed, bool noPitchLock, bool antiSpeedLock)
48+
AutoStrafeParams(AutoStrafeType type, AutoStrafeDirection dir, AutoStrafeSpeed speed, bool noPitchLock, bool antiSpeedLock, float turnRate, float force)
4749
: TasToolParams(true)
4850
, strafeType(type)
4951
, strafeDir(dir)
5052
, strafeSpeed(speed)
5153
, noPitchLock(noPitchLock)
52-
, antiSpeedLock(antiSpeedLock) {
54+
, antiSpeedLock(antiSpeedLock)
55+
, turnRate(turnRate)
56+
, force(force) {
5357
}
5458
};
5559

0 commit comments

Comments
 (0)