diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-02-19 11:09:00 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-02-19 11:09:00 -0700 |
commit | fcc8e48e96f017e4d7551ce7e686dd2e2a1bbcb9 (patch) | |
tree | d1a683e4145cfb78a56189fcdea7a99eddcb66d3 /src | |
parent | 35ea5c4f99dde984f9b22dd92699c24ac46dc718 (diff) | |
download | mana-fcc8e48e96f017e4d7551ce7e686dd2e2a1bbcb9.tar.gz mana-fcc8e48e96f017e4d7551ce7e686dd2e2a1bbcb9.tar.bz2 mana-fcc8e48e96f017e4d7551ce7e686dd2e2a1bbcb9.tar.xz mana-fcc8e48e96f017e4d7551ce7e686dd2e2a1bbcb9.zip |
Prevent target toggling when the button is held
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 52 | ||||
-rw-r--r-- | src/game.h | 2 |
2 files changed, 27 insertions, 27 deletions
diff --git a/src/game.cpp b/src/game.cpp index cc5121fd..fd89e085 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -276,7 +276,8 @@ Game::Game(Network *network): mNpcHandler(new NPCHandler), mPlayerHandler(new PlayerHandler), mSkillHandler(new SkillHandler), - mTradeHandler(new TradeHandler) + mTradeHandler(new TradeHandler), + mLastTarget(Being::UNKNOWN) { createGuiWindows(network); engine = new Engine(network); @@ -865,35 +866,32 @@ void Game::handleInput() player_node->attack(target, newTarget); } - // Target the nearest player if 'q' is pressed - if ( keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) - { - Being *target = beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER); - - player_node->setTarget(target); - } - - // Target the nearest monster if 'a' pressed - if ((keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || + // Target the nearest player/monster/npc + if ((keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) || + keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || + keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) || (joystick && joystick->buttonPressed(3))) && !keyboard.isKeyActive(keyboard.KEY_TARGET)) { - Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::MONSTER); - - player_node->setTarget(target); - } - - // Target the nearest npc if 'n' pressed - if ( keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) - { - Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); - - player_node->setTarget(target); - } + Being::Type currentTarget = Being::UNKNOWN; + if (keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER)) + currentTarget = Being::PLAYER; + else if (keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || + (joystick && joystick->buttonPressed(3))) + currentTarget = Being::MONSTER; + else if (keyboard.isKeyActive(keyboard.KEY_TARGET_NPC)) + currentTarget = Being::NPC; + + Being *target = beingManager->findNearestLivingBeing(player_node, + 20, currentTarget); + + if (target && (target != player_node->getTarget() || + currentTarget != mLastTarget)) + { + player_node->setTarget(target); + mLastTarget = currentTarget; + } + } else mLastTarget = Being::UNKNOWN; // Reset last target // Talk to the nearest NPC if 't' pressed if ( keyboard.isKeyActive(keyboard.KEY_TALK) ) @@ -65,6 +65,8 @@ class Game : public ConfigListener MessageHandlerPtr mPlayerHandler; MessageHandlerPtr mSkillHandler; MessageHandlerPtr mTradeHandler; + + int mLastTarget; }; /** |