diff options
Diffstat (limited to 'apps/fparkan-game/src')
| -rw-r--r-- | apps/fparkan-game/src/audio.rs | 4 | ||||
| -rw-r--r-- | apps/fparkan-game/src/audio/capture_voice.rs | 52 | ||||
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 1 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_notices.rs | 3 |
4 files changed, 59 insertions, 1 deletions
diff --git a/apps/fparkan-game/src/audio.rs b/apps/fparkan-game/src/audio.rs index e4580707..90ddd6d7 100644 --- a/apps/fparkan-game/src/audio.rs +++ b/apps/fparkan-game/src/audio.rs @@ -21,6 +21,8 @@ use std::io::Cursor; use std::sync::{Arc, Mutex}; use std::time::{SystemTime, UNIX_EPOCH}; +mod capture_voice; + const SWAV_TYPE: u32 = u32::from_le_bytes(*b"SWAV"); const DEFAULT_MUSIC_TRACK: u8 = 2; const FIRST_MUSIC_TRACK: u8 = 2; @@ -636,6 +638,7 @@ pub(crate) struct GameAudio { music: Player, variations: Player, mission_voice: Player, + vehicle_capture_voice: capture_voice::VehicleCaptureVoice, mission_cfg: NormalizedPath, weather_loop: NativeSpatialPlayer, control_sounds: BTreeMap<ControlSoundId, NativeSpatialPlayer>, @@ -683,6 +686,7 @@ impl GameAudio { music, variations, mission_voice, + vehicle_capture_voice: capture_voice::VehicleCaptureVoice::new(random_seed()), mission_cfg, weather_loop, control_sounds: BTreeMap::new(), diff --git a/apps/fparkan-game/src/audio/capture_voice.rs b/apps/fparkan-game/src/audio/capture_voice.rs new file mode 100644 index 00000000..86ecee63 --- /dev/null +++ b/apps/fparkan-game/src/audio/capture_voice.rs @@ -0,0 +1,52 @@ +use super::{GameAudio, VariationRng}; + +// iron3d+0x8ecc0 selects bank 3 for warbots and mobile command centres. +const ACKNOWLEDGEMENTS: [&str; 5] = [ + "VOICE_ACKNOWLEDGE_B", + "VOICE_AFFIRMATIVE_B", + "VOICE_OK_B", + "VOICE_YES_SIR_B", + "VOICE_EXECUTE_B", +]; + +pub(super) struct VehicleCaptureVoice { + rng: VariationRng, + previous: i32, +} + +impl VehicleCaptureVoice { + pub(super) fn new(seed: u32) -> Self { + Self { + rng: VariationRng::from_clock(seed), + previous: -1, + } + } + + fn next(&mut self) -> &'static str { + let index = self + .rng + .choose(ACKNOWLEDGEMENTS.len(), &mut self.previous) + .expect("non-empty acknowledgement bank"); + ACKNOWLEDGEMENTS[index] + } +} + +impl GameAudio { + pub(crate) fn queue_vehicle_capture_voice(&mut self) -> Result<String, String> { + let symbol = self.vehicle_capture_voice.next(); + self.queue_game_voice(symbol) + } +} + +#[cfg(test)] +mod tests { + use super::{VehicleCaptureVoice, ACKNOWLEDGEMENTS}; + + #[test] + fn capture_acknowledgements_follow_the_native_bank_order_and_skip_repeats() { + let mut voice = VehicleCaptureVoice::new(0x156a_e3bf); + let expected = [2, 3, 2, 3, 2, 4, 3, 4, 3, 0].map(|i| ACKNOWLEDGEMENTS[i]); + let actual = std::array::from_fn::<_, 10, _>(|_| voice.next()); + assert_eq!(actual, expected); + } +} diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 77a1dec5..cd6ce717 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -10941,6 +10941,7 @@ impl StaticVulkanApp { ) { let entry = enter_vehicle(engine, cockpit, self.boarding_target) .map_err(|error| error.to_string())?; + capture_notice = entry.capture_notice(); if let Some(target) = entry.captured { self.boarding_target = mission_object_handle(engine, target); eprintln!( diff --git a/apps/fparkan-game/src/mission_notices.rs b/apps/fparkan-game/src/mission_notices.rs index 739eb628..1a0bc6a2 100644 --- a/apps/fparkan-game/src/mission_notices.rs +++ b/apps/fparkan-game/src/mission_notices.rs @@ -4,7 +4,7 @@ use fparkan_runtime::MissionNotice; impl StaticVulkanApp { pub(super) fn present_mission_notice(&mut self, notice: MissionNotice, clock_ms: u32) { match notice { - MissionNotice::BuildingCaptured { .. } => {} + MissionNotice::BuildingCaptured { .. } | MissionNotice::VehicleCaptured => {} MissionNotice::ObjectiveComplete(index) => { eprintln!( "mission_objective index={index} status=complete queue_time_ms={clock_ms}" @@ -45,6 +45,7 @@ impl StaticVulkanApp { } else { "VOICE_EBUILD_CAPTURE" }), + MissionNotice::VehicleCaptured => audio.queue_vehicle_capture_voice(), MissionNotice::Completed => audio.queue_game_voice("VOICE_MISSION_COMPLETE"), MissionNotice::Failed => audio.queue_game_voice("VOICE_MISSION_FAIL"), }; |
