Expand description
Ammunition and reload timing. A shot spends one round only on acceptance.
Advance with simulation time on actual ticks. Status queries do not advance
the reload or emit completion; use the result of Magazine::advance for
accepted reload feedback.
use ferravex_play::gameplay::magazine::Magazine;
let mut magazine = Magazine::new(4, 6, 2.0)?;
assert_eq!(magazine.capacity(), 4);
assert_eq!(magazine.total_ammo(), 10);
assert!(magazine.can_fire());
assert!(!magazine.can_reload());
assert!(magazine.fire());
assert!(magazine.can_reload());
assert!(magazine.reload());
assert!(!magazine.can_fire());
assert!(!magazine.can_reload());
assert!(!magazine.advance(0.5)?);
let status = magazine.reload_status().unwrap();
assert_eq!(status.duration_seconds, 2.0);
assert_eq!(status.remaining_seconds, 1.5);
assert_eq!(status.progress, 0.25);
assert_eq!(status.rounds, 1);
assert!(magazine.advance(1.5)?);
assert_eq!(magazine.reload_status(), None);
assert!(!magazine.advance(1.0)?); // No duplicate completion.Structsยง
- Magazine
- Bounded ammunition storage and a caller-driven reload timer.
- Reload
Status - Read-only snapshot of an active reload, obtained with
Magazine::reload_status. Ammo remains in reserve until completion.