diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-03-23 22:41:21 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-03-23 22:41:21 +0000 |
commit | fa8b0a19084c0c2d369cda199b87c03fe838fa79 (patch) | |
tree | bee92807a496dcc2494d9fdfbf7afb59cbca736b /src | |
parent | 9dd811b55587aeb76344b835006cb4a01601bb5d (diff) | |
download | mana-client-fa8b0a19084c0c2d369cda199b87c03fe838fa79.tar.gz mana-client-fa8b0a19084c0c2d369cda199b87c03fe838fa79.tar.bz2 mana-client-fa8b0a19084c0c2d369cda199b87c03fe838fa79.tar.xz mana-client-fa8b0a19084c0c2d369cda199b87c03fe838fa79.zip |
Merged revisions 3828-3829,3831-3838,3841,3843-3844,3847-3872,3874,3876-3900 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0
........
r3828 | crush_tmw | 2007-12-31 17:14:27 +0100 (Mon, 31 Dec 2007) | 1 line
Added config options to set the scroll center. Retained scroll offset during map change for smoother map transitions.
........
r3859 | b_lindeijer | 2008-01-26 20:38:43 +0100 (Sat, 26 Jan 2008) | 3 lines
Fixed a GCC 4.3 compile error and constified the usage of auto_ptr, since
that's the way in which we are using them.
........
r3876 | crush_tmw | 2008-02-11 20:00:43 +0100 (Mon, 11 Feb 2008) | 1 line
Added music and overlay to snake dungeon.
........
r3883 | crush_tmw | 2008-02-12 15:00:22 +0100 (Tue, 12 Feb 2008) | 1 line
Particle emitters are now activated after the parent particle has moved instead of before (small change which allows a little trick to create polar emitters)
........
r3887 | umperio | 2008-02-12 20:49:37 +0100 (Tue, 12 Feb 2008) | 1 line
Made pathfinding not halt on collision destination tile, made moving around with mouse smoother. Added possibility to pass through players with key controls.
........
r3888 | crush_tmw | 2008-02-13 21:49:55 +0100 (Wed, 13 Feb 2008) | 1 line
Added new headgears by Black Don (thanks to QOAL for testing and implementation)
........
r3891 | umperio | 2008-02-18 09:52:06 +0100 (Mon, 18 Feb 2008) | 1 line
Fixed image name.
........
r3892 | umperio | 2008-02-18 11:00:45 +0100 (Mon, 18 Feb 2008) | 1 line
Forgot a %s
........
r3899 | crush_tmw | 2008-02-19 14:23:34 +0100 (Tue, 19 Feb 2008) | 1 line
Map fixes at snake dungeon by QOAL
........
r3900 | crush_tmw | 2008-02-19 14:32:24 +0100 (Tue, 19 Feb 2008) | 1 line
More map fixes at snake dungeon by QOAL
........
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 6 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/gui/trade.h | 1 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 59 | ||||
-rw-r--r-- | src/gui/viewport.h | 18 | ||||
-rw-r--r-- | src/localplayer.h | 4 | ||||
-rw-r--r-- | src/map.h | 19 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 15 | ||||
-rw-r--r-- | src/particle.cpp | 41 | ||||
-rw-r--r-- | src/player.h | 18 | ||||
-rw-r--r-- | src/sound.cpp | 3 | ||||
-rw-r--r-- | src/utils/strprintf.cpp | 2 |
12 files changed, 106 insertions, 82 deletions
diff --git a/src/being.cpp b/src/being.cpp index b187d28a..5a877d85 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -500,6 +500,12 @@ Being::nextStep() setDirection(dir); + if (!mMap->getWalk(node.x / 32, node.y / 32)) + { + setAction(STAND); + return; + } + setPositionInPixels(node.x, node.y); setAction(WALK); mWalkTime += mStepTime / 10; @@ -59,7 +59,7 @@ class Game : public ConfigListener /** The minimum frame time (used for frame limiting). */ int mMinFrameTime; - typedef std::auto_ptr<MessageHandler> MessageHandlerPtr; + typedef const std::auto_ptr<MessageHandler> MessageHandlerPtr; MessageHandlerPtr mBeingHandler; MessageHandlerPtr mBuySellHandler; MessageHandlerPtr mChatHandler; diff --git a/src/gui/trade.h b/src/gui/trade.h index b5b0db6a..cd943a41 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -92,7 +92,6 @@ class TradeWindow : public Window, gcn::ActionListener, SelectionListener void action(const gcn::ActionEvent &event); private: - enum Status { PREPARING, /**< Players are adding items. */ diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index d6c49fb2..7c68b577 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -52,8 +52,6 @@ Viewport::Viewport(): mMap(0), mViewX(0.0f), mViewY(0.0f), - mCameraX(0), - mCameraY(0), mShowDebugPath(false), mPlayerFollowMouse(false) { @@ -62,6 +60,8 @@ Viewport::Viewport(): mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); mScrollRadius = (int) config.getValue("ScrollRadius", 32); + mScrollCenterOffsetX = (int) config.getValue("ScrollCenterOffsetX", 0); + mScrollCenterOffsetY = (int) config.getValue("ScrollCenterOffsetY", 0); config.addListener("ScrollLaziness", this); config.addListener("ScrollRadius", this); @@ -150,8 +150,8 @@ Viewport::draw(gcn::Graphics *gcnGraphics) } // Calculate viewpoint - int midTileX = graphics->getWidth() / 2; - int midTileY = graphics->getHeight() / 2; + int midTileX = (graphics->getWidth() + mScrollCenterOffsetX) / 2; + int midTileY = (graphics->getHeight() + mScrollCenterOffsetX) / 2; int player_x = player_node->mX - midTileX + player_node->getXOffset(); int player_y = player_node->mY - midTileY + player_node->getYOffset(); @@ -211,19 +211,16 @@ Viewport::draw(gcn::Graphics *gcnGraphics) } } - mCameraX = (int) mViewX; - mCameraY = (int) mViewY; - // Draw tiles and sprites if (mMap) { - mMap->draw(graphics, mCameraX, mCameraY, 0); + mMap->draw(graphics, (int) mViewX, (int) mViewY, 0); drawTargetCursor(graphics); - mMap->draw(graphics, mCameraX, mCameraY, 1); - mMap->draw(graphics, mCameraX, mCameraY, 2); + mMap->draw(graphics, (int) mViewX, (int) mViewY, 1); + mMap->draw(graphics, (int) mViewX, (int) mViewY, 2); if (mShowDebugPath) { - mMap->drawCollision(graphics, mCameraX, mCameraY); + mMap->drawCollision(graphics, (int) mViewX, (int) mViewY); } mMap->drawOverlay(graphics, mViewX, mViewY, (int) config.getValue("OverlayDetail", 2)); @@ -239,9 +236,9 @@ Viewport::draw(gcn::Graphics *gcnGraphics) Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) { - (*i)->drawSpeech(graphics, -mCameraX, -mCameraY); - (*i)->drawName(graphics, -mCameraX, -mCameraY); - (*i)->drawEmotion(graphics, -mCameraX, -mCameraY); + (*i)->drawSpeech(graphics, -(int) mViewX, -(int) mViewY); + (*i)->drawName(graphics, -(int) mViewX, -(int) mViewY); + (*i)->drawEmotion(graphics, -(int) mViewX, -(int) mViewY); } // Draw contained widgets @@ -262,8 +259,8 @@ Viewport::logic() if (mPlayerFollowMouse && button & SDL_BUTTON(1) && mWalkTime != player_node->mWalkTime) { - player_node->setDestination(mouseX + mCameraX, - mouseY + mCameraY); + player_node->setDestination(mouseX + (int) mViewX, + mouseY + (int) mViewY); mWalkTime = player_node->mWalkTime; } @@ -301,9 +298,9 @@ Viewport::drawTargetCursor(Graphics *graphics) // Draw the target cursor at the correct position int posX = target->getPixelX() + 16 - - targetCursor->getWidth() / 2 - mCameraX; + targetCursor->getWidth() / 2 - (int) mViewX; int posY = target->getPixelY() + 16 - - targetCursor->getHeight() / 2 - mCameraY; + targetCursor->getHeight() / 2 - (int) mViewY; graphics->drawImage(targetCursor, posX, posY); } @@ -320,8 +317,8 @@ Viewport::drawTargetName(Graphics *graphics) graphics->setColor(gcn::Color(255, 32, 32)); const MonsterInfo &mi = static_cast<Monster*>(target)->getInfo(); - int posX = target->getPixelX() + 16 - mCameraX; - int posY = target->getPixelY() + 16 - target->getHeight() - mCameraY; + int posX = target->getPixelX() + 16 - (int) mViewX; + int posY = target->getPixelY() + 16 - target->getHeight() - (int) mViewY; graphics->drawText(mi.getName(), posX, posY, gcn::Graphics::CENTER); } @@ -334,8 +331,8 @@ Viewport::drawDebugPath(Graphics *graphics) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = (mouseX + mCameraX) / 32; - int mouseTileY = (mouseY + mCameraY) / 32; + const int mouseTileX = (mouseX + (int) mViewX) / 32; + const int mouseTileY = (mouseY + (int) mViewY) / 32; Path debugPath = mMap->findPath( player_node->mX / 32, player_node->mY / 32, @@ -344,8 +341,8 @@ Viewport::drawDebugPath(Graphics *graphics) graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) { - int squareX = i->x * 32 - mCameraX + 12; - int squareY = i->y * 32 - mCameraY + 12; + int squareX = i->x * 32 - (int) mViewX + 12; + int squareY = i->y * 32 - (int) mViewY + 12; graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); graphics->drawText( @@ -363,8 +360,8 @@ Viewport::mousePressed(gcn::MouseEvent &event) mPlayerFollowMouse = false; - int tilex = (event.getX() + mCameraX) / 32; - int tiley = (event.getY() + mCameraY) / 32; + const int tilex = (event.getX() + (int) mViewX) / 32; + const int tiley = (event.getY() + (int) mViewY) / 32; // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) @@ -403,14 +400,14 @@ Viewport::mousePressed(gcn::MouseEvent &event) player_node->pickUp(item); } // Just walk around - else if (mMap->getWalk(tilex, tiley, player_node->getWalkMask())) + else { // XXX XXX XXX REALLY UGLY! Uint8 *keys = SDL_GetKeyState(NULL); if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) { - player_node->setDestination(event.getX() + mCameraX, - event.getY() + mCameraY); + player_node->setDestination(event.getX() + (int) mViewX, + event.getY() + (int) mViewY); } mPlayerFollowMouse = true; } @@ -437,8 +434,8 @@ Viewport::mouseDragged(gcn::MouseEvent &event) if (mPlayerFollowMouse && mWalkTime == player_node->mWalkTime) { - player_node->setDestination(event.getX() + mCameraX, - event.getY() + mCameraY); + player_node->setDestination(event.getX() + (int) mViewX, + event.getY() + (int) mViewY); } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 1547c0a4..c8f7a9ec 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -117,16 +117,22 @@ class Viewport : public WindowContainer, public gcn::MouseListener, optionChanged(const std::string &name); /** - * Returns camera x offset in tiles. + * Returns camera x offset in pixels. */ int - getCameraX() { return mCameraX; } + getCameraX() const { return (int) mViewX; } /** - * Returns camera y offset in tiles. + * Returns camera y offset in pixels. */ int - getCameraY() { return mCameraY; } + getCameraY() const { return (int) mViewY; } + + /** + * Changes viewpoint by relative pixel coordinates. + */ + void + scrollBy(float x, float y) { mViewX += x; mViewY += y; } private: /** @@ -156,10 +162,10 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mScrollRadius; int mScrollLaziness; + int mScrollCenterOffsetX; + int mScrollCenterOffsetY; float mViewX; /**< Current viewpoint in pixels. */ float mViewY; /**< Current viewpoint in pixels. */ - int mCameraX; /**< Current viewpoint in tiles. */ - int mCameraY; /**< Current viewpoint in tiles. */ bool mShowDebugPath; /**< Show a path from player to pointer. */ /** Images of in range target cursor. */ diff --git a/src/localplayer.h b/src/localplayer.h index 9bad9436..f325e19a 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -26,6 +26,8 @@ #include "player.h" +#include <memory> + // TODO move into some sane place... #define MAX_SLOT 2 @@ -336,7 +338,7 @@ class LocalPlayer : public Player float mLastAttackTime; /**< Used to synchronize the charge dialog */ Inventory *mInventory; - std::auto_ptr<Equipment> mEquipment; + const std::auto_ptr<Equipment> mEquipment; protected: void walk(unsigned char dir); @@ -57,13 +57,13 @@ struct MetaTile MetaTile():whichList(0), blockmask(0) {}; // Pathfinding members - int Fcost; /**< Estimation of total path cost */ - int Gcost; /**< Cost from start to this location */ - int Hcost; /**< Estimated cost to goal */ - int whichList; /**< No list, open list or closed list */ - int parentX; /**< X coordinate of parent tile */ - int parentY; /**< Y coordinate of parent tile */ - unsigned char blockmask; /**< Can beings walk on this tile */ + int Fcost; /**< Estimation of total path cost */ + int Gcost; /**< Cost from start to this location */ + int Hcost; /**< Estimated cost to goal */ + int whichList; /**< No list, open list or closed list */ + int parentX; /**< X coordinate of parent tile */ + int parentY; /**< Y coordinate of parent tile */ + unsigned char blockmask; /**< Blocking properties of this tile */ }; /** @@ -153,9 +153,10 @@ class Map : public Properties void freeTile(int x, int y, BlockType type); /** - * Gets walkability for a tile with a blocking bitmask + * 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) const; + bool getWalk(int x, int y, char walkmask = BLOCKMASK_WALL) const; /** * Returns the width of this map. diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index b908eae5..ea581095 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -34,11 +34,13 @@ #include "../gui/buy.h" #include "../gui/chat.h" +#include "../gui/gui.h" #include "../gui/npclistdialog.h" #include "../gui/npc_text.h" #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" +#include "../gui/viewport.h" // TODO Move somewhere else OkDialog *weightNotice = NULL; @@ -289,9 +291,9 @@ void PlayerHandler::handleMessage(MessageIn &msg) void PlayerHandler::handleMapChangeMessage(MessageIn &msg) { - std::string mapName = msg.readString(); - unsigned short x = msg.readInt16(); - unsigned short y = msg.readInt16(); + const std::string mapName = msg.readString(); + const unsigned short x = msg.readInt16(); + const unsigned short y = msg.readInt16(); logger->log("Changing map to %s (%d, %d)", mapName.c_str(), x, y); @@ -300,6 +302,13 @@ PlayerHandler::handleMapChangeMessage(MessageIn &msg) current_npc = 0; + const float scrollOffsetX = x - player_node->mX; + const float scrollOffsetY = y - player_node->mY; + player_node->setAction(Being::STAND); player_node->setPositionInPixels(x, y); + + logger->log("Adjust scrolling by %d,%d", (int) scrollOffsetX, + (int) scrollOffsetY); + viewport->scrollBy(scrollOffsetX, scrollOffsetY); } diff --git a/src/particle.cpp b/src/particle.cpp index 11d91b47..dcb2eed3 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -96,26 +96,7 @@ Particle::update() if (mAlive) { - // Update child emitters - if (mLifetimePast%Particle::emitterSkip == 0) - { - for ( EmitterIterator e = mChildEmitters.begin(); - e != mChildEmitters.end(); - e++ - ) - { - Particles newParticles = (*e)->createParticles(); - for ( ParticleIterator p = newParticles.begin(); - p != newParticles.end(); - p++ - ) - { - (*p)->moveBy(mPos.x, mPos.y, mPos.z); - mChildParticles.push_back (*p); - } - } - } - + //calculate particle movement if (mMomentum != 1.0f) { mVelocity *= mMomentum; @@ -187,6 +168,26 @@ Particle::update() mAlive = false; } } + + // Update child emitters + if (mLifetimePast%Particle::emitterSkip == 0) + { + for ( EmitterIterator e = mChildEmitters.begin(); + e != mChildEmitters.end(); + e++ + ) + { + Particles newParticles = (*e)->createParticles(); + for ( ParticleIterator p = newParticles.begin(); + p != newParticles.end(); + p++ + ) + { + (*p)->moveBy(mPos.x, mPos.y, mPos.z); + mChildParticles.push_back (*p); + } + } + } } // Update child particles diff --git a/src/player.h b/src/player.h index 76d6b460..4949783e 100644 --- a/src/player.h +++ b/src/player.h @@ -101,34 +101,36 @@ class Player : public Being void removeGuild(int id); /** - * Returns a pointer to the specified guild + * Returns a pointer to the specified guild. */ Guild* getGuild(const std::string &guildName); /** - * Returns a pointer to the guild with matching id + * Returns a pointer to the guild with matching id. */ Guild* getGuild(int id); /** - * Get number of guilds the player belongs to + * Get number of guilds the player belongs to. */ short getNumberOfGuilds(); /** - * Gets the way the character is blocked by other objects + * 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 0x82; } // blocked by walls and monsters (bin 1000 0010) protected: - // Character guild information - std::map<int, Guild*> mGuilds; /** - * Gets the way the monster blocks pathfinding for other objects + * Gets the way the monster blocks pathfinding for other objects. */ virtual Map::BlockType getBlockType() const { return Map::BLOCKTYPE_CHARACTER; } + + // Character guild information + std::map<int, Guild*> mGuilds; + private: Gender mGender; Uint8 mHairStyle; diff --git a/src/sound.cpp b/src/sound.cpp index 063195ae..0a20d3f2 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -145,7 +145,8 @@ void Sound::playMusic(const std::string &filename, int loop) Mix_PlayMusic(mMusic, loop); } else { - logger->log("Sound::startMusic() Warning: error loading file."); + logger->log("Sound::startMusic() Warning: error loading file: %s", + Mix_GetError()); } } diff --git a/src/utils/strprintf.cpp b/src/utils/strprintf.cpp index 27dd5462..26313fe9 100644 --- a/src/utils/strprintf.cpp +++ b/src/utils/strprintf.cpp @@ -22,7 +22,7 @@ */ #ifndef _TMW_UTILS_TOSTRING_H -#define _TMW_UTISL_TOSTRING_H +#define _TMW_UTILS_TOSTRING_H #include <cstdarg> |