diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-10-17 17:45:19 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-10-17 17:48:39 +0200 |
commit | a500c675a87bf11e7d5980d208555002149d8ccc (patch) | |
tree | 12dfd4241c74517524dd5883957c7cf3042915d2 /src/game-server/actor.cpp | |
parent | c911fa41d12dbb9f33d51977ba578e83bfdd3be4 (diff) | |
download | manaserv-a500c675a87bf11e7d5980d208555002149d8ccc.tar.gz manaserv-a500c675a87bf11e7d5980d208555002149d8ccc.tar.bz2 manaserv-a500c675a87bf11e7d5980d208555002149d8ccc.tar.xz manaserv-a500c675a87bf11e7d5980d208555002149d8ccc.zip |
Dehardcode the tileWidth and height, except for the speed conversion.
The speed conversion needs a standard tile length anyway
and can be improved later once the movement code
will start to handle beings size.
Reviewed-by: Crush.
Diffstat (limited to 'src/game-server/actor.cpp')
-rw-r--r-- | src/game-server/actor.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/game-server/actor.cpp b/src/game-server/actor.cpp index 7295e8e2..8c183224 100644 --- a/src/game-server/actor.cpp +++ b/src/game-server/actor.cpp @@ -32,27 +32,39 @@ void Actor::setPosition(const Point &p) // Update blockmap if (getMap()) { + Map *map = getMap()->getMap(); + int tileWidth = map->getTileWidth(); + int tileHeight = map->getTileHeight(); const Point &oldP = getPosition(); - if ((oldP.x / 32 != p.x / 32 || oldP.y / 32 != p.y / 32)) + if ((oldP.x / tileWidth != p.x / tileWidth + || oldP.y / tileHeight != p.y / tileHeight)) { - getMap()->getMap()->freeTile(oldP.x / 32, oldP.y / 32, getBlockType()); - getMap()->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); + map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, + getBlockType()); + map->blockTile(p.x / tileWidth, p.y / tileHeight, getBlockType()); } } } -void Actor::setMap(MapComposite *map) +void Actor::setMap(MapComposite *mapComposite) { - assert (map); - MapComposite *oldMap = getMap(); + assert (mapComposite); + MapComposite *oldMapComposite = getMap(); Point p = getPosition(); - if (oldMap) + if (oldMapComposite) { - oldMap->getMap()->freeTile(p.x / 32, p.y / 32, getBlockType()); + Map *oldMap = oldMapComposite->getMap(); + int oldTileWidth = oldMap->getTileWidth(); + int oldTileHeight = oldMap->getTileHeight(); + oldMap->freeTile(p.x / oldTileWidth, p.y / oldTileHeight, + getBlockType()); } - Thing::setMap(map); - map->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); + Thing::setMap(mapComposite); + Map *map = mapComposite->getMap(); + int tileWidth = map->getTileWidth(); + int tileHeight = map->getTileHeight(); + map->blockTile(p.x / tileWidth, p.y / tileHeight, getBlockType()); /* the last line might look illogical because the current position is * invalid on the new map, but it is necessary to block the old position * because the next call of setPosition() will automatically free the old |