Fixed crash bug with snares and possibly in other places.
This commit is contained in:
@@ -84,7 +84,12 @@ void spawn_bandit(int expansion_start, int expansion_end) {
|
||||
Bandit@ b = Bandit(spawn_x, expansion_start, expansion_end);
|
||||
bandits.insert_last(b);
|
||||
// Play looping sound that follows the bandit
|
||||
b.sound_handle = play_1d_with_volume_step(b.alert_sound, x, spawn_x, true, BANDIT_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)) {
|
||||
b.sound_handle = play_1d_with_volume_step(b.alert_sound, x, spawn_x, true, BANDIT_SOUND_VOLUME_STEP);
|
||||
}
|
||||
}
|
||||
|
||||
bool can_bandit_attack_player(Bandit@ bandit) {
|
||||
@@ -174,9 +179,14 @@ void try_attack_barricade_bandit(Bandit@ bandit) {
|
||||
}
|
||||
}
|
||||
|
||||
void update_bandit(Bandit@ bandit) {
|
||||
void update_bandit(Bandit@ bandit, bool audio_active) {
|
||||
// Update looping sound position
|
||||
if (bandit.sound_handle != -1 && p.sound_is_active(bandit.sound_handle)) {
|
||||
if (!audio_active) {
|
||||
if (bandit.sound_handle != -1) {
|
||||
p.destroy_sound(bandit.sound_handle);
|
||||
bandit.sound_handle = -1;
|
||||
}
|
||||
} else if (bandit.sound_handle != -1 && p.sound_is_active(bandit.sound_handle)) {
|
||||
p.update_sound_1d(bandit.sound_handle, bandit.position);
|
||||
} else if (bandit.sound_handle == -1 || !p.sound_is_active(bandit.sound_handle)) {
|
||||
// Restart looping sound if it stopped
|
||||
@@ -227,7 +237,9 @@ void update_bandit(Bandit@ bandit) {
|
||||
bandit.wander_direction = -bandit.wander_direction;
|
||||
} else {
|
||||
bandit.position = target_x;
|
||||
play_creature_footstep(x, bandit.position, BASE_END, GRASS_END, BANDIT_FOOTSTEP_MAX_DISTANCE, BANDIT_SOUND_VOLUME_STEP);
|
||||
if (audio_active) {
|
||||
play_creature_footstep(x, bandit.position, BASE_END, GRASS_END, BANDIT_FOOTSTEP_MAX_DISTANCE, BANDIT_SOUND_VOLUME_STEP);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Hit map boundary, reverse direction
|
||||
@@ -270,13 +282,21 @@ void update_bandit(Bandit@ bandit) {
|
||||
}
|
||||
|
||||
bandit.position = target_x;
|
||||
play_creature_footstep(x, bandit.position, BASE_END, GRASS_END, BANDIT_FOOTSTEP_MAX_DISTANCE, BANDIT_SOUND_VOLUME_STEP);
|
||||
if (audio_active) {
|
||||
play_creature_footstep(x, bandit.position, BASE_END, GRASS_END, BANDIT_FOOTSTEP_MAX_DISTANCE, BANDIT_SOUND_VOLUME_STEP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_bandits() {
|
||||
int[] areaStarts;
|
||||
int[] areaEnds;
|
||||
get_active_audio_areas(areaStarts, areaEnds);
|
||||
bool limit_audio = (areaStarts.length() > 0);
|
||||
|
||||
for (uint i = 0; i < bandits.length(); i++) {
|
||||
update_bandit(bandits[i]);
|
||||
bool audio_active = !limit_audio || range_overlaps_active_areas(bandits[i].position, bandits[i].position, areaStarts, areaEnds);
|
||||
update_bandit(bandits[i], audio_active);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user