00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <landscapemap/GroundMaps.h>
00022 #include <landscapemap/HeightMapLoader.h>
00023 #include <landscapemap/LandscapeMaps.h>
00024 #include <landscapedef/LandscapeInclude.h>
00025 #include <landscapedef/LandscapeTex.h>
00026 #include <landscapedef/LandscapeDefinitions.h>
00027 #include <landscapedef/LandscapeDefinitionCache.h>
00028 #include <target/Target.h>
00029 #include <placement/PlacementTankPosition.h>
00030 #include <movement/TargetMovement.h>
00031 #include <common/Logger.h>
00032 #include <tankai/TankAIAdder.h>
00033 #include <lang/LangResource.h>
00034 #ifndef S3D_SERVER
00035 #include <land/VisibilityPatchGrid.h>
00036 #endif
00037
00038 GroundMaps::GroundMaps(LandscapeDefinitionCache &defnCache) :
00039 defnCache_(defnCache),
00040 arenaX_(-1),
00041 arenaY_(-1),
00042 arenaWidth_(-1),
00043 arenaHeight_(-1)
00044 {
00045 }
00046
00047 GroundMaps::~GroundMaps()
00048 {
00049 }
00050
00051 void GroundMaps::generateMaps(
00052 ScorchedContext &context,
00053 ProgressCounter *counter)
00054 {
00055 arenaWidth_ = context.getLandscapeMaps().getDefinitions().getDefn()->getArenaWidth();
00056 arenaHeight_ = context.getLandscapeMaps().getDefinitions().getDefn()->getArenaHeight();
00057 arenaX_ = context.getLandscapeMaps().getDefinitions().getDefn()->getArenaX();
00058 arenaY_ = context.getLandscapeMaps().getDefinitions().getDefn()->getArenaY();
00059
00060 generateHMap(context, counter);
00061 #ifndef S3D_SERVER
00062 if (!context.getServerMode())
00063 {
00064 VisibilityPatchGrid::instance()->generate();
00065 }
00066 #endif
00067 generateObjects(context, counter);
00068
00069
00070
00071 PlacementTankPosition::flattenTankPositions(context);
00072
00073
00074
00075 context.getTargetMovement().generate(context);
00076 nmap_.create(getLandscapeWidth(), getLandscapeHeight());
00077 }
00078
00079 int GroundMaps::getLandscapeWidth()
00080 {
00081 return map_.getMapWidth();
00082 }
00083
00084 int GroundMaps::getLandscapeHeight()
00085 {
00086 return map_.getMapHeight();
00087 }
00088
00089 int GroundMaps::getArenaWidth()
00090 {
00091 return arenaWidth_;
00092 }
00093
00094 int GroundMaps::getArenaHeight()
00095 {
00096 return arenaHeight_;
00097 }
00098
00099 int GroundMaps::getArenaX()
00100 {
00101 return arenaX_;
00102 }
00103
00104 int GroundMaps::getArenaY()
00105 {
00106 return arenaY_;
00107 }
00108
00109 void GroundMaps::generateHMap(
00110 ScorchedContext &context,
00111 ProgressCounter *counter)
00112 {
00113
00114 map_.create(defnCache_.getDefn()->getLandscapeWidth(),
00115 defnCache_.getDefn()->getLandscapeHeight());
00116
00117
00118 bool levelSurround = false;
00119 if (!HeightMapLoader::generateTerrain(
00120 defnCache_.getSeed(),
00121 defnCache_.getDefn()->heightmap,
00122 map_,
00123 levelSurround,
00124 counter))
00125 {
00126 S3D::dialogExit("Landscape", "Failed to generate landscape");
00127 }
00128 }
00129
00130 void GroundMaps::generateObject(RandomGenerator &generator,
00131 LandscapeInclude &place,
00132 ScorchedContext &context,
00133 unsigned int &playerId,
00134 ProgressCounter *counter)
00135 {
00136 if (counter) counter->setNewOp(LANG_RESOURCE("POPULATING_LANDSCAPE", "Populating Landscape"));
00137
00138
00139 for (unsigned int i=0; i<place.placements.size(); i++)
00140 {
00141 PlacementType *type = place.placements[i];
00142 type->createObjects(context, generator, playerId, counter);
00143 }
00144 }
00145
00146 void GroundMaps::generateObjects(
00147 ScorchedContext &context,
00148 ProgressCounter *counter)
00149 {
00150 LandscapeTex *tex = defnCache_.getTex();
00151 LandscapeDefn *defn = defnCache_.getDefn();
00152
00153
00154 groups_.getShadows().clear();
00155
00156
00157 groups_.clearGroups();
00158
00159
00160
00161 unsigned int playerId = TargetID::MIN_TARGET_ID;
00162 {
00163
00164 std::vector<LandscapeInclude *>::iterator itor;
00165 for (itor = defn->texDefn.includes.begin();
00166 itor != defn->texDefn.includes.end();
00167 itor++)
00168 {
00169 LandscapeInclude *place = (*itor);
00170 RandomGenerator objectsGenerator;
00171 objectsGenerator.seed(defnCache_.getSeed());
00172 generateObject(objectsGenerator, *place,
00173 context, playerId, counter);
00174 }
00175 }
00176 {
00177
00178 std::vector<LandscapeInclude *>::iterator itor;
00179 for (itor = tex->texDefn.includes.begin();
00180 itor != tex->texDefn.includes.end();
00181 itor++)
00182 {
00183 LandscapeInclude *place = (*itor);
00184 RandomGenerator objectsGenerator;
00185 objectsGenerator.seed(defnCache_.getSeed());
00186 generateObject(objectsGenerator, *place,
00187 context, playerId, counter);
00188 }
00189 }
00190
00191
00192 {
00193 std::list<PlacementShadowDefinition::Entry> &shadows =
00194 groups_.getShadows();
00195 std::list<PlacementShadowDefinition::Entry>::iterator itor;
00196 for (itor = shadows.begin();
00197 itor != shadows.end();
00198 itor++)
00199 {
00200 PlacementShadowDefinition::Entry &entry = (*itor);
00201 entry.definition_->updateLandscapeHeight(
00202 context,
00203 entry.position_, entry.size_);
00204 }
00205 }
00206 }
00207
00208 fixed GroundMaps::getHeight(int w, int h)
00209 {
00210 return map_.getHeight(w, h);
00211 }
00212
00213 fixed GroundMaps::getInterpHeight(fixed w, fixed h)
00214 {
00215 return map_.getInterpHeight(w, h);
00216 }
00217
00218 FixedVector &GroundMaps::getNormal(int w, int h)
00219 {
00220 return map_.getNormal(w, h);
00221 }
00222
00223 void GroundMaps::getInterpNormal(fixed w, fixed h, FixedVector &normal)
00224 {
00225 FixedVector result;
00226 map_.getInterpNormal(w, h, normal);
00227 }
00228
00229 bool GroundMaps::getIntersect(Line &direction, Vector &intersect)
00230 {
00231 return map_.getIntersect(direction, intersect);
00232 }
00233