4
4
#include < string>
5
5
6
6
#include " bot.h"
7
+ #include " color.h"
7
8
#include " interface.h"
8
9
#include " rlbot_generated.h"
9
10
#include " scopedrenderer.h"
13
14
14
15
ExampleBot::ExampleBot (int _index, int _team, std::string _name)
15
16
: Bot(_index, _team, _name) {
16
- rlbotcpp ::GameState gamestate = rlbotcpp ::GameState ();
17
+ rlbot ::GameState gamestate = rlbot ::GameState ();
17
18
18
19
gamestate.ballState .physicsState .location = {0 , 0 , 1000 };
19
20
gamestate.ballState .physicsState .velocity = {0 , 0 , 5000 };
20
21
21
- rlbotcpp ::CarState carstate = rlbotcpp ::CarState ();
22
+ rlbot ::CarState carstate = rlbot ::CarState ();
22
23
carstate.physicsState .location = {0 , 500 , 1000 };
23
24
carstate.physicsState .velocity = {500 , 1000 , 1000 };
24
25
carstate.physicsState .angularVelocity = {1 , 2 , 3 };
@@ -27,14 +28,13 @@ ExampleBot::ExampleBot(int _index, int _team, std::string _name)
27
28
28
29
gamestate.carStates [_index] = carstate;
29
30
30
- rlbotcpp ::Interface::SetGameState (gamestate);
31
+ rlbot ::Interface::SetGameState (gamestate);
31
32
}
32
33
33
- rlbotcpp ::Controller
34
+ rlbot ::Controller
34
35
ExampleBot::GetOutput (const rlbot::flat::GameTickPacket *gameTickPacket,
35
36
const rlbot::flat::FieldInfo *fieldInfo,
36
37
const rlbot::flat::BallPrediction *ballPrediction) {
37
- rlbotcpp::Controller controller{0 };
38
38
39
39
rlbot::flat::Vector3 ballLocation =
40
40
*gameTickPacket->ball ()->physics ()->location ();
@@ -45,38 +45,39 @@ ExampleBot::GetOutput(const rlbot::flat::GameTickPacket *gameTickPacket,
45
45
rlbot::flat::Rotator carRotation =
46
46
*gameTickPacket->players ()->Get (index)->physics ()->rotation ();
47
47
48
+ // Calculate the velocity of the ball.
48
49
float velocity = sqrt (ballVelocity.x () * ballVelocity.x () +
49
50
ballVelocity.y () * ballVelocity.y () +
50
51
ballVelocity.z () * ballVelocity.z ());
51
52
52
- // This renderer will build and send the packet once it goes out of scope
53
- rlbotcpp::ScopedRenderer renderer (" test" );
54
-
53
+ // Load the ballprediction into a vector to use for rendering.
55
54
std::vector<const rlbot::flat::Vector3 *> points;
56
55
57
56
for (uint32_t i = 0 ; i < ballPrediction->slices ()->size (); i++) {
58
57
points.push_back (ballPrediction->slices ()->Get (i)->physics ()->location ());
59
58
}
60
59
61
- renderer.DrawPolyLine3D (rlbotcpp::Color{0xFF , 0x00 , 0x00 , 0xFF }, points);
60
+ // This renderer will build and send the packet once it goes out of scope.
61
+ rlbot::ScopedRenderer renderer (" test" );
62
62
63
- renderer.DrawString2D (" Hello world!" , rlbotcpp::Color{0x00 , 0xFF , 0x00 , 0xFF },
63
+ renderer.DrawPolyLine3D (rlbot::Color::red, points);
64
+ renderer.DrawString2D (" Hello world!" , rlbot::Color::green,
64
65
rlbot::flat::Vector3{10 , 10 , 0 }, 4 , 4 );
65
-
66
- renderer.DrawString3D (std::to_string (velocity),
67
- rlbotcpp::Color{0xFF , 0x00 , 0xFF , 0xFF }, ballLocation,
68
- 2 , 2 );
66
+ renderer.DrawString3D (std::to_string (velocity), rlbot::Color::magenta,
67
+ ballLocation, 2 , 2 );
69
68
70
69
// Calculate to get the angle from the front of the bot's car to the ball.
71
70
double botToTargetAngle = atan2 (ballLocation.y () - carLocation.y (),
72
71
ballLocation.x () - carLocation.x ());
73
72
double botFrontToTargetAngle = botToTargetAngle - carRotation.yaw ();
74
- // Correct the angle
73
+ // Correct the angle.
75
74
if (botFrontToTargetAngle < -PI)
76
75
botFrontToTargetAngle += 2 * PI;
77
76
if (botFrontToTargetAngle > PI)
78
77
botFrontToTargetAngle -= 2 * PI;
79
78
79
+ rlbot::Controller controller{0 };
80
+
80
81
// Decide which way to steer in order to get to the ball.
81
82
if (botFrontToTargetAngle > 0 )
82
83
controller.steer = 1 ;
0 commit comments