home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / audio / random_sound.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2008-09-25  |  17.8 KB  |  615 lines

  1. /***************************************************************************
  2.  * random_sound.cpp  -  random sounds support
  3.  *
  4.  * Copyright (C) 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #include "../audio/random_sound.h"
  17. #include "../core/game_core.h"
  18. #include "../core/camera.h"
  19. #include "../core/framerate.h"
  20. #include "../audio/audio.h"
  21. #include "../video/renderer.h"
  22. #include "../input/mouse.h"
  23. #include "../core/math/utilities.h"
  24. #include "../core/i18n.h"
  25.  
  26. /* *** *** *** *** *** cRandom_Sound *** *** *** *** *** *** *** *** *** *** *** */
  27.  
  28. cRandom_Sound :: cRandom_Sound( void )
  29. : cSprite()
  30. {
  31.     // Set defaults
  32.     cRandom_Sound::Init();
  33. }
  34.  
  35. cRandom_Sound :: cRandom_Sound( CEGUI::XMLAttributes &attributes )
  36. : cSprite()
  37. {
  38.     cRandom_Sound::Init();
  39.     cRandom_Sound::Create_from_Stream( attributes );
  40. }
  41.  
  42. cRandom_Sound :: ~cRandom_Sound( void )
  43. {
  44.  
  45. }
  46.  
  47. void cRandom_Sound :: Create_from_Stream( CEGUI::XMLAttributes &attributes )
  48. {
  49.     // filename
  50.     Set_Filename( attributes.getValueAsString( "file" ).c_str() );
  51.     // position
  52.     Set_Pos( static_cast<float>(attributes.getValueAsInteger( "pos_x" )), static_cast<float>(attributes.getValueAsInteger( "pos_y" )), 1 );
  53.     // 
  54.     Set_Continuous( attributes.getValueAsBool( "continuous", m_continuous ) );
  55.     // delay
  56.     Set_Delay_Min( attributes.getValueAsInteger( "delay_min", m_delay_min ) );
  57.     Set_Delay_Max( attributes.getValueAsInteger( "delay_max", m_delay_max ) );
  58.     // volume
  59.     Set_Volume_Min( attributes.getValueAsFloat( "volume_min", m_volume_min ) );
  60.     Set_Volume_Max( attributes.getValueAsFloat( "volume_max", m_volume_max ) );
  61.     // volume reduction
  62.     Set_Volume_Reduction_Begin( attributes.getValueAsFloat( "volume_reduction_begin", m_volume_reduction_begin ) );
  63.     Set_Volume_Reduction_End( attributes.getValueAsFloat( "volume_reduction_end", m_volume_reduction_end ) );
  64. }
  65.  
  66. void cRandom_Sound :: Save_to_Stream( ofstream &ofile )
  67. {
  68.     ofile << "\t<sound>" << std::endl;
  69.  
  70.     // filename
  71.     ofile << "\t\t<Property name=\"file\" value=\"" << m_filename.c_str() << "\" />" << std::endl;
  72.     // position
  73.     ofile << "\t\t<Property name=\"pos_x\" value=\"" << static_cast<int>(startposx) << "\" />" << std::endl;
  74.     ofile << "\t\t<Property name=\"pos_y\" value=\"" << static_cast<int>(startposy) << "\" />" << std::endl;
  75.     // continuous
  76.     ofile << "\t\t<Property name=\"continuous\" value=\"" << m_continuous << "\" />" << std::endl;
  77.     // delay
  78.     ofile << "\t\t<Property name=\"delay_min\" value=\"" << m_delay_min << "\" />" << std::endl;
  79.     ofile << "\t\t<Property name=\"delay_max\" value=\"" << m_delay_max << "\" />" << std::endl;
  80.     // volume
  81.     ofile << "\t\t<Property name=\"volume_min\" value=\"" << m_volume_min << "\" />" << std::endl;
  82.     ofile << "\t\t<Property name=\"volume_max\" value=\"" << m_volume_max << "\" />" << std::endl;
  83.     // volume reduction
  84.     ofile << "\t\t<Property name=\"volume_reduction_begin\" value=\"" << m_volume_reduction_begin << "\" />" << std::endl;
  85.     ofile << "\t\t<Property name=\"volume_reduction_end\" value=\"" << m_volume_reduction_end << "\" />" << std::endl;
  86.  
  87.     ofile << "\t</sound>" << std::endl;
  88. }
  89.  
  90. void cRandom_Sound :: Init( void )
  91. {
  92.     sprite_array = ARRAY_ACTIVE;
  93.     type = TYPE_SOUND;
  94.     massivetype = MASS_PASSIVE;
  95.     editor_posz = 0.111f;
  96.     player_range = 0;
  97.     name = "Sound";
  98.  
  99.     rect.w = 10;
  100.     rect.h = 10;
  101.     col_rect.w = rect.w;
  102.     col_rect.h = rect.h;
  103.     start_rect.w = rect.w;
  104.     start_rect.h = rect.h;
  105.  
  106.     // default values
  107.     m_continuous = 0;
  108.     m_delay_min = 1000;
  109.     m_delay_max = 5000;
  110.     m_volume_min = 90;
  111.     m_volume_max = 100;
  112.     m_volume_reduction_begin = 400;
  113.     m_volume_reduction_end = 1000;
  114.     
  115.     m_distance_to_camera = 0;
  116.     m_next_play_delay = 0;
  117.     m_volume_update_counter = 0;
  118.  
  119.     m_editor_color_volume_reduction_begin = Color( 0.1f, 0.5f, 0.1f, 0.2f );
  120.     m_editor_color_volume_reduction_end = Color( 0.2f, 0.4f, 0.1f, 0.2f );
  121. }
  122.  
  123. cRandom_Sound *cRandom_Sound :: Copy( void )
  124. {
  125.     cRandom_Sound *random_sound = new cRandom_Sound();
  126.     random_sound->Set_Pos( startposx, startposy, 1 );
  127.     random_sound->Set_Filename( m_filename.c_str() );
  128.     random_sound->Set_Continuous( m_continuous );
  129.     random_sound->Set_Delay_Min( m_delay_min );
  130.     random_sound->Set_Delay_Max( m_delay_max );
  131.     random_sound->Set_Volume_Min( m_volume_min );
  132.     random_sound->Set_Volume_Max( m_volume_max );
  133.     random_sound->Set_Volume_Reduction_Begin( m_volume_reduction_begin );
  134.     random_sound->Set_Volume_Reduction_End( m_volume_reduction_end );
  135.  
  136.     return random_sound;
  137. }
  138.  
  139. void cRandom_Sound :: Set_Filename( string str )
  140. {
  141.     // stop playing sounds
  142.     for( unsigned int i = 0; i < 100; i++ )
  143.     {
  144.         cAudio_Sound *sound = pAudio->Get_Playing_Sound( m_filename );
  145.  
  146.         if( !sound )
  147.         {
  148.             break;
  149.         }
  150.  
  151.         sound->Stop();
  152.     }
  153.  
  154.     m_filename = str;
  155. }
  156.  
  157. string cRandom_Sound :: Get_Filename( void ) const
  158. {
  159.     return m_filename;
  160. }
  161.  
  162. void cRandom_Sound :: Set_Continuous( bool continuous )
  163. {
  164.     m_continuous = continuous;
  165. }
  166.  
  167. void cRandom_Sound :: Set_Delay_Min( unsigned int delay )
  168. {
  169.     if( delay < 20 )
  170.     {
  171.         delay = 20;
  172.     }
  173.  
  174.     m_delay_min = delay;
  175. }
  176.  
  177. unsigned int cRandom_Sound :: Get_Delay_Min( void ) const
  178. {
  179.     return m_delay_min;
  180. }
  181.  
  182. void cRandom_Sound :: Set_Delay_Max( unsigned int delay )
  183. {
  184.     if( delay < 20 )
  185.     {
  186.         delay = 20;
  187.     }
  188.     else if( delay < m_delay_min )
  189.     {
  190.         delay = m_delay_min;
  191.     }
  192.  
  193.     m_delay_max = delay;
  194. }
  195.  
  196. unsigned int cRandom_Sound :: Get_Delay_Max( void ) const
  197. {
  198.     return m_delay_max;
  199. }
  200.  
  201. void cRandom_Sound :: Set_Volume_Min( float volume )
  202. {
  203.     if( volume < 0.1f )
  204.     {
  205.         volume = 0.1f;
  206.     }
  207.     else if( volume > m_volume_max )
  208.     {
  209.         volume = m_volume_max;
  210.     }
  211.     else if( volume > 100 )
  212.     {
  213.         volume = 100;
  214.     }
  215.  
  216.     m_volume_min = volume;
  217. }
  218.  
  219. float cRandom_Sound :: Get_Volume_Min( void ) const
  220. {
  221.     return m_volume_min;
  222. }
  223.  
  224. void cRandom_Sound :: Set_Volume_Max( float volume )
  225. {
  226.     if( volume < 0.1f )
  227.     {
  228.         volume = 0.1f;
  229.     }
  230.     else if( volume < m_volume_min )
  231.     {
  232.         volume = m_volume_min;
  233.     }
  234.     else if( volume > 100 )
  235.     {
  236.         volume = 100;
  237.     }
  238.  
  239.     m_volume_max = volume;
  240. }
  241.  
  242. float cRandom_Sound :: Get_Volume_Max( void ) const
  243. {
  244.     return m_volume_max;
  245. }
  246.  
  247. void cRandom_Sound :: Set_Volume_Reduction_Begin( float distance )
  248. {
  249.     if( distance < 1 )
  250.     {
  251.         distance = 1;
  252.     }
  253.     else if( distance > m_volume_reduction_end )
  254.     {
  255.         distance = m_volume_reduction_end;
  256.     }
  257.  
  258.     m_volume_reduction_begin = distance;
  259. }
  260.  
  261. float cRandom_Sound :: Get_Volume_Reduction_Begin( void ) const
  262. {
  263.     return m_volume_reduction_begin;
  264. }
  265.  
  266. void cRandom_Sound :: Set_Volume_Reduction_End( float distance )
  267. {
  268.     if( distance < 1 )
  269.     {
  270.         distance = 1;
  271.     }
  272.     else if( distance < m_volume_reduction_begin )
  273.     {
  274.         distance = m_volume_reduction_begin;
  275.     }
  276.  
  277.     m_volume_reduction_end = distance;
  278. }
  279.  
  280. float cRandom_Sound :: Get_Volume_Reduction_End( void ) const
  281. {
  282.     return m_volume_reduction_end;
  283. }
  284.  
  285. float cRandom_Sound :: Get_Distance_Volume_Mod( void )
  286. {
  287.     // if in volume reduction range
  288.     if( m_distance_to_camera > m_volume_reduction_begin )
  289.     {
  290.         float distance = m_distance_to_camera - m_volume_reduction_begin;
  291.         return ( 1.0f - distance / ( m_volume_reduction_end - m_volume_reduction_begin ) );
  292.     }
  293.  
  294.     // no reduction
  295.     return 1.0f;
  296. }
  297.  
  298. void cRandom_Sound :: Update( void )
  299. {
  300.     Update_Valid_Update();
  301.  
  302.     if( !valid_update )
  303.     {
  304.         return;
  305.     }
  306.  
  307.     bool play = 0;
  308.  
  309.     if( m_continuous )
  310.     {
  311.         m_volume_update_counter -= ( pFramerate->speedfactor * 1000 ) / static_cast<float>(speedfactor_fps);
  312.  
  313.         // get the sound
  314.         cAudio_Sound *sound = pAudio->Get_Playing_Sound( m_filename );
  315.  
  316.         // if not playing
  317.         if( !sound )
  318.         {
  319.             // play it
  320.             play = 1;
  321.         }
  322.         // update volume
  323.         else if( m_volume_update_counter <= 0 )
  324.         {
  325.             // volume based on maximum
  326.             float sound_volume = m_volume_max * 0.01f;
  327.             // apply distance modifier
  328.             sound_volume *= Get_Distance_Volume_Mod();
  329.             // set to mixer volume
  330.             sound_volume *= static_cast<float>(MIX_MAX_VOLUME);
  331.             // set volume
  332.             pAudio->Set_Sound_Volume( static_cast<int>(sound_volume), sound->m_channel );
  333.  
  334.             // update volume every 100 ms
  335.             m_volume_update_counter = 100;
  336.         }
  337.     }
  338.     else
  339.     {
  340.         // subtract duration of this frame in milliseconds
  341.         m_next_play_delay -= ( pFramerate->speedfactor * 1000 ) / static_cast<float>(speedfactor_fps);
  342.  
  343.         // play it
  344.         if( m_next_play_delay <= 0 )
  345.         {
  346.             play = 1;
  347.  
  348.             // set next delay
  349.             m_next_play_delay = static_cast<float>(m_delay_min);
  350.  
  351.             if( m_delay_max > m_delay_min )
  352.             {
  353.                 m_next_play_delay += Get_Random_Float( 0, static_cast<float>(m_delay_max - m_delay_min) );
  354.             }
  355.         }
  356.     }
  357.  
  358.     if( play )
  359.     {
  360.         float sound_volume = 0;
  361.  
  362.         // always maximum volume
  363.         if( m_continuous )
  364.         {
  365.             sound_volume = m_volume_max;
  366.         }
  367.         // set random volume
  368.         else
  369.         {
  370.             // random
  371.             if( m_volume_max > m_volume_min )
  372.             {
  373.                 sound_volume = Get_Random_Float( m_volume_min, m_volume_max );
  374.             }
  375.             // static
  376.             else
  377.             {
  378.                 sound_volume = m_volume_max;
  379.             }
  380.         }
  381.  
  382.         sound_volume *= 0.01f;
  383.  
  384.         // adjust volume based on distance
  385.         sound_volume *= Get_Distance_Volume_Mod();
  386.  
  387.         int loops = 0;
  388.  
  389.         if( m_continuous )
  390.         {
  391.             // unlimited
  392.             loops = -1;
  393.         }
  394.  
  395.         sound_volume *= static_cast<float>(MIX_MAX_VOLUME);
  396.  
  397.         // play sound
  398.         pAudio->Play_Sound( m_filename, -1, static_cast<int>(sound_volume), loops );
  399.     }
  400. }
  401.  
  402. void cRandom_Sound :: Draw( cSurfaceRequest *request /* = NULL */ )
  403. {
  404.     if( !valid_draw )
  405.     {
  406.         return;
  407.     }
  408.  
  409.     // draw color rect
  410.     pVideo->Draw_Rect( col_rect.x - pActive_Camera->x, col_rect.y - pActive_Camera->y, col_rect.w, col_rect.h, editor_posz, &greenyellow );
  411.     // volume reduction begin
  412.     cCircleRequest *circle_request = new cCircleRequest();
  413.     pVideo->Draw_Circle( col_rect.x - pActive_Camera->x, col_rect.y - pActive_Camera->y, m_volume_reduction_begin, editor_posz - 0.0001f, &m_editor_color_volume_reduction_begin, circle_request );
  414.     circle_request->line_width = 3;
  415.     // add request
  416.     pRenderer->Add( circle_request );
  417.     // volume reduction end
  418.     circle_request = new cCircleRequest();
  419.     pVideo->Draw_Circle( col_rect.x - pActive_Camera->x, col_rect.y - pActive_Camera->y, m_volume_reduction_end, editor_posz - 0.0002f, &m_editor_color_volume_reduction_end, circle_request  );
  420.     circle_request->line_width = 3;
  421.     // add request
  422.     pRenderer->Add( circle_request );
  423. }
  424.  
  425. bool cRandom_Sound :: Is_Update_Valid( void )
  426. {
  427.     // if destroyed
  428.     if( destroy )
  429.     {
  430.         return 0;
  431.     }
  432.  
  433.     // get distance from camera center position
  434.     float dx = fabs( pActive_Camera->x + (game_res_w * 0.5f) - posx );
  435.     float dy = fabs( pActive_Camera->y + (game_res_h * 0.5f) - posy );
  436.  
  437.     m_distance_to_camera = sqrt( dx * dx + dy * dy );
  438.  
  439.     // if outside the range
  440.     if( m_distance_to_camera >= m_volume_reduction_end )
  441.     {
  442.         Event_Out_Of_Range();
  443.         return 0;
  444.     }
  445.  
  446.     return 1;
  447. }
  448.  
  449. bool cRandom_Sound :: Is_Draw_Valid( void )
  450. {
  451.     // if editor not enabled
  452.     if( !editor_enabled )
  453.     {
  454.         return 0;
  455.     }
  456.  
  457.     // if not visible on the screen or not mouse object
  458.     if( !visible || ( !Is_Visible_on_Screen() && pMouseCursor->active_object != this ) )
  459.     {
  460.         return 0;
  461.     }
  462.  
  463.     return 1;
  464. }
  465.  
  466. void cRandom_Sound :: Event_Out_Of_Range( void )
  467. {
  468.     // fade out sounds if out of range
  469.     pAudio->Fadeout_Sounds( 500, m_filename );
  470. }
  471.  
  472. void cRandom_Sound :: Editor_Activate( void )
  473. {
  474.     CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
  475.  
  476.     // filename
  477.     CEGUI::Editbox *editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_filename" ));
  478.     Editor_Add( UTF8_("Filename"), UTF8_("Sound filename"), editbox, 200 );
  479.  
  480.     editbox->setText( m_filename.c_str() );
  481.     editbox->subscribeEvent( CEGUI::Editbox::EventTextChanged, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Filename_Key, this ) );
  482.  
  483.     // continuous
  484.     CEGUI::Checkbox *checkbox = static_cast<CEGUI::Checkbox *>(wmgr.createWindow( "TaharezLook/Checkbox", "editor_sound_continuous" ));
  485.     Editor_Add( UTF8_("Continuous"), UTF8_("Check if the sound should be played continuously instead of randomly"), checkbox, 50 );
  486.  
  487.     checkbox->setSelected( m_continuous );
  488.     checkbox->subscribeEvent( CEGUI::Checkbox::EventCheckStateChanged, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Continuous_Changed, this ) );
  489.  
  490.     // delay min
  491.     editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_delay_min" ));
  492.     Editor_Add( UTF8_("Delay Minimum"), UTF8_("Minimal delay until played again"), editbox, 90 );
  493.  
  494.     editbox->setText( int_to_string( m_delay_min ) );
  495.     editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Delay_Min_Key, this ) );
  496.  
  497.     // delay max
  498.     editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_delay_max" ));
  499.     Editor_Add( UTF8_("Maximum"), UTF8_("Maximal delay until played again"), editbox, 90, 28, 0 );
  500.  
  501.     editbox->setText( int_to_string( m_delay_max ) );
  502.     editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Delay_Max_Key, this ) );
  503.  
  504.     // volume min
  505.     editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_volume_min" ));
  506.     Editor_Add( UTF8_("Volume Minimum"), UTF8_("Minimal random volume for each play"), editbox, 90 );
  507.  
  508.     editbox->setText( int_to_string( static_cast<int>(m_volume_min) ) );
  509.     editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Volume_Min_Key, this ) );
  510.  
  511.     // volume max
  512.     editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_volume_max" ));
  513.     Editor_Add( UTF8_("Maximum"), UTF8_("Maximal random volume for each play"), editbox, 90, 28, 0 );
  514.  
  515.     editbox->setText( int_to_string( static_cast<int>(m_volume_max) ) );
  516.     editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Volume_Max_Key, this ) );
  517.  
  518.     // volume reduction begin
  519.     editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_volume_reduction_begin" ));
  520.     Editor_Add( UTF8_("Volume Reduction Begin"), UTF8_("Volume reduction begins gradually at this distance"), editbox, 90 );
  521.  
  522.     editbox->setText( int_to_string( static_cast<int>(m_volume_reduction_begin) ) );
  523.     editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Volume_Reduction_Begin_Key, this ) );
  524.  
  525.     // volume reduction end
  526.     editbox = static_cast<CEGUI::Editbox *>(wmgr.createWindow( "TaharezLook/Editbox", "editor_sound_volume_reduction_end" ));
  527.     Editor_Add( UTF8_("End"), UTF8_("Volume reduction ends at this distance. Sound is not played beyond this."), editbox, 90, 28, 0 );
  528.  
  529.     editbox->setText( int_to_string( static_cast<int>(m_volume_reduction_end) ) );
  530.     editbox->subscribeEvent( CEGUI::Editbox::EventKeyUp, CEGUI::Event::Subscriber( &cRandom_Sound::Editor_Volume_Reduction_End_Key, this ) );
  531.  
  532.     // init
  533.     Editor_Init();
  534. }
  535.  
  536. bool cRandom_Sound :: Editor_Filename_Key( const CEGUI::EventArgs &event )
  537. {
  538.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  539.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  540.  
  541.     Set_Filename( str_text );
  542.  
  543.     return 1;
  544. }
  545.  
  546. bool cRandom_Sound :: Editor_Continuous_Changed( const CEGUI::EventArgs &event )
  547. {
  548.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  549.     bool enabled = static_cast<CEGUI::Checkbox *>( windowEventArgs.window )->isSelected();
  550.  
  551.     Set_Continuous( enabled );
  552.  
  553.     return 1;
  554. }
  555.  
  556. bool cRandom_Sound :: Editor_Delay_Min_Key( const CEGUI::EventArgs &event )
  557. {
  558.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  559.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  560.  
  561.     Set_Delay_Min( string_to_int( str_text ) );
  562.  
  563.     return 1;
  564. }
  565.  
  566. bool cRandom_Sound :: Editor_Delay_Max_Key( const CEGUI::EventArgs &event )
  567. {
  568.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  569.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  570.  
  571.     Set_Delay_Max( string_to_int( str_text ) );
  572.  
  573.     return 1;
  574. }
  575.  
  576. bool cRandom_Sound :: Editor_Volume_Min_Key( const CEGUI::EventArgs &event )
  577. {
  578.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  579.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  580.  
  581.     Set_Volume_Min( string_to_float( str_text ) );
  582.  
  583.     return 1;
  584. }
  585.  
  586. bool cRandom_Sound :: Editor_Volume_Max_Key( const CEGUI::EventArgs &event )
  587. {
  588.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  589.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  590.  
  591.     Set_Volume_Max( string_to_float( str_text ) );
  592.  
  593.     return 1;
  594. }
  595.  
  596. bool cRandom_Sound :: Editor_Volume_Reduction_Begin_Key( const CEGUI::EventArgs &event )
  597. {
  598.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  599.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  600.  
  601.     Set_Volume_Reduction_Begin( string_to_float( str_text ) );
  602.  
  603.     return 1;
  604. }
  605.  
  606. bool cRandom_Sound :: Editor_Volume_Reduction_End_Key( const CEGUI::EventArgs &event )
  607. {
  608.     const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event );
  609.     string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str();
  610.  
  611.     Set_Volume_Reduction_End( string_to_float( str_text ) );
  612.  
  613.     return 1;
  614. }
  615.