Merge from development branch heightmap to main.
[scorched3d.git] / src / common / actions / SoundAction.cpp
blob60534a62715343337f0a75dc31f134a14deb24d2
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2004
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <actions/SoundAction.h>
22 #include <weapons/WeaponSound.h>
23 #include <weapons/AccessoryStore.h>
24 #ifndef S3D_SERVER
25 #include <sound/SoundUtils.h>
26 #endif
27 #include <common/Defines.h>
29 SoundAction::SoundAction(FixedVector &position, WeaponSound *weapon) :
30 ActionReferenced("SoundAction"),
31 weapon_(weapon), position_(position)
36 SoundAction::~SoundAction()
40 void SoundAction::init()
44 void SoundAction::simulate(fixed frameTime, bool &remove)
46 #ifndef S3D_SERVER
47 if (!context_->getServerMode())
49 SoundBuffer *activateSound =
50 Sound::instance()->fetchOrCreateBuffer(
51 S3D::getDataFile(weapon_->getSound()));
53 VirtualSoundSource *source = new VirtualSoundSource(
54 VirtualSoundPriority::eAction, false, true);
55 if (weapon_->getRelative()) source->setRelative();
56 else source->setPosition(position_.asVector());
57 source->setGain(weapon_->getGain().asFloat());
58 source->setReferenceDistance(weapon_->getReferenceDistance().asFloat());
59 source->setRolloff(weapon_->getRolloff().asFloat());
60 source->play(activateSound);
62 #endif // #ifndef S3D_SERVER
64 remove = true;
65 Action::simulate(frameTime, remove);
68 std::string SoundAction::getActionDetails()
70 return weapon_->getParent()->getName();