diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-30 00:02:14 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-30 00:02:14 +0000 |
commit | 8d4dc1c28ee54f67c155b6759cf5776a917904ff (patch) | |
tree | ecf910e7214008c9a89f9d1bded37a8057abe1f2 | |
parent | 8e28cc3ac0f679cf35bc6a9ce1740ac7ae4aac47 (diff) | |
download | mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.tar.gz mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.tar.bz2 mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.tar.xz mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.zip |
Added a key for targeting the nearest player character based on patches by Trinexx. Some mapping fixes at snake dungeon map.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/beingmanager.cpp | 27 | ||||
-rw-r--r-- | src/beingmanager.h | 9 | ||||
-rw-r--r-- | src/game.cpp | 13 | ||||
-rw-r--r-- | src/keyboardconfig.cpp | 1 | ||||
-rw-r--r-- | src/keyboardconfig.h | 1 |
6 files changed, 58 insertions, 0 deletions
@@ -1,3 +1,10 @@ +2007-12-30 Philipp Sehmisch <tmw@crushnet.org> + + * data/maps/new_22-1.tmx: Some mapping fixes at snake dungeon map. + * src/game.cpp, src/beingmanager.cpp, src/beingmanager.h, + src/keyboardconfig.cpp, src/keyboardconfig.h: Added a key for targeting + the nearest player character based on patches by Trinexx. + 2007-12-28 Philipp Sehmisch <tmw@crushnet.org> * data/maps/new_7-1.tmx, data/maps/new_22-1.tmx: Added new map by 5t3v3 diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index f35a305d..daceca5e 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -188,3 +188,30 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being::Type type) +{ + Being *closestBeing = NULL; + int dist = 0; + int x = aroundBeing->mX; + int y = aroundBeing->mY; + + 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 != aroundBeing + ) + { + dist = d; + closestBeing = being; + } + } + + return (maxdist >= dist) ? closestBeing : NULL; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 152fb640..a9d0db35 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -78,6 +78,15 @@ class BeingManager Being::Type type = Being::UNKNOWN); /** + * Return a being nearest to another being. + * + * \param maxdist maximal distance. If minimal distance is larger, + * no being is returned + */ + Being* findNearestLivingBeing(Being *aroundBeing, 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 b3fa6f07..52d70bc0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -770,6 +770,19 @@ void Game::handleInput() player_node->attack(target, newTarget); } + // Target the nearest player if 'q' is pressed + if ( keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) ) + //if (keys[SDLK_q]) + { + Being *target = + beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER); + + if (target) + { + player_node->setTarget(target); + } + } + // Target the nearest monster if 'a' pressed if ( keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) ) //if (keys[SDLK_a]) diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 271961c8..a959e244 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -45,6 +45,7 @@ static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = { {"keyAttack", SDLK_LCTRL, "Attack"}, {"keyTarget", SDLK_LSHIFT, "Target"}, {"keyTargetClosest", SDLK_a, "Target Closest"}, + {"keyTargetPlayer", SDLK_q, "Target Player"}, {"keyPickup", SDLK_z, "Pickup"}, {"keyHideWindows", SDLK_h, "Hide Windows"}, {"keyBeingSit", SDLK_s, "Sit"}, diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index 46394fa5..53a5c96d 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -153,6 +153,7 @@ class KeyboardConfig KEY_ATTACK, KEY_TARGET, KEY_TARGET_CLOSEST, + KEY_TARGET_PLAYER, KEY_PICKUP, KEY_HIDE_WINDOWS, KEY_SIT, |