|
| 1 | +#include "ATBA.h" |
| 2 | + |
| 3 | +#include <tracy/Tracy.hpp> |
| 4 | + |
| 5 | +#include <algorithm> |
| 6 | +#include <cmath> |
| 7 | +#include <concepts> |
| 8 | +#include <cstdio> |
| 9 | +#include <cstdlib> |
| 10 | +#include <numbers> |
| 11 | +#include <unordered_set> |
| 12 | + |
| 13 | +/////////////////////////////////////////////////////////////////////////// |
| 14 | +ATBA::~ATBA () noexcept = default; |
| 15 | + |
| 16 | +ATBA::ATBA (std::unordered_set<unsigned> indices_, unsigned const team_, std::string name_) noexcept |
| 17 | + : rlbot::Bot (std::move (indices_), team_, std::move (name_)) |
| 18 | +{ |
| 19 | + std::set<unsigned> sorted (std::begin (indices), std::end (indices)); |
| 20 | + for (auto const &index : sorted) |
| 21 | + std::printf ("Team %u Index %u: Example Bot created\n", team_, index); |
| 22 | +} |
| 23 | + |
| 24 | +void ATBA::update (rlbot::flat::GamePacket const *const packet_, |
| 25 | + rlbot::flat::BallPrediction const *const ballPrediction_, |
| 26 | + rlbot::flat::FieldInfo const *const fieldInfo_, |
| 27 | + rlbot::flat::MatchSettings const *const matchSettings_) noexcept |
| 28 | +{ |
| 29 | + for (auto const &index : this->indices) |
| 30 | + { |
| 31 | + auto &controller = outputs[index]; |
| 32 | + controller = {}; |
| 33 | + |
| 34 | + // If there's no ball, there's nothing to chase; don't do anything |
| 35 | + if (packet_->balls ()->size () == 0) |
| 36 | + continue; |
| 37 | + |
| 38 | + // We're not in the game packet; skip this tick |
| 39 | + if (packet_->players ()->size () <= index) |
| 40 | + continue; |
| 41 | + |
| 42 | + auto const target = packet_->balls ()->Get (0)->physics (); |
| 43 | + auto const car = packet_->players ()->Get (index)->physics (); |
| 44 | + |
| 45 | + auto const botToTargetAngle = std::atan2 (target->location ().y () - car->location ().y (), |
| 46 | + target->location ().z () - car->location ().z ()); |
| 47 | + |
| 48 | + auto botFrontToTargetAngle = botToTargetAngle - car->rotation ().yaw (); |
| 49 | + if (botFrontToTargetAngle > std::numbers::pi_v<float>) |
| 50 | + botFrontToTargetAngle -= 2.0f * std::numbers::pi_v<float>; |
| 51 | + if (botFrontToTargetAngle < -std::numbers::pi_v<float>) |
| 52 | + botFrontToTargetAngle += 2.0f * std::numbers::pi_v<float>; |
| 53 | + |
| 54 | + auto const throttle = 1.0f; |
| 55 | + auto const steer = std::copysign (1.0f, botFrontToTargetAngle); |
| 56 | + |
| 57 | + controller = {throttle, steer, 0.0f, 0.0f, 0.0f, false, false, false, false}; |
| 58 | + }; |
| 59 | +} |
0 commit comments