TankFired.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <actions/TankFired.h>
00022 #include <actions/Explosion.h>
00023 #include <actions/TankSay.h>
00024 #include <weapons/AccessoryStore.h>
00025 #include <engine/ScorchedContext.h>
00026 #include <engine/ActionController.h>
00027 #ifndef S3D_SERVER
00028         #include <sound/SoundUtils.h>
00029 #endif
00030 #include <common/Defines.h>
00031 #include <tank/TankContainer.h>
00032 #include <tank/TankPosition.h>
00033 #include <tankai/TankAIStrings.h>
00034 #include <target/TargetRenderer.h>
00035 
00036 TankFired::TankFired(unsigned int playerId,
00037                                          Weapon *weapon,
00038                                          fixed rotXY, fixed rotXZ) :
00039         ActionReferenced("TankFired"),
00040         playerId_(playerId), weapon_(weapon),
00041         rotXY_(rotXY), rotXZ_(rotXZ), firstTime_(true)
00042 {
00043 
00044 }
00045 
00046 TankFired::~TankFired()
00047 {
00048 }
00049 
00050 void TankFired::init()
00051 {
00052 
00053 }
00054 
00055 std::string TankFired::getActionDetails()
00056 {
00057         return S3D::formatStringBuffer("%u %s",
00058                 playerId_, weapon_->getParent()->getName());
00059 }
00060 
00061 void TankFired::simulate(fixed frameTime, bool &remove)
00062 {
00063         if (firstTime_)
00064         {
00065                 firstTime_ = false;
00066                 Tank *tank = 
00067                         context_->getTankContainer().getTankById(playerId_);
00068                 if (tank)
00069                 {
00070                         tank->getPosition().rotateGunXY(rotXY_, false);
00071                         tank->getPosition().rotateGunYZ(rotXZ_, false);
00072                         tank->getPosition().madeShot();
00073 
00074                         if (tank->getDestinationId() == 0)
00075                         {
00076                                 const char *line = TankAIStrings::instance()->getAttackLine(*context_);
00077                                 if (line)
00078                                 {
00079                                         context_->getActionController().addAction(
00080                                                 new TankSay(tank->getPlayerId(), 
00081                                                 LANG_STRING(line)));
00082                                 }
00083                         }
00084 
00085 #ifndef S3D_SERVER
00086                         if (!context_->getServerMode()) 
00087                         {
00088                                 TargetRenderer *renderer = tank->getRenderer();
00089                                 if (renderer)
00090                                 {
00091                                         renderer->fired();
00092                                 }
00093 
00094                                 // play fired sound
00095                                 if (weapon_->getParent()->getActivationSound() &&
00096                                         0 != strcmp("none", weapon_->getParent()->getActivationSound()))
00097                                 {
00098                                         SoundBuffer *firedSound = 
00099                                                 Sound::instance()->fetchOrCreateBuffer(
00100                                                         S3D::getDataFile(S3D::formatStringBuffer("data/wav/%s", 
00101                                                         weapon_->getParent()->getActivationSound())));
00102                                         SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00103                                                 firedSound, tank->getPosition().getTankPosition().asVector());
00104                                 }
00105                         }
00106 #endif // #ifndef S3D_SERVER
00107 
00108                         if (weapon_->getParent()->getMuzzleFlash())
00109                         {
00110                                 WeaponFireContext weaponContext(playerId_, 0);
00111                                 Weapon *muzzleFlash = context_->getAccessoryStore().getMuzzelFlash();
00112                                 if (muzzleFlash) muzzleFlash->fireWeapon(*context_, weaponContext, 
00113                                         tank->getPosition().getTankGunPosition(), FixedVector::getNullVector());
00114                         }
00115                 }
00116         }
00117 
00118         remove = true;
00119         Action::simulate(frameTime, remove);
00120 }

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3