2026-11-30 22:31:51 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "assets/level.hpp"
|
|
|
|
|
#include "core/math.hpp"
|
|
|
|
|
#include "input/input_manager.hpp"
|
|
|
|
|
#include "sim/vehicle_defs.hpp"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace top_octane::sim {
|
|
|
|
|
|
|
|
|
|
struct CraftPose {
|
|
|
|
|
Vec3 pos{0.0f, 0.0f, 0.0f};
|
|
|
|
|
float yaw = 0.0f;
|
|
|
|
|
float pitch = 0.0f;
|
|
|
|
|
float roll = 0.0f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class RecoveryState {
|
|
|
|
|
Active = 0,
|
|
|
|
|
CallingRepair,
|
|
|
|
|
AwaitingRepair,
|
|
|
|
|
Repairing,
|
|
|
|
|
Destroyed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CraftState {
|
|
|
|
|
int id = 0;
|
|
|
|
|
bool is_human = false;
|
|
|
|
|
int player_index = -1; // 0 = P1, 1 = P2, -1 = AI
|
|
|
|
|
int vehicle_idx = 0;
|
|
|
|
|
int team_idx = 7;
|
|
|
|
|
std::string pilot_name;
|
|
|
|
|
|
|
|
|
|
CraftPose prev_pose{};
|
|
|
|
|
CraftPose curr_pose{};
|
|
|
|
|
Vec3 vel{0.0f, 0.0f, 0.0f};
|
|
|
|
|
float yaw_rate = 0.0f;
|
|
|
|
|
|
|
|
|
|
bool airborne = false;
|
|
|
|
|
float airtime = 0.0f;
|
|
|
|
|
float air_spin_accum = 0.0f;
|
|
|
|
|
|
|
|
|
|
// Resources & upgrades
|
|
|
|
|
float fuel = 100.0f;
|
|
|
|
|
float max_fuel = 100.0f;
|
|
|
|
|
float shield = 100.0f;
|
|
|
|
|
float max_shield = 100.0f;
|
|
|
|
|
float ammo = 100.0f;
|
|
|
|
|
float max_ammo = 100.0f;
|
|
|
|
|
int minigun_level = 1;
|
|
|
|
|
int missile_level = 1;
|
|
|
|
|
int booster_level = 1;
|
|
|
|
|
|
|
|
|
|
// Timers & weapons
|
|
|
|
|
float minigun_cd = 0.0f;
|
|
|
|
|
float missile_cd = 0.0f;
|
|
|
|
|
float boost_timer = 0.0f;
|
|
|
|
|
float boost_cooldown = 0.0f;
|
|
|
|
|
float damage_flash = 0.0f;
|
|
|
|
|
int lock_target_id = -1;
|
|
|
|
|
float lock_progress = 0.0f;
|
|
|
|
|
float scrape_intensity = 0.0f;
|
|
|
|
|
float refuel_sound_cd = 0.0f;
|
|
|
|
|
bool autopilot = false;
|
|
|
|
|
|
|
|
|
|
// Recovery / repair
|
|
|
|
|
RecoveryState recovery_state = RecoveryState::Active;
|
|
|
|
|
float recovery_timer = 0.0f;
|
|
|
|
|
Vec3 recovery_pos{0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
|
|
// Race / Deathmatch progression
|
|
|
|
|
int lap = 1;
|
|
|
|
|
int next_checkpoint = 1;
|
|
|
|
|
int checkpoints_passed = 0;
|
|
|
|
|
int current_wp = 0;
|
|
|
|
|
bool wrong_way = false;
|
|
|
|
|
bool finished = false;
|
|
|
|
|
float race_time = 0.0f;
|
|
|
|
|
float current_lap_time = 0.0f;
|
|
|
|
|
float best_lap_time = 0.0f;
|
|
|
|
|
int placement = 1;
|
|
|
|
|
int kills = 0;
|
|
|
|
|
int deaths = 0;
|
|
|
|
|
float fuel_used = 0.0f;
|
|
|
|
|
float armour_used = 0.0f;
|
|
|
|
|
int shots_fired = 0;
|
|
|
|
|
int shots_hit = 0;
|
|
|
|
|
std::string killed_by;
|
|
|
|
|
|
|
|
|
|
// AI state
|
|
|
|
|
int ai_target_wp = 0;
|
|
|
|
|
float ai_fire_delay = 0.0f;
|
|
|
|
|
bool ai_seeking_pit = false;
|
|
|
|
|
int ai_pit_pad_idx = -1;
|
|
|
|
|
|
|
|
|
|
float speed_horizontal() const {
|
|
|
|
|
return std::sqrt(vel.x * vel.x + vel.z * vel.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vec3 forward_dir() const {
|
|
|
|
|
return Vec3(std::sin(curr_pose.yaw), 0.0f, std::cos(curr_pose.yaw));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CraftStepFeedback {
|
|
|
|
|
bool collided_wall = false;
|
|
|
|
|
float impact_speed = 0.0f;
|
|
|
|
|
bool scraping = false;
|
|
|
|
|
bool boosting = false;
|
|
|
|
|
int stunt_degrees = 0; // 180, 360, or 720 on landing
|
|
|
|
|
bool out_of_fuel = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Pure deterministic 60 Hz hover physics step for one active craft
|
|
|
|
|
CraftStepFeedback step_craft_physics(CraftState& craft, const CraftInput& input,
|
2026-11-30 23:57:29 +02:00
|
|
|
const assets::LevelData& level, float dt,
|
|
|
|
|
bool fuel_enabled = true);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
// Resolves world boundary, column AABB, ceiling, and cliff collisions for one active craft
|
|
|
|
|
bool resolve_world_collisions(CraftState& craft, const assets::LevelData& level,
|
|
|
|
|
float& out_impact_speed, bool& out_scraping);
|
|
|
|
|
|
|
|
|
|
// Resolves sphere-sphere bounce between two active crafts
|
|
|
|
|
bool resolve_craft_pair_collision(CraftState& a, CraftState& b, float& out_rel_speed);
|
|
|
|
|
|
|
|
|
|
// Interpolates craft pose for smooth rendering at arbitrary refresh rate
|
|
|
|
|
CraftPose interpolate_pose(const CraftState& craft, float alpha);
|
|
|
|
|
|
|
|
|
|
} // namespace top_octane::sim
|