Enhance enemy AI and area connectivity

- Introduced area grid management in WolfEngine to track player-connected areas.
- Updated enemy behavior to consider area connectivity when alerting and moving.
- Added debugging logs for enemy states and movements to assist in tracking AI behavior.
- Implemented fallback area generation for levels lacking area data.
- Enhanced patrol behavior for dogs and guards to prevent rapid direction changes after hitting walls.
- Updated tests to validate new area connectivity logic and enemy behavior under various conditions.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-19 18:03:01 +01:00
parent 7b1ec777d3
commit 4700e669ce
21 changed files with 565 additions and 135 deletions
@@ -1,3 +1,4 @@
import 'dart:developer';
import 'dart:typed_data';
import 'package:audioplayers/audioplayers.dart';
@@ -11,7 +12,7 @@ class WolfAudio implements EngineAudio {
// Play the first 50 sounds with a 2-second gap to identify them
for (int i = 0; i < 50; i++) {
Future.delayed(Duration(seconds: i * 2), () {
print("[AUDIO] Testing Sound ID: $i");
log("[AUDIO] Testing Sound ID: $i");
playSoundEffect(i);
});
}
@@ -50,11 +51,11 @@ class WolfAudio implements EngineAudio {
}
_isInitialized = true;
print(
log(
"[AUDIO] AudioPlayers initialized successfully with $_maxSfxChannels SFX channels.",
);
} catch (e) {
print("[AUDIO] Failed to initialize AudioPlayers - $e");
log("[AUDIO] Failed to initialize AudioPlayers - $e");
}
}
@@ -90,7 +91,7 @@ class WolfAudio implements EngineAudio {
);
await _musicPlayer.play(BytesSource(wavBytes));
} catch (e) {
print("[AUDIO] Error playing music track - $e");
log("[AUDIO] Error playing music track - $e");
}
}
@@ -124,7 +125,7 @@ class WolfAudio implements EngineAudio {
if (index < data.music.length) {
await playMusic(data.music[index]);
} else {
print("[AUDIO] Warning - Track index $index out of bounds.");
log("[AUDIO] Warning - Track index $index out of bounds.");
}
}
@@ -134,7 +135,7 @@ class WolfAudio implements EngineAudio {
@override
Future<void> playSoundEffect(int sfxId) async {
print("[AUDIO] Playing sfx id $sfxId");
log("[AUDIO] Playing sfx id $sfxId");
// The original engine uses a specific starting chunk for digitized sounds.
// In many loaders, the 'sounds' list is already just the digitized ones.
// If your list contains EVERYTHING, you need to add the offset (174).
@@ -168,7 +169,7 @@ class WolfAudio implements EngineAudio {
// Note: We use BytesSource because createWavFile returns Uint8List (the file bytes)
await player.play(BytesSource(wavBytes));
} catch (e) {
print("[AUDIO] SFX Error - $e");
log("[AUDIO] SFX Error - $e");
}
}
}