summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-22 18:58:47 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-22 18:58:47 +0200
commit852ff45c35c422b5264487669934b392a8657465 (patch)
tree380751fae34a7dcd7b31bd84e303b9086eb17485
parent2a11c6c5d874d661dcb7f016183c3c3e64e65f3c (diff)
parentec3c689c64922baf4a9f99bc6e9345e0a80403e8 (diff)
downloadmana-852ff45c35c422b5264487669934b392a8657465.tar.gz
mana-852ff45c35c422b5264487669934b392a8657465.tar.bz2
mana-852ff45c35c422b5264487669934b392a8657465.tar.xz
mana-852ff45c35c422b5264487669934b392a8657465.zip
Merge branch 'master' of gitorious.org:~bertram/mana/mana-any-square-tile-size
-rw-r--r--src/actorspritemanager.cpp16
-rw-r--r--src/being.cpp10
-rw-r--r--src/commandhandler.cpp4
-rw-r--r--src/game.cpp16
-rw-r--r--src/game.h6
-rw-r--r--src/gui/minimap.cpp24
-rw-r--r--src/gui/minimap.h1
-rw-r--r--src/gui/outfitwindow.cpp8
-rw-r--r--src/gui/viewport.cpp3
-rw-r--r--src/gui/widgets/shoplistbox.cpp2
-rw-r--r--src/item.h2
-rw-r--r--src/localplayer.cpp116
-rw-r--r--src/map.cpp98
-rw-r--r--src/map.h6
-rw-r--r--src/net/manaserv/playerhandler.cpp5
-rw-r--r--src/net/tmwa/charserverhandler.cpp4
-rw-r--r--src/net/tmwa/gamehandler.cpp4
-rw-r--r--src/net/tmwa/playerhandler.cpp2
-rw-r--r--src/particleemitter.cpp9
-rw-r--r--src/resources/mapreader.cpp2
-rw-r--r--src/simpleanimation.cpp13
21 files changed, 220 insertions, 131 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index 0134dd63..fedf880c 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -21,6 +21,7 @@
#include "actorspritemanager.h"
+#include "game.h"
#include "localplayer.h"
#include "utils/dtor.h"
@@ -37,12 +38,17 @@ class FindBeingFunctor
{
if (actor->getType() == ActorSprite::FLOOR_ITEM)
return false;
+ Game *game = Game::instance();
+ if (!game)
+ return false;
+
Being* b = static_cast<Being*>(actor);
uint16_t other_y = y + ((b->getType() == ActorSprite::NPC) ? 1 : 0);
const Vector &pos = b->getPosition();
- return ((int) pos.x / 32 == x &&
- ((int) pos.y / 32 == y || (int) pos.y / 32 == other_y) &&
+ return ((int) pos.x / game->getCurrentTileWidth() == x &&
+ ((int) pos.y / game->getCurrentTileHeight() == y
+ || (int) pos.y / game->getCurrentTileHeight() == other_y) &&
b->isAlive() &&
(type == ActorSprite::UNKNOWN || b->getType() == type));
}
@@ -272,10 +278,14 @@ Being *ActorSpriteManager::findNearestLivingBeing(int x, int y,
ActorSprite::Type type,
Being *excluded) const
{
+ Game *game = Game::instance();
+ if (!game)
+ return 0;
+
Being *closestBeing = 0;
int dist = 0;
- const int maxDist = maxTileDist * 32;
+ const int maxDist = maxTileDist * game->getCurrentTileWidth();
for_actors
{
diff --git a/src/being.cpp b/src/being.cpp
index d9180bc9..42043313 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -27,6 +27,7 @@
#include "configuration.h"
#include "effectmanager.h"
#include "event.h"
+#include "game.h"
#include "graphics.h"
#include "guild.h"
#include "localplayer.h"
@@ -67,8 +68,6 @@
#define HAIR_FILE "hair.xml"
-static const int DEFAULT_BEING_WIDTH = 32;
-static const int DEFAULT_BEING_HEIGHT = 32;
int Being::mNumberOfHairstyles = 1;
Being::Being(int id, Type type, int subtype, Map *map):
@@ -197,8 +196,8 @@ void Being::setDestination(int dstX, int dstY)
return;
// If the destination is unwalkable, don't bother trying to get there
- int tileWidth = mMap->getTileWidth();
- int tileHeight = mMap->getTileHeight();
+ const int tileWidth = mMap->getTileWidth();
+ const int tileHeight = mMap->getTileHeight();
if (!mMap->getWalk(dstX / tileWidth, dstY / tileHeight))
return;
@@ -592,7 +591,8 @@ void Being::fireMissile(Being *victim, const std::string &particle)
if (missile)
{
Particle *target = particleEngine->createChild();
- target->moveBy(Vector(0.0f, 0.0f, 32.0f));
+ target->moveBy(Vector(0.0f, 0.0f,
+ Game::instance()->getCurrentTileWidth()));
target->setLifetime(1000);
victim->controlParticle(target);
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index f5864a24..25067fca 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -339,8 +339,8 @@ void CommandHandler::handleWhere(const std::string &args, ChatTab *tab)
{
std::ostringstream where;
where << Game::instance()->getCurrentMapName() << ", coordinates: "
- << ((player_node->getPixelX() - 16) / 32) << ", "
- << ((player_node->getPixelY() - 32) / 32);
+ << player_node->getTileX() << ", "
+ << player_node->getTileY();
tab->chatLog(where.str(), BY_SERVER);
}
diff --git a/src/game.cpp b/src/game.cpp
index 5bbe2d07..af9c2c39 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -979,3 +979,19 @@ void Game::changeMap(const std::string &mapPath)
event.setString("mapPath", mapPath);
event.trigger(Event::GameChannel);
}
+
+int Game::getCurrentTileWidth() const
+{
+ if (mCurrentMap)
+ return mCurrentMap->getTileWidth();
+
+ return DEFAULT_TILE_LENGTH;
+}
+
+int Game::getCurrentTileHeight() const
+{
+ if (mCurrentMap)
+ return mCurrentMap->getTileHeight();
+
+ return DEFAULT_TILE_LENGTH;
+}
diff --git a/src/game.h b/src/game.h
index b2fae121..22e242c9 100644
--- a/src/game.h
+++ b/src/game.h
@@ -67,6 +67,12 @@ class Game
const std::string &getCurrentMapName() { return mMapName; }
+ /**
+ * Convenience functions used to get the current tile width and height.
+ */
+ int getCurrentTileWidth() const;
+ int getCurrentTileHeight() const;
+
private:
int mLastTarget;
bool mDisconnected;
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 993814ea..7ad034e4 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -43,6 +43,7 @@ bool Minimap::mShow = true;
Minimap::Minimap():
Window(_("Map")),
+ mMap(0),
mMapImage(0),
mWidthProportion(0.5),
mHeightProportion(0.5)
@@ -96,6 +97,7 @@ void Minimap::setMap(Map *map)
if (map)
{
+ mMap = map;
std::string tempname =
"graphics/minimaps/" + map->getFilename() + ".png";
ResourceManager *resman = ResourceManager::getInstance();
@@ -159,14 +161,17 @@ void Minimap::draw(gcn::Graphics *graphics)
int mapOriginX = 0;
int mapOriginY = 0;
- if (mMapImage)
+ if (mMapImage && mMap)
{
if (mMapImage->getWidth() > a.width ||
mMapImage->getHeight() > a.height)
{
const Vector &p = player_node->getPosition();
- mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mWidthProportion) / 32);
- mapOriginY = (int) (((a.height) / 2) - (int) (p.y * mHeightProportion) / 32);
+ mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mWidthProportion)
+ / mMap->getTileWidth());
+ mapOriginY = (int) (((a.height) / 2)
+ - (int) (p.y * mHeightProportion)
+ / mMap->getTileHeight());
const int minOriginX = a.width - mMapImage->getWidth();
const int minOriginY = a.height - mMapImage->getHeight();
@@ -230,10 +235,15 @@ void Minimap::draw(gcn::Graphics *graphics)
const int offsetWidth = (int) ((dotSize - 1) * mWidthProportion);
const Vector &pos = being->getPosition();
- graphics->fillRectangle(gcn::Rectangle(
- (int) (pos.x * mWidthProportion) / 32 + mapOriginX - offsetWidth,
- (int) (pos.y * mHeightProportion) / 32 + mapOriginY - offsetHeight,
- dotSize, dotSize));
+ if (mMap)
+ {
+ graphics->fillRectangle(gcn::Rectangle(
+ (int) (pos.x * mWidthProportion) / mMap->getTileWidth()
+ + mapOriginX - offsetWidth,
+ (int) (pos.y * mHeightProportion) / mMap->getTileHeight()
+ + mapOriginY - offsetHeight,
+ dotSize, dotSize));
+ }
}
graphics->popClipArea();
diff --git a/src/gui/minimap.h b/src/gui/minimap.h
index a376a15c..0916a1da 100644
--- a/src/gui/minimap.h
+++ b/src/gui/minimap.h
@@ -58,6 +58,7 @@ class Minimap : public Window
void draw(gcn::Graphics *graphics);
private:
+ Map *mMap;
Image *mMapImage;
float mWidthProportion;
float mHeightProportion;
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index efa0e08b..053c6659 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -196,9 +196,13 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
const int itemY = 25 + (i / mGridWidth) * mBoxHeight;
graphics->setColor(gcn::Color(0, 0, 0, 64));
- graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
+ graphics->drawRectangle(gcn::Rectangle(itemX, itemY,
+ ITEM_ICON_SIZE,
+ ITEM_ICON_SIZE));
graphics->setColor(gcn::Color(255, 255, 255, 32));
- graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
+ graphics->fillRectangle(gcn::Rectangle(itemX, itemY,
+ ITEM_ICON_SIZE,
+ ITEM_ICON_SIZE));
if (mItems[mCurrentOutfit][i] < 0)
{
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index e10a1a60..0353fd44 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -402,7 +402,8 @@ void Viewport::_drawPath(Graphics *graphics, const Path &path,
graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4,
8, 8));
graphics->drawText(
- toString(mMap->getMetaTile(i->x / 32, i->y / 32)->Gcost),
+ toString(mMap->getMetaTile(i->x / mMap->getTileWidth(),
+ i->y / mMap->getTileHeight())->Gcost),
squareX + 4, squareY + 12, gcn::Graphics::CENTER);
}
}
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index ae7d4d9b..2d25185a 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -36,8 +36,6 @@
#include <guichan/font.hpp>
#include <guichan/listmodel.hpp>
-const int ITEM_ICON_SIZE = 32;
-
float ShopListBox::mAlpha = 1.0;
ShopListBox::ShopListBox(gcn::ListModel *listModel):
diff --git a/src/item.h b/src/item.h
index f6574f8c..adca4b79 100644
--- a/src/item.h
+++ b/src/item.h
@@ -28,6 +28,8 @@
class Image;
+const int ITEM_ICON_SIZE = 32;
+
/**
* Represents one or more instances of a certain item type.
*/
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index a375da92..f941dd5f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -213,11 +213,14 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!mMap || (!dx && !dy))
return Position((int)pos.x, (int)pos.y);
+ const int tileW = mMap->getTileWidth();
+ const int tileH = mMap->getTileHeight();
+
// Get the current tile pos and its offset
- int tileX = (int)pos.x / mMap->getTileWidth();
- int tileY = (int)pos.y / mMap->getTileHeight();
- int offsetX = (int)pos.x % mMap->getTileWidth();
- int offsetY = (int)pos.y % mMap->getTileHeight();
+ const int tileX = (int)pos.x / tileW;
+ const int tileY = (int)pos.y / tileH;
+ int offsetX = (int)pos.x % tileW;
+ int offsetY = (int)pos.y % tileH;
// Get the walkability of every surrounding tiles.
bool wTopLeft = mMap->getWalk(tileX - 1, tileY - 1, getWalkMask());
@@ -262,14 +265,14 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wTop && !wRight)
dx = 0;
else if (!wTop && !wRight)
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + tileW
+ - getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
else // Both straight direction are walkable
{
// Go right when below the corner
- if (offsetY >= (offsetX / mMap->getTileHeight()
- - (offsetX / mMap->getTileWidth()
- * mMap->getTileHeight()) ))
+ if (offsetY >=
+ (offsetX / tileH - (offsetX / tileW * tileH)))
dy = 0;
else // Go up otherwise
dx = 0;
@@ -278,7 +281,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x + 32, (int)pos.y - 32));
+ Position((int)pos.x + tileW,
+ (int)pos.y - tileH));
}
// Going top-left
@@ -292,8 +296,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wTop && !wLeft)
dx = 0;
else if (!wTop && !wLeft)
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
else // Both straight direction are walkable
{
// Go left when below the corner
@@ -307,7 +311,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x - 32, (int)pos.y - 32));
+ Position((int)pos.x - tileW,
+ (int)pos.y - tileH));
}
// Going bottom-left
@@ -321,8 +326,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wBottom && !wLeft)
dx = 0;
else if (!wBottom && !wLeft)
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + tileH - getCollisionRadius());
else // Both straight direction are walkable
{
// Go down when below the corner
@@ -337,7 +342,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x - 32, (int)pos.y + 32));
+ Position((int)pos.x - tileW,
+ (int)pos.y + tileH));
}
// Going bottom-right
@@ -351,8 +357,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wBottom && !wRight)
dx = 0;
else if (!wBottom && !wRight)
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW + tileW - getCollisionRadius(),
+ tileY * tileH + tileH - getCollisionRadius());
else // Both straight direction are walkable
{
// Go down when below the corner
@@ -366,7 +372,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x + 32, (int)pos.y + 32));
+ Position((int)pos.x + tileW,
+ (int)pos.y + tileH));
}
} // End of diagonal cases
@@ -378,7 +385,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wRight)
- return Position(tileX * 32 + 32 - getCollisionRadius(), (int)pos.y);
+ return Position(tileX * tileW + tileW - getCollisionRadius(),
+ (int)pos.y);
else
{
if (!wTopRight)
@@ -388,8 +396,9 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
@@ -397,18 +406,21 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!wBottomRight)
{
// If we're going to collide with the bottom-right corner
- if (offsetY + getCollisionRadius() > 32)
+ if (offsetY + getCollisionRadius() > tileH)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x + 32, (int)pos.y));
+ Position((int)pos.x + tileW,
+ (int)pos.y));
}
}
@@ -418,7 +430,7 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wLeft)
- return Position(tileX * 32 + getCollisionRadius(), (int)pos.y);
+ return Position(tileX * tileW + getCollisionRadius(), (int)pos.y);
else
{
if (!wTopLeft)
@@ -428,8 +440,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
@@ -437,18 +449,20 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!wBottomLeft)
{
// If we're going to collide with the bottom-left corner
- if (offsetY + getCollisionRadius() > 32)
+ if (offsetY + getCollisionRadius() > tileH)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x - 32, (int)pos.y));
+ Position((int)pos.x - tileW,
+ (int)pos.y));
}
}
@@ -458,7 +472,7 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wTop)
- return Position((int)pos.x, tileY * 32 + getCollisionRadius());
+ return Position((int)pos.x, tileY * tileH + getCollisionRadius());
else
{
if (!wTopLeft)
@@ -468,8 +482,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
@@ -477,18 +491,20 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!wTopRight)
{
// If we're going to collide with the top-right corner
- if (offsetX + getCollisionRadius() > 32)
+ if (offsetX + getCollisionRadius() > tileW)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x, (int)pos.y - 32));
+ Position((int)pos.x,
+ (int)pos.y - tileH));
}
}
@@ -498,7 +514,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wBottom)
- return Position((int)pos.x, tileY * 32 + 32 - getCollisionRadius());
+ return Position((int)pos.x, tileY * tileH
+ + tileH - getCollisionRadius());
else
{
if (!wBottomLeft)
@@ -508,27 +525,30 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
-
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
if (!wBottomRight)
{
// If we're going to collide with the bottom-right corner
- if (offsetX + getCollisionRadius() > 32)
+ if (offsetX + getCollisionRadius() > tileW)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x, (int)pos.y + 32));
+ Position((int)pos.x,
+ (int)pos.y + tileH));
}
}
diff --git a/src/map.cpp b/src/map.cpp
index 0ffdb2ac..3f1f9167 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -94,10 +94,12 @@ void TileAnimation::update(int ticks)
}
}
-MapLayer::MapLayer(int x, int y, int width, int height, bool isFringeLayer):
+MapLayer::MapLayer(int x, int y, int width, int height, bool isFringeLayer,
+ Map *map):
mX(x), mY(y),
mWidth(width), mHeight(height),
- mIsFringeLayer(isFringeLayer)
+ mIsFringeLayer(isFringeLayer),
+ mMap(map)
{
const int size = mWidth * mHeight;
mTiles = new Image*[size];
@@ -135,37 +137,38 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY,
Actors::const_iterator ai = actors.begin();
- int dx = (mX * 32) - scrollX;
- int dy = (mY * 32) - scrollY + 32;
+ int dx = (mX * mMap->getTileWidth()) - scrollX;
+ int dy = (mY * mMap->getTileHeight()) - scrollY + mMap->getTileHeight();
for (int y = startY; y < endY; y++)
{
- int y32 = y * 32;
+ int pixelY = y * mMap->getTileHeight();
// If drawing the fringe layer, make sure all actors above this row of
// tiles have been drawn
if (mIsFringeLayer)
{
- while (ai != actors.end() && (*ai)->getPixelY() <= y * 32)
+ while (ai != actors.end() && (*ai)->getPixelY()
+ <= y * mMap->getTileHeight())
{
(*ai)->draw(graphics, -scrollX, -scrollY);
- ai++;
+ ++ai;
}
}
if (!(debugFlags & Map::MAP_SPECIAL3))
{
- const int py0 = y32 + dy;
+ const int py0 = pixelY + dy;
for (int x = startX; x < endX; x++)
{
Image *img = getTile(x, y);
if (img)
{
- const int px = (x * 32) + dx;
+ const int px = (x * mMap->getTileWidth()) + dx;
const int py = py0 - img->getHeight();
if (!(debugFlags & (Map::MAP_SPECIAL1 | Map::MAP_SPECIAL2))
- || img->getHeight() <= 32)
+ || img->getHeight() <= mMap->getTileHeight())
{
int width = 0;
int c = getTileDrawWidth(x, y, endX, width);
@@ -440,7 +443,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY,
graphics->drawRectangle(gcn::Rectangle(
x * mTileWidth - scrollX,
y * mTileHeight - scrollY,
- 33, 33));
+ mTileWidth + 1, mTileHeight + 1));
}
if (!(debugFlags & MAP_COLLISION_TILES))
@@ -452,7 +455,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY,
graphics->fillRectangle(gcn::Rectangle(
x * mTileWidth - scrollX,
y * mTileHeight - scrollY,
- 32, 32));
+ mTileWidth, mTileHeight));
}
if (!getWalk(x, y, BLOCKMASK_MONSTER))
@@ -461,7 +464,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY,
graphics->fillRectangle(gcn::Rectangle(
x * mTileWidth - scrollX,
y * mTileHeight - scrollY,
- 32, 32));
+ mTileWidth, mTileHeight));
}
if (!getWalk(x, y, BLOCKMASK_CHARACTER))
@@ -470,7 +473,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY,
graphics->fillRectangle(gcn::Rectangle(
x * mTileWidth - scrollX,
y * mTileHeight - scrollY,
- 32, 32));
+ mTileWidth, mTileHeight));
}
}
}
@@ -667,20 +670,20 @@ Position Map::checkNodeOffsets(int radius, unsigned char walkMask,
const Position &position) const
{
// Pre-computing character's position in tiles
- const int tx = position.x / 32;
- const int ty = position.y / 32;
+ const int tx = position.x / mTileWidth;
+ const int ty = position.y / mTileHeight;
// Pre-computing character's position offsets.
- int fx = position.x % 32;
- int fy = position.y % 32;
+ int fx = position.x % mTileWidth;
+ int fy = position.y % mTileHeight;
// Compute the being radius:
// FIXME: Hande beings with more than 1/2 tile radius by not letting them
// go or spawn in too narrow places. The server will have to be aware
// of being's radius value (in tiles) to handle this gracefully.
- if (radius > 32 / 2) radius = 32 / 2;
+ if (radius > mTileWidth / 2) radius = mTileWidth / 2;
// set a default value if no value returned.
- if (radius < 1) radius = 32 / 3;
+ if (radius < 1) radius = mTileWidth / 3;
// We check diagonal first as they are more restrictive.
// Top-left border check
@@ -691,36 +694,37 @@ Position Map::checkNodeOffsets(int radius, unsigned char walkMask,
}
// Top-right border check
if (!getWalk(tx + 1, ty - 1, walkMask)
- && (fy < radius) && fx > (32 - radius))
+ && (fy < radius) && fx > (mTileWidth - radius))
{
- fx = 32 -radius;
+ fx = mTileWidth - radius;
fy = radius;
}
// Bottom-left border check
if (!getWalk(tx - 1, ty + 1, walkMask)
- && fy > (32 - radius) && fx < radius)
+ && fy > (mTileHeight - radius) && fx < radius)
{
fx = radius;
- fy = 32 - radius;
+ fy = mTileHeight - radius;
}
// Bottom-right border check
if (!getWalk(tx + 1, ty + 1, walkMask)
- && fy > (32 - radius) && fx > (32 - radius))
+ && fy > (mTileHeight - radius) && fx > (mTileWidth - radius))
{
- fx = fy = 32 -radius;
+ fx = mTileWidth - radius;
+ fy = mTileHeight - radius;
}
// Fix coordinates so that the player does not seem to dig into walls.
- if (fx > (32 - radius) && !getWalk(tx + 1, ty, walkMask))
- fx = 32 - radius;
+ if (fx > (mTileWidth - radius) && !getWalk(tx + 1, ty, walkMask))
+ fx = mTileWidth - radius;
else if (fx < radius && !getWalk(tx - 1, ty, walkMask))
fx = radius;
- else if (fy > (32 - radius) && !getWalk(tx, ty + 1, walkMask))
- fy = 32 - radius;
+ else if (fy > (mTileHeight - radius) && !getWalk(tx, ty + 1, walkMask))
+ fy = mTileHeight - radius;
else if (fy < radius && !getWalk(tx, ty - 1, walkMask))
fy = radius;
- return Position(tx * 32 + fx, ty * 32 + fy);
+ return Position(tx * mTileWidth + fx, ty * mTileHeight + fy);
}
Path Map::findTilePath(int startPixelX, int startPixelY, int endPixelX,
@@ -751,20 +755,21 @@ Path Map::findPixelPath(int startPixelX, int startPixelY, int endPixelX,
int endPixelY,
int radius, unsigned char walkMask, int maxCost)
{
- Path myPath = findPath(startPixelX / 32, startPixelY / 32,
- endPixelX / 32, endPixelY / 32, walkMask, maxCost);
+ Path myPath = findPath(startPixelX / mTileWidth, startPixelY / mTileHeight,
+ endPixelX / mTileWidth, endPixelY / mTileHeight,
+ walkMask, maxCost);
// Don't compute empty coordinates.
if (myPath.empty())
return myPath;
// Find the starting offset
- float startOffsetX = (startPixelX % 32);
- float startOffsetY = (startPixelY % 32);
+ float startOffsetX = (startPixelX % mTileWidth);
+ float startOffsetY = (startPixelY % mTileHeight);
// Find the ending offset
- float endOffsetX = (endPixelX % 32);
- float endOffsetY = (endPixelY % 32);
+ float endOffsetX = (endPixelX % mTileWidth);
+ float endOffsetY = (endPixelY % mTileHeight);
// Find the distance, and divide it by the number of steps
int changeX = (int)((endOffsetX - startOffsetX) / myPath.size());
@@ -779,10 +784,10 @@ Path Map::findPixelPath(int startPixelX, int startPixelY, int endPixelX,
// A position that is valid on the start and end tile is not
// necessarily valid on all the tiles in between, so check the offsets.
*it = checkNodeOffsets(radius, walkMask,
- it->x * 32 + startOffsetX + changeX * i,
- it->y * 32 + startOffsetY + changeY * i);
- i++;
- it++;
+ it->x * mTileWidth + startOffsetX + changeX * i,
+ it->y * mTileHeight + startOffsetY + changeY * i);
+ ++i;
+ ++it;
}
// Remove the last path node, as it's more clever to go to the destination.
@@ -800,7 +805,9 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
unsigned char walkmask, int maxCost)
{
// The basic walking cost of a tile.
- static int const basicCost = 100;
+ const int basicCost = 100;
+ // Used to compute the path G cost for diagonal moves.
+ const int GCOST_SQRT2 = 362 / 256;
// Path to be built up (empty by default)
Path path;
@@ -874,7 +881,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
// Calculate G cost for this route, ~sqrt(2) for moving diagonal
int Gcost = curr.tile->Gcost +
- (dx == 0 || dy == 0 ? basicCost : basicCost * 362 / 256);
+ (dx == 0 || dy == 0 ? basicCost : basicCost * GCOST_SQRT2);
/* Demote an arbitrary direction to speed pathfinding by
adding a defect (TODO: change depending on the desired
@@ -916,7 +923,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
forbidden here. */
int dx = std::abs(x - destX), dy = std::abs(y - destY);
newTile->Hcost = std::abs(dx - dy) * basicCost +
- std::min(dx, dy) * (basicCost * 362 / 256);
+ std::min(dx, dy) * (basicCost * GCOST_SQRT2);
// Set the current tile as the parent of the new tile
newTile->parentX = curr.x;
@@ -998,7 +1005,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
return path;
}
-void Map::addParticleEffect(const std::string &effectFile, int x, int y, int w, int h)
+void Map::addParticleEffect(const std::string &effectFile, int x, int y, int w,
+ int h)
{
ParticleEffectData newEffect;
newEffect.file = effectFile;
diff --git a/src/map.h b/src/map.h
index 7dbc14af..56ddae11 100644
--- a/src/map.h
+++ b/src/map.h
@@ -40,6 +40,8 @@ class Tileset;
typedef std::vector<Tileset*> Tilesets;
typedef std::vector<MapLayer*> Layers;
+#define DEFAULT_TILE_LENGTH 32
+
/**
* 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
@@ -88,7 +90,8 @@ class MapLayer
* fringe layer. The fringe layer is the layer that draws the actors.
* There can be only one fringe layer per map.
*/
- MapLayer(int x, int y, int width, int height, bool isFringeLayer);
+ MapLayer(int x, int y, int width, int height, bool isFringeLayer,
+ Map *map);
~MapLayer();
@@ -132,6 +135,7 @@ class MapLayer
int mWidth, mHeight;
bool mIsFringeLayer; /**< Whether the actors are drawn. */
Image **mTiles;
+ Map *mMap; /** The mother map pointer */
};
/**
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 4249bac8..a114da3d 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -46,12 +46,11 @@
#include "net/manaserv/attributes.h"
/**
- * Max. distance we are willing to scroll after a teleport;
+ * Max. distance in tiles 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 * 32;
+const int MAP_TELEPORT_SCROLL_DISTANCE = 256;
extern Net::PlayerHandler *playerHandler;
diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp
index dcc68fb3..1df84b84 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -186,8 +186,8 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg)
mNetwork->disconnect();
Client::setState(STATE_CHANGE_MAP);
Map *map = player_node->getMap();
- int tileWidth = map->getTileWidth();
- int tileHeight = map->getTileHeight();
+ const int tileWidth = map->getTileWidth();
+ const int tileHeight = map->getTileHeight();
player_node->setPosition(Vector(x * tileWidth + tileWidth / 2,
y * tileHeight + tileHeight / 2));
player_node->setMap(0);
diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp
index 8ba2e200..6430b476 100644
--- a/src/net/tmwa/gamehandler.cpp
+++ b/src/net/tmwa/gamehandler.cpp
@@ -109,8 +109,8 @@ void GameHandler::event(Event::Channel channel, const Event &event)
Game *game = Game::instance();
game->changeMap(mMap);
Map *map = game->getCurrentMap();
- int tileWidth = map->getTileWidth();
- int tileHeight = map->getTileHeight();
+ const int tileWidth = map->getTileWidth();
+ const int tileHeight = map->getTileHeight();
if (mTileX && mTileY)
{
player_node->setPosition(Vector(mTileX * tileWidth + tileWidth / 2,
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index ab63cc1d..f30baecd 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -50,7 +50,7 @@ extern OkDialog *deathNotice;
// Max. distance we are willing to scroll after a teleport;
// everything beyond will reset the port hard.
-static const int MAP_TELEPORT_SCROLL_DISTANCE = 8;
+const int MAP_TELEPORT_SCROLL_DISTANCE = 8;
// TODO Move somewhere else
namespace {
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index b9855c10..32b63c9e 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -29,6 +29,7 @@
#include "resources/image.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "map.h"
#include <cmath>
@@ -199,8 +200,12 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
int delay = XML::getProperty(frameNode, "delay", 0);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- offsetY -= imageset->getHeight() - 32;
- offsetX -= imageset->getWidth() / 2 - 16;
+ if (mMap)
+ {
+ offsetX -= imageset->getWidth() / 2
+ - mMap->getTileWidth() / 2;
+ offsetY -= imageset->getHeight() - mMap->getTileHeight();
+ }
if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
{
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 1dd12723..e509e4c2 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -254,7 +254,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
if (!isCollisionLayer)
{
- layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer);
+ layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer, map);
map->addLayer(layer);
}
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 7ef433ea..24a17ce7 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -21,6 +21,7 @@
#include "simpleanimation.h"
+#include "game.h"
#include "graphics.h"
#include "log.h"
@@ -132,15 +133,19 @@ void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode)
return;
// Get animation frames
- for ( xmlNodePtr frameNode = animationNode->xmlChildrenNode;
- frameNode;
+ for (xmlNodePtr frameNode = animationNode->xmlChildrenNode; frameNode;
frameNode = frameNode->next)
{
int delay = XML::getProperty(frameNode, "delay", 0);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- offsetY -= imageset->getHeight() - 32;
- offsetX -= imageset->getWidth() / 2 - 16;
+ Game *game = Game::instance();
+ if (game)
+ {
+ offsetX -= imageset->getWidth() / 2
+ - game->getCurrentTileWidth() / 2;
+ offsetY -= imageset->getHeight() - game->getCurrentTileHeight();
+ }
if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
{