From b7f93f0b2ec91e04d3ed9035c9e21015b8b57cdd Mon Sep 17 00:00:00 2001 From: Bertram Date: Tue, 9 Feb 2010 03:18:35 +0100 Subject: Got successfully rid of tile width/height fallback values as asked by Jaxad. But I added some logs when speed and other actions where refused due to game/map uninitialized. This could help. --- src/being.cpp | 10 +--------- src/gui/debugwindow.cpp | 2 +- src/map.cpp | 6 ------ src/map.h | 8 ++------ src/net/manaserv/beinghandler.cpp | 9 +++------ src/net/manaserv/playerhandler.cpp | 10 +++++----- src/resources/mapreader.cpp | 27 ++++++++++++++++++--------- 7 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/being.cpp b/src/being.cpp index d5ee4a30..4b972e3d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -799,7 +799,7 @@ int Being::getOffset(char pos, char neg) const if (mAction != WALK || !(mDirection & (pos | neg))) return 0; - int offset; + int offset = 0; if (mMap) { @@ -809,14 +809,6 @@ int Being::getOffset(char pos, char neg) const (int)((get_elapsed_time(mWalkTime) * mMap->getTileHeight()) / mWalkSpeed.y); } - else - { - offset = (pos == LEFT && neg == RIGHT) ? - (int)((get_elapsed_time(mWalkTime) - * DEFAULT_TILE_WIDTH) / mWalkSpeed.x) : - (int)((get_elapsed_time(mWalkTime) - * DEFAULT_TILE_HEIGHT) / mWalkSpeed.y); - } // We calculate the offset _from_ the _target_ location offset -= 32; diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 9adbc84f..299118d9 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -98,7 +98,7 @@ void DebugWindow::logic() mTileMouseLabel->setCaption(strprintf(_("Cursor: (%d, %d)"), mouseTileX, mouseTileY)); - // TODO: Add gettext support below + mMusicFileLabel->setCaption(strprintf( _("Music: %s"), map->getProperty("music").c_str())); mMinimapLabel->setCaption( diff --git a/src/map.cpp b/src/map.cpp index c18d38ba..efb3017d 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -40,12 +40,6 @@ extern volatile int tick_time; -/** - * The used side-length for tiles - */ -const int DEFAULT_TILE_WIDTH = 32; -const int DEFAULT_TILE_HEIGHT = 32; - /** * A location on a tile map. Used for pathfinding, open list. */ diff --git a/src/map.h b/src/map.h index d33f31db..3cf2ff59 100644 --- a/src/map.h +++ b/src/map.h @@ -43,10 +43,6 @@ typedef std::list MapSprites; typedef MapSprites::iterator MapSprite; typedef std::vector Layers; -/** Default fallback values for tiles width and height */ -extern const int DEFAULT_TILE_WIDTH; /**< Used for X coords */ -extern const int DEFAULT_TILE_HEIGHT; /**< Used for Y coords */ - /** * A meta tile stores additional information about a location on a tile map. * This is information that doesn't need to be repeated for each tile in each @@ -259,13 +255,13 @@ class Map : public Properties * Returns the tile width of this map. */ int getTileWidth() const - { return mTileWidth > 0 ? mTileWidth : DEFAULT_TILE_WIDTH; } + { return mTileWidth; } /** * Returns the tile height used by this map. */ int getTileHeight() const - { return mTileHeight > 0 ? mTileHeight : DEFAULT_TILE_HEIGHT; } + { return mTileHeight; } const std::string &getMusicFile() const; const std::string &getName() const; diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index d1fff43d..99b01090 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -112,12 +112,9 @@ Vector BeingHandler::giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds) if (!game || !map) { - speedInTicks.x = speedInTilesPerSeconds - * (float)DEFAULT_TILE_WIDTH - / 1000 * (float)MILLISECONDS_IN_A_TICK; - speedInTicks.y = speedInTilesPerSeconds - * (float)DEFAULT_TILE_HEIGHT - / 1000 * (float)MILLISECONDS_IN_A_TICK; + speedInTicks.x = speedInTicks.y = 0; + logger->log("Manaserv::BeingHandler: Speed wasn't given back" + " because game/Map not initialized."); } // We don't use z for now. speedInTicks.z = 0; diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 042e0284..23158cc5 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -53,13 +53,13 @@ extern Window *buySellDialog; /** @see in game.cpp */ extern const int MILLISECONDS_IN_A_TICK; -/** @see in map.cpp */ -extern const int DEFAULT_TILE_WIDTH; - -/* Max. distance we are willing to scroll after a teleport; +/** + * Max. distance we are willing to scroll after a teleport; * everything beyond will reset the port hard. + * 32 is the nominal tile width/height. + * @todo: Make this parameter read from config. */ -static const int MAP_TELEPORT_SCROLL_DISTANCE = 8 * DEFAULT_TILE_WIDTH; +static const int MAP_TELEPORT_SCROLL_DISTANCE = 8 * 32; /** * Listener used for handling the overweigth message. diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 7f08fe91..3499c54a 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -31,6 +31,7 @@ #include "utils/base64.h" #include "utils/stringutils.h" +#include "utils/gettext.h" #include "utils/xml.h" #include @@ -117,19 +118,19 @@ int inflateMemory(unsigned char *in, unsigned int inLength, { if (ret == Z_MEM_ERROR) { - logger->log("Error: Out of memory while decompressing map data!"); + logger->log(_("Error: Out of memory while decompressing map data!")); } else if (ret == Z_VERSION_ERROR) { - logger->log("Error: Incompatible zlib version!"); + logger->log(_("Error: Incompatible zlib version!")); } else if (ret == Z_DATA_ERROR) { - logger->log("Error: Incorrect zlib compressed data!"); + logger->log(_("Error: Incorrect zlib compressed data!")); } else { - logger->log("Error: Unknown error while decompressing map data!"); + logger->log(_("Error: Unknown error while decompressing map data!")); } free(out); @@ -142,7 +143,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, Map *MapReader::readMap(const std::string &filename) { - logger->log("Attempting to read map %s", filename.c_str()); + logger->log(_("Attempting to read map %s"), filename.c_str()); // Load the file through resource manager ResourceManager *resman = ResourceManager::getInstance(); int fileSize; @@ -151,7 +152,7 @@ Map *MapReader::readMap(const std::string &filename) if (buffer == NULL) { - logger->log("Map file not found (%s)", filename.c_str()); + logger->log(_("Map file not found (%s)"), filename.c_str()); return NULL; } @@ -167,7 +168,7 @@ Map *MapReader::readMap(const std::string &filename) if (inflated == NULL) { - logger->log("Could not decompress map file (%s)", + logger->log(_("Could not decompress map file (%s)"), filename.c_str()); return NULL; } @@ -212,8 +213,16 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) const int w = XML::getProperty(node, "width", 0); const int h = XML::getProperty(node, "height", 0); - const int tilew = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH); - const int tileh = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT); + const int tilew = XML::getProperty(node, "tilewidth", -1); + const int tileh = XML::getProperty(node, "tileheight", -1); + + if (tilew < 0 || tileh < 0) + { + logger->log(_("MapReader: Warning: " + "Unitialized tile width or height value for map: %s"), path.c_str()); + return 0; + } + Map *map = new Map(w, h, tilew, tileh); for_each_xml_child_node(childNode, node) -- cgit v1.2.3-70-g09d2