From 218ad29dc13b1b89da9804dec15f32692d8709d6 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 27 Oct 2008 04:23:43 +0000 Subject: Made targets draw on the fringe layer, as well as added t for talking to an NPC, n for targeting an NPC, and changed basic targeting code so that it'll time out after being on a target for longer than a minute. --- src/being.h | 1 - src/game.cpp | 29 ++++++++++++++++++++++++----- src/gui/viewport.cpp | 3 --- src/keyboardconfig.cpp | 2 ++ src/keyboardconfig.h | 2 ++ src/localplayer.cpp | 23 ++++++++++++++++++++--- src/localplayer.h | 1 + src/map.cpp | 2 ++ src/particle.cpp | 6 ++---- 9 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/being.h b/src/being.h index 1eeeb9db..a2d5e5a7 100644 --- a/src/being.h +++ b/src/being.h @@ -393,7 +393,6 @@ class Being : public Sprite std::string mName; /**< Name of character */ SpriteIterator mSpriteIterator; bool mIsGM; - bool mTargeted; bool mParticleEffects; /**< Whether to display particles or not */ /** Engine-related infos about weapon. */ diff --git a/src/game.cpp b/src/game.cpp index 5e7ee1e8..2fc23a53 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -830,10 +830,7 @@ void Game::handleInput() { Being *target = beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER); - if (target) - { - player_node->setTarget(target); - } + player_node->setTarget(target); } // Target the nearest monster if 'a' pressed @@ -841,9 +838,31 @@ void Game::handleInput() { 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) ) + { + Being *target = beingManager->findNearestLivingBeing(x, y, 20, Being::NPC); + + player_node->setTarget(target); + } + + // Talk to the nearest NPC if 't' pressed + if ( keyboard.isKeyActive(keyboard.KEY_TALK) ) + { + Being *target = player_node->getTarget(); + + if (!target) + { + target = beingManager->findNearestLivingBeing(x, y, 20, Being::NPC); + } + if (target) { - player_node->setTarget(target); + if (target->getType() == Being::NPC) + dynamic_cast(target)->talk(); } } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 7f420e0a..426906a0 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -28,7 +28,6 @@ #include "gui.h" #include "popupmenu.h" -#include "../simpleanimation.h" #include "../beingmanager.h" #include "../configuration.h" #include "../flooritemmanager.h" @@ -174,8 +173,6 @@ Viewport::draw(gcn::Graphics *gcnGraphics) if (mMap) { mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); - player_node->drawTargetCursor(graphics, (int) mPixelViewX, (int) mPixelViewY); - // Find a path from the player to the mouse, and draw it. This is for debug // purposes. diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 9f558883..6694e5e2 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -44,8 +44,10 @@ static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = { {"keyMoveRight", SDLK_RIGHT, "Move Right"}, {"keyAttack", SDLK_LCTRL, "Attack"}, {"keySmilie", SDLK_LALT, "Smilie"}, + {"keyTalk", SDLK_t, "Talk"}, {"keyTarget", SDLK_LSHIFT, "Target"}, {"keyTargetClosest", SDLK_a, "Target Closest"}, + {"keyTargetNPC", SDLK_n, "Target NPC"}, {"keyTargetPlayer", SDLK_q, "Target Player"}, {"keyPickup", SDLK_z, "Pickup"}, {"keyHideWindows", SDLK_h, "Hide Windows"}, diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index b57136dc..a4329b09 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -152,8 +152,10 @@ class KeyboardConfig KEY_MOVE_RIGHT, KEY_ATTACK, KEY_SMILIE, + KEY_TALK, KEY_TARGET, KEY_TARGET_CLOSEST, + KEY_TARGET_NPC, KEY_TARGET_PLAYER, KEY_PICKUP, KEY_HIDE_WINDOWS, diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 4cdaf03c..440ea636 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -117,6 +117,14 @@ void LocalPlayer::logic() mLastAction = -1; } + // Remove target if its been on a being for more than a minute + if (get_elapsed_time(mTargetTime) >= 60000) + { + mTargetTime = -1; + setTarget(mTarget); + mLastAction = -1; + } + for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++) { player_node->mTargetCursorInRange[i]->update(10); @@ -262,8 +270,16 @@ void LocalPlayer::walk(unsigned char dir) void LocalPlayer::setTarget(Being *target) { + if (mLastAction != -1) + return; + mLastAction = tick_time; + if (target == mTarget) { + if (target != NULL) + { + target->mTargetCursor = NULL; + } return; } if (mTarget && mTarget->getType() == Being::MONSTER) @@ -562,7 +578,7 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height, } } -void LocalPlayer::drawTargetCursor(Graphics *graphics, int offsetX, int offsetY) +void LocalPlayer::drawTargetCursor(Graphics *graphics, int scrollX, int scrollY) { // Draw target marker if needed if (mTarget) @@ -587,9 +603,10 @@ void LocalPlayer::drawTargetCursor(Graphics *graphics, int offsetX, int offsetY) } // Draw the target cursor at the correct position - int posX = mTarget->getPixelX() + 16 - mTarget->mTargetCursor->getWidth() / 2 - offsetX; - int posY = mTarget->getPixelY() + 16 - mTarget->mTargetCursor->getHeight() / 2 - offsetY; + int posX = mTarget->getPixelX() + 16 - mTarget->mTargetCursor->getWidth() / 2 - scrollX; + int posY = mTarget->getPixelY() + 16 - mTarget->mTargetCursor->getHeight() / 2 - scrollY; graphics->drawImage(mTarget->mTargetCursor, posX, posY); } + return; } diff --git a/src/localplayer.h b/src/localplayer.h index c0627378..dcdcbeec 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -236,6 +236,7 @@ class LocalPlayer : public Player bool mTrading; bool mInStorage; /**< Whether storage is currently accessible */ bool mGoingToTarget; + int mTargetTime; /** How long the being has been targeted **/ 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/map.cpp b/src/map.cpp index f9454187..15d5e5f3 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -29,6 +29,7 @@ #include "configuration.h" #include "game.h" #include "graphics.h" +#include "localplayer.h" #include "particle.h" #include "sprite.h" #include "tileset.h" @@ -112,6 +113,7 @@ void MapLayer::draw(Graphics *graphics, // If drawing the fringe layer, make sure all sprites above this row of // tiles have been drawn if (mIsFringeLayer) { + player_node->drawTargetCursor(graphics, scrollX, scrollY); while (si != sprites.end() && (*si)->getPixelY() <= y * 32 - 32) { (*si)->draw(graphics, -scrollX, -scrollY); si++; diff --git a/src/particle.cpp b/src/particle.cpp index b7071674..af54a4b5 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -360,11 +360,9 @@ Particle::~Particle() void Particle::clear() { - std::for_each(mChildEmitters.begin(), mChildEmitters.end(), - make_dtor(mChildEmitters)); + delete_all(mChildEmitters); mChildEmitters.clear(); - std::for_each(mChildParticles.begin(), mChildParticles.end(), - make_dtor(mChildParticles)); + delete_all(mChildParticles); mChildParticles.clear(); } -- cgit v1.2.3-70-g09d2