aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/audio
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 12:53:20 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 12:53:20 +0300
commitad31192ab5d8c5f2b0d2d44b787d04c29cb49dc8 (patch)
tree3aac936c8df186039c6d2e9d91d917abad36105f /apps/fparkan-game/src/audio
parentf12b2c55910fe4c79272a9a7b17ed49293078e4a (diff)
downloadfparkan-ad31192ab5d8c5f2b0d2d44b787d04c29cb49dc8.tar.xz
fparkan-ad31192ab5d8c5f2b0d2d44b787d04c29cb49dc8.zip
feat(ui): acknowledge accepted strategic warbot orders
Use the original size-based shared acknowledgement selector. Verify direct orders, a patrol target, and single- and multi-point routes from the stock Two Fortresses start. A valid right-click supplies the final waypoint and sends the route.
Diffstat (limited to 'apps/fparkan-game/src/audio')
-rw-r--r--apps/fparkan-game/src/audio/capture_voice.rs52
-rw-r--r--apps/fparkan-game/src/audio/unit_acknowledgement.rs78
2 files changed, 78 insertions, 52 deletions
diff --git a/apps/fparkan-game/src/audio/capture_voice.rs b/apps/fparkan-game/src/audio/capture_voice.rs
deleted file mode 100644
index 86ecee63..00000000
--- a/apps/fparkan-game/src/audio/capture_voice.rs
+++ /dev/null
@@ -1,52 +0,0 @@
-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/audio/unit_acknowledgement.rs b/apps/fparkan-game/src/audio/unit_acknowledgement.rs
new file mode 100644
index 00000000..ac960d32
--- /dev/null
+++ b/apps/fparkan-game/src/audio/unit_acknowledgement.rs
@@ -0,0 +1,78 @@
+use super::{GameAudio, VariationRng};
+
+// The size banks at iron3d+0x5d8ba use these entries in the same order.
+const ACKNOWLEDGEMENTS: [&str; 5] = [
+ "VOICE_ACKNOWLEDGE",
+ "VOICE_AFFIRMATIVE",
+ "VOICE_OK",
+ "VOICE_YES_SIR",
+ "VOICE_EXECUTE",
+];
+
+pub(super) struct UnitAcknowledgement {
+ rng: VariationRng,
+ previous: i32,
+}
+
+impl UnitAcknowledgement {
+ pub(super) fn new(seed: u32) -> Self {
+ Self {
+ rng: VariationRng::from_clock(seed),
+ previous: -1,
+ }
+ }
+
+ fn next(&mut self, size: u32) -> String {
+ // iron3d+0x8ecc0 changes banks without resetting the previous index.
+ let suffix = match size {
+ 1 | 2 => "_S",
+ 4 | 5 => "_B",
+ _ => "",
+ };
+ let index = self
+ .rng
+ .choose(ACKNOWLEDGEMENTS.len(), &mut self.previous)
+ .expect("non-empty acknowledgement bank");
+ format!("{}{suffix}", ACKNOWLEDGEMENTS[index])
+ }
+}
+
+impl GameAudio {
+ pub(crate) fn queue_vehicle_capture_voice(&mut self) -> Result<String, String> {
+ self.queue_unit_acknowledgement(4)
+ }
+
+ pub(crate) fn queue_unit_acknowledgement(&mut self, size: u32) -> Result<String, String> {
+ let symbol = self.unit_acknowledgement.next(size);
+ self.queue_game_voice(&symbol)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{UnitAcknowledgement, ACKNOWLEDGEMENTS};
+
+ #[test]
+ fn capture_acknowledgements_follow_the_native_bank_order_and_skip_repeats() {
+ let mut voice = UnitAcknowledgement::new(0x156a_e3bf);
+ let expected = [2, 3, 2, 3, 2, 4, 3, 4, 3, 0].map(|i| format!("{}_B", ACKNOWLEDGEMENTS[i]));
+ let actual = std::array::from_fn::<_, 10, _>(|_| voice.next(4));
+ assert_eq!(actual, expected);
+ }
+
+ #[test]
+ fn changing_size_banks_keeps_the_same_non_repeating_selector() {
+ let mut voice = UnitAcknowledgement::new(0x156a_e3bf);
+ let actual = [4, 3, 2, 5, 1].map(|size| voice.next(size));
+ assert_eq!(
+ actual,
+ [
+ "VOICE_OK_B",
+ "VOICE_YES_SIR",
+ "VOICE_OK_S",
+ "VOICE_YES_SIR_B",
+ "VOICE_OK_S",
+ ]
+ );
+ }
+}