Various bug fixes.

This commit is contained in:
Storm Dragon
2026-01-22 23:30:36 -05:00
parent 35e192cb21
commit 9ded17873d
14 changed files with 357 additions and 93 deletions

View File

@@ -10,9 +10,7 @@ class Bandit {
string weapon_type; // "spear" or "axe"
int sound_handle;
timer move_timer;
timer alert_timer;
timer attack_timer;
int next_alert_delay;
int move_interval;
// Wandering behavior properties
@@ -38,9 +36,7 @@ class Bandit {
move_interval = random(BANDIT_MOVE_INTERVAL_MIN, BANDIT_MOVE_INTERVAL_MAX);
move_timer.restart();
alert_timer.restart();
attack_timer.restart();
next_alert_delay = random(BANDIT_ALERT_MIN_DELAY, BANDIT_ALERT_MAX_DELAY);
// Initialize wandering behavior (start aggressive during invasion)
behavior_state = "aggressive";
@@ -87,7 +83,8 @@ void spawn_bandit(int expansion_start, int expansion_end) {
Bandit@ b = Bandit(spawn_x, expansion_start, expansion_end);
bandits.insert_last(b);
b.sound_handle = play_creature_voice(b.alert_sound, x, spawn_x, BANDIT_SOUND_VOLUME_STEP);
// 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);
}
bool can_bandit_attack_player(Bandit@ bandit) {
@@ -177,18 +174,15 @@ void try_attack_barricade_bandit(Bandit@ bandit) {
}
void update_bandit(Bandit@ bandit) {
// Play alert sound at intervals
if (bandit.alert_timer.elapsed > bandit.next_alert_delay) {
bandit.alert_timer.restart();
bandit.next_alert_delay = random(BANDIT_ALERT_MIN_DELAY, BANDIT_ALERT_MAX_DELAY);
// Destroy old sound handle before playing new one to prevent overlapping
// Update looping sound position
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
if (bandit.sound_handle != -1) {
p.destroy_sound(bandit.sound_handle);
bandit.sound_handle = -1;
}
bandit.sound_handle = play_creature_voice(bandit.alert_sound, x, bandit.position, BANDIT_SOUND_VOLUME_STEP);
bandit.sound_handle = play_1d_with_volume_step(bandit.alert_sound, x, bandit.position, true, BANDIT_SOUND_VOLUME_STEP);
}
if (try_attack_player_bandit(bandit)) {