WeaponProjectile.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/AccessoryStore.h>
00022 #include <weapons/WeaponProjectile.h>
00023 #include <actions/ShotProjectile.h>
00024 #include <engine/ActionController.h>
00025 #include <common/Logger.h>
00026 
00027 REGISTER_ACCESSORY_SOURCE(WeaponProjectile);
00028 
00029 WeaponProjectile::WeaponProjectile() : 
00030         under_(false), collisionAction_(0), 
00031         apexCollision_(false), waterCollision_(false), wallCollision_(true),
00032         showShotPath_(false), showEndPoint_(false), 
00033         createSmoke_(true),     createFlame_(true), 
00034         spinSpeed_(1), apexNoDud_(false), timedDud_(false),
00035         timedCollision_(0), shieldHurtFactor_(1), windFactor_(1),
00036         flameLife_(1.0f), smokeLife_(4.0f),
00037         flameStartColor1_(0.9f, 0.0f, 0.0f), flameStartColor2_(1.0f, 0.2f, 0.2f),
00038         flameEndColor1_(0.95f, 0.9f, 0.2f), flameEndColor2_(1.0f, 1.0f, 0.3f),
00039         flameStartSize_(0.5f), flameEndSize_(3.0f),
00040         smokeStartSize_(0.5f), smokeEndSize_(4.0f),
00041         thrustAmount_(0), thrustTime_(0),
00042         drag_(0),
00043         engineSound_("data/wav/misc/rocket.wav"),
00044         scale_(1), flareType_(0)
00045 {
00046 
00047 }
00048 
00049 WeaponProjectile::~WeaponProjectile()
00050 {
00051 
00052 }
00053 
00054 bool WeaponProjectile::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
00055 {
00056         if (!Weapon::parseXML(context, accessoryNode)) return false;
00057 
00058         // Get the accessory under
00059         XMLNode *underNode = 0;
00060         accessoryNode->getNamedChild("under", underNode, false);
00061         if (underNode) under_ = true;
00062 
00063         // Get the spin
00064         accessoryNode->getNamedChild("spinspeed", spinSpeed_, false);
00065 
00066         // Get the optional weapon model scale
00067         accessoryNode->getNamedChild("projectilescale", scale_, false);
00068 
00069         // Get the optional weapon model
00070         XMLNode *modelNode = 0;
00071         if (accessoryNode->getNamedChild("projectilemodel", modelNode, false))
00072         {
00073                 if (!modelId_.initFromNode("data/accessories", modelNode)) return false;
00074         }
00075 
00076         // Get smoke life
00077         accessoryNode->getNamedChild("smokelife", smokeLife_, false);
00078         accessoryNode->getNamedChild("flamelife", flameLife_, false);
00079         accessoryNode->getNamedChild("flamestartsize", flameStartSize_, false);
00080         accessoryNode->getNamedChild("flameendsize", flameEndSize_, false);
00081         accessoryNode->getNamedChild("smokestartsize", smokeStartSize_, false);
00082         accessoryNode->getNamedChild("smokeendsize", smokeEndSize_, false);
00083 
00084         // flame color
00085         accessoryNode->getNamedChild("flamestartcolor1", flameStartColor1_, false);
00086         accessoryNode->getNamedChild("flamestartcolor2", flameStartColor2_, false);
00087         accessoryNode->getNamedChild("flameendcolor1", flameEndColor1_, false);
00088         accessoryNode->getNamedChild("flameendcolor2", flameEndColor2_, false);
00089 
00090         // Drag
00091         accessoryNode->getNamedChild("drag", drag_, false);
00092 
00093         // Thrust
00094         accessoryNode->getNamedChild("thrusttime", thrustTime_, false);
00095         accessoryNode->getNamedChild("thrustamount", thrustAmount_, false);
00096 
00097         // Get the smoke trails
00098         XMLNode *smokeNode = 0;
00099         accessoryNode->getNamedChild("showshotpath", smokeNode, false);
00100         if (smokeNode) showShotPath_ = true;
00101 
00102         // Get the end point
00103         XMLNode *endPointNode = 0;
00104         accessoryNode->getNamedChild("showendpoint", endPointNode, false);
00105         if (endPointNode) showEndPoint_ = true;
00106         
00107         // Get the apex point
00108         XMLNode *apexNode = 0, *apexNoDudNode = 0;
00109         accessoryNode->getNamedChild("apexcollision", apexNode, false);
00110         accessoryNode->getNamedChild("apexnodud", apexNoDudNode, false);
00111         if (apexNode) apexCollision_ = true;
00112         if (apexNoDudNode) apexNoDud_ = true;
00113 
00114         // Water collision
00115         XMLNode *waterNode = 0;
00116         accessoryNode->getNamedChild("watercollision", waterNode, false);
00117         if (waterNode) waterCollision_ = true;  
00118 
00119         // Wall collision
00120         XMLNode *wallCollNode = 0;
00121         accessoryNode->getNamedChild("nowallcollision", wallCollNode, false);
00122         if (wallCollNode) wallCollision_ = false;       
00123 
00124         // Get the timed collision point
00125         XMLNode *timedDudNode = 0;
00126         accessoryNode->getNamedChild("timedcollision", timedCollision_, false);
00127         accessoryNode->getNamedChild("timeddud", timedDudNode, false);
00128         if (timedDudNode) timedDud_ = true;
00129 
00130         // Get the no smoke node
00131         XMLNode *noCreateSmokeNode = 0;
00132         accessoryNode->getNamedChild("nocreatesmoke", noCreateSmokeNode, false);
00133         if (noCreateSmokeNode) createSmoke_ = false;
00134 
00135         // Get the no smoke node
00136         XMLNode *noCreateFlameNode = 0;
00137         accessoryNode->getNamedChild("nocreateflame", noCreateFlameNode, false);
00138         if (noCreateFlameNode) createFlame_ = false;
00139 
00140         // Get the engine sound (if any)
00141         accessoryNode->getNamedChild("enginesound", engineSound_, false);
00142 
00143         // Get the flare type (if any)
00144         accessoryNode->getNamedChild("flaretype", flareType_, false);
00145 
00146         // Get the hurt factor (if any)
00147         accessoryNode->getNamedChild("shieldhurtfactor", shieldHurtFactor_, false);
00148 
00149         // Get the wind factor (if any)
00150         accessoryNode->getNamedChild("windfactor", windFactor_, false);
00151 
00152         // Get the next weapon
00153         XMLNode *subNode = 0;
00154         if (!accessoryNode->getNamedChild("collisionaction", subNode)) return false;
00155 
00156         // Check next weapon is correct type
00157         AccessoryPart *accessory = context.getAccessoryStore().
00158                 createAccessoryPart(context, parent_, subNode);
00159         if (!accessory || accessory->getType() != AccessoryPart::AccessoryWeapon)
00160         {
00161                 return false;
00162         }
00163         collisionAction_ = (Weapon*) accessory;
00164 
00165         return true;
00166 }
00167 
00168 fixed WeaponProjectile::getWindFactor(ScorchedContext &context)
00169 {
00170         return windFactor_.getValue(context);
00171 }
00172 
00173 fixed WeaponProjectile::getShieldHurtFactor(ScorchedContext &context)
00174 {
00175         return shieldHurtFactor_.getValue(context);
00176 }
00177 
00178 void WeaponProjectile::fireWeapon(ScorchedContext &context,
00179         WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity)
00180 {
00181         Action *action = new ShotProjectile(
00182                 position, 
00183                 velocity,
00184                 this, 
00185                 weaponContext,
00186                 flareType_, // FlareType
00187                 spinSpeed_.getValue(context)); 
00188         context.getActionController().addAction(action);        
00189 }

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