00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }