diff --git a/changelog/entries/2026-12-01_battle_stun_sound.md b/changelog/entries/2026-12-01_battle_stun_sound.md new file mode 100644 index 000000000..aa1427fcc --- /dev/null +++ b/changelog/entries/2026-12-01_battle_stun_sound.md @@ -0,0 +1,7 @@ +--- +issues: [] +prs: [] +--- + +# Fixed +Restore the repeating bird chirps when a combatant is stunned. diff --git a/crates/battle/src/prepare.rs b/crates/battle/src/prepare.rs index 156d49c49..f4dc1b453 100644 --- a/crates/battle/src/prepare.rs +++ b/crates/battle/src/prepare.rs @@ -171,6 +171,7 @@ pub(crate) struct BattleResources { pub(crate) unison_gauge: i16, pub(crate) unison_available: bool, pub(crate) escape: Option, + pub(crate) stun_sound: Option, pub(crate) overlimit_boosted_gain: bool, pub(crate) items: Option, pub(crate) grade_rank: crate::Difficulty, @@ -447,6 +448,7 @@ impl PreparedBattle { grade_rank: crate::Difficulty::Normal, overlimit_boosted_gain: false, escape: None, + stun_sound: None, unison_gauge: 0, unison_available: false, arena_boundary: false, diff --git a/crates/battle/src/stun.rs b/crates/battle/src/stun.rs index 37af92e64..7838be34c 100644 --- a/crates/battle/src/stun.rs +++ b/crates/battle/src/stun.rs @@ -35,6 +35,13 @@ fn chance_percent(owner: &Actor, target: &Actor, base: u8) -> u16 { adjusted + if owner.equipment.stun_ex_bonus { 5 } else { 0 } } +impl crate::PreparedBattle { + pub fn with_stun_sound(mut self, sound: Option) -> Self { + self.resources.stun_sound = sound; + self + } +} + impl Battle { pub(crate) fn enter_action_stun(&mut self, id: ActorId, cues: &mut Vec) { self.enter_stun(id, cues); @@ -119,6 +126,15 @@ impl Battle { if let Some(models) = &mut self.models { models.preserve_pose_through(id, self.update + 1); } + } else if remaining.is_multiple_of(40) + && let Some(sound) = self.prepared.stun_sound + { + cues.push(Cue::Sound { + actor: id, + sound, + position: self.actors[index].audio_position(), + priority: 1, + }); } let actor = &mut self.actors[index]; actor diff --git a/crates/battle/src/stun/tests.rs b/crates/battle/src/stun/tests.rs index ab011663f..b2a5711ca 100644 --- a/crates/battle/src/stun/tests.rs +++ b/crates/battle/src/stun/tests.rs @@ -520,10 +520,11 @@ fn stun_interrupts_work_and_recovers_without_resuming_it() { } #[test] -fn stun_recovery_respects_pause_immunity_and_manual_struggle() { - fn recovery_time(control: Control, short: bool, struggle: bool) -> u32 { +fn stun_recovery_and_chirps_follow_the_active_countdown() { + fn recovery(control: Control, short: bool, struggle: bool) -> (u32, Vec) { let mut target = actor(Side::Party); target.control = control; + target.position = [24., 0., -10.]; if short { target.conditions = crate::conditions::Conditions::new(crate::conditions::Layers { immunity: ConditionSet::of(&[Condition::ShortStun]), @@ -544,12 +545,14 @@ fn stun_recovery_respects_pause_immunity_and_manual_struggle() { })), ..Default::default() }; + let sound = crate::Sound::Cue(321); let mut battle = PreparedBattle::new( vec![(target, setup), (actor(Side::Enemy), Default::default())], actions, 0, ) .unwrap() + .with_stun_sound(Some(sound)) .finish() .unwrap(); battle.enter_stun(ActorId(0), &mut vec![]); @@ -561,22 +564,44 @@ fn stun_recovery_respects_pause_immunity_and_manual_struggle() { }], ..Default::default() }; - for _ in 0..DURATION + 1 { - battle.step(input(true, true)).unwrap(); - } - assert_eq!(battle.activity(ActorId(0)), Activity::Stunned); + let chirp = Cue::Sound { + actor: ActorId(0), + sound, + position: battle.actors[0].audio_position(), + priority: 1, + }; + let mut heard = Vec::new(); for elapsed in 1..=DURATION + 1 { - battle.step(input(false, struggle)).unwrap(); - if battle.activity(ActorId(0)) == Activity::Idle { - return elapsed; + // A single struggle at 161 skips the chirp at 160. + let frame = battle + .step(input(false, struggle && elapsed == 20)) + .unwrap(); + let remaining = frame.actors[0].stun_remaining; + for cue in frame.cues { + if matches!(cue, Cue::Sound { .. }) { + assert_eq!(cue, chirp); + heard.push(remaining); + } + } + if remaining == 80 { + let paused = battle.step(input(true, true)).unwrap(); + assert_eq!(paused.actors[0].stun_remaining, remaining); + assert!(!paused.cues.contains(&chirp)); + } + if frame.actors[0].activity == Activity::Idle { + return (elapsed, heard); } } panic!("stun did not recover"); } - let ordinary = recovery_time(Control::Manual, false, false); - assert!(recovery_time(Control::Manual, true, false) < ordinary); - assert!(recovery_time(Control::SemiAuto, false, true) < ordinary); - assert_eq!(recovery_time(Control::Auto, false, true), ordinary); + let ordinary = (181, vec![160, 120, 80, 40]); + assert_eq!(recovery(Control::Manual, false, false), ordinary); + assert_eq!(recovery(Control::Manual, true, false), (91, vec![80, 40])); + assert_eq!( + recovery(Control::SemiAuto, false, true), + (179, vec![120, 80, 40]) + ); + assert_eq!(recovery(Control::Auto, false, true), ordinary); } #[test] diff --git a/crates/game/src/battle/audio.rs b/crates/game/src/battle/audio.rs index 67e659593..22de1d285 100644 --- a/crates/game/src/battle/audio.rs +++ b/crates/game/src/battle/audio.rs @@ -1,6 +1,7 @@ //! Native sound IDs requested by battle behavior. pub const TARGET_CHANGED: u16 = 108; pub const RESULT_ADVANCEMENT: u16 = 80; +pub const STUN_CHIRP: u16 = 117; pub const STORED_SPELL_RELEASE: u16 = 122; pub const SPELL_RELEASE: u16 = 123; @@ -27,6 +28,7 @@ pub(crate) const COMMON_CUES: &[u16] = &[ 95, TARGET_CHANGED, 109, + STUN_CHIRP, STORED_SPELL_RELEASE, SPELL_RELEASE, 126, diff --git a/crates/game/src/battle/encounter/preparation.rs b/crates/game/src/battle/encounter/preparation.rs index 21326edbd..988cc4374 100644 --- a/crates/game/src/battle/encounter/preparation.rs +++ b/crates/game/src/battle/encounter/preparation.rs @@ -2295,6 +2295,7 @@ impl Assets { .with_hosted_participants(hosted_participants)? .with_entry_choices(entry_choices)? .with_arena_boundary() + .with_stun_sound(sound(Sound::Cue(battle::audio::STUN_CHIRP))?) .with_hover_bobbing(hover_bobbing)? .with_unison_gauge(party.unison_gauge, enabled & 0x02 != 0, initial_unison_full)? .with_grade_rank(difficulty)