Rebalance Medium AI difficulty pacing and combat aggression
This commit is contained in:
1 parent
9f276a432b
commit
8e6bb5540b
2 files changed
+161
-21
No files matched your search
+76
-21
@@ -201,14 +201,20 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
|
||||
return out;
|
||||
}
|
||||
|
||||
// Portal-safe forward waypoint advance
|
||||
// Portal-safe forward waypoint advance (tighter apex adherence on sharp hairpin turns)
|
||||
int prev_wp_idx = (wp_idx + n_wp - 1) % n_wp;
|
||||
int next_wp_idx = (wp_idx + 1) % n_wp;
|
||||
Vec2 prev_wp_pos(level.main_waypoints[prev_wp_idx].x, level.main_waypoints[prev_wp_idx].z);
|
||||
Vec2 next_wp_pos(level.main_waypoints[next_wp_idx].x, level.main_waypoints[next_wp_idx].z);
|
||||
Vec2 seg_from_prev = cur_wp_pos - prev_wp_pos;
|
||||
Vec2 seg_to_next = next_wp_pos - cur_wp_pos;
|
||||
const bool sharp_hairpin =
|
||||
(seg_from_prev.len_sq() > 0.25f && seg_to_next.len_sq() > 0.25f &&
|
||||
seg_from_prev.normalized().dot(seg_to_next.normalized()) < 0.25f);
|
||||
float dist_to_next = (next_wp_pos - cur_pos).len();
|
||||
bool passed_geom = ((cur_pos - cur_wp_pos).dot(seg_to_next) > 0.0f) && (dist_to_next < dist_to_wp);
|
||||
bool advance_wp = (dist_to_wp < 3.4f);
|
||||
if (!advance_wp && (dist_to_wp < 5.2f || passed_geom)) {
|
||||
bool advance_wp = (dist_to_wp < (sharp_hairpin ? 1.8f : 3.4f));
|
||||
if (!advance_wp && ((!sharp_hairpin && dist_to_wp < 5.2f) || passed_geom)) {
|
||||
advance_wp = has_clear_corridor(cur_pos, next_wp_pos, ai.curr_pose.pos.y);
|
||||
}
|
||||
|
||||
@@ -330,8 +336,27 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
|
||||
|
||||
out.steer = std::clamp(-err * 1.85f, -1.0f, 1.0f);
|
||||
|
||||
float diff_pace = (difficulty == 0) ? 0.78f : (difficulty == 2 ? 1.0f : 0.90f);
|
||||
bool is_corner = (level.main_waypoints[wp_idx].subtype == 1);
|
||||
struct DifficultyProfile {
|
||||
float pace;
|
||||
float speed_cap;
|
||||
float corner_frac;
|
||||
float min_ammo;
|
||||
float gun_range;
|
||||
float gun_cone;
|
||||
};
|
||||
static constexpr DifficultyProfile kDifficultyProfiles[3] = {
|
||||
{0.72f, 0.74f, 0.58f, 20.0f, 14.0f, 0.965f}, // Easy
|
||||
{0.82f, 0.83f, 0.65f, 15.0f, 17.5f, 0.955f}, // Medium
|
||||
{1.00f, 1.00f, 0.74f, 5.0f, 22.0f, 0.930f}, // Hard
|
||||
};
|
||||
const DifficultyProfile& prof = kDifficultyProfiles[std::clamp(difficulty, 0, 2)];
|
||||
|
||||
const bool is_corner = (level.main_waypoints[wp_idx].subtype == 1);
|
||||
const Vec3 fwd_u = ai.forward_dir();
|
||||
const Vec3 surf_n = level.sample_normal_world(ai.curr_pose.pos.x, ai.curr_pose.pos.z);
|
||||
const bool steep_straight_ramp =
|
||||
!ai.airborne && !is_corner && std::abs(err) < 0.22f &&
|
||||
((surf_n.x * fwd_u.x + surf_n.z * fwd_u.z) < -0.18f);
|
||||
|
||||
if (charging_pit) {
|
||||
out.throttle = (spd > 3.5f) ? 0.0f : 0.18f;
|
||||
@@ -340,21 +365,40 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
|
||||
out.throttle = 0.0f;
|
||||
out.brake = 0.65f;
|
||||
} else if (std::abs(err) > 0.65f && spd > spec.top_speed * 0.52f) {
|
||||
out.throttle = 0.25f * diff_pace;
|
||||
out.throttle = 0.25f * prof.pace;
|
||||
out.brake = 0.35f;
|
||||
} else if (is_corner && spd > spec.top_speed * 0.72f * diff_pace) {
|
||||
out.throttle = 0.50f * diff_pace;
|
||||
} else if (is_corner && spd > spec.top_speed * prof.corner_frac) {
|
||||
out.throttle = 0.50f * prof.pace;
|
||||
} else {
|
||||
out.throttle = diff_pace;
|
||||
if (difficulty >= 1 && std::abs(err) < 0.18f && ai.fuel > ai.max_fuel * 0.45f &&
|
||||
(ai.id + static_cast<int>(ai.race_time)) % 3 == 0) {
|
||||
out.boost = true;
|
||||
out.throttle = steep_straight_ramp ? 1.0f : prof.pace;
|
||||
if (difficulty >= 2) {
|
||||
if (std::abs(err) < 0.18f && ai.fuel > ai.max_fuel * 0.45f &&
|
||||
(ai.id + static_cast<int>(ai.race_time)) % 3 == 0) {
|
||||
out.boost = true;
|
||||
}
|
||||
} else if (difficulty == 1) {
|
||||
if (std::abs(err) < 0.10f && ai.fuel > ai.max_fuel * 0.72f &&
|
||||
spd < spec.top_speed * 0.86f &&
|
||||
static_cast<int>(ai.race_time * 3.0f) % 24 == ((ai.id * 3) % 24)) {
|
||||
out.boost = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combat AI: shoot visible opponents in sights!
|
||||
if (ai.ammo > 5.0f) {
|
||||
Vec3 fwd = ai.forward_dir();
|
||||
// Smooth cruise speed ceiling so Easy and Medium AI race clearly below Hard pace
|
||||
// while preserving full thrust on steep straight jump ramps (e.g. Arctic Land bridge).
|
||||
if (prof.speed_cap < 0.99f && !out.boost && !steep_straight_ramp && out.throttle > 0.08f) {
|
||||
const float target_spd = spec.top_speed * prof.speed_cap;
|
||||
if (spd > target_spd) {
|
||||
const float hold_throttle =
|
||||
std::clamp((0.55f * target_spd) / std::max(spec.accel, 1.0f), 0.10f, prof.pace);
|
||||
const float over = std::clamp((spd - target_spd) / 2.5f, 0.0f, 1.0f);
|
||||
out.throttle = std::min(out.throttle, lerp(hold_throttle, 0.08f, over));
|
||||
}
|
||||
}
|
||||
|
||||
// Combat AI: shoot visible opponents in sights (tiered by difficulty)
|
||||
if (ai.ammo > prof.min_ammo) {
|
||||
const Vec3 eye_a = ai.curr_pose.pos + Vec3(0.0f, 0.25f, 0.0f);
|
||||
for (const auto& other : all_crafts) {
|
||||
if (other.id == ai.id || other.recovery_state != RecoveryState::Active ||
|
||||
@@ -363,16 +407,27 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
|
||||
}
|
||||
Vec3 to_e = other.curr_pose.pos - ai.curr_pose.pos;
|
||||
float dist = to_e.len();
|
||||
if (dist < 1.2f || dist > 22.0f) continue;
|
||||
float cos_ang = (to_e / dist).dot(fwd);
|
||||
if (cos_ang > 0.93f && difficulty >= 0 &&
|
||||
if (dist < 1.2f || dist > prof.gun_range) continue;
|
||||
float cos_ang = (to_e / dist).dot(fwd_u);
|
||||
if (cos_ang > prof.gun_cone &&
|
||||
has_line_of_sight(level, eye_a, other.curr_pose.pos + Vec3(0.0f, 0.25f, 0.0f))) {
|
||||
out.fire_minigun = (difficulty == 2 || (static_cast<int>(ai.race_time * 10.0f) % 2 == 0));
|
||||
if (difficulty >= 2) {
|
||||
out.fire_minigun = true;
|
||||
} else if (difficulty == 1) {
|
||||
out.fire_minigun = (static_cast<int>(ai.race_time * 4.0f) % 4 == 0);
|
||||
} else {
|
||||
out.fire_minigun = (static_cast<int>(ai.race_time * 3.0f) % 5 == 0);
|
||||
}
|
||||
if (out.fire_minigun) break;
|
||||
}
|
||||
}
|
||||
if (ai.lock_progress >= 1.0f && difficulty >= 1 && ai.ammo >= 20.0f) {
|
||||
out.fire_missile = true;
|
||||
if (ai.lock_progress >= 1.0f) {
|
||||
if (difficulty >= 2 && ai.ammo >= 20.0f) {
|
||||
out.fire_missile = true;
|
||||
} else if (difficulty == 1 && ai.ammo >= 36.0f &&
|
||||
static_cast<int>(ai.race_time * 2.0f) % 14 == (ai.id % 14)) {
|
||||
out.fire_missile = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user