00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <landscapemap/RoofMaps.h>
00022 #include <landscapemap/HeightMapLoader.h>
00023 #include <common/ProgressCounter.h>
00024 #include <engine/ScorchedContext.h>
00025 #include <landscapedef/LandscapeDefinitionCache.h>
00026 #include <landscapedef/LandscapeDefn.h>
00027
00028 RoofMaps::RoofMaps(LandscapeDefinitionCache &defnCache) :
00029 defnCache_(defnCache)
00030 {
00031 }
00032
00033 RoofMaps::~RoofMaps()
00034 {
00035 }
00036
00037 void RoofMaps::generateMaps(
00038 ScorchedContext &context,
00039 ProgressCounter *counter)
00040 {
00041 generateRMap(context, counter);
00042 }
00043
00044 fixed RoofMaps::getRoofHeight(int x, int y)
00045 {
00046 if (defnCache_.getDefn()->roof->getType() != LandscapeDefnType::eRoofCavern)
00047 {
00048 return fixed::MAX_FIXED;
00049 }
00050
00051
00052 int const xFactor = defnCache_.getDefn()->getLandscapeWidth() / rmap_.getMapWidth();
00053 int const yFactor = defnCache_.getDefn()->getLandscapeHeight() / rmap_.getMapHeight();
00054
00055 x /= xFactor;
00056 y /= yFactor;
00057 if (x < 0 || y < 0)
00058 {
00059 return rmap_.getHeight(0, 0);
00060 }
00061 else if (x > rmap_.getMapWidth() || y > rmap_.getMapHeight())
00062 {
00063 return rmap_.getHeight(
00064 rmap_.getMapWidth(), rmap_.getMapHeight());
00065 }
00066
00067 return rmap_.getHeight(x, y);
00068 }
00069
00070 fixed RoofMaps::getInterpRoofHeight(fixed x, fixed y)
00071 {
00072 if (defnCache_.getDefn()->roof->getType() != LandscapeDefnType::eRoofCavern)
00073 {
00074 return fixed::MAX_FIXED;
00075 }
00076
00077
00078 int const xFactor = defnCache_.getDefn()->getLandscapeWidth() / rmap_.getMapWidth();
00079 int const yFactor = defnCache_.getDefn()->getLandscapeHeight() / rmap_.getMapHeight();
00080
00081 x /= xFactor;
00082 y /= yFactor;
00083 if (x < 0 || y < 0 || x > rmap_.getMapWidth() || y > rmap_.getMapHeight())
00084 {
00085 return fixed::MAX_FIXED;
00086 }
00087 return rmap_.getInterpHeight(x, y);
00088 }
00089
00090 void RoofMaps::generateRMap(
00091 ScorchedContext &context,
00092 ProgressCounter *counter)
00093 {
00094
00095 int mapWidth = defnCache_.getDefn()->getLandscapeWidth() / 4;
00096 int mapHeight = defnCache_.getDefn()->getLandscapeHeight() / 4;
00097 rmap_.create(mapWidth, mapHeight);
00098
00099
00100 if (defnCache_.getDefn()->roof->getType() == LandscapeDefnType::eRoofCavern)
00101 {
00102 LandscapeDefnRoofCavern *cavern =
00103 (LandscapeDefnRoofCavern *) defnCache_.getDefn()->roof;
00104
00105 bool smooth = false;
00106 if (!HeightMapLoader::generateTerrain(
00107 defnCache_.getSeed() + 1,
00108 cavern->heightmap,
00109 rmap_,
00110 smooth,
00111 counter))
00112 {
00113 S3D::dialogExit("Landscape", "Failed to generate roof");
00114 }
00115
00116 for (int j=0; j<=rmap_.getMapHeight(); j++)
00117 {
00118 for (int i=0; i<=rmap_.getMapWidth(); i++)
00119 {
00120 fixed height = rmap_.getHeight(i, j);
00121 height = fixed(cavern->height) - height;
00122 rmap_.setHeight(i, j, height);
00123 rmap_.getNormal(i, j)[2] = -rmap_.getNormal(i, j)[2];
00124 }
00125 }
00126 }
00127 }