// -------------------------------------------------------- // get an sound from a stack // -------------------------------------------------------- t_sound_ptr get_combat_sound( t_creature_stack const& stack, t_combat_actor_action_id action ) { t_hero const* hero = stack.get_hero(); if (hero != 0) return get_sound( hero->get_alignment(), hero->uses_spellcaster_model(), hero->has_ability( k_ability_ranged ), hero->is_male(), action ); return get_sound( stack.get_creature_type(), action ); }
// ---------------------------------------------------------------------------- // get a sound for a creature // ---------------------------------------------------------------------------- static t_sound_ptr get_sound( t_creature_type creature, t_combat_actor_action_id action ) { static bool initialized = false; static t_sound_cache caches[k_creature_type_count][k_combat_actor_action_count]; if (!initialized) { t_creature_type index; t_combat_actor_action_id id; std::string name; for (index = t_creature_type(0); index < k_creature_type_count; enum_incr(index)) { for (id = t_combat_actor_action_id(0); id < k_combat_actor_action_count; enum_incr(id)) { name = get_keyword( index ); name += "."; name += get_combat_actor_action_name( id ); caches[index][id] = t_sound_cache( name ); } } initialized = true; } t_sound_ptr result = caches[creature][action].get(); if (result == 0) if ( action == k_combat_actor_action_melee_down || action == k_combat_actor_action_melee_up) return get_sound( creature, k_combat_actor_action_melee ); return result; }
void sound_resume_all() { for (size_t i = 0; i < sound_resources.size(); i++) { get_sound(snd, i, 0); snd->soundBuffer->Play(0, 0, 0); } }
void sound_stop_all() { for (size_t i = 0; i < sound_resources.size(); i++) { get_sound(snd, i, 0); snd->soundBuffer->Stop(); } }
bool sound_loop(int sound) // Returns whether sound is playing { get_sound(snd, sound, false); snd->soundBuffer->SetCurrentPosition(0); snd->soundBuffer->Play(0, 0, DSBPLAY_LOOPING); return true; }
bool sound_isplaying(int sound) { get_sound(snd, sound, false); LPDWORD ret = NULL; snd->soundBuffer->GetStatus(ret); if (*ret == DSBSTATUS_LOOPING || *ret == DSBSTATUS_LOOPING) { return true; } else { return false; } }
// -------------------------------------------------------- // get an sound based on a hero's alignment and traits // -------------------------------------------------------- static t_sound_ptr get_sound( t_town_type alignment, bool is_spellcaster, bool has_archery, bool is_male, t_combat_actor_action_id action) { static bool initialized = false; t_hero_combat_model_type type; static t_sound_cache caches[k_town_type_count][k_hero_combat_model_count][2][k_combat_actor_action_count]; if (!initialized) { t_town_type town; std::string base_name; std::string name; int sex; t_combat_actor_action_id id; for (town = t_town_type(0); town < k_town_type_count; enum_incr(town)) { for (type = t_hero_combat_model_type(0); type < k_hero_combat_model_count; enum_incr(type)) { for (sex = 0; sex < 2; sex++) { base_name = get_combat_type_keyword( town, type, sex == 1); for (id = t_combat_actor_action_id(0); id < k_combat_actor_action_count; enum_incr(id)) { name = base_name; name += "."; name += get_combat_actor_action_name( id ); caches[town][type][sex][id] = t_sound_cache( name ); } } } } initialized = true; } if (is_spellcaster && alignment != k_town_might) type = k_model_spellcaster; else if (has_archery) type = k_model_archer; else type = k_model_fighter; t_sound_ptr result = caches[alignment][type][is_male][action].get(); if (result == 0) result = get_sound( k_mage, action ); return result; }
void Resources::prepare_resources() throw (ResourcesException) { /* load animation sounds */ for (ResourceObjects::iterator it = animations.begin(); it != animations.end(); it++) { ResourceObject& ro = *it; Animation *ani = static_cast<Animation *>(ro.object); const std::string& sound_name = ani->get_value("sound_name"); if (sound_name.length()) { ani->set_sound(get_sound(sound_name)); } } }
float sound_get_volume(int sound) { get_sound(snd, sound, -1); LPLONG ret = NULL; snd->soundBuffer->GetVolume(ret); return *ret; }
float sound_get_pan(int sound) { get_sound(snd, sound, -1); LPLONG ret = NULL; snd->soundBuffer->GetPan(ret); return *ret; }
bool sound_ispaused(int sound) { get_sound(snd, sound, false); return !snd->idle and !snd->playing; }
bool sound_resume(int sound) // Returns whether the sound is playing { get_sound(snd, sound, false); snd->soundBuffer->Play(0, 0, 0); return true; }
bool sound_play(int sound) // Returns whether sound is playing { get_sound(snd, sound, 0); snd->soundBuffer->SetCurrentPosition(0); snd->soundBuffer->Play(0, 0, 0); }
void sound_seek(int sound, float position) { get_sound(snd, sound, 0); snd->soundBuffer->SetCurrentPosition(position); }
void sound_volume(int sound, float volume) { get_sound(snd,sound,0); snd->soundBuffer->SetVolume((1-volume) * DSBVOLUME_MIN); }
void sound_delete(int sound) { get_sound(snd,sound,0); sound_stop(sound); sound_resources.erase(sound_resources.begin() + sound); }
void sound_stop(int sound) { get_sound(snd, sound, 0); snd->soundBuffer->Stop(); }
float sound_get_length(int sound) { // Not for Streams get_sound(snd, sound, -1); //snd->soundBuffer->GetLength(); return 0; }
float sound_get_position(int sound) { // Not for Streams get_sound(snd, sound, -1); LPDWORD ret = NULL; snd->soundBuffer->GetCurrentPosition(ret, NULL); return *ret; }
void sound_pan(int sound, float value) { get_sound(snd, sound, 0); snd->soundBuffer->SetPan(value * 10000); }
bool sound_pause(int sound) // Returns whether the sound was successfully paused { get_sound(snd, sound, false); snd->soundBuffer->Stop(); return true; }
void sound_seek_all(float position) { for (size_t i = 0; i < sound_resources.size(); i++) { get_sound(snd, i, 0); snd->soundBuffer->SetCurrentPosition(position); } }