//! Timed scoring mode with an accelerating gravity curve.

use crate::replay::Handling;
use crate::sim::config::SCORE_ATTACK_LEVEL_TOTALS;
use crate::sim::{EngineConfig, LeveledGravity};

pub fn engine_config(handling: Handling, allow_180: bool) -> EngineConfig {
    EngineConfig {
        handling,
        allow_180,
        gravity: Some(LeveledGravity {
            thresholds: SCORE_ATTACK_LEVEL_TOTALS.to_vec(),
            base: 0.65,
            speed: 0.007,
        }),
        gravity_may20g: true,
    }
}

/// Returns the gravity level for a cumulative line count.
pub fn level_for(lines: u32) -> u32 {
    let mut level = 1u32;
    for (index, &threshold) in SCORE_ATTACK_LEVEL_TOTALS.iter().enumerate().skip(1) {
        let level_number = (index + 1) as u32;
        if lines < threshold {
            return level;
        }
        level = level_number;
    }
    level
}
