summaryrefslogtreecommitdiff
path: root/tools/tmxcopy/map.cpp
diff options
context:
space:
mode:
authorSteve Cotton <steve@s.cotton.clara.co.uk>2009-04-03 03:11:15 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-16 11:34:39 +0200
commitbb216d7fb966156b8ea2ecb284b680309b92585b (patch)
treec418b5e455cb8e01eb30e091d040c7a0256d0dc6 /tools/tmxcopy/map.cpp
parent1d48fa06e9f1bdca6ca28b2b43c8a1bc01a96dca (diff)
downloadmana-client-bb216d7fb966156b8ea2ecb284b680309b92585b.tar.gz
mana-client-bb216d7fb966156b8ea2ecb284b680309b92585b.tar.bz2
mana-client-bb216d7fb966156b8ea2ecb284b680309b92585b.tar.xz
mana-client-bb216d7fb966156b8ea2ecb284b680309b92585b.zip
Collision layer generation tool
Diffstat (limited to 'tools/tmxcopy/map.cpp')
-rw-r--r--tools/tmxcopy/map.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tools/tmxcopy/map.cpp b/tools/tmxcopy/map.cpp
index 30f16a2d..109d1742 100644
--- a/tools/tmxcopy/map.cpp
+++ b/tools/tmxcopy/map.cpp
@@ -440,6 +440,76 @@ bool Map::randomFill(Map* templateMap, const std::string& destLayerName,
return true;
}
+bool Map::translateAllLayers(Map* templateMap, const std::string& destLayerName,
+ const ConfigurationOptions& config)
+{
+ bool checkPassed = true;
+ if (templateMap->getNumberOfLayers() != 2)
+ {
+ std::cerr<<"Error: template should have exactly 2 layers"<<std::endl;
+ checkPassed = false;
+ }
+ if (!config.createMissingLayers && !getLayer(destLayerName))
+ {
+ std::cerr<<"Error: target map has no layer named \""<<destLayerName<<"\""<<std::endl
+ <<"(and the command-line \"create layers\" option was not used)"<<std::endl;
+ checkPassed = false;
+ }
+ if (!checkPassed) return false;
+
+ //FIXME - as is, this will add tilesets that are in the template but
+ //not used in the main map
+ std::map<int, int> tilesetTranslation = addAndTranslateTilesets(templateMap);
+
+ //Lacking a better name, we'll say this is translating visible layers to collision
+ std::map<Tile, Tile> collisionTranslation;
+
+ Layer* fromLayer = templateMap->getLayer(0);
+ Layer* toLayer = templateMap->getLayer(1);
+ for (int xy = (templateMap->getWidth() * templateMap->getHeight() -1);
+ xy >= 0; xy--)
+ {
+ Tile& fromTile = fromLayer->at(xy);
+ Tile& toTile = toLayer->at(xy);
+ if (!fromTile.empty())
+ {
+ collisionTranslation[fromTile] = toTile; //FIXME - just getting it compiling so far
+ }
+ }
+
+ /* Now apply that template to the game map */
+ Layer* destLayer = getLayer(destLayerName);
+ if (!destLayer)
+ {
+ destLayer = new Layer(destLayerName, mWidth * mHeight);
+ mLayers.push_back(destLayer);
+ std::cout<<"Created new layer "<<destLayerName<<std::endl;
+ }
+
+ for (std::vector<Layer*>::iterator layer = mLayers.begin();
+ layer != mLayers.end();
+ layer++)
+ {
+ if ((*layer)->getName() == destLayerName)
+ continue;
+
+ for (int xy = mWidth * mHeight -1; xy >= 0; xy--)
+ {
+ Tile& fromTile = (*layer)->at(xy);
+ Tile& toTile = destLayer->at(xy);
+ std::map<Tile,Tile>::iterator iteratedTile = collisionTranslation.find(fromTile);
+
+ if (iteratedTile != collisionTranslation.end())
+ {
+ toTile = (*iteratedTile).second;
+ }
+ }
+
+ }
+
+ return true;
+}
+
int Map::save(std::string filename)