WeaponReference.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/WeaponReference.h>
00022 #include <weapons/AccessoryStore.h>
00023 #include <common/DefinesString.h>
00024 
00025 REGISTER_ACCESSORY_SOURCE(WeaponReference);
00026 
00027 WeaponReference::WeaponReference()
00028 {
00029 
00030 }
00031 
00032 WeaponReference::~WeaponReference()
00033 {
00034 
00035 }
00036 
00037 bool WeaponReference::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
00038 {
00039         if (!Weapon::parseXML(context, accessoryNode)) return false;
00040 
00041         // Get the next weapon
00042         std::string subNode;
00043         if (!accessoryNode->getNamedChild("weapon", subNode)) return false;
00044 
00045         // Find the accessory name
00046         std::map<std::string, XMLNode *> &nodes = context.getAccessoryStore().getParsingNodes();
00047         std::map<std::string, XMLNode *>::iterator finditor =
00048                 nodes.find(subNode.c_str());
00049         if (finditor == nodes.end()) 
00050         {
00051                 S3D::dialogMessage("WeaponReference", S3D::formatStringBuffer(
00052                         "Failed to find weapon \"%s\"",
00053                         subNode.c_str()));
00054                 return false;   
00055         }
00056         XMLNode *weaponNode = (*finditor).second;
00057         weaponNode->resurrectRemovedChildren();
00058 
00059         // Action
00060         XMLNode *actionNode = 0;
00061         if (!weaponNode->getNamedChild("accessoryaction", actionNode)) return false;
00062         
00063         // Create the new weapon
00064         AccessoryPart *accessory = context.getAccessoryStore().
00065                 createAccessoryPart(context, parent_, actionNode);
00066         if (!accessory || accessory->getType() != AccessoryPart::AccessoryWeapon)
00067         {
00068                 S3D::dialogMessage("Accessory", S3D::formatStringBuffer(
00069                         "Failed to find create weapon/wrong type \"%s\"",
00070                         subNode.c_str()));
00071                 return false;
00072         }
00073         refWeapon_ = (Weapon*) accessory;
00074 
00075         return true;
00076 }
00077 
00078 void WeaponReference::fireWeapon(ScorchedContext &context,
00079         WeaponFireContext &weaponContext, FixedVector &position, FixedVector &velocity)
00080 {
00081         refWeapon_->fireWeapon(context, weaponContext, position, velocity);
00082 }
00083 

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