From abeecf1255d28a7870aef9f70dc3353d9b5f4f2d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 3 Aug 2016 20:03:30 +0300 Subject: Replace some ifs to switches. --- src/gui/viewport.cpp | 81 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 31 deletions(-) (limited to 'src/gui') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 485c93e44..8e43dd38f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -49,6 +49,8 @@ #include "input/inputmanager.h" +#include "utils/checkutils.h" + #include "resources/map/map.h" #include "resources/map/mapitem.h" #include "resources/map/speciallayer.h" @@ -432,44 +434,61 @@ bool Viewport::leftMouseAction() else { const ActorTypeT type = mHoverBeing->getType(); - if (type == ActorType::Player) - { - validateSpeed(); - if (actorManager) - { - if (localPlayer != mHoverBeing || mSelfMouseHeal) - actorManager->heal(mHoverBeing); - if (localPlayer == mHoverBeing && mHoverItem) - localPlayer->pickUp(mHoverItem); - return true; - } - } - else if (!stopAttack && - (type == ActorType::Monster || - type == ActorType::Npc || - type == ActorType::SkillUnit)) + switch (type) { - if ((localPlayer->withinAttackRange(mHoverBeing) || - inputManager.isActionActive(InputAction::ATTACK))) - { + case ActorType::Player: validateSpeed(); - if (!mStatsReUpdated && localPlayer != mHoverBeing) + if (actorManager) { - localPlayer->attack(mHoverBeing, - !inputManager.isActionActive( - InputAction::STOP_ATTACK)); + if (localPlayer != mHoverBeing || mSelfMouseHeal) + actorManager->heal(mHoverBeing); + if (localPlayer == mHoverBeing && mHoverItem) + localPlayer->pickUp(mHoverItem); return true; } - } - else if (!inputManager.isActionActive(InputAction::ATTACK)) - { - validateSpeed(); - if (!mStatsReUpdated && localPlayer != mHoverBeing) + break; + case ActorType::Monster: + case ActorType::Npc: + case ActorType::SkillUnit: + if (!stopAttack) { - localPlayer->setGotoTarget(mHoverBeing); - return true; + if ((localPlayer->withinAttackRange(mHoverBeing) || + inputManager.isActionActive(InputAction::ATTACK))) + { + validateSpeed(); + if (!mStatsReUpdated && localPlayer != mHoverBeing) + { + localPlayer->attack(mHoverBeing, + !inputManager.isActionActive( + InputAction::STOP_ATTACK)); + return true; + } + } + else if (!inputManager.isActionActive(InputAction::ATTACK)) + { + validateSpeed(); + if (!mStatsReUpdated && localPlayer != mHoverBeing) + { + localPlayer->setGotoTarget(mHoverBeing); + return true; + } + } } - } + break; + case ActorType::FloorItem: + case ActorType::Portal: + case ActorType::Pet: + case ActorType::Mercenary: + case ActorType::Homunculus: + case ActorType::Elemental: + break; + case ActorType::Unknown: + case ActorType::LocalPet: + case ActorType::Avatar: + default: + reportAlways("Left click on unknown actor type: %d", + CAST_S32(type)); + break; } } } -- cgit v1.2.3-60-g2f50