summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-02-18 19:17:57 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-02-18 19:17:57 +0000
commit8f28636093d75b33cc5071e659291ac2ff54db8b (patch)
tree3a14a0f1f3993f12bf54990c417d5858acdf6de0 /src/map.cpp
parent9a4006a58aa332855fa6e3c143de915cae2e952b (diff)
downloadmana-8f28636093d75b33cc5071e659291ac2ff54db8b.tar.gz
mana-8f28636093d75b33cc5071e659291ac2ff54db8b.tar.bz2
mana-8f28636093d75b33cc5071e659291ac2ff54db8b.tar.xz
mana-8f28636093d75b33cc5071e659291ac2ff54db8b.zip
Merged revisions 3762-3772,3776-3782 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r3762 | crush_tmw | 2007-12-04 00:25:25 +0100 (Tue, 04 Dec 2007) | 1 line Added/renamed some headgears for the christmas event. ........ r3763 | crush_tmw | 2007-12-04 14:51:20 +0100 (Tue, 04 Dec 2007) | 1 line tophead -> tophat ........ r3764 | b_lindeijer | 2007-12-05 21:20:25 +0100 (Wed, 05 Dec 2007) | 3 lines Fix drawing of very high fringe tiles by keeping track of the maximum tile height. ........ r3765 | crush_tmw | 2007-12-07 01:50:15 +0100 (Fri, 07 Dec 2007) | 1 line Added a new drop item for the christmas event. ........ r3768 | crush_tmw | 2007-12-09 20:45:53 +0100 (Sun, 09 Dec 2007) | 1 line New versions of funky hat and elf hat by QOAL. ........ r3769 | crush_tmw | 2007-12-10 03:22:59 +0100 (Mon, 10 Dec 2007) | 1 line Simplified player subsprite handling by treating equipment, hairstyle and base sprites alike. Implementing female hairstyles is now a purely content-sided task. ........ r3770 | crush_tmw | 2007-12-10 03:50:15 +0100 (Mon, 10 Dec 2007) | 1 line Added an option to show log messages in the chat console. ........ r3771 | crush_tmw | 2007-12-10 17:12:56 +0100 (Mon, 10 Dec 2007) | 1 line Implemented female hairstyles. ........ r3772 | b_lindeijer | 2007-12-10 21:42:11 +0100 (Mon, 10 Dec 2007) | 2 lines Include cassert header. ........ r3777 | crush_tmw | 2007-12-14 18:33:45 +0100 (Fri, 14 Dec 2007) | 1 line Fixed some errors with the filenames of the new items (unrelated to my eAthena problems). ........ r3778 | crush_tmw | 2007-12-14 19:21:39 +0100 (Fri, 14 Dec 2007) | 1 line fixed some more screwups with the new items. ........ r3780 | crush_tmw | 2007-12-14 19:40:12 +0100 (Fri, 14 Dec 2007) | 1 line Put new items in equipment.xml for backward compatibility with the last client release. ........ r3782 | b_lindeijer | 2007-12-17 16:59:04 +0100 (Mon, 17 Dec 2007) | 2 lines Fixed the item tags. ........
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp88
1 files changed, 36 insertions, 52 deletions
diff --git a/src/map.cpp b/src/map.cpp
index ac570627..c2b0b9a1 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -65,6 +65,7 @@ struct Location
Map::Map(int width, int height, int tileWidth, int tileHeight):
mWidth(width), mHeight(height),
mTileWidth(tileWidth), mTileHeight(tileHeight),
+ mMaxTileHeight(height),
mOnClosedList(1), mOnOpenList(2),
mLastScrollX(0.0f), mLastScrollY(0.0f)
{
@@ -87,8 +88,7 @@ Map::~Map()
for_each(mOverlays.begin(), mOverlays.end(), make_dtor(mOverlays));
}
-void
-Map::initializeOverlays()
+void Map::initializeOverlays()
{
ResourceManager *resman = ResourceManager::getInstance();
@@ -114,10 +114,12 @@ Map::initializeOverlays()
}
}
-void
-Map::addTileset(Tileset *tileset)
+void Map::addTileset(Tileset *tileset)
{
mTilesets.push_back(tileset);
+
+ if (tileset->getHeight() > mMaxTileHeight)
+ mMaxTileHeight = tileset->getHeight();
}
bool spriteCompare(const Sprite *a, const Sprite *b)
@@ -125,13 +127,9 @@ bool spriteCompare(const Sprite *a, const Sprite *b)
return a->getPixelY() < b->getPixelY();
}
-void
-Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
+void Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
{
- int startX = scrollX / 32;
- int startY = scrollY / 32;
- int endX = (graphics->getWidth() + scrollX + 31) / 32;
- int endY = (graphics->getHeight() + scrollY + 31) / 32;
+ int endPixelY = graphics->getHeight() + scrollY + mTileHeight - 1;
// If drawing the fringe layer, make sure sprites are sorted
SpriteIterator si;
@@ -139,13 +137,14 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
{
mSprites.sort(spriteCompare);
si = mSprites.begin();
-
- // Increase endY to account for high fringe tiles
- // TODO: Improve this hack so that it'll dynamically account for the
- // highest tile.
- endY += 2;
+ endPixelY += mMaxTileHeight - mTileHeight;
}
+ int startX = scrollX / mTileWidth;
+ int startY = scrollY / mTileHeight;
+ int endX = (graphics->getWidth() + scrollX + mTileWidth - 1) / mTileWidth;
+ int endY = endPixelY / mTileHeight;
+
if (startX < 0) startX = 0;
if (startY < 0) startY = 0;
if (endX > mWidth) endX = mWidth;
@@ -169,8 +168,9 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
Image *img = getTile(x, y, layer);
if (img) {
graphics->drawImage(img,
- x * 32 - scrollX,
- y * 32 - scrollY + 32 - img->getHeight());
+ x * mTileWidth - scrollX,
+ y * mTileHeight - scrollY +
+ mTileHeight - img->getHeight());
}
}
}
@@ -186,8 +186,8 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
}
}
-void
-Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail)
+void Map::drawOverlay(Graphics *graphics,
+ float scrollX, float scrollY, int detail)
{
static int lastTick = tick_time;
@@ -226,8 +226,7 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail)
};
}
-void
-Map::setTileWithGid(int x, int y, int layer, int gid)
+void Map::setTileWithGid(int x, int y, int layer, int gid)
{
if (layer == 3)
{
@@ -251,19 +250,17 @@ class ContainsGidFunctor
int gid;
} containsGid;
-Tileset*
-Map::getTilesetWithGid(int gid)
+Tileset* Map::getTilesetWithGid(int gid) const
{
containsGid.gid = gid;
- TilesetIterator i = find_if(mTilesets.begin(), mTilesets.end(),
+ Tilesets::const_iterator i = find_if(mTilesets.begin(), mTilesets.end(),
containsGid);
return (i == mTilesets.end()) ? NULL : *i;
}
-Image*
-Map::getTileWithGid(int gid)
+Image* Map::getTileWithGid(int gid) const
{
Tileset *set = getTilesetWithGid(gid);
@@ -274,20 +271,17 @@ Map::getTileWithGid(int gid)
return NULL;
}
-void
-Map::setWalk(int x, int y, bool walkable)
+void Map::setWalk(int x, int y, bool walkable)
{
mMetaTiles[x + y * mWidth].walkable = walkable;
}
-bool
-Map::getWalk(int x, int y) const
+bool Map::getWalk(int x, int y) const
{
return !tileCollides(x, y) && !occupied(x, y);
}
-bool
-Map::occupied(int x, int y) const
+bool Map::occupied(int x, int y) const
{
Beings &beings = beingManager->getAll();
for (BeingIterator i = beings.begin(); i != beings.end(); i++)
@@ -302,53 +296,45 @@ Map::occupied(int x, int y) const
return false;
}
-bool
-Map::tileCollides(int x, int y) const
+bool Map::tileCollides(int x, int y) const
{
return !(contains(x, y) && mMetaTiles[x + y * mWidth].walkable);
}
-bool
-Map::contains(int x, int y) const
+bool Map::contains(int x, int y) const
{
return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
}
-void
-Map::setTile(int x, int y, int layer, Image *img)
+void Map::setTile(int x, int y, int layer, Image *img)
{
mTiles[x + y * mWidth + layer * (mWidth * mHeight)] = img;
}
-Image*
-Map::getTile(int x, int y, int layer)
+Image* Map::getTile(int x, int y, int layer) const
{
return mTiles[x + y * mWidth + layer * (mWidth * mHeight)];
}
-MetaTile*
-Map::getMetaTile(int x, int y)
+MetaTile* Map::getMetaTile(int x, int y) const
{
return &mMetaTiles[x + y * mWidth];
}
-SpriteIterator
-Map::addSprite(Sprite *sprite)
+SpriteIterator Map::addSprite(Sprite *sprite)
{
mSprites.push_front(sprite);
return mSprites.begin();
}
-void
-Map::removeSprite(SpriteIterator iterator)
+void Map::removeSprite(SpriteIterator iterator)
{
mSprites.erase(iterator);
}
static int const basicCost = 100;
-Path
-Map::findPath(int startX, int startY, int destX, int destY)
+Path Map::findPath(int startX, int startY, int destX, int destY)
{
// Path to be built up (empty by default)
Path path;
@@ -532,8 +518,7 @@ Map::findPath(int startX, int startY, int destX, int destY)
return path;
}
-void
-Map::addParticleEffect (std::string effectFile, int x, int y)
+void Map::addParticleEffect (std::string effectFile, int x, int y)
{
ParticleEffectData newEffect;
newEffect.file = effectFile;
@@ -542,8 +527,7 @@ Map::addParticleEffect (std::string effectFile, int x, int y)
particleEffects.push_back(newEffect);
}
-void
-Map::initializeParticleEffects(Particle* particleEngine)
+void Map::initializeParticleEffects(Particle* particleEngine)
{
for (std::list<ParticleEffectData>::iterator i = particleEffects.begin();
i != particleEffects.end();