00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <landscapedef/LandscapeTex.h>
00022 #include <landscapedef/LandscapeDefinitions.h>
00023 #include <engine/ScorchedContext.h>
00024 #include <weapons/AccessoryStore.h>
00025 #include <common/Defines.h>
00026 #include <string.h>
00027 #include <stdlib.h>
00028 #include <time.h>
00029 #include <float.h>
00030
00031 static LandscapeTexType *fetchBorderTexType(const char *type)
00032 {
00033 if (0 == strcmp(type, "water")) return new LandscapeTexBorderWater;
00034 if (0 == strcmp(type, "none")) return new LandscapeTexTypeNone;
00035 S3D::dialogMessage("LandscapeTexType", S3D::formatStringBuffer("Unknown border type %s", type));
00036 return 0;
00037 }
00038
00039 static LandscapeTexType *fetchTextureTexType(const char *type)
00040 {
00041 if (0 == strcmp(type, "generate")) return new LandscapeTexTextureGenerate;
00042 S3D::dialogMessage("LandscapeTexType", S3D::formatStringBuffer("Unknown texture type %s", type));
00043 return 0;
00044 }
00045
00046 static LandscapeTexType *fetchPrecipitationTexType(const char *type)
00047 {
00048 if (0 == strcmp(type, "none")) return new LandscapeTexTypeNone;
00049 if (0 == strcmp(type, "rain")) return new LandscapeTexPrecipitationRain;
00050 if (0 == strcmp(type, "snow")) return new LandscapeTexPrecipitationSnow;
00051 S3D::dialogMessage("LandscapeTexType", S3D::formatStringBuffer("Unknown precipitation type %s", type));
00052 return 0;
00053 }
00054
00055 bool LandscapeTexTypeNone::readXML(XMLNode *node)
00056 {
00057 return node->failChildren();
00058 }
00059
00060
00061 bool LandscapeTexPrecipitation::readXML(XMLNode *node)
00062 {
00063 if (!node->getNamedChild("particles", particles)) return false;
00064 return node->failChildren();
00065 }
00066
00067
00068 bool LandscapeTexBorderWater::readXML(XMLNode *node)
00069 {
00070 if (!node->getNamedChild("reflection", reflection)) return false;
00071 if (!node->getNamedChild("texture", texture)) return false;
00072 if (!node->getNamedChild("foam", foam)) return false;
00073 if (!S3D::checkDataFile(reflection.c_str())) return false;
00074 if (!S3D::checkDataFile(texture.c_str())) return false;
00075 if (!S3D::checkDataFile(foam.c_str())) return false;
00076
00077 if (!node->getNamedChild("height", height)) return false;
00078 if (!node->getNamedChild("wavetopa", wavetopa)) return false;
00079 if (!node->getNamedChild("wavetopb", wavetopb)) return false;
00080 if (!node->getNamedChild("wavebottoma", wavebottoma)) return false;
00081 if (!node->getNamedChild("wavebottomb", wavebottomb)) return false;
00082 if (!node->getNamedChild("wavelight", wavelight)) return false;
00083
00084 return node->failChildren();
00085 }
00086
00087
00088 bool LandscapeTexTextureGenerate::readXML(XMLNode *node)
00089 {
00090 if (!node->getNamedChild("roof", roof)) return false;
00091 if (!node->getNamedChild("rockside", rockside)) return false;
00092 if (!node->getNamedChild("shore", shore)) return false;
00093 if (!node->getNamedChild("texture0", texture0)) return false;
00094 if (!node->getNamedChild("texture1", texture1)) return false;
00095 if (!node->getNamedChild("texture2", texture2)) return false;
00096 if (!node->getNamedChild("texture3", texture3)) return false;
00097 if (!S3D::checkDataFile(roof.c_str())) return false;
00098 if (!S3D::checkDataFile(rockside.c_str())) return false;
00099 if (!S3D::checkDataFile(shore.c_str())) return false;
00100 if (!S3D::checkDataFile(texture0.c_str())) return false;
00101 if (!S3D::checkDataFile(texture1.c_str())) return false;
00102 if (!S3D::checkDataFile(texture2.c_str())) return false;
00103 if (!S3D::checkDataFile(texture3.c_str())) return false;
00104 return node->failChildren();
00105 }
00106
00107
00108 LandscapeTex::LandscapeTex() :
00109 border(0), texture(0)
00110 {
00111 }
00112
00113 LandscapeTex::~LandscapeTex()
00114 {
00115 delete border;
00116 delete texture;
00117 }
00118
00119 bool LandscapeTex::readXML(LandscapeDefinitions *definitions, XMLNode *node)
00120 {
00121 seed = 0;
00122 node->getNamedChild("seed", seed, false);
00123 skytexturestatic = "";
00124 nosunfog = false; nohorizonglow = false; nosunblend = false;
00125 if (!node->getNamedChild("detail", detail)) return false;
00126 if (!node->getNamedChild("magmasmall", magmasmall)) return false;
00127 if (!node->getNamedChild("scorch", scorch)) return false;
00128 if (!node->getNamedChild("fog", fog)) return false;
00129 if (!node->getNamedChild("suncolor", suncolor)) return false;
00130 if (!node->getNamedChild("suntexture", suntexture)) return false;
00131 node->getNamedChild("suntexturemask", suntexturemask, false);
00132 if (!node->getNamedChild("fogdensity", fogdensity)) return false;
00133 if (!node->getNamedChild("skytexture", skytexture)) return false;
00134 node->getNamedChild("skytexturestatic", skytexturestatic, false);
00135 node->getNamedChild("nosunfog", nosunfog, false);
00136 node->getNamedChild("nohorizonglow", nohorizonglow, false);
00137 node->getNamedChild("nosunblend", nosunblend, false);
00138 node->getNamedChild("skyline", skyline, false);
00139 node->getNamedChild("skylinemask", skylinemask, false);
00140 if (!node->getNamedChild("skytexturemask", skytexturemask)) return false;
00141 if (!node->getNamedChild("skycolormap", skycolormap)) return false;
00142 if (!node->getNamedChild("skytimeofday", skytimeofday)) return false;
00143 if (!node->getNamedChild("skysunxy", skysunxy)) return false;
00144 if (!node->getNamedChild("skysunyz", skysunyz)) return false;
00145 if (!node->getNamedChild("skydiffuse", skydiffuse)) return false;
00146 if (!node->getNamedChild("skyambience", skyambience)) return false;
00147
00148 if (!S3D::checkDataFile(detail.c_str())) return false;
00149 if (!S3D::checkDataFile(magmasmall.c_str())) return false;
00150 if (!S3D::checkDataFile(scorch.c_str())) return false;
00151 if (!S3D::checkDataFile(skytexture.c_str())) return false;
00152 if (!S3D::checkDataFile(skytexturemask.c_str())) return false;
00153 if (!S3D::checkDataFile(skycolormap.c_str())) return false;
00154 if (!S3D::checkDataFile(suntexture.c_str())) return false;
00155
00156 {
00157 XMLNode *borderNode;
00158 std::string bordertype;
00159 if (!node->getNamedChild("border", borderNode)) return false;
00160 if (!borderNode->getNamedParameter("type", bordertype)) return false;
00161 if (!(border = fetchBorderTexType(bordertype.c_str()))) return false;
00162 if (!border->readXML(borderNode)) return false;
00163 }
00164 {
00165 XMLNode *textureNode;
00166 std::string texturetype;
00167 if (!node->getNamedChild("texture", textureNode)) return false;
00168 if (!textureNode->getNamedParameter("type", texturetype)) return false;
00169 if (!(texture = fetchTextureTexType(texturetype.c_str()))) return false;
00170 if (!texture->readXML(textureNode)) return false;
00171 }
00172 {
00173 XMLNode *precipitationNode;
00174 std::string precipitationtype;
00175 if (node->getNamedChild("precipitation", precipitationNode, false))
00176 {
00177 if (!precipitationNode->getNamedParameter("type", precipitationtype)) return false;
00178 if (!(precipitation = fetchPrecipitationTexType(precipitationtype.c_str()))) return false;
00179 if (!precipitation->readXML(precipitationNode)) return false;
00180 }
00181 else
00182 {
00183 precipitation = new LandscapeTexTypeNone();
00184 }
00185 }
00186
00187 if (!texDefn.readXML(definitions, node)) return false;
00188
00189 return node->failChildren();
00190 }
00191