summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-17 17:45:19 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-17 17:48:39 +0200
commita500c675a87bf11e7d5980d208555002149d8ccc (patch)
tree12dfd4241c74517524dd5883957c7cf3042915d2
parentc911fa41d12dbb9f33d51977ba578e83bfdd3be4 (diff)
downloadmanaserv-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.
-rw-r--r--src/game-server/actor.cpp32
-rw-r--r--src/game-server/being.cpp37
-rw-r--r--src/game-server/character.cpp5
-rw-r--r--src/game-server/map.cpp4
-rw-r--r--src/game-server/map.hpp9
-rw-r--r--src/game-server/mapcomposite.cpp6
-rw-r--r--src/game-server/mapreader.cpp1
-rw-r--r--src/game-server/monster.cpp33
-rw-r--r--src/game-server/monstermanager.cpp2
-rw-r--r--src/game-server/state.cpp13
-rw-r--r--src/utils/speedconv.cpp2
11 files changed, 92 insertions, 52 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
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 39eaeb27..5fbd9a8b 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -192,16 +192,20 @@ void Being::setDestination(const Point &dst)
Path Being::findPath()
{
mOld = getPosition();
- int startX = mOld.x / 32, startY = mOld.y / 32;
- int destX = mDst.x / 32, destY = mDst.y / 32;
Map *map = getMap()->getMap();
+ int tileWidth = map->getTileWidth();
+ int tileHeight = map->getTileHeight();
+ int startX = mOld.x / tileWidth, startY = mOld.y / tileHeight;
+ int destX = mDst.x / tileWidth, destY = mDst.y / tileHeight;
+
return map->findPath(startX, startY, destX, destY, getWalkMask());
}
void Being::move()
{
// Immobile beings cannot move.
- if (!checkAttributeExists(ATTR_MOVE_SPEED_RAW) || !getModifiedAttribute(ATTR_MOVE_SPEED_RAW))
+ if (!checkAttributeExists(ATTR_MOVE_SPEED_RAW)
+ || !getModifiedAttribute(ATTR_MOVE_SPEED_RAW))
return;
mOld = getPosition();
@@ -213,8 +217,12 @@ void Being::move()
return;
}
- int tileSX = mOld.x / 32, tileSY = mOld.y / 32;
- int tileDX = mDst.x / 32, tileDY = mDst.y / 32;
+ Map *map = getMap()->getMap();
+ int tileWidth = map->getTileWidth();
+ int tileHeight = map->getTileHeight();
+ int tileSX = mOld.x / tileWidth, tileSY = mOld.y / tileHeight;
+ int tileDX = mDst.x / tileWidth, tileDY = mDst.y / tileHeight;
+
if (tileSX == tileDX && tileSY == tileDY)
{
if (mAction == WALK)
@@ -225,8 +233,6 @@ void Being::move()
return;
}
- Map *map = getMap()->getMap();
-
/* If no path exists, the for-loop won't be entered. Else a path for the
* current destination has already been calculated.
* The tiles in this path have to be checked for walkability,
@@ -279,9 +285,10 @@ void Being::move()
pos = mDst;
break;
}
- // position the actor in the middle of the tile for pathfinding purposes
- pos.x = next.x * 32 + 16;
- pos.y = next.y * 32 + 16;
+
+ // Position the actor in the middle of the tile for pathfinding purposes
+ pos.x = next.x * tileWidth + (tileWidth / 2);
+ pos.y = next.y * tileHeight + (tileHeight / 2);
}
while (mActionTime < 100);
setPosition(pos);
@@ -308,10 +315,11 @@ int Being::performAttack(Being *target, const Damage &damage) {
int Being::performAttack(Being *target, unsigned range, const Damage &damage)
{
// check target legality
- if (!target || target == this || target->getAction() == Being::DEAD || !target->canFight())
+ if (!target || target == this || target->getAction() == Being::DEAD
+ || !target->canFight())
return -1;
- if (getMap()->getPvP() == PVP_NONE && target->getType() == OBJECT_CHARACTER &&
- getType() == OBJECT_CHARACTER)
+ if (getMap()->getPvP() == PVP_NONE && target->getType() == OBJECT_CHARACTER
+ && getType() == OBJECT_CHARACTER)
return -1;
// check if target is in range using the pythagorean theorem
@@ -360,7 +368,8 @@ void Being::setAttribute(unsigned int id, double value, bool calc)
/*
* The attribute does not yet exist, so we must attempt to create it.
*/
- LOG_ERROR("Being: Attempt to access non-existing attribute '" << id << "'!");
+ LOG_ERROR("Being: Attempt to access non-existing attribute '"
+ << id << "'!");
LOG_WARN("Being: Creation of new attributes dynamically is not "
"implemented yet!");
}
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index b96bc6fe..1bb8ffa6 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -652,8 +652,11 @@ Character::~Character()
{
if (getMap())
{
+ Map *map = getMap()->getMap();
+ int tileWidth = map->getTileWidth();
+ int tileHeight = map->getTileHeight();
Point oldP = getPosition();
- getMap()->getMap()->freeTile(oldP.x / 32, oldP.y / 32, getBlockType());
+ map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, getBlockType());
}
}
diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp
index 147d5afa..e5af1c32 100644
--- a/src/game-server/map.cpp
+++ b/src/game-server/map.cpp
@@ -45,7 +45,7 @@ bool Location::operator< (const Location &loc) const
Map::Map(int width, int height, int twidth, int theight):
mWidth(width), mHeight(height),
- tileWidth(twidth), tileHeight(theight),
+ mTileWidth(twidth), mTileHeight(theight),
onClosedList(1), onOpenList(2)
{
mMetaTiles = new MetaTile[mWidth * mHeight];
@@ -142,7 +142,7 @@ void Map::freeTile(int x, int y, BlockType type)
mMetaTiles[tileNum].blockmask &= (BLOCKMASK_MONSTER xor 0xff);
break;
default:
- // shut up!
+ // nothing
break;
}
}
diff --git a/src/game-server/map.hpp b/src/game-server/map.hpp
index 6e70b519..fab5baaf 100644
--- a/src/game-server/map.hpp
+++ b/src/game-server/map.hpp
@@ -106,7 +106,8 @@ class Map
/**
* Constructor that takes initial map size as parameters.
*/
- Map(int width = 0, int height = 0, int twidth = 32, int theight = 32);
+ Map(int width = 0, int height = 0,
+ int twidth = DEFAULT_TILE_WIDTH, int theight = DEFAULT_TILE_HEIGHT);
/**
* Destructor.
@@ -159,13 +160,13 @@ class Map
* Returns the tile width of this map.
*/
int getTileWidth() const
- { return tileWidth; }
+ { return mTileWidth; }
/**
* Returns the tile height used by this map.
*/
int getTileHeight() const
- { return tileHeight; }
+ { return mTileHeight; }
/**
* Returns a general map property defined in the map file
@@ -204,7 +205,7 @@ class Map
// map properties
int mWidth, mHeight;
- int tileWidth, tileHeight;
+ int mTileWidth, mTileHeight;
std::map<std::string, std::string> mProperties;
// Pathfinding members
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index fa7a38c6..30d31bc7 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -334,8 +334,10 @@ MapContent::MapContent(Map *map)
{
buckets[i] = NULL;
}
- mapWidth = (map->getWidth() * 32 + zoneDiam - 1) / zoneDiam;
- mapHeight = (map->getHeight() * 32 + zoneDiam - 1) / zoneDiam;
+ mapWidth = (map->getWidth() * map->getTileWidth() + zoneDiam - 1)
+ / zoneDiam;
+ mapHeight = (map->getHeight() * map->getTileHeight() + zoneDiam - 1)
+ / zoneDiam;
zones = new MapZone[mapWidth * mapHeight];
}
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 94da287c..52dd08bf 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -120,7 +120,6 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
std::string pathDir = path.substr(0, path.rfind("/") + 1);
int w = XML::getProperty(node, "width", 0);
int h = XML::getProperty(node, "height", 0);
- // We only support tile width of 32 at the moment
int tilew = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH);
int tileh = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT);
Map* map = new Map(w, h, tilew, tileh);
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 91737ed1..2412c849 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -134,7 +134,10 @@ Monster::~Monster()
if (getMap())
{
Point oldP = getPosition();
- getMap()->getMap()->freeTile(oldP.x / 32, oldP.y / 32, getBlockType());
+ Map *map = getMap()->getMap();
+ int tileWidth = map->getTileWidth();
+ int tileHeight = map->getTileHeight();
+ map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, getBlockType());
}
}
@@ -349,18 +352,22 @@ int Monster::calculatePositionPriority(Point position, int targetPriority)
unsigned range = mSpecy->getTrackRange();
+ Map *map = getMap()->getMap();
+ int tileWidth = map->getTileWidth();
+ int tileHeight = map->getTileHeight();
+
// Check if we already are on this position
- if (thisPos.x / 32 == position.x / 32 &&
- thisPos.y / 32 == position.y / 32)
+ if (thisPos.x / tileWidth == position.x / tileWidth &&
+ thisPos.y / tileHeight == position.y / tileHeight)
{
return targetPriority *= range;
}
Path path;
- path = getMap()->getMap()->findPath(thisPos.x / 32, thisPos.y / 32,
- position.x / 32, position.y / 32,
- getWalkMask(),
- range);
+ path = map->findPath(thisPos.x / tileWidth, thisPos.y / tileHeight,
+ position.x / tileWidth, position.y / tileHeight,
+ getWalkMask(),
+ range);
if (path.empty() || path.size() >= range)
{
@@ -388,7 +395,8 @@ void Monster::forgetTarget(Thing *t)
void Monster::changeAnger(Actor *target, int amount)
{
- if (target && (target->getType() == OBJECT_MONSTER || target->getType() == OBJECT_CHARACTER))
+ if (target && (target->getType() == OBJECT_MONSTER
+ || target->getType() == OBJECT_CHARACTER))
{
Being *t = static_cast< Being * >(target);
if (mAnger.find(t) != mAnger.end())
@@ -415,16 +423,19 @@ int Monster::damage(Actor *source, const Damage &damage)
Character *s = static_cast< Character * >(source);
std::list<size_t>::const_iterator iSkill;
- for (iSkill = damage.usedSkills.begin(); iSkill != damage.usedSkills.end(); ++iSkill)
+ for (iSkill = damage.usedSkills.begin();
+ iSkill != damage.usedSkills.end(); ++iSkill)
{
if (*iSkill)
{
mExpReceivers[s].insert(*iSkill);
- if (!isTimerRunning(T_M_KILLSTEAL_PROTECTED) || mOwner == s || mOwner->getParty() == s->getParty())
+ if (!isTimerRunning(T_M_KILLSTEAL_PROTECTED) || mOwner == s
+ || mOwner->getParty() == s->getParty())
{
mOwner = s;
mLegalExpReceivers.insert(s);
- setTimerHard(T_M_KILLSTEAL_PROTECTED, KILLSTEAL_PROTECTION_TIME);
+ setTimerHard(T_M_KILLSTEAL_PROTECTED,
+ KILLSTEAL_PROTECTION_TIME);
}
}
}
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index d7540281..f59799c3 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -194,7 +194,7 @@ void MonsterManager::reload()
monster->setAggressive(true);
}
monster->setTrackRange(XML::getProperty(subnode, "track-range", 1));
- monster->setStrollRange(XML::getProperty(subnode, "stroll-range", 0) * 32);
+ monster->setStrollRange(XML::getProperty(subnode, "stroll-range", 0));
monster->setAttackDistance(XML::getProperty(subnode, "attack-distance", 0));
}
else if (xmlStrEqual(subnode->name, BAD_CAST "attack"))
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index ee7c95fd..6d0f68bc 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -109,7 +109,8 @@ static void serializeLooks(Character *ch, MessageOut &msg, bool full)
int changed = (1 << nb_slots) - 1;
if (!full)
{
- // TODO: do not assume the whole equipment changed, when an update is asked for.
+ // TODO: do not assume the whole equipment changed,
+ // when an update is asked for.
changed = (1 << nb_slots) - 1;
}
@@ -316,7 +317,8 @@ static void informPlayer(MapComposite *map, Character *p)
// We multiply the sent speed (in tiles per second) by ten
// to get it within a byte with decimal precision.
// For instance, a value of 4.5 will be sent as 45.
- moveMsg.writeByte((unsigned short) (o->getModifiedAttribute(ATTR_MOVE_SPEED_TPS) * 10));
+ moveMsg.writeByte((unsigned short)
+ (o->getModifiedAttribute(ATTR_MOVE_SPEED_TPS) * 10));
}
}
@@ -356,7 +358,8 @@ static void informPlayer(MapComposite *map, Character *p)
// Inform client about items on the ground around its character
MessageOut itemMsg(GPMSG_ITEMS);
- for (FixedActorIterator i(map->getAroundBeingIterator(p, visualRange)); i; ++i)
+ for (FixedActorIterator i(map->getAroundBeingIterator(p, visualRange)); i;
+ ++i)
{
assert((*i)->getType() == OBJECT_ITEM ||
(*i)->getType() == OBJECT_EFFECT);
@@ -529,8 +532,8 @@ bool GameState::insert(Thing *ptr)
Actor *obj = static_cast< Actor * >(ptr);
Map *mp = map->getMap();
Point pos = obj->getPosition();
- if (pos.x / 32 >= (unsigned)mp->getWidth() ||
- pos.y / 32 >= (unsigned)mp->getHeight())
+ if ((int)pos.x / mp->getTileWidth() >= mp->getWidth() ||
+ (int)pos.y / mp->getTileHeight() >= mp->getHeight())
{
LOG_ERROR("Tried to insert an actor at position " << pos.x << ','
<< pos.y << " outside map " << map->getID() << '.');
diff --git a/src/utils/speedconv.cpp b/src/utils/speedconv.cpp
index 14d328fd..18602abf 100644
--- a/src/utils/speedconv.cpp
+++ b/src/utils/speedconv.cpp
@@ -22,7 +22,7 @@
double utils::tpsToSpeed(double tps)
{
- return (32000 / (tps * DEFAULT_TILE_LENGTH));
+ return (32000 / (tps * DEFAULT_TILE_LENGTH));
}
double utils::speedToTps(double speed)