ShieldHit.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/ShieldHit.h>
00022 #include <common/Defines.h>
00023 #include <engine/ScorchedContext.h>
00024 #include <weapons/Accessory.h>
00025 #include <weapons/Shield.h>
00026 #include <target/TargetContainer.h>
00027 #include <target/TargetShield.h>
00028 #include <target/TargetRenderer.h>
00029 #ifndef S3D_SERVER
00030         #include <sound/SoundUtils.h>
00031         #include <GLEXT/GLLenseFlare.h>
00032 #endif
00033 
00034 ShieldHit::ShieldHit(unsigned int playerId,
00035         FixedVector &position,
00036         fixed hitPercentage) :
00037         ActionReferenced("ShieldHit"),
00038         totalTime_(0),
00039         firstTime_(true), playerId_(playerId),
00040         hitPercentage_(hitPercentage),
00041         position_(position)
00042 {
00043 }
00044 
00045 ShieldHit::~ShieldHit()
00046 {
00047 }
00048 
00049 void ShieldHit::init()
00050 {
00051 }
00052 
00053 void ShieldHit::simulate(fixed frameTime, bool &remove)
00054 {
00055         if (firstTime_)
00056         {
00057                 firstTime_ = false;
00058 
00059                 Target *target = 
00060                         context_->getTargetContainer().getTargetById(playerId_);
00061                 if (target)
00062                 {
00063                         Accessory *accessory = 
00064                                 target->getShield().getCurrentShield();
00065                         if (accessory)
00066                         {
00067                                 Shield *shield = (Shield *) accessory->getAction();
00068 #ifndef S3D_SERVER
00069                                 if (!context_->getServerMode()) 
00070                                 {
00071                                         SoundBuffer *shieldSound = 
00072                                                 Sound::instance()->fetchOrCreateBuffer(
00073                                                         S3D::getDataFile(S3D::formatStringBuffer("data/wav/%s", shield->getCollisionSound())));
00074                                         SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00075                                                 shieldSound, position_.asVector());
00076 
00077                                         TargetRenderer *renderer = target->getRenderer();
00078                                         if (renderer)
00079                                         {
00080                                                 renderer->shieldHit();
00081                                         }
00082                                 }
00083 #endif // #ifndef S3D_SERVER
00084 
00085                                 target->getShield().setShieldPower(
00086                                         target->getShield().getShieldPower() -
00087                                         shield->getHitRemovePower() * hitPercentage_);
00088                         }
00089                 }
00090         }
00091 
00092         totalTime_ += frameTime;
00093         if (totalTime_ > fixed(true, 2000)) remove = true;
00094         Action::simulate(frameTime, remove);
00095 }
00096 
00097 void ShieldHit::draw()
00098 {
00099 #ifndef S3D_SERVER
00100         if (!context_->getServerMode())
00101         {
00102                 GLLenseFlare::instance()->draw(position_.asVector(), false, 0, 
00103                         1.0f, 1.0f);
00104         }
00105 #endif // #ifndef S3D_SERVER
00106 }

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