1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <landscapedef/LandscapeTex.h>
22 #include <landscapedef/LandscapeDefinitions.h>
23 #include <engine/ScorchedContext.h>
24 #include <weapons/AccessoryStore.h>
25 #include <common/Defines.h>
31 static LandscapeTexType
*fetchBorderTexType(const char *type
)
33 if (0 == strcmp(type
, "water")) return new LandscapeTexBorderWater
;
34 if (0 == strcmp(type
, "none")) return new LandscapeTexTypeNone
;
35 S3D::dialogMessage("LandscapeTexType", S3D::formatStringBuffer("Unknown border type %s", type
));
39 static LandscapeTexType
*fetchTextureTexType(const char *type
)
41 if (0 == strcmp(type
, "generate")) return new LandscapeTexTextureGenerate
;
42 S3D::dialogMessage("LandscapeTexType", S3D::formatStringBuffer("Unknown texture type %s", type
));
46 static LandscapeTexType
*fetchPrecipitationTexType(const char *type
)
48 if (0 == strcmp(type
, "none")) return new LandscapeTexTypeNone
;
49 if (0 == strcmp(type
, "rain")) return new LandscapeTexPrecipitationRain
;
50 if (0 == strcmp(type
, "snow")) return new LandscapeTexPrecipitationSnow
;
51 S3D::dialogMessage("LandscapeTexType", S3D::formatStringBuffer("Unknown precipitation type %s", type
));
55 bool LandscapeTexTypeNone::readXML(XMLNode
*node
)
57 return node
->failChildren();
60 // LandscapeTexPrecipitation
61 bool LandscapeTexPrecipitation::readXML(XMLNode
*node
)
63 if (!node
->getNamedChild("particles", particles
)) return false;
64 return node
->failChildren();
67 // LandscapeTexBorderWater
68 bool LandscapeTexBorderWater::readXML(XMLNode
*node
)
70 if (!node
->getNamedChild("reflection", reflection
)) return false;
71 if (!node
->getNamedChild("texture", texture
)) return false;
72 if (!node
->getNamedChild("foam", foam
)) return false;
73 if (!S3D::checkDataFile(reflection
.c_str())) return false;
74 if (!S3D::checkDataFile(texture
.c_str())) return false;
75 if (!S3D::checkDataFile(foam
.c_str())) return false;
77 if (!node
->getNamedChild("height", height
)) return false;
78 if (!node
->getNamedChild("wavetopa", wavetopa
)) return false;
79 if (!node
->getNamedChild("wavetopb", wavetopb
)) return false;
80 if (!node
->getNamedChild("wavebottoma", wavebottoma
)) return false;
81 if (!node
->getNamedChild("wavebottomb", wavebottomb
)) return false;
82 if (!node
->getNamedChild("wavelight", wavelight
)) return false;
84 return node
->failChildren();
87 // LandscapeTexTextureGenerate
88 bool LandscapeTexTextureGenerate::readXML(XMLNode
*node
)
90 if (!node
->getNamedChild("roof", roof
)) return false;
91 if (!node
->getNamedChild("rockside", rockside
)) return false;
92 if (!node
->getNamedChild("shore", shore
)) return false;
93 if (!node
->getNamedChild("texture0", texture0
)) return false;
94 if (!node
->getNamedChild("texture1", texture1
)) return false;
95 if (!node
->getNamedChild("texture2", texture2
)) return false;
96 if (!node
->getNamedChild("texture3", texture3
)) return false;
97 if (!S3D::checkDataFile(roof
.c_str())) return false;
98 if (!S3D::checkDataFile(rockside
.c_str())) return false;
99 if (!S3D::checkDataFile(shore
.c_str())) return false;
100 if (!S3D::checkDataFile(texture0
.c_str())) return false;
101 if (!S3D::checkDataFile(texture1
.c_str())) return false;
102 if (!S3D::checkDataFile(texture2
.c_str())) return false;
103 if (!S3D::checkDataFile(texture3
.c_str())) return false;
104 return node
->failChildren();
108 LandscapeTex::LandscapeTex() :
109 border(0), texture(0)
113 LandscapeTex::~LandscapeTex()
119 bool LandscapeTex::readXML(LandscapeDefinitions
*definitions
, XMLNode
*node
)
122 node
->getNamedChild("seed", seed
, false);
123 skytexturestatic
= "";
124 nosunfog
= false; nohorizonglow
= false; nosunblend
= false;
125 if (!node
->getNamedChild("detail", detail
)) return false;
126 if (!node
->getNamedChild("magmasmall", magmasmall
)) return false;
127 if (!node
->getNamedChild("scorch", scorch
)) return false;
128 if (!node
->getNamedChild("fog", fog
)) return false;
129 if (!node
->getNamedChild("suncolor", suncolor
)) return false;
130 if (!node
->getNamedChild("suntexture", suntexture
)) return false;
131 node
->getNamedChild("suntexturemask", suntexturemask
, false);
132 if (!node
->getNamedChild("fogdensity", fogdensity
)) return false;
133 if (!node
->getNamedChild("skytexture", skytexture
)) return false;
134 node
->getNamedChild("skytexturestatic", skytexturestatic
, false);
135 node
->getNamedChild("nosunfog", nosunfog
, false);
136 node
->getNamedChild("nohorizonglow", nohorizonglow
, false);
137 node
->getNamedChild("nosunblend", nosunblend
, false);
138 node
->getNamedChild("skyline", skyline
, false);
139 node
->getNamedChild("skylinemask", skylinemask
, false);
140 if (!node
->getNamedChild("skytexturemask", skytexturemask
)) return false;
141 if (!node
->getNamedChild("skycolormap", skycolormap
)) return false;
142 if (!node
->getNamedChild("skytimeofday", skytimeofday
)) return false;
143 if (!node
->getNamedChild("skysunxy", skysunxy
)) return false;
144 if (!node
->getNamedChild("skysunyz", skysunyz
)) return false;
145 if (!node
->getNamedChild("skydiffuse", skydiffuse
)) return false;
146 if (!node
->getNamedChild("skyambience", skyambience
)) return false;
148 if (!S3D::checkDataFile(detail
.c_str())) return false;
149 if (!S3D::checkDataFile(magmasmall
.c_str())) return false;
150 if (!S3D::checkDataFile(scorch
.c_str())) return false;
151 if (!S3D::checkDataFile(skytexture
.c_str())) return false;
152 if (!S3D::checkDataFile(skytexturemask
.c_str())) return false;
153 if (!S3D::checkDataFile(skycolormap
.c_str())) return false;
154 if (!S3D::checkDataFile(suntexture
.c_str())) return false;
158 std::string bordertype
;
159 if (!node
->getNamedChild("border", borderNode
)) return false;
160 if (!borderNode
->getNamedParameter("type", bordertype
)) return false;
161 if (!(border
= fetchBorderTexType(bordertype
.c_str()))) return false;
162 if (!border
->readXML(borderNode
)) return false;
165 XMLNode
*textureNode
;
166 std::string texturetype
;
167 if (!node
->getNamedChild("texture", textureNode
)) return false;
168 if (!textureNode
->getNamedParameter("type", texturetype
)) return false;
169 if (!(texture
= fetchTextureTexType(texturetype
.c_str()))) return false;
170 if (!texture
->readXML(textureNode
)) return false;
173 XMLNode
*precipitationNode
;
174 std::string precipitationtype
;
175 if (node
->getNamedChild("precipitation", precipitationNode
, false))
177 if (!precipitationNode
->getNamedParameter("type", precipitationtype
)) return false;
178 if (!(precipitation
= fetchPrecipitationTexType(precipitationtype
.c_str()))) return false;
179 if (!precipitation
->readXML(precipitationNode
)) return false;
183 precipitation
= new LandscapeTexTypeNone();
187 if (!texDefn
.readXML(definitions
, node
)) return false;
189 return node
->failChildren();