diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-11 01:47:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-11 01:51:41 +0300 |
commit | a54f29e3313c2eb60369055731b0f50bd2ff20a3 (patch) | |
tree | 4d0c59fb180063f9e0933a2c6ee61bc387609d87 /src | |
parent | 9be7d0ac1127477a5ff5ffb3fb3dd45487eec213 (diff) | |
download | manaplus-a54f29e3313c2eb60369055731b0f50bd2ff20a3.tar.gz manaplus-a54f29e3313c2eb60369055731b0f50bd2ff20a3.tar.bz2 manaplus-a54f29e3313c2eb60369055731b0f50bd2ff20a3.tar.xz manaplus-a54f29e3313c2eb60369055731b0f50bd2ff20a3.zip |
Convert attack handling code to new format.
Diffstat (limited to 'src')
-rw-r--r-- | src/actionmanager.cpp | 72 | ||||
-rw-r--r-- | src/actionmanager.h | 5 | ||||
-rw-r--r-- | src/game.cpp | 83 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/gui/setup_input.cpp | 4 | ||||
-rw-r--r-- | src/inputmanager.cpp | 6 | ||||
-rw-r--r-- | src/inputmanager.h | 1 | ||||
-rw-r--r-- | src/keyboarddata.h | 26 | ||||
-rw-r--r-- | src/keydata.h | 2 |
9 files changed, 102 insertions, 99 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index bbfaf5430..b2df9967b 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -934,6 +934,9 @@ impHandler0(stopAttack) if (player_node) { player_node->stopAttack(); + // not consume if target attack key pressed + if (inputManager.isActionActive(Input::KEY_TARGET_ATTACK)) + return false; return true; } return false; @@ -949,4 +952,73 @@ impHandler0(untarget) return false; } +impHandler0(attack) +{ + if (player_node) + { + if (player_node->getTarget()) + player_node->attack(player_node->getTarget(), true); + return true; + } + return false; +} + +impHandler0(targetAttack) +{ + Being *target = nullptr; + + if (player_node && actorSpriteManager) + { + bool newTarget = !inputManager.isActionActive( + Input::KEY_STOP_ATTACK); + // A set target has highest priority + if (!player_node->getTarget()) + { + // Only auto target Monsters + target = actorSpriteManager->findNearestLivingBeing( + player_node, 90, ActorSprite::MONSTER); + } + else + { + target = player_node->getTarget(); + } + + player_node->attack2(target, newTarget); + return true; + } + return false; +} + +bool setTarget(ActorSprite::Type type); + +bool setTarget(ActorSprite::Type type) +{ + if (actorSpriteManager && player_node) + { + Being *target = actorSpriteManager->findNearestLivingBeing( + player_node, 20, type); + + if (target && target != player_node->getTarget()) + player_node->setTarget(target); + + return true; + } + return false; +} + +impHandler0(targetPlayer) +{ + return setTarget(ActorSprite::PLAYER); +} + +impHandler0(targetMonster) +{ + return setTarget(ActorSprite::MONSTER); +} + +impHandler0(targetNPC) +{ + return setTarget(ActorSprite::NPC); +} + } diff --git a/src/actionmanager.h b/src/actionmanager.h index 0950b4e3d..d474603da 100644 --- a/src/actionmanager.h +++ b/src/actionmanager.h @@ -87,6 +87,11 @@ namespace ActionManager decHandler(talk); decHandler(stopAttack); decHandler(untarget); + decHandler(attack); + decHandler(targetAttack); + decHandler(targetPlayer); + decHandler(targetMonster); + decHandler(targetNPC); decHandler(hideWindows); decHandler(helpWindowShow); diff --git a/src/game.cpp b/src/game.cpp index 68d637829..902411f69 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -709,7 +709,7 @@ void Game::resetAdjustLevel() mAdjustLevel = 0; } -void Game::handleMoveAndAttack() +void Game::handleMove() { // Moving player around if (player_node->isAlive() && !Being::isTalking() @@ -783,85 +783,6 @@ void Game::handleMoveAndAttack() viewport->moveCamera(dx, dy); } } - - bool joyAttack(false); - if (joystick && joystick->buttonPressed(0)) - joyAttack = true; - - if ((player_node->getFollow().empty() || joyAttack) && mValidSpeed) - { - // Attacking monsters - if (inputManager.isActionActive(Input::KEY_ATTACK)) - { - if (player_node->getTarget()) - player_node->attack(player_node->getTarget(), true); - } - - if ((inputManager.isActionActive(Input::KEY_TARGET_ATTACK) - || joyAttack) - /*&& !inputManager.isActionActive(Input::KEY_MOVE_TO_TARGET)*/ - ) - { - Being *target = nullptr; - - bool newTarget = !inputManager.isActionActive( - Input::KEY_STOP_ATTACK); - // A set target has highest priority - if (!player_node->getTarget()) - { - // Only auto target Monsters - target = actorSpriteManager->findNearestLivingBeing( - player_node, 90, ActorSprite::MONSTER); - } - else - { - target = player_node->getTarget(); - } - - player_node->attack2(target, newTarget); - } - } - - if (!inputManager.isActionActive(Input::KEY_EMOTE)) - { - // Target the nearest player/monster/npc - if ((inputManager.isActionActive(Input::KEY_TARGET_PLAYER) || - inputManager.isActionActive(Input::KEY_TARGET_CLOSEST) || - inputManager.isActionActive(Input::KEY_TARGET_NPC) || - (joystick && joystick->buttonPressed(3))) && - !inputManager.isActionActive(Input::KEY_STOP_ATTACK) && - !inputManager.isActionActive(Input::KEY_UNTARGET)) - { - ActorSprite::Type currentTarget = ActorSprite::UNKNOWN; - if (inputManager.isActionActive(Input::KEY_TARGET_CLOSEST) || - (joystick && joystick->buttonPressed(3))) - { - currentTarget = ActorSprite::MONSTER; - } - else if (inputManager.isActionActive(Input::KEY_TARGET_PLAYER)) - { - currentTarget = ActorSprite::PLAYER; - } - else if (inputManager.isActionActive(Input::KEY_TARGET_NPC)) - { - currentTarget = ActorSprite::NPC; - } - - Being *target = actorSpriteManager->findNearestLivingBeing( - player_node, 20, currentTarget); - - if (target && (target != player_node->getTarget() || - currentTarget != mLastTarget)) - { - player_node->setTarget(target); - mLastTarget = currentTarget; - } - } - else - { - mLastTarget = ActorSprite::UNKNOWN; // Reset last target - } - } } } @@ -967,7 +888,7 @@ void Game::handleInput() return; } - handleMoveAndAttack(); + handleMove(); } /** diff --git a/src/game.h b/src/game.h index 637c29c7a..7ff997809 100644 --- a/src/game.h +++ b/src/game.h @@ -78,7 +78,7 @@ class Game void handleInput(); - void handleMoveAndAttack(); + void handleMove(); void handleActive(SDL_Event &event); diff --git a/src/gui/setup_input.cpp b/src/gui/setup_input.cpp index f4d2f51e1..35badbe9c 100644 --- a/src/gui/setup_input.cpp +++ b/src/gui/setup_input.cpp @@ -111,8 +111,8 @@ static SetupActionData const setupActionData[] = Input::KEY_UNTARGET }, { - N_("Target Closest"), - Input::KEY_TARGET_CLOSEST + N_("Target monster"), + Input::KEY_TARGET_MONSTER }, { N_("Target NPC"), diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 12993c0cb..8a9e89995 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -521,7 +521,7 @@ int InputManager::getInputConditionMask() if (Game::instance()->getValidSpeed()) mask += COND_VALIDSPEED; - if (!gui->getFocusHandler()->getModalFocused()) + if (gui && !gui->getFocusHandler()->getModalFocused()) mask += COND_NOMODAL; NpcDialog *dialog = NpcDialog::getActive(); @@ -536,6 +536,10 @@ int InputManager::getInputConditionMask() { mask += COND_NOTARGET; } + + if (!player_node || player_node->getFollow().empty()) + mask += COND_NOFOLLOW; + return mask; } diff --git a/src/inputmanager.h b/src/inputmanager.h index b95233f2d..0738fbebb 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -73,6 +73,7 @@ enum KeyCondition COND_NONPCINPUT = 128, // npc input field inactive COND_EMODS = 256, // game modifiers enabled COND_NOTARGET = 512, // no target/untarget keys pressed + COND_NOFOLLOW = 1024, // follow mode disabled COND_SHORTCUT = 2 + 4 + 16 + 512, // flags for shortcut keys COND_GAME = 2 + 4 + 8 + 16 + 64, // main game key COND_GAME2 = 2 + 8 + 16 + 64 diff --git a/src/keyboarddata.h b/src/keyboarddata.h index d1b77f3ea..46a442d1d 100644 --- a/src/keyboarddata.h +++ b/src/keyboarddata.h @@ -67,16 +67,16 @@ static KeyData const keyData[Input::KEY_TOTAL] = { INPUT_KEYBOARD, SDLK_LCTRL, INPUT_UNKNOWN, Input::KEY_NO_VALUE, Input::GRP_DEFAULT, - nullptr, + &ActionManager::attack, Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, + COND_GAME | COND_NOFOLLOW | COND_VALIDSPEED}, {"keyTargetAttack", INPUT_KEYBOARD, SDLK_x, - INPUT_UNKNOWN, Input::KEY_NO_VALUE, + INPUT_JOYSTICK, 0, Input::GRP_DEFAULT, - nullptr, + &ActionManager::targetAttack, Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, + COND_GAME | COND_NOFOLLOW | COND_VALIDSPEED}, {"keyMoveToTarget", INPUT_KEYBOARD, SDLK_v, INPUT_UNKNOWN, Input::KEY_NO_VALUE, @@ -133,27 +133,27 @@ static KeyData const keyData[Input::KEY_TOTAL] = { &ActionManager::untarget, Input::KEY_NO_VALUE, 50, COND_GAME}, - {"keyTargetClosest", + {"keyTargetMonster", INPUT_KEYBOARD, SDLK_a, - INPUT_UNKNOWN, Input::KEY_NO_VALUE, + INPUT_JOYSTICK, 0, Input::GRP_DEFAULT, - nullptr, + &ActionManager::targetMonster, Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, + COND_GAME | COND_NOTARGET}, {"keyTargetNPC", INPUT_KEYBOARD, SDLK_n, INPUT_UNKNOWN, Input::KEY_NO_VALUE, Input::GRP_DEFAULT, - nullptr, + &ActionManager::targetNPC, Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, + COND_GAME | COND_NOTARGET}, {"keyTargetPlayer", INPUT_KEYBOARD, SDLK_q, INPUT_UNKNOWN, Input::KEY_NO_VALUE, Input::GRP_DEFAULT, - nullptr, + &ActionManager::targetPlayer, Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, + COND_GAME | COND_NOTARGET}, {"keyPickup", INPUT_KEYBOARD, SDLK_z, INPUT_JOYSTICK, 1, diff --git a/src/keydata.h b/src/keydata.h index 5351b715f..50bfb2d2f 100644 --- a/src/keydata.h +++ b/src/keydata.h @@ -78,7 +78,7 @@ namespace Input KEY_TALK, KEY_STOP_ATTACK, KEY_UNTARGET, - KEY_TARGET_CLOSEST, + KEY_TARGET_MONSTER, KEY_TARGET_NPC, KEY_TARGET_PLAYER, KEY_PICKUP, |