From 35dcb50b5fefae76c5d9a88ffc27faaa96eaa9eb Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 13 Aug 2008 21:11:15 +0000 Subject: Corrected the distance needed to speak to NPC and trade with others characters. --- src/game-server/gamehandler.cpp | 18 ++++++++++++------ src/game-server/map.hpp | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index cfa6ad5f..8b7be98b 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -42,6 +42,8 @@ #include "utils/logger.h" #include "utils/tokendispenser.hpp" +const unsigned int TILES_TO_BE_NEAR = 7; + GameHandler::GameHandler(): mTokenCollector(this) { @@ -133,12 +135,14 @@ static MovingObject *findBeingNear(Object *p, int id) { MapComposite *map = p->getMap(); Point const &ppos = p->getPosition(); - // TODO: use a less arbitrary value. - for (MovingObjectIterator i(map->getAroundPointIterator(ppos, 48)); i; ++i) + // See map.hpp for tiles constants + for (MovingObjectIterator i(map->getAroundPointIterator(ppos, + DEFAULT_TILE_WIDTH * TILES_TO_BE_NEAR)); i; ++i) { MovingObject *o = *i; if (o->getPublicID() != id) continue; - return ppos.inRangeOf(o->getPosition(), 48) ? o : NULL; + return ppos.inRangeOf(o->getPosition(), DEFAULT_TILE_WIDTH * + TILES_TO_BE_NEAR) ? o : NULL; } return NULL; } @@ -147,12 +151,14 @@ static Character *findCharacterNear(Object *p, int id) { MapComposite *map = p->getMap(); Point const &ppos = p->getPosition(); - // TODO: use a less arbitrary value. - for (CharacterIterator i(map->getAroundPointIterator(ppos, 64)); i; ++i) + // See map.hpp for tiles constants + for (CharacterIterator i(map->getAroundPointIterator(ppos, + DEFAULT_TILE_WIDTH * TILES_TO_BE_NEAR)); i; ++i) { Character *o = *i; if (o->getPublicID() != id) continue; - return ppos.inRangeOf(o->getPosition(), 64) ? o : NULL; + return ppos.inRangeOf(o->getPosition(), DEFAULT_TILE_WIDTH * + TILES_TO_BE_NEAR) ? o : NULL; } return NULL; } diff --git a/src/game-server/map.hpp b/src/game-server/map.hpp index 54a61283..3d28430a 100644 --- a/src/game-server/map.hpp +++ b/src/game-server/map.hpp @@ -28,6 +28,8 @@ #include #include +const unsigned int DEFAULT_TILE_WIDTH = 32; +const unsigned int DEFAULT_TILE_HEIGHT = 32; struct PATH_NODE { PATH_NODE(unsigned short u, unsigned short v) -- cgit v1.2.3-60-g2f50