Fixed crash bug with snares and possibly in other places.

This commit is contained in:
Storm Dragon
2026-01-25 15:46:45 -05:00
parent f80e3263a3
commit 815ac97a64
19 changed files with 575 additions and 154 deletions

View File

@@ -62,7 +62,12 @@ void spawn_undead() {
Undead@ z = Undead(spawn_x, "zombie");
undeads.insert_last(z);
// Play looping sound that follows the zombie
z.sound_handle = play_1d_with_volume_step(z.voice_sound, x, spawn_x, true, ZOMBIE_SOUND_VOLUME_STEP);
int[] areaStarts;
int[] areaEnds;
get_active_audio_areas(areaStarts, areaEnds);
if (areaStarts.length() == 0 || range_overlaps_active_areas(spawn_x, spawn_x, areaStarts, areaEnds)) {
z.sound_handle = play_1d_with_volume_step(z.voice_sound, x, spawn_x, true, ZOMBIE_SOUND_VOLUME_STEP);
}
}
void try_attack_barricade_undead(Undead@ undead) {
@@ -128,9 +133,14 @@ bool try_attack_player_undead(Undead@ undead) {
return true;
}
void update_undead(Undead@ undead) {
void update_undead(Undead@ undead, bool audio_active) {
// Update looping sound position
if (undead.sound_handle != -1 && p.sound_is_active(undead.sound_handle)) {
if (!audio_active) {
if (undead.sound_handle != -1) {
p.destroy_sound(undead.sound_handle);
undead.sound_handle = -1;
}
} else if (undead.sound_handle != -1 && p.sound_is_active(undead.sound_handle)) {
p.update_sound_1d(undead.sound_handle, undead.position);
} else if (undead.sound_handle == -1 || !p.sound_is_active(undead.sound_handle)) {
// Restart looping sound if it stopped for some reason
@@ -175,7 +185,9 @@ void update_undead(Undead@ undead) {
}
undead.position = target_x;
play_creature_footstep(x, undead.position, BASE_END, GRASS_END, ZOMBIE_FOOTSTEP_MAX_DISTANCE, ZOMBIE_SOUND_VOLUME_STEP);
if (audio_active) {
play_creature_footstep(x, undead.position, BASE_END, GRASS_END, ZOMBIE_FOOTSTEP_MAX_DISTANCE, ZOMBIE_SOUND_VOLUME_STEP);
}
}
void update_undeads() {
@@ -195,8 +207,14 @@ void update_undeads() {
spawn_undead();
}
int[] areaStarts;
int[] areaEnds;
get_active_audio_areas(areaStarts, areaEnds);
bool limit_audio = (areaStarts.length() > 0);
for (uint i = 0; i < undeads.length(); i++) {
update_undead(undeads[i]);
bool audio_active = !limit_audio || range_overlaps_active_areas(undeads[i].position, undeads[i].position, areaStarts, areaEnds);
update_undead(undeads[i], audio_active);
}
}