diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-09-02 12:50:40 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-09-02 12:50:40 +0000 |
commit | 3213f41daeed034c8aa9b8be9e86796737a38a78 (patch) | |
tree | 5441dd101209774d6e7c6612281b3ef12bd941a5 | |
parent | f5fc009543a0a189bcde5acf91ff315dd9cd05e9 (diff) | |
download | mana-client-3213f41daeed034c8aa9b8be9e86796737a38a78.tar.gz mana-client-3213f41daeed034c8aa9b8be9e86796737a38a78.tar.bz2 mana-client-3213f41daeed034c8aa9b8be9e86796737a38a78.tar.xz mana-client-3213f41daeed034c8aa9b8be9e86796737a38a78.zip |
Applied patch by Bernard Lidicky, adding targetting nearest monster with either
keyboard or mouse. Also made clicking beings in general a bit easier (patch
applied by Bjørn Lindeijer).
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | data/help/commands.txt | 1 | ||||
-rw-r--r-- | src/beingmanager.cpp | 25 | ||||
-rw-r--r-- | src/beingmanager.h | 17 | ||||
-rw-r--r-- | src/game.cpp | 12 | ||||
-rw-r--r-- | src/gui/gui.cpp | 16 | ||||
-rw-r--r-- | src/localplayer.h | 7 |
9 files changed, 82 insertions, 6 deletions
@@ -1,3 +1,11 @@ +2006-09-02 Bernard Lidicky <bernard@matfyz.cz> + + * src/game.cpp, src/beingmanager.h, src/gui/gui.cpp, + src/beingmanager.cpp, src/localplayer.h, README, + data/help/commands.txt, NEWS: Added targetting nearest monster with + either keyboard or mouse. Also made clicking beings in general a bit + easier (patch applied by Bjørn Lindeijer). + 2006-09-01 Eugenio Favalli <elvenprogrammer@gmail.com> * data/graphics/sprites/monster19.png, @@ -5,6 +5,7 @@ - Added option to turn off the joystick - Added --playername option for automatic character picking - Added --configfile option for specifying which configuration file to use +- Added shortcut and middle mouse button for targetting nearest monster - Fixed updating system on Windows - Fixed player animations going out of sync on changing equipment or hairstyle - Fixed SDL_image configure check on some systems by first checking for libpng @@ -53,6 +53,7 @@ Use arrow keys to move around. Other keys: - Alt + S sit down / stand up - Alt + F toggle debug pathfinding feature - Alt + P take screenshot +- A target nearest monster - H hide all non-sticky windows - G or Z pick up item - Enter focus chat window / send message diff --git a/data/help/commands.txt b/data/help/commands.txt index 37c77df2..ab93b54e 100644 --- a/data/help/commands.txt +++ b/data/help/commands.txt @@ -23,6 +23,7 @@ ##2Alt + S##P sit down / stand up ##2Alt + F##P toggle debug pathfinding feature ##2Alt + P##P take screenshot + ##2A##P target nearest monster ##2H##P hide all non-sticky windows ##2G or Z##P pick up item ##2Enter##P focus chat window / send message diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 25edeb24..027e08d3 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -159,3 +159,28 @@ void BeingManager::clear() mBeings.push_back(player_node); } } + +Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being::Type type) +{ + Being *closestBeing = NULL; + int dist = 0; + + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + Being *being = (*i); + int d = abs(being->mX - x) + abs(being->mY - y); + + if ((being->getType() == type || type == Being::UNKNOWN) + && (d < dist || closestBeing == NULL) // it is closer + && being->mAction != Being::DEAD // no dead beings + && being->mAction != Being::MONSTER_DEAD + ) + { + dist = d; + closestBeing = being; + } + } + + return (maxdist >= dist) ? closestBeing : NULL; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index cfaf7fbf..152fb640 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -49,26 +49,35 @@ class BeingManager void setPlayer(LocalPlayer *player); /** - * Create a being and add it to the list of beings + * Create a being and add it to the list of beings. */ Being* createBeing(Uint32 id, Uint16 job); /** - * Remove a Being + * Remove a Being. */ void destroyBeing(Being *being); /** - * Return a specific id Being + * Return a specific id Being. */ Being* findBeing(Uint32 id); /** - * Return a being at specific coordinates + * Return a being at specific coordinates. */ Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); /** + * Return a being nearest to specific coordinates. + * + * \param maxdist maximal distance. If minimal distance is larger, + * no being is returned + */ + Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being::Type type = Being::UNKNOWN); + + /** * Returns the whole list of beings */ Beings& getAll(); diff --git a/src/game.cpp b/src/game.cpp index ed8ad827..7921c388 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -686,6 +686,18 @@ void Game::handleInput() player_node->attack(target, newTarget); } + // Target the nearest monster if 'a' pressed + if (keys[SDLK_a]) + { + Being *target = + beingManager->findNearestLivingBeing(x, y, 20, Being::MONSTER); + + if (target) + { + player_node->setTarget(target); + } + } + if (joystick) { if (joystick->buttonPressed(1)) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index a0548e9c..6c46d636 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -280,7 +280,7 @@ Gui::mousePress(int mx, int my, int button) FloorItem *item; // Interact with some being - if ((being = beingManager->findBeing(tilex, tiley))) + if ((being = beingManager->findNearestLivingBeing(tilex, tiley, 1))) { switch (being->getType()) { @@ -317,6 +317,20 @@ Gui::mousePress(int mx, int my, int button) } } } + + if (button == gcn::MouseInput::MIDDLE) + { + // Find the being nearest to the clicked position + Being *target = beingManager->findNearestLivingBeing( + player_node->mX, + player_node->mY, + 20, Being::MONSTER); + + if (target) + { + player_node->setTarget(target); + } + } } void diff --git a/src/localplayer.h b/src/localplayer.h index 1f8c836f..a3fe91f7 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -99,12 +99,17 @@ class LocalPlayer : public Player * Sets the trading state of the player, i.e. whether or not he is * currently involved into some trade. */ - void setTrading(bool trading) { mTrading = trading; }; + void setTrading(bool trading) { mTrading = trading; } void attack(Being *target=NULL, bool keep=false); void stopAttack(); Being* getTarget() const; + /** + * Sets the target being of the player. + */ + void setTarget(Being* target) { mTarget = target; } + void walk(unsigned char dir); /** |