00001 /* 00002 * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net) 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 */ 00009 #include "SoundAgent.h" 00010 00011 #include "OptionAgent.h" 00012 #include "StringMsg.h" 00013 #include "UnknownMsgException.h" 00014 00015 //----------------------------------------------------------------- 00016 /** 00017 * Set sound and music volume. 00018 */ 00019 void 00020 SoundAgent::own_init() 00021 { 00022 OptionAgent *options = OptionAgent::agent(); 00023 options->setDefault("volume_sound", 90); 00024 options->setDefault("volume_music", 50); 00025 setSoundVolume(options->getAsInt("volume_sound")); 00026 setMusicVolume(options->getAsInt("volume_music")); 00027 00028 registerWatcher("volume_sound"); 00029 registerWatcher("volume_music"); 00030 } 00031 //----------------------------------------------------------------- 00032 /** 00033 * Handle incoming message. 00034 * Messages: 00035 * - param_changed(volume_sound) ... set sound volume 00036 * - param_changed(volume_music) ... set music volume 00037 * 00038 * @throws UnknownMsgException 00039 */ 00040 void 00041 SoundAgent::receiveString(const StringMsg *msg) 00042 { 00043 if (msg->equalsName("param_changed")) { 00044 std::string param = msg->getValue(); 00045 if ("volume_sound" == param) { 00046 int volume = OptionAgent::agent()->getAsInt("volume_sound"); 00047 setSoundVolume(volume); 00048 } 00049 else if ("volume_music" == param) { 00050 int volume = OptionAgent::agent()->getAsInt("volume_music"); 00051 setMusicVolume(volume); 00052 } 00053 } 00054 else { 00055 throw UnknownMsgException(msg); 00056 } 00057 } 00058 00059 00060