221 lines
7.3 KiB
Plaintext
221 lines
7.3 KiB
Plaintext
#include "libstorm-nvgt/volume_controls.nvgt"
|
|
|
|
bool audio_asset_exists(const string& in soundFile) {
|
|
if (file_exists(soundFile)) {
|
|
return true;
|
|
}
|
|
|
|
pack @activePack = cast<pack @>(sound_default_pack);
|
|
if (@activePack != null && activePack.file_exists(soundFile)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
string get_footstep_sound(int current_x, int base_end, int grass_end) {
|
|
// Check if in water first (regular streams or mountain streams)
|
|
if (is_deep_stream_at(current_x)) {
|
|
return "sounds/terrain/deep_water.ogg";
|
|
}
|
|
if (is_position_in_water(current_x) || is_mountain_stream_at(current_x)) {
|
|
return "sounds/terrain/shallow_water.ogg";
|
|
}
|
|
|
|
// Firepit uses hard stone sound
|
|
if (get_firepit_at(current_x) != null) {
|
|
return "sounds/terrain/hard_stone.ogg";
|
|
}
|
|
|
|
if (current_x <= base_end) {
|
|
// Base area
|
|
return "sounds/terrain/wood.ogg";
|
|
} else if (current_x <= grass_end) {
|
|
// Grass area
|
|
return "sounds/terrain/grass.ogg";
|
|
} else if (current_x <= GRAVEL_END) {
|
|
// Gravel area
|
|
return "sounds/terrain/gravel.ogg";
|
|
} else if (expanded_area_start != -1 && current_x >= expanded_area_start && current_x <= expanded_area_end) {
|
|
// Check for mountain terrain first
|
|
MountainRange @mountain = get_mountain_at(current_x);
|
|
if (mountain !is null) {
|
|
string terrain = mountain.get_terrain_at(current_x);
|
|
if (terrain == "stone") {
|
|
return "sounds/terrain/stone.ogg";
|
|
} else if (terrain == "gravel") {
|
|
return "sounds/terrain/gravel.ogg";
|
|
} else if (terrain == "snow") {
|
|
return "sounds/terrain/snow.ogg";
|
|
} else if (terrain == "forest") {
|
|
return "sounds/terrain/forest.ogg";
|
|
} else if (terrain == "deep_forest") {
|
|
return "sounds/terrain/deep_forest.ogg";
|
|
}
|
|
}
|
|
|
|
// Regular expanded area - check terrain type
|
|
int index = current_x - expanded_area_start;
|
|
if (index >= 0 && index < int(expanded_terrain_types.length())) {
|
|
string terrain = expanded_terrain_types[index];
|
|
// Handle "mountain:terrain" format from older saves
|
|
if (terrain.find("mountain:") == 0) {
|
|
terrain = terrain.substr(9);
|
|
}
|
|
if (terrain == "stone") {
|
|
return "sounds/terrain/stone.ogg";
|
|
} else if (terrain == "grass") {
|
|
return "sounds/terrain/grass.ogg";
|
|
} else if (terrain == "snow") {
|
|
return "sounds/terrain/snow.ogg";
|
|
} else if (terrain == "gravel") {
|
|
return "sounds/terrain/gravel.ogg";
|
|
} else if (terrain == "forest") {
|
|
return "sounds/terrain/forest.ogg";
|
|
} else if (terrain == "deep_forest") {
|
|
return "sounds/terrain/deep_forest.ogg";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Default to gravel
|
|
return "sounds/terrain/gravel.ogg";
|
|
}
|
|
|
|
void play_footstep(int current_x, int base_end, int grass_end) {
|
|
string sound_file = get_footstep_sound(current_x, base_end, grass_end);
|
|
|
|
if (audio_asset_exists(sound_file)) {
|
|
p.play_stationary(sound_file, false);
|
|
}
|
|
}
|
|
|
|
int to_audio_position(int tile_x) {
|
|
return tile_x * AUDIO_TILE_SCALE;
|
|
}
|
|
|
|
float to_audio_volume_step(float volume_step) {
|
|
return volume_step / float(AUDIO_TILE_SCALE);
|
|
}
|
|
|
|
int play_1d_tile(string sound_file, int listener_x, int sound_x, bool looping, bool persistent = false) {
|
|
return p.play_1d(sound_file, to_audio_position(listener_x), to_audio_position(sound_x), looping, persistent);
|
|
}
|
|
|
|
bool update_sound_1d_tile(int slot, int sound_x) {
|
|
return p.update_sound_1d(slot, to_audio_position(sound_x));
|
|
}
|
|
|
|
void update_listener_tile(int listener_x) {
|
|
p.update_listener_1d(to_audio_position(listener_x));
|
|
}
|
|
|
|
void update_sound_range_1d_tile(int slot, int range_tiles) {
|
|
p.update_sound_range_1d(slot, range_tiles * AUDIO_TILE_SCALE, range_tiles * AUDIO_TILE_SCALE);
|
|
}
|
|
|
|
int play_1d_with_volume_step(string sound_file, int listener_x, int sound_x, bool looping, float volume_step) {
|
|
int slot = p.play_1d(sound_file, listener_x, sound_x, looping);
|
|
if (slot != -1) {
|
|
p.update_sound_positioning_values(slot, -1.0, volume_step, true);
|
|
}
|
|
return slot;
|
|
}
|
|
|
|
void play_positional_footstep(int listener_x, int step_x, int base_end, int grass_end, int max_distance,
|
|
float volume_step) {
|
|
if (abs(step_x - listener_x) > max_distance) {
|
|
return;
|
|
}
|
|
|
|
string sound_file = get_footstep_sound(step_x, base_end, grass_end);
|
|
|
|
if (audio_asset_exists(sound_file)) {
|
|
play_1d_with_volume_step(sound_file, listener_x, step_x, false, volume_step);
|
|
}
|
|
}
|
|
|
|
void play_land_sound(int current_x, int base_end, int grass_end) {
|
|
// Reusing the same logic to play the terrain sound on landing
|
|
string sound_file = get_footstep_sound(current_x, base_end, grass_end);
|
|
|
|
if (audio_asset_exists(sound_file)) {
|
|
p.play_stationary(sound_file, false);
|
|
}
|
|
}
|
|
|
|
string get_item_collect_sound(string itemName) {
|
|
string lookupName = itemName;
|
|
if (lookupName == "sticks") {
|
|
lookupName = "stick";
|
|
} else if (lookupName == "vines") {
|
|
lookupName = "vine";
|
|
} else if (lookupName == "reeds") {
|
|
lookupName = "reed";
|
|
} else if (lookupName == "stones") {
|
|
lookupName = "stone";
|
|
} else if (lookupName == "logs") {
|
|
lookupName = "log";
|
|
}
|
|
|
|
if (lookupName == "reed") {
|
|
lookupName = "stick";
|
|
}
|
|
|
|
string soundFile = "sounds/items/" + lookupName + ".ogg";
|
|
if (audio_asset_exists(soundFile)) {
|
|
return soundFile;
|
|
}
|
|
return "sounds/items/miscellaneous.ogg";
|
|
}
|
|
|
|
void play_item_collect_sound(string itemName) {
|
|
string soundFile = get_item_collect_sound(itemName);
|
|
if (audio_asset_exists(soundFile)) {
|
|
p.play_stationary(soundFile, false);
|
|
}
|
|
}
|
|
|
|
string get_player_damage_sound() {
|
|
if (player_sex == SEX_FEMALE) {
|
|
return "sounds/player_female_damage.ogg";
|
|
}
|
|
return "sounds/player_male_damage.ogg";
|
|
}
|
|
|
|
void play_player_damage_sound() {
|
|
string soundFile = get_player_damage_sound();
|
|
if (audio_asset_exists(soundFile)) {
|
|
p.play_stationary(soundFile, false);
|
|
}
|
|
}
|
|
|
|
// Safe sound handle cleanup - checks if handle is valid and sound is active before destroying
|
|
void safe_destroy_sound(int& inout handle) {
|
|
safe_destroy_sound_in_pool(p, handle);
|
|
}
|
|
|
|
float master_volume_db = MASTER_VOLUME_MAX_DB;
|
|
|
|
void apply_master_volume_from_controls(float volumeDb) {
|
|
master_volume_db = volumeDb;
|
|
sound_master_volume = volumeDb;
|
|
}
|
|
|
|
void init_master_volume() {
|
|
volume_controls_set_apply_callback(apply_master_volume_from_controls);
|
|
volume_controls_configure(MASTER_VOLUME_MIN_DB, MASTER_VOLUME_MAX_DB, MASTER_VOLUME_STEP_DB, MASTER_VOLUME_MAX_DB);
|
|
volume_controls_set_current_db(MASTER_VOLUME_MAX_DB, false);
|
|
master_volume_db = volume_controls_get_current_db();
|
|
}
|
|
|
|
void set_game_master_volume_db(float volume_db, bool announce = true) {
|
|
volume_controls_set_current_db(volume_db, announce);
|
|
master_volume_db = volume_controls_get_current_db();
|
|
}
|
|
|
|
void handle_global_volume_keys() {
|
|
volume_controls_handle_keys(KEY_PAGEDOWN, KEY_PAGEUP, true);
|
|
master_volume_db = volume_controls_get_current_db();
|
|
}
|