Skip to content

Commit 352b019

Browse files
committed
feat: add jump tool for tas
1 parent 1d5df76 commit 352b019

File tree

7 files changed

+112
-90
lines changed

7 files changed

+112
-90
lines changed

src/Cheats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "Features/Routing/EntityInspector.hpp"
1313
#include "Features/Speedrun/SpeedrunTimer.hpp"
1414
#include "Features/Tas/TasParser.hpp"
15-
#include "Features/Tas/TasTools/AutoJumpTool.hpp"
15+
#include "Features/Tas/TasTools/JumpTool.hpp"
1616
#include "Features/Tas/TasTools/StrafeTool.hpp"
1717
#include "Features/Timer/Timer.hpp"
1818
#include "Features/WorkshopList.hpp"

src/Features/Tas/TasPlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <climits>
1919
#include <fstream>
20-
#include "TasTools/AutoJumpTool.hpp"
20+
#include "TasTools/JumpTool.hpp"
2121

2222
Variable sar_tas_debug("sar_tas_debug", "0", 0, 2, "Debug TAS information. 0 - none, 1 - basic, 2 - all.\n");
2323
Variable sar_tas_dump_usercmd("sar_tas_dump_usercmd", "0", "Dump TAS-generated usercmds to a file.\n");
@@ -427,7 +427,7 @@ TasPlayerInfo TasPlayer::GetPlayerInfo(int slot, void *player, CUserCmd *cmd, bo
427427

428428
// predict the result of autojump tool so other tools can react appropriately.
429429
FOR_TAS_SCRIPT_VERSIONS_SINCE(8) {
430-
if (autoJumpTool[slot].GetCurrentParams().enabled && autoJumpTool[slot].ShouldJump(pi)) {
430+
if (autoJumpTool[slot].WillJump(pi) || jumpTool[slot].WillJump(pi)) {
431431
pi.willBeGrounded = false;
432432
}
433433
}

src/Features/Tas/TasTools/AutoJumpTool.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/Features/Tas/TasTools/AutoJumpTool.hpp

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "JumpTool.hpp"
2+
3+
#include "Modules/Engine.hpp"
4+
#include "Modules/Server.hpp"
5+
#include "Features/Tas/TasParser.hpp"
6+
#include "Features/Tas/TasPlayer.hpp"
7+
8+
JumpTool autoJumpTool[2] = {{0, true}, {1, true}};
9+
JumpTool jumpTool[2] = {{0, false}, {1, false}};
10+
11+
void JumpTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
12+
if (this->updated) {
13+
hasJumpedLastTick = false;
14+
}
15+
16+
if (params.enabled) {
17+
bool shouldJump;
18+
19+
if (this->automatic) {
20+
shouldJump = ShouldJump(pInfo);
21+
} else {
22+
shouldJump = true;
23+
params.enabled = false;
24+
}
25+
26+
SetJumpInput(bulk, shouldJump);
27+
} else {
28+
hasJumpedLastTick = false;
29+
}
30+
}
31+
32+
bool JumpTool::WillJump(const TasPlayerInfo &pInfo) {
33+
return params.enabled && ShouldJump(pInfo);
34+
}
35+
36+
bool JumpTool::ShouldJump(const TasPlayerInfo &pInfo) {
37+
return pInfo.grounded && !pInfo.ducked && !hasJumpedLastTick;
38+
}
39+
40+
void JumpTool::SetJumpInput(TasFramebulk &bulk, bool jump) {
41+
bulk.buttonStates[TasControllerInput::Jump] = jump;
42+
if (params.ducked) {
43+
bulk.buttonStates[TasControllerInput::Crouch] = jump;
44+
}
45+
hasJumpedLastTick = jump;
46+
}
47+
48+
std::shared_ptr<TasToolParams> JumpTool::ParseParams(std::vector<std::string> vp) {
49+
if (vp.size() == 0 && !this->automatic) {
50+
// allow 0 parameters for non-automated jump tool
51+
return std::make_shared<JumpToolsParams>(true, false);
52+
}
53+
54+
if (vp.size() != 1)
55+
throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), vp.size()));
56+
57+
bool ducked = false;
58+
bool enabled = false;
59+
60+
if (vp[0] == "on" || vp[0] == "unducked" || vp[0] == "unduck") {
61+
enabled = true;
62+
} else if (vp[0] == "ducked" || vp[0] == "duck") {
63+
enabled = true;
64+
ducked = true;
65+
} else if (vp[0] != "off") {
66+
throw TasParserException(Utils::ssprintf("Bad parameter for tool %s: %s", this->GetName(), vp[0].c_str()));
67+
}
68+
69+
return std::make_shared<JumpToolsParams>(enabled, ducked);
70+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
#include "../TasTool.hpp"
3+
4+
struct JumpToolsParams : public TasToolParams {
5+
JumpToolsParams()
6+
: TasToolParams() {
7+
}
8+
JumpToolsParams(bool enabled, bool ducked)
9+
: TasToolParams(enabled)
10+
, ducked(ducked) {
11+
}
12+
13+
bool ducked = false;
14+
};
15+
16+
class JumpTool : public TasToolWithParams<JumpToolsParams> {
17+
public:
18+
JumpTool(int slot, bool automatic)
19+
: TasToolWithParams(automatic ? "autojump" : "jump", slot)
20+
, automatic(automatic) {
21+
}
22+
23+
virtual std::shared_ptr<TasToolParams> ParseParams(std::vector<std::string>);
24+
virtual void Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo);
25+
26+
bool WillJump(const TasPlayerInfo &pInfo);
27+
private:
28+
bool ShouldJump(const TasPlayerInfo &pInfo);
29+
void SetJumpInput(TasFramebulk &bulk, bool jump);
30+
31+
private:
32+
bool automatic;
33+
bool hasJumpedLastTick = false;
34+
};
35+
36+
extern JumpTool autoJumpTool[2];
37+
extern JumpTool jumpTool[2];

src/Features/Tas/TasTools/StrafeTool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "StrafeTool.hpp"
22

33
#include "../TasParser.hpp"
4-
#include "AutoJumpTool.hpp"
4+
#include "JumpTool.hpp"
55
#include "Modules/Client.hpp"
66
#include "Modules/Console.hpp"
77
#include "Modules/Engine.hpp"
@@ -23,7 +23,7 @@ void AutoStrafeTool::Apply(TasFramebulk &fb, const TasPlayerInfo &pInfo) {
2323

2424
FOR_TAS_SCRIPT_VERSIONS_UNTIL(7) {
2525
// handled by TasPlayer in newer versions
26-
if (autoJumpTool[this->slot].GetCurrentParams().enabled) {
26+
if (autoJumpTool[this->slot].GetCurrentParams().enabled || jumpTool[this->slot].GetCurrentParams().enabled) {
2727
// if autojump is enabled, we're never grounded.
2828
fakePlayerInfo.willBeGrounded = false;
2929
}

0 commit comments

Comments
 (0)