From 052cdbd8fce689b64371da82409bfd4e0f189f45 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 31 Oct 2008 23:01:23 +0000 Subject: Merged revisions 4071,4093,4100,4363 via svnmerge from https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r4071 | the_enemy | 2008-04-11 16:12:30 +0200 (Fri, 11 Apr 2008) | 3 lines Players now need to click on the monster sprites rather than the tile. Players will now move to the target before attacking it. ........ r4093 | the_enemy | 2008-04-15 18:10:32 +0200 (Tue, 15 Apr 2008) | 1 line Fixed clicking near player. ........ r4100 | peaveydk | 2008-04-16 13:59:36 +0200 (Wed, 16 Apr 2008) | 1 line Cancel walking to a clicked monster if the target is lost while getting to it (killed or otherwise removed). ........ r4363 | crush_tmw | 2008-06-24 14:42:04 +0200 (Tue, 24 Jun 2008) | 1 line corrected date in changelog ........ --- src/localplayer.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index fce9506a..fe3f1f45 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -66,8 +66,9 @@ LocalPlayer::LocalPlayer(): mTotalWeight(1), mMaxWeight(1), mHP(1), mMaxHP(1), mTarget(NULL), mPickUpTarget(NULL), - mTrading(false), - mLastAction(-1), mWalkingDir(0), + mTrading(false), mGoingToTarget(false), + mLastAction(-1), + mWalkingDir(0), mDestX(0), mDestY(0), mLocalWalkTime(-1), mExpMessageTime(0) @@ -122,6 +123,21 @@ void LocalPlayer::nextStep() walk(mWalkingDir); } } + + // TODO: Fix automatically walking within range of target, when wanted + if (mGoingToTarget && mTarget && withinAttackRange(mTarget)) + { + mAction = Being::STAND; + //attack(mTarget, true); + mGoingToTarget = false; + mPath.clear(); + return; + } + else if (mGoingToTarget && !mTarget) + { + mGoingToTarget = false; + mPath.clear(); + } } bool LocalPlayer::checkInviteRights(const std::string &guildName) @@ -541,12 +557,29 @@ std::pair LocalPlayer::getExperience(int skill) int LocalPlayer::getAttackRange() { Item *weapon = mEquipment->getEquipment(EQUIP_FIGHT1_SLOT); - if(weapon) + if (weapon) { const ItemInfo info = weapon->getInfo(); return info.getAttackRange(); } - return 32; //unarmed range - + return 32; // unarmed range } +bool LocalPlayer::withinAttackRange(Being *target) +{ + const Vector &targetPos = target->getPosition(); + const Vector &pos = getPosition(); + const int dx = abs(targetPos.x - pos.x); + const int dy = abs(targetPos.y - pos.y); + const int range = getAttackRange(); + + return !(dx > range || dy > range); +} + +void LocalPlayer::setGotoTarget(Being *target) +{ + mTarget = target; + mGoingToTarget = true; + const Vector &targetPos = target->getPosition(); + setDestination(targetPos.x, targetPos.y); +} -- cgit v1.2.3-70-g09d2