LandscapeMovement.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 <landscapedef/LandscapeMovement.h>
00022 #include <XML/XMLNode.h>
00023 #include <common/Defines.h>
00024 
00025 LandscapeMovementType *LandscapeMovementType::create(const char *type)
00026 {
00027         if (0 == strcmp(type, "boids")) return new LandscapeMovementTypeBoids;
00028         if (0 == strcmp(type, "ships")) return new LandscapeMovementTypeShips;
00029         if (0 == strcmp(type, "spline")) return new LandscapeMovementTypeSpline;
00030         S3D::dialogMessage("LandscapeMovementType", S3D::formatStringBuffer("Unknown movement type %s", type));
00031         return 0;
00032 }
00033 
00034 bool LandscapeMovementType::readXML(XMLNode *node)
00035 {
00036         if (!node->getNamedChild("groupname", groupname)) return false;
00037 
00038         return node->failChildren();
00039 }
00040 
00041 bool LandscapeMovementTypeShips::readXML(XMLNode *node)
00042 {
00043         if (!node->getNamedChild("speed", speed)) return false;
00044         if (!node->getNamedChild("controlpoints", controlpoints)) return false;
00045         if (!node->getNamedChild("controlpointswidth", controlpointswidth)) return false;
00046         if (!node->getNamedChild("controlpointsheight", controlpointsheight)) return false;
00047         if (!node->getNamedChild("controlpointsrand", controlpointsrand)) return false;
00048         if (!node->getNamedChild("starttime", starttime)) return false;
00049 
00050         return LandscapeMovementType::readXML(node);
00051 }
00052 
00053 bool LandscapeMovementTypeSpline::readXML(XMLNode *node)
00054 {
00055         if (!node->getNamedChild("speed", speed)) return false;
00056         if (!node->getNamedChild("starttime", starttime)) return false;
00057         if (!node->getNamedChild("groundonly", groundonly)) return false;
00058         FixedVector point;
00059         while (node->getNamedChild("controlpoint", point, false))
00060         {
00061                 points.push_back(point);
00062         }
00063 
00064         if (points.size() < 3) return node->returnError("Must have at least 3 control points");
00065 
00066         return LandscapeMovementType::readXML(node);
00067 }
00068 
00069 bool LandscapeMovementTypeBoids::readXML(XMLNode *node)
00070 {
00071         if (!node->getNamedChild("minbounds", minbounds)) return false;
00072         if (!node->getNamedChild("maxbounds", maxbounds)) return false;
00073         if (!node->getNamedChild("maxvelocity", maxvelocity)) return false;
00074         if (!node->getNamedChild("cruisedistance", cruisedistance)) return false;
00075         if (!node->getNamedChild("maxacceleration", maxacceleration)) return false;
00076 
00077         if (maxbounds[0] - minbounds[0] < fixed(25) ||
00078                 maxbounds[1] - minbounds[1] < fixed(25) ||
00079                 maxbounds[2] - minbounds[2] < fixed(10))
00080         {
00081                 return node->returnError(
00082                         "Boid bounding box is too small, it must be at least 25x10 units");
00083         }
00084 
00085         return LandscapeMovementType::readXML(node);
00086 }

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