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 <tank/TankTypes.h> 00022 #include <common/Defines.h> 00023 #include <XML/XMLFile.h> 00024 00025 TankTypes::TankTypes() 00026 { 00027 } 00028 00029 TankTypes::~TankTypes() 00030 { 00031 } 00032 00033 bool TankTypes::loadTankTypes(ScorchedContext &context) 00034 { 00035 XMLFile file; 00036 if (!file.readFile(S3D::getDataFile("data/tanktypes.xml"))) 00037 { 00038 S3D::dialogMessage("Scorched3D", 00039 S3D::formatStringBuffer("Failed to parse data/tanktypes.xml\n%s", 00040 file.getParserError())); 00041 return false; 00042 } 00043 00044 // Check file exists 00045 if (!file.getRootNode()) 00046 { 00047 S3D::dialogMessage("Scorched3D", 00048 "Failed to find tank definition file \"data/tanktypes.xml\""); 00049 return false; 00050 } 00051 00052 // Itterate all of the tanktype in the file 00053 XMLNode *currentNode = 0; 00054 while (file.getRootNode()->getNamedChild("tanktype", currentNode, false)) 00055 { 00056 // Create the tanktype 00057 TankType *type= new TankType(); 00058 if (!type->initFromXML(context, currentNode)) return false; 00059 types_.push_back(type); 00060 } 00061 00062 if (!getType("none")) 00063 { 00064 return file.getRootNode()->returnError( 00065 "TankTypes file must define the \"none\" type"); 00066 } 00067 00068 return file.getRootNode()->failChildren(); 00069 } 00070 00071 TankType *TankTypes::getType(const char *name) 00072 { 00073 std::vector<TankType *>::iterator itor; 00074 for (itor = types_.begin(); 00075 itor != types_.end(); 00076 itor++) 00077 { 00078 TankType *type = (*itor); 00079 if (0 == strcmp(name, type->getName())) return type; 00080 } 00081 return 0; 00082 }
1.5.3