1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2011-2015 Joerg Henrichs, Marianne Gagnon
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 #include "audio/sfx_base.hpp"
20 #include "audio/sfx_manager.hpp"
21 #include "graphics/weather.hpp"
22 #include "modes/world.hpp"
23 #include "tracks/track.hpp"
24 #include "utils/random_generator.hpp"
25
26
27 /** The weather manager stores information about the weather.
28 */
Weather()29 Weather::Weather()
30 {
31 m_thunder_sound = NULL;
32 m_weather_sound = NULL;
33 m_lightning = 0.0f;
34
35 if (Track::getCurrentTrack()->getWeatherLightning())
36 {
37 m_thunder_sound = SFXManager::get()->createSoundSource("thunder");
38 }
39
40 const std::string &sound = Track::getCurrentTrack()->getWeatherSound();
41 if (!sound.empty())
42 {
43 m_weather_sound = SFXManager::get()->createSoundSource(sound);
44 }
45
46 RandomGenerator g;
47 m_next_lightning = (float)g.get(35);
48 } // Weather
49
50 // ----------------------------------------------------------------------------
51
~Weather()52 Weather::~Weather()
53 {
54 if (m_thunder_sound != NULL)
55 m_thunder_sound->deleteSFX();
56
57 if (m_weather_sound != NULL)
58 m_weather_sound->deleteSFX();
59 } // ~Weather
60
61 // ----------------------------------------------------------------------------
62
update(float dt)63 void Weather::update(float dt)
64 {
65 if (!Track::getCurrentTrack()->getWeatherLightning())
66 return;
67
68 if (World::getWorld()->getRaceGUI() == NULL)
69 return;
70
71 m_next_lightning -= dt;
72
73 if (m_next_lightning < 0.0f)
74 {
75 startLightning();
76
77 if (m_thunder_sound)
78 {
79 m_thunder_sound->play();
80 }
81
82 RandomGenerator g;
83 m_next_lightning = 35 + (float)g.get(35);
84 }
85
86 if (m_lightning > 0.0f)
87 {
88 m_lightning -= dt;
89 }
90 } // update
91
92 // ----------------------------------------------------------------------------
93
playSound()94 void Weather::playSound()
95 {
96 if (m_weather_sound)
97 {
98 m_weather_sound->setLoop(true);
99 m_weather_sound->play();
100 }
101 }
102
getIntensity()103 irr::core::vector3df Weather::getIntensity()
104 {
105 irr::core::vector3df value = {0.7f * m_lightning,
106 0.7f * m_lightning,
107 0.7f * std::min(1.0f, m_lightning * 1.5f)};
108
109 return value;
110 }
111