From 9d51b2e1077042ae42d42a0e6314e439c62e2925 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 21 Mar 2007 02:05:37 +0000 Subject: Avoiding magic numbers where possible (1002) and also display the target when other players are targeted. --- ChangeLog | 3 + src/gui/viewport.cpp | 74 +++++++++------------ src/monster.h | 1 - src/resources/monsterdb.h | 90 ++++++++++++------------- src/resources/monsterinfo.h | 158 +++++++++++++++++++++++--------------------- 5 files changed, 163 insertions(+), 163 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3fa7c7a..55f73e71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,9 @@ in the server entry field properly. * src/main.cpp: Display a progress bar and connecting status for each server and display the version using a gcn::Label. + * src/gui/viewport.cpp, src/monster.h: Avoiding magic numbers where + possible (1002) and also display the target when other players are + targeted. 2007-03-20 David Athay diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index eb5939fd..c1f17804 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -35,10 +35,11 @@ #include "../graphics.h" #include "../localplayer.h" #include "../map.h" +#include "../monster.h" #include "../npc.h" #include "../resources/animation.h" -#include "../resources/monsterdb.h" +#include "../resources/monsterinfo.h" #include "../resources/resourcemanager.h" #include "../resources/spriteset.h" @@ -64,7 +65,7 @@ Viewport::Viewport(): config.addListener("ScrollRadius", this); mPopupMenu = new PopupMenu(); - + // Load target cursors. ResourceManager *resman = ResourceManager::getInstance(); Animation *animInRange = new Animation(); @@ -183,7 +184,7 @@ Viewport::draw(gcn::Graphics *gcnGraphics) mCameraX = (int) (mViewX + 16) / 32; mCameraY = (int) (mViewY + 16) / 32; - + // Draw tiles and sprites if (mMap) { @@ -223,7 +224,7 @@ Viewport::draw(gcn::Graphics *gcnGraphics) squareX + 4, squareY + 12, gcn::Graphics::CENTER); } } - + // Draw player nickname, speech, and emotion sprite as needed Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) @@ -267,34 +268,27 @@ Viewport::drawTargetCursor(Graphics *graphics) Being *target = player_node->getTarget(); if (target) { - if (target->mJob >= 1002) + // Find whether target is in range + int rangeX = abs(target->mX - player_node->mX); + int rangeY = abs(target->mY - player_node->mY); + int attackRange = player_node->getAttackRange(); + + // Draw the target cursor, which one depends if the target is in range + if (rangeX > attackRange || rangeY > attackRange) { - // Find whether target is in range - int rangeX = target->mX - player_node->mX; - int rangeY = target->mY - player_node->mY; - int attackRange = player_node->getAttackRange(); - - // Make sure the ranges are positive - rangeX = abs(rangeX); - rangeY = abs(rangeY); - - // Draw the target cursor, which one depends if the target is in range - if (rangeX > attackRange || rangeY > attackRange) - { - // Draw the out of range cursor - graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), - target->getPixelX() - (int) mViewX, - target->getPixelY() - (int) mViewY); - } - else - { - // Draw the in range cursor - graphics->drawImage(mTargetCursorInRange->getCurrentImage(), - target->getPixelX() - (int) mViewX, - target->getPixelY() - (int) mViewY); - } + // Draw the out of range cursor + graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), + target->getPixelX() - (int) mViewX, + target->getPixelY() - (int) mViewY); } - } + else + { + // Draw the in range cursor + graphics->drawImage(mTargetCursorInRange->getCurrentImage(), + target->getPixelX() - (int) mViewX, + target->getPixelY() - (int) mViewY); + } + } } void @@ -302,22 +296,16 @@ Viewport::drawTargetName(Graphics *graphics) { // Draw target marker if needed Being *target = player_node->getTarget(); - if (target) + if (target && target->getType() == Being::MONSTER) { graphics->setFont(speechFont); graphics->setColor(gcn::Color(255, 32, 32)); - int dy = (target->getType() == Being::PLAYER) ? 80 : 42; - - std::string mobName = ""; - if (target->mJob >= 1002) - { - int mobId = target->mJob - 1002; - mobName = MonsterDB::get(mobId).getName(); - graphics->drawText(mobName, - target->getPixelX() - (int) mViewX + 15, - target->getPixelY() - (int) mViewY - dy, - gcn::Graphics::CENTER); - } + + const MonsterInfo &mi = static_cast(target)->getInfo(); + graphics->drawText(mi.getName(), + target->getPixelX() - (int) mViewX + 15, + target->getPixelY() - (int) mViewY - 42, + gcn::Graphics::CENTER); } } diff --git a/src/monster.h b/src/monster.h index 1b666db4..0e0e1af5 100644 --- a/src/monster.h +++ b/src/monster.h @@ -48,7 +48,6 @@ class Monster : public Being */ virtual void handleAttack(Being *victim, int damage); - protected: /** * Returns the MonsterInfo, with static data about this monster. */ diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index b105665a..9757d7f1 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -1,45 +1,45 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: - */ - -#ifndef _TMW_MONSTER_DB_H -#define _TMW_MONSTER_DB_H - -#include - -#include "monsterinfo.h" - -namespace MonsterDB -{ - void - load(); - - void - unload(); - - const MonsterInfo& get (int id); - - typedef std::map MonsterInfos; - typedef MonsterInfos::iterator MonsterInfoIterator; -} - -#endif +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: + */ + +#ifndef _TMW_MONSTER_DB_H +#define _TMW_MONSTER_DB_H + +#include + +#include "monsterinfo.h" + +namespace MonsterDB +{ + void + load(); + + void + unload(); + + const MonsterInfo& get(int id); + + typedef std::map MonsterInfos; + typedef MonsterInfos::iterator MonsterInfoIterator; +} + +#endif diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index 413dafa0..b65237da 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -1,74 +1,84 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: monsterinfo.h 2650 2006-09-03 15:00:47Z b_lindeijer $ - */ - -#ifndef _TMW_MONSTERINFO_H_ -#define _TMW_MONSTERINFO_H_ - -#include -#include -#include - - -enum SoundEvent -{ - EVENT_HIT, - EVENT_MISS, - EVENT_HURT, - EVENT_DIE -}; - - -class MonsterInfo -{ - public: - MonsterInfo(); - - ~MonsterInfo(); - - void - setName(std::string name) { mName = name; } ; - - void - setSprite(std::string filename) { mSprite = filename; } - - void - addSound (SoundEvent event, std::string filename); - - const std::string& - getName () const { return mName; }; - - const std::string& - getSprite () const { return mSprite; }; - - std::string - getSound (SoundEvent event) const; - - private: - - std::string mName; - std::string mSprite; - - std::map* > mSounds; -}; - -#endif +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: monsterinfo.h 2650 2006-09-03 15:00:47Z b_lindeijer $ + */ + +#ifndef _TMW_MONSTERINFO_H_ +#define _TMW_MONSTERINFO_H_ + +#include +#include +#include + + +enum SoundEvent +{ + EVENT_HIT, + EVENT_MISS, + EVENT_HURT, + EVENT_DIE +}; + +/** + * Holds information about a certain type of monster. This includes the name + * of the monster, the sprite to display and the sounds the monster makes. + * + * @see MonsterDB + */ +class MonsterInfo +{ + public: + /** + * Constructor. + */ + MonsterInfo(); + + /** + * Destructor. + */ + ~MonsterInfo(); + + void + setName(std::string name) { mName = name; } + + void + setSprite(std::string filename) { mSprite = filename; } + + void + addSound(SoundEvent event, std::string filename); + + const std::string& + getName() const { return mName; } + + const std::string& + getSprite() const { return mSprite; } + + std::string + getSound(SoundEvent event) const; + + private: + std::string mName; + std::string mSprite; + + std::map* > mSounds; +}; + +#endif -- cgit v1.2.3-70-g09d2