Refactored SoundKind and UtteranceKind

This commit is contained in:
socksonme 2021-10-15 22:49:25 +03:00
parent 045621993a
commit c631341da9
3 changed files with 8 additions and 7 deletions

View File

@ -327,8 +327,6 @@ pub enum SoundKind {
Beam, Beam,
Shockwave, Shockwave,
Utterance(UtteranceKind, Body), Utterance(UtteranceKind, Body),
// TODO: unify VillagerAlarm with Utterance
VillagerAlarm,
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]

View File

@ -104,6 +104,7 @@ pub enum UtteranceKind {
Surprised, Surprised,
Hurt, Hurt,
Greeting, Greeting,
Scream,
/* Death, /* Death,
* TODO: Wait for more post-death features (i.e. animiations) before implementing death * TODO: Wait for more post-death features (i.e. animiations) before implementing death
* sounds */ * sounds */

View File

@ -716,7 +716,7 @@ impl<'a> AgentData<'a> {
// Should the agent flee? // Should the agent flee?
if agent.action_state.timer == 0.0 && can_speak(agent) { if agent.action_state.timer == 0.0 && can_speak(agent) {
self.chat_general("npc.speech.villager_under_attack", event_emitter); self.chat_general("npc.speech.villager_under_attack", event_emitter);
self.emit_villager_alarm(read_data.time.0, event_emitter); self.emit_alarm(read_data.time.0, event_emitter);
agent.action_state.timer = 0.01; agent.action_state.timer = 0.01;
} else if agent.action_state.timer < FLEE_DURATION } else if agent.action_state.timer < FLEE_DURATION
|| dist_sq < MAX_FLEE_DIST.powi(2) || dist_sq < MAX_FLEE_DIST.powi(2)
@ -4355,10 +4355,12 @@ impl<'a> AgentData<'a> {
))); )));
} }
fn emit_villager_alarm(&self, time: f64, event_emitter: &mut Emitter<'_, ServerEvent>) { fn emit_alarm(&self, time: f64, event_emitter: &mut Emitter<'_, ServerEvent>) {
event_emitter.emit(ServerEvent::Sound { if let Some(body) = self.body {
sound: Sound::new(SoundKind::VillagerAlarm, self.pos.0, 100.0, time), event_emitter.emit(ServerEvent::Sound {
}); sound: Sound::new(SoundKind::Utterance(UtteranceKind::Scream, *body), self.pos.0, 100.0, time),
});
}
} }
} }