summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-03-17 02:05:52 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-03-17 02:05:52 +0100
commit45c3f943b42423dbe162bfac4a57cad013ba0630 (patch)
tree0bb0caaa15af42f1d2c3bc14061202aacf9bee6d
parentfe153c7b2598262281477882a2ef82400b24f5b5 (diff)
downloadmana-45c3f943b42423dbe162bfac4a57cad013ba0630.tar.gz
mana-45c3f943b42423dbe162bfac4a57cad013ba0630.tar.bz2
mana-45c3f943b42423dbe162bfac4a57cad013ba0630.tar.xz
mana-45c3f943b42423dbe162bfac4a57cad013ba0630.zip
Simplified the get/setAttackRange() functions as requested.
The attack range is still hardcoded for Manaserv as long as generic equipment handling hasn't been implemented.
-rw-r--r--src/localplayer.cpp34
-rw-r--r--src/localplayer.h9
-rw-r--r--src/net/manaserv/gamehandler.cpp3
-rw-r--r--src/net/tmwa/inventoryhandler.cpp4
-rw-r--r--src/resources/iteminfo.h4
5 files changed, 19 insertions, 35 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 5ce21916..7daceb0f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -69,7 +69,7 @@ LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(int id, int subtype):
Being(id, PLAYER, subtype, 0),
- mAttackRange(-1),
+ mAttackRange(ATTACK_RANGE_NOT_SET),
mTargetTime(-1),
mLastTarget(-1),
mTarget(NULL),
@@ -911,48 +911,22 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
void LocalPlayer::setAttackRange(int range)
{
- // Still no map, so don't do anything for now.
- if (!mMap)
- return;
// When the range is more than the minimal, we accept it
- int unarmedRange = mMap->getTileWidth() / 2 * 3;
- if (range >= unarmedRange)
+ if (range > ATTACK_RANGE_NOT_SET)
{
mAttackRange = range;
}
else if (Net::getNetworkType() == ServerInfo::TMWATHENA)
{
// TODO: Fix this to be more generic
- Item *weapon = PlayerInfo::getEquipment(
- TmwAthena::EQUIP_FIGHT1_SLOT);
+ Item *weapon = PlayerInfo::getEquipment(TmwAthena::EQUIP_FIGHT1_SLOT);
if (weapon)
{
const ItemInfo info = weapon->getInfo();
- if (info.getAttackRange() >= unarmedRange)
+ if (info.getAttackRange() > ATTACK_RANGE_NOT_SET)
mAttackRange = info.getAttackRange();
- else
- mAttackRange = unarmedRange;
}
}
- else
- {
- mAttackRange = unarmedRange;
- }
-}
-
-int LocalPlayer::getAttackRange()
-{
- // Still no map, so don't return anything for now.
- if (!mMap)
- return -1;
- // When the range is realistic, we return it
- int unarmedRange = mMap->getTileWidth() / 2 * 3;
- if (mAttackRange < unarmedRange)
- {
- // This will set a proper value to the attack range.
- setAttackRange(unarmedRange);
- }
- return mAttackRange;
}
bool LocalPlayer::withinAttackRange(Being *target)
diff --git a/src/localplayer.h b/src/localplayer.h
index 696211ee..01f31e01 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -58,6 +58,11 @@ enum
PICKUP_DROP_STEAL,
};
+/**
+ * Attack range not set value
+ */
+enum { ATTACK_RANGE_NOT_SET = -1 };
+
/**
* The local player character.
@@ -116,7 +121,9 @@ class LocalPlayer : public Being
/**
* Gets the attack range.
*/
- int getAttackRange();
+ int getAttackRange()
+ { return mAttackRange; }
+
void attack(Being *target = NULL, bool keep = false);
void setGMLevel(int level);
diff --git a/src/net/manaserv/gamehandler.cpp b/src/net/manaserv/gamehandler.cpp
index 040a5e6c..63f84fd1 100644
--- a/src/net/manaserv/gamehandler.cpp
+++ b/src/net/manaserv/gamehandler.cpp
@@ -141,7 +141,8 @@ void GameHandler::gameLoading()
chatHandler->connect();
// Attack range from item DB
- player_node->setAttackRange(-1);
+ // TODO: Deharcode it through equipment handling
+ player_node->setAttackRange(48);
}
} // namespace ManaServ
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 8ec97a38..88c72ed6 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -416,7 +416,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
mEquips.setEquipment(getSlot(equipType), -1);
// Reset the attack range to unarmed.
- player_node->setAttackRange(-1);
+ player_node->setAttackRange(ATTACK_RANGE_NOT_SET);
}
break;
@@ -433,7 +433,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
logger->log("Couldn't set attacke range due to the lack"
"of an initialized map.");
- player_node->setAttackRange(-1);
+ player_node->setAttackRange(ATTACK_RANGE_NOT_SET);
}
}
break;
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index c7e97b3c..2fbcc228 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -163,7 +163,9 @@ class ItemInfo
* Attack action sub-types (bow, sword, ...) are defined in items.xml.
*/
std::string mAttackAction;
- int mAttackRange; /**< Attack range, will be -1 if no weapon. */
+
+ /** Attack range, will be equal to ATTACK_RANGE_NOT_SET if no weapon. */
+ int mAttackRange;
// Particle to be shown when weapon attacks
std::string mMissileParticle;