Shield.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/Shield.h>
00022 #include <common/VectorLib.h>
00023 #include <common/Defines.h>
00024 #include <math.h>
00025 
00026 Shield::Shield() : 
00027         laserProof_(ShieldLaserProofNone), 
00028         movementProof_(ShieldMovementAll)
00029 {
00030 }
00031 
00032 Shield::~Shield()
00033 {
00034 }
00035 
00036 bool Shield::parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode)
00037 {
00038         // Get the remove power 
00039         if (!accessoryNode->getNamedChild("removepower", removePower_)) return false;
00040 
00041         // Get the penetration
00042         if (!accessoryNode->getNamedChild("penetration", penetration_)) return false;
00043 
00044         // Get the penetration
00045         if (!accessoryNode->getNamedChild("power", power_)) return false;
00046 
00047         // Get the collision sound
00048         if (!accessoryNode->getNamedChild("collisionsound", collisionSound_)) return false;
00049         if (!S3D::checkDataFile(S3D::formatStringBuffer("data/wav/%s", getCollisionSound()))) return false;
00050 
00051         // Get the accessory color
00052         XMLNode *colorNode = 0;
00053         if (!accessoryNode->getNamedChild("color", colorNode)) return false;
00054         if (!colorNode->getNamedChild("r", color_[0])) return false;
00055         if (!colorNode->getNamedChild("g", color_[1])) return false;
00056         if (!colorNode->getNamedChild("b", color_[2])) return false;
00057 
00058         std::string laserproof;
00059         if (accessoryNode->getNamedChild("laserproof", laserproof, false))
00060         {
00061                 if (0 == strcmp(laserproof.c_str(), "false"))
00062                         laserProof_ = ShieldLaserProofNone;
00063                 else if (0 == strcmp(laserproof.c_str(), "true"))
00064                         laserProof_ = ShieldLaserProofStop;
00065                 else if (0 == strcmp(laserproof.c_str(), "total"))
00066                         laserProof_ = ShieldLaserProofTotal;
00067                 else return accessoryNode->returnError("Unknown laserproof type");
00068         }
00069 
00070         std::string movementproof;
00071         if (accessoryNode->getNamedChild("movementproof", movementproof, false))
00072         {
00073                 if (0 == strcmp(movementproof.c_str(), "false"))
00074                         movementProof_ = ShieldMovementAll;
00075                 else if (0 == strcmp(movementproof.c_str(), "true"))
00076                         movementProof_ = ShieldMovementSame;
00077                 else if (0 == strcmp(movementproof.c_str(), "none"))
00078                         movementProof_ = ShieldMovementNone;
00079                 else if (0 == strcmp(movementproof.c_str(), "team1")) 
00080                         movementProof_ = ShieldMovementTeam1;
00081                 else if (0 == strcmp(movementproof.c_str(), "team2")) 
00082                         movementProof_ = ShieldMovementTeam2;
00083                 else if (0 == strcmp(movementproof.c_str(), "team3")) 
00084                         movementProof_ = ShieldMovementTeam3;
00085                 else if (0 == strcmp(movementproof.c_str(), "team4")) 
00086                         movementProof_ = ShieldMovementTeam4;
00087                 else return accessoryNode->returnError("Unknown movementproof type");
00088         }
00089 
00090         return true;
00091 }
00092 
00093 const char *Shield::getCollisionSound()
00094 {
00095         if (!collisionSound_.c_str()[0]) return 0;
00096         return collisionSound_.c_str();
00097 }

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