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 ........ --- ChangeLog | 17 ++++++++++++++--- src/beingmanager.cpp | 22 ++++++++++++++++++++++ src/beingmanager.h | 1 + src/effectmanager.cpp | 14 ++++++-------- src/gui/viewport.cpp | 8 +++++--- src/localplayer.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- src/localplayer.h | 11 +++++++++++ src/resources/iteminfo.h | 2 +- 8 files changed, 98 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 94b3644e..307bca84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2008-10-27 David Athay - * src/commandhandler.cpp: Remove check command, now there is an NPC for - checking for post. + * src/commandhandler.cpp: Remove check command, now there is an NPC + for checking for post. 2008-10-27 Chuck Miller @@ -9,7 +9,7 @@ src/net/effecthandler.cpp: Added a handler for handling effects sent from the server, you'll need the latest server patch for them too work * src/effectmanager.cpp: Removed some debugging code left in by - mistake + mistake. 2008-10-26 Chuck Miller @@ -614,6 +614,8 @@ * src/gui/browserbox.cpp: Fix a basic_string::at sometimes being out of range in BrowserBox::draw when checking for color codes. + * src/localplayer.cpp: Cancel walking to a clicked monster if the + target is lost while getting to it (killed or otherwise removed). 2008-04-15 David Athay @@ -625,6 +627,8 @@ src/Makefile.am, data/graphics/gui/circle-green.png data/graphics/gui/circle-gray.png, tmw.cbp: Added online status of guild members. + * src/gui/viewport.cpp, src/beingmanager.cpp, tmw.cbp: Fixed clicking + near player. 2008-04-14 Yohann Ferreira @@ -659,6 +663,13 @@ src/gui/scrollarea.cpp, src/gui/itemshortcutwindow.h: Fixed display of item shortcut container. gcn::Widget::setWidth is no longer virtual. +2008-04-11 David Athay + + * src/localplayer.cpp, src/beingmanager.h, src/gui/viewport.cpp, + src/beingmanager.cpp, src/localplayer.h, tmw.cbp: Players now need to + click on the monster sprites rather than the tile. Players will now + move to the target before attacking it. + 2008-04-09 Bjørn Lindeijer * src/gui/shoplistbox.cpp, src/gui/shoplistbox.h: Fixed problem with diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 2ab29fd2..40f438df 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -117,6 +117,28 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } +Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) +{ + BeingIterator itr = mBeings.begin(); + BeingIterator itr_end = mBeings.end(); + + for (; itr != itr_end; ++itr) + { + Being *being = (*itr); + if ((being->mAction != Being::DEAD) && + (being != player_node) && + (being->getPixelX() <= x) && + (being->getPixelX() + being->getWidth() >= x) && + (being->getPixelY() <= y) && + (being->getPixelY() + being->getHeight() >= y)) + { + return being; + } + } + + return NULL; +} + Beings& BeingManager::getAll() { return mBeings; diff --git a/src/beingmanager.h b/src/beingmanager.h index 6792ed0e..f7a3b8f0 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -64,6 +64,7 @@ class BeingManager * Returns a being at specific coordinates. */ Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + Being* findBeingByPixel(Uint16 x, Uint16 y); /** * Returns a being nearest to specific coordinates. diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index bb8b5733..87d98834 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -42,12 +42,10 @@ EffectManager::EffectManager() else { logger->log("Effects are now loading"); - } + } for_each_xml_child_node(node, root) { - int id; - if (xmlStrEqual(node->name, BAD_CAST "effect")) { EffectDescription ed; @@ -61,22 +59,22 @@ EffectManager::EffectManager() EffectManager::~EffectManager() { - } bool EffectManager::trigger(int id, int x, int y) { bool rValue = false; - for (std::list::iterator i = mEffects.begin(); i != mEffects.end(); ++i) + for (std::list::iterator i = mEffects.begin(); + i != mEffects.end(); ++i) { if ((*i).id == id) { rValue = true; - if((*i).GFX != "") + if ((*i).GFX != "") particleEngine->addEffect((*i).GFX, x, y); - if((*i).SFX != "") + if ((*i).SFX != "") sound.playSfx((*i).SFX); - break; + break; } } return rValue; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index d086418f..9671e34f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -370,8 +370,10 @@ void Viewport::mousePressed(gcn::MouseEvent &event) mPlayerFollowMouse = false; - const int tilex = (event.getX() + (int) mViewX) / 32; - const int tiley = (event.getY() + (int) mViewY) / 32; + const int pixelx = event.getX() + (int) mViewX; + const int pixely = event.getY() + (int) mViewY; + const int tilex = pixelx / mMap->getTileWidth(); + const int tiley = pixely / mMap->getTileHeight(); // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) @@ -379,7 +381,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) Being *being; FloorItem *floorItem; - if ((being = beingManager->findBeing(tilex, tiley)) && + if ((being = beingManager->findBeingByPixel(tilex, tiley)) && being != player_node) { mPopupMenu->showPopup(event.getX(), event.getY(), being); 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); +} diff --git a/src/localplayer.h b/src/localplayer.h index 7a5158cc..b44ac14a 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -257,6 +257,16 @@ class LocalPlayer : public Player int getWalkingDir() const { return mWalkingDir; } + /** + * Sets going to being to attack + */ + void setGotoTarget(Being *target); + + /** + * Returns whether the target is in range to attack + */ + bool withinAttackRange(Being *target); + /** * Stops the player dead in his tracks */ @@ -377,6 +387,7 @@ class LocalPlayer : public Player FloorItem *mPickUpTarget; bool mTrading; + bool mGoingToTarget; int mLastAction; /**< Time stamp of the last action, -1 if none. */ int mWalkingDir; /**< The direction the player is walking in. */ int mDestX; /**< X coordinate of destination. */ diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index a8e9f2e4..5b500dcf 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -64,7 +64,7 @@ enum EquipmentSlot EQUIP_FIGHT2_SLOT = 9, // Projectile: // this item does not amount to one, it only indicates the chosen projectile. - EQUIP_PROJECTILE_SLOT = 10, + EQUIP_PROJECTILE_SLOT = 10 }; -- cgit v1.2.3-60-g2f50