diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-06-08 23:10:13 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-06-08 23:10:13 +0200 |
commit | 420e770c619c23e6bff94260bb260d289e769534 (patch) | |
tree | 58c3c464db0a3ad3cbeb835e0c52911de816e8d2 | |
parent | 8596b1a8102726de0d7b3df12dff86f5c974e6fe (diff) | |
parent | 2a60ed3f85004c872eb9d0ae39d4aa1c47626543 (diff) | |
download | mana-420e770c619c23e6bff94260bb260d289e769534.tar.gz mana-420e770c619c23e6bff94260bb260d289e769534.tar.bz2 mana-420e770c619c23e6bff94260bb260d289e769534.tar.xz mana-420e770c619c23e6bff94260bb260d289e769534.zip |
Merge branch '0.0.29'
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/map.cpp | 35 | ||||
-rw-r--r-- | src/map.h | 20 | ||||
-rw-r--r-- | src/monster.h | 6 | ||||
-rw-r--r-- | src/npc.h | 6 | ||||
-rw-r--r-- | src/player.h | 2 |
6 files changed, 55 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp index 86008d7f..3ea8aa2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -940,7 +940,7 @@ int main(int argc, char *argv[]) setupButton->setPosition(top->getWidth() - setupButton->getWidth() - 3, 3); top->add(setupButton); - sound.playMusic(branding.getValue("loginMusic", "Login.ogg")); + sound.playMusic(branding.getValue("loginMusic", "Magick - Real.ogg")); // Initialize login data loginData.hostname = options.serverName; diff --git a/src/map.cpp b/src/map.cpp index f0a5eae0..4e12ac97 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -407,7 +407,7 @@ void Map::blockTile(int x, int y, BlockType type) if (type == BLOCKTYPE_NONE || !contains(x, y)) return; - int tileNum = x + y * mWidth; + const int tileNum = x + y * mWidth; if ((++mOccupation[type][tileNum]) > 0) { @@ -429,7 +429,7 @@ void Map::blockTile(int x, int y, BlockType type) } } -bool Map::getWalk(int x, int y, char walkmask) const +bool Map::getWalk(int x, int y, unsigned char walkmask) const { // You can't walk outside of the map if (!contains(x, y)) @@ -439,6 +439,23 @@ bool Map::getWalk(int x, int y, char walkmask) const return !(mMetaTiles[x + y * mWidth].blockmask & walkmask); } +#ifdef EATHENA_SUPPORT +bool Map::occupied(int x, int y) const +{ + const Beings &beings = beingManager->getAll(); + for (Beings::const_iterator i = beings.begin(); i != beings.end(); i++) + { + const Being *being = *i; + + // job 45 is a portal, they don't collide + if (being->mX == x && being->mY == y && being->mJob != 45) + return true; + } + + return false; +} +#endif + bool Map::contains(int x, int y) const { return x >= 0 && y >= 0 && x < mWidth && y < mHeight; @@ -475,7 +492,8 @@ const std::string &Map::getName() const static int const basicCost = 100; -Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost) +Path Map::findPath(int startX, int startY, int destX, int destY, + unsigned char walkmask, int maxCost) { // Path to be built up (empty by default) Path path; @@ -533,7 +551,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char w // Skip if the tile is on the closed list or is not walkable // unless its the destination tile if (newTile->whichList == mOnClosedList || - ((newTile->blockmask & walkmask) && !(x == destX && y == destY))) + ((newTile->blockmask & walkmask) + && !(x == destX && y == destY))) { continue; } @@ -545,10 +564,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char w MetaTile *t1 = getMetaTile(curr.x, curr.y + dy); MetaTile *t2 = getMetaTile(curr.x + dx, curr.y); - if (t1->blockmask & walkmask && !(t2->blockmask & walkmask)) // I hope I didn't fuck this line up - { + if ((t1->blockmask | t2->blockmask) & BLOCKMASK_WALL) continue; - } } // Calculate G cost for this route, ~sqrt(2) for moving diagonal @@ -569,12 +586,14 @@ Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char w ++Gcost; } +#ifdef EATHENA_SUPPORT // It costs extra to walk through a being (needs to be enough // to make it more attractive to walk around). - if (!getWalk(x, y, BLOCKMASK_CHARACTER | BLOCKMASK_MONSTER)) + if (occupied(x, y)) { Gcost += 3 * basicCost; } +#endif // Skip if Gcost becomes too much // Warning: probably not entirely accurate @@ -152,6 +152,13 @@ class Map : public Properties NB_BLOCKTYPES }; + enum BlockMask + { + BLOCKMASK_WALL = 0x80, // = bin 1000 0000 + BLOCKMASK_CHARACTER = 0x01, // = bin 0000 0001 + BLOCKMASK_MONSTER = 0x02 // = bin 0000 0010 + }; + /** * Constructor, taking map and tile size as parameters. */ @@ -217,7 +224,15 @@ class Map : public Properties * Gets walkability for a tile with a blocking bitmask. When called * without walkmask, only blocks against colliding tiles. */ - bool getWalk(int x, int y, char walkmask = BLOCKMASK_WALL) const; + bool getWalk(int x, int y, + unsigned char walkmask = BLOCKMASK_WALL) const; + +#ifdef EATHENA_SUPPORT + /** + * Tells whether a tile is occupied by a being. + */ + bool occupied(int x, int y) const; +#endif /** * Returns the width of this map in tiles. @@ -294,9 +309,6 @@ class Map : public Properties /** * Blockmasks for different entities */ - static const unsigned char BLOCKMASK_WALL = 0x80; // = bin 1000 0000 - static const unsigned char BLOCKMASK_CHARACTER = 0x01;// = bin 0000 0001 - static const unsigned char BLOCKMASK_MONSTER = 0x02; // = bin 0000 0010 int *mOccupation[NB_BLOCKTYPES]; int mWidth, mHeight; diff --git a/src/monster.h b/src/monster.h index bf52ed6d..7b44b5a8 100644 --- a/src/monster.h +++ b/src/monster.h @@ -82,7 +82,11 @@ class Monster : public Being * Gets the way the monster is blocked by other objects */ virtual unsigned char getWalkMask() const - { return 0x83; } // blocked by walls, other monsters and players ( bin 1000 0011) + { + return Map::BLOCKMASK_WALL + | Map::BLOCKMASK_CHARACTER + | Map::BLOCKMASK_MONSTER; + } protected: /** @@ -46,7 +46,11 @@ class NPC : public Player * Gets the way an NPC is blocked by other things on the map */ virtual unsigned char getWalkMask() const - { return 0x83; } // blocked like a monster by walls, monsters and characters ( bin 1000 0011) + { + return Map::BLOCKMASK_WALL + | Map::BLOCKMASK_CHARACTER + | Map::BLOCKMASK_MONSTER; + } static bool isTalking; diff --git a/src/player.h b/src/player.h index bb44f462..9a5c6c94 100644 --- a/src/player.h +++ b/src/player.h @@ -132,7 +132,7 @@ class Player : public Being * Gets the way the character is blocked by other objects. */ virtual unsigned char getWalkMask() const - { return 0x82; } // blocked by walls and monsters (bin 1000 0010) + { return Map::BLOCKMASK_WALL | Map::BLOCKMASK_MONSTER; } /** * Called when a option (set with config.addListener()) is changed |