Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/entries/2026-12-01_battle_stun_sound.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
issues: []
prs: []
---

# Fixed
Restore the repeating bird chirps when a combatant is stunned.
2 changes: 2 additions & 0 deletions crates/battle/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub(crate) struct BattleResources {
pub(crate) unison_gauge: i16,
pub(crate) unison_available: bool,
pub(crate) escape: Option<crate::EscapeDefinition>,
pub(crate) stun_sound: Option<crate::Sound>,
pub(crate) overlimit_boosted_gain: bool,
pub(crate) items: Option<crate::item::Definition>,
pub(crate) grade_rank: crate::Difficulty,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions crates/battle/src/stun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Sound>) -> Self {
self.resources.stun_sound = sound;
self
}
}

impl Battle {
pub(crate) fn enter_action_stun(&mut self, id: ActorId, cues: &mut Vec<Cue>) {
self.enter_stun(id, cues);
Expand Down Expand Up @@ -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
Expand Down
51 changes: 38 additions & 13 deletions crates/battle/src/stun/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>) {
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]),
Expand All @@ -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![]);
Expand All @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions crates/game/src/battle/audio.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -27,6 +28,7 @@ pub(crate) const COMMON_CUES: &[u16] = &[
95,
TARGET_CHANGED,
109,
STUN_CHIRP,
STORED_SPELL_RELEASE,
SPELL_RELEASE,
126,
Expand Down
1 change: 1 addition & 0 deletions crates/game/src/battle/encounter/preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading