WeaponNapalm.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 <weapons/WeaponNapalm.h>
00022 #include <actions/Napalm.h>
00023 #include <common/Defines.h>
00024 #ifndef S3D_SERVER
00025         #include <sound/SoundUtils.h>
00026 #endif
00027 #include <engine/ActionController.h>
00028 #include <landscapemap/LandscapeMaps.h>
00029 
00030 REGISTER_ACCESSORY_SOURCE(WeaponNapalm);
00031 
00032 WeaponNapalm::WeaponNapalm()
00033 {
00034 
00035 }
00036 
00037 WeaponNapalm::~WeaponNapalm()
00038 {
00039 
00040 }
00041 
00042 bool WeaponNapalm::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
00043 {
00044         if (!Weapon::parseXML(context, accessoryNode)) return false;
00045 
00046         if (!accessoryNode->getNamedChild("napalmtime", napalmTime_)) return false;
00047         if (!accessoryNode->getNamedChild("napalmheight", napalmHeight_)) return false;
00048         if (!accessoryNode->getNamedChild("steptime", stepTime_)) return false;
00049         if (!accessoryNode->getNamedChild("hurtsteptime", hurtStepTime_)) return false;
00050         if (!accessoryNode->getNamedChild("hurtpersecond", hurtPerSecond_)) return false;
00051         if (!accessoryNode->getNamedChild("numberstreams", numberStreams_)) return false;
00052         if (!accessoryNode->getNamedChild("napalmsound", napalmSound_)) return false;
00053         if (!S3D::checkDataFile(S3D::formatStringBuffer("data/wav/%s", napalmSound_.c_str()))) return false;
00054 
00055         if (!params_.parseXML(accessoryNode)) return false;
00056 
00057         return true;
00058 }
00059 
00060 void WeaponNapalm::fireWeapon(ScorchedContext &context,
00061         WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity)
00062 {
00063         fixed minHeight = context.getLandscapeMaps().getGroundMaps().getInterpHeight(
00064                 position[0], position[1]);
00065 
00066         // Make sure position is not underground
00067         if (position[2] < minHeight)
00068         {
00069                 if (minHeight - position[2] > 10) // Give room for shields as well
00070                 {
00071                         return;
00072                 }
00073         }
00074 
00075         RandomGenerator &random = context.getActionController().getRandom();
00076         for (int i=0; i<numberStreams_; i++)
00077         {
00078                 int x = (position[0] + random.getRandFixed() * 4 - 2).asInt();
00079                 int y = (position[1] + random.getRandFixed() * 4 - 2).asInt();
00080                 addNapalm(context, weaponContext, x, y);
00081         }
00082 
00083 #ifndef S3D_SERVER
00084         if (!context.getServerMode()) 
00085         {
00086                 if (napalmSound_.c_str()[0] &&
00087                         0 != strcmp(napalmSound_.c_str(), "none"))
00088                 {
00089                         SoundBuffer *expSound = 
00090                                 Sound::instance()->fetchOrCreateBuffer(
00091                                         S3D::getDataFile(S3D::formatStringBuffer("data/wav/%s", napalmSound_.c_str())));
00092                         SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00093                                 expSound, position.asVector());
00094                 }
00095         }
00096 #endif
00097 }
00098 
00099 void WeaponNapalm::addNapalm(ScorchedContext &context, 
00100         WeaponFireContext &weaponContext, int x, int y)
00101 {
00102         NapalmParams *params = new NapalmParams(params_);
00103         params->setNapalmTime(napalmTime_.getValue(context));
00104         params->setNapalmHeight(napalmHeight_.getValue(context));
00105         params->setStepTime(stepTime_.getValue(context));
00106         params->setHurtStepTime(hurtStepTime_.getValue(context));
00107         params->setHurtPerSecond(hurtPerSecond_.getValue(context));
00108 
00109         // Ensure that the napalm has not hit the walls
00110         // or anything outside the landscape
00111         context.getActionController().addAction(
00112                 new Napalm(x, y, this, params, weaponContext));
00113 }

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