summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--src/beingmanager.cpp39
-rw-r--r--src/localplayer.cpp14
-rw-r--r--src/localplayer.h9
-rw-r--r--src/resources/itemdb.cpp2
-rw-r--r--src/resources/iteminfo.h37
6 files changed, 78 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index c25a82e4..e91af135 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,15 @@
2008-10-24 Chuck Miller <shadowmil@gmail.com>
+
+ * src/resources/iteminfo.h,src/resources/itemdb.cpp: Added attack
+ range to item's info
+ * src/localplayer.h,src/localplayer.cpp: Changed the getAttackRange
+ method to use item's info, this is so targets will turn blue when you
+ are close enough, as a result mAttackRange and setAttackRange were
+ removed
+ * src/beingmanager.cpp: Fixed not selecting closest being, and cleaned
+ up some so the selecting code is only in one place
+
+2008-10-24 Chuck Miller <shadowmil@gmail.com>
* src/localplayer.cpp: Made it so the player will auto face its target
* src/net/beinghandler.cpp: Fixed it so the correct direction will be
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 22b3de9b..2ab29fd2 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -165,11 +165,21 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist,
Being *closestBeing = NULL;
int dist = 0;
+ //Why do we do this:
+ //For some reason x,y passed to this function is always
+ //in map coords, while down below its in pixels
+ //
+ //I believe there is a deeper problem under this, but
+ //for a temp solution we'll convert to coords to pixels
+ x = x * 32;
+ y = y * 32;
+ maxdist = maxdist * 32;
+
for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
{
Being *being = (*i);
const Vector &pos = being->getPosition();
- int d = abs((int) pos.x - x) + abs((int) pos.y - y);
+ int d = abs(((int) pos.x) - x) + abs(((int) pos.y) - y);
if ((being->getType() == type || type == Being::UNKNOWN)
&& (d < dist || closestBeing == NULL) // it is closer
@@ -180,34 +190,13 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist,
closestBeing = being;
}
}
-
- return (maxdist >= dist) ? NULL : closestBeing;
+
+ return (maxdist >= dist) ? closestBeing : NULL;
}
Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist,
Being::Type type)
{
- Being *closestBeing = NULL;
- int dist = 0;
const Vector &aroundBeingPos = aroundBeing->getPosition();
-
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
- {
- Being *being = (*i);
- const Vector &pos = being->getPosition();
- int d = abs((int) pos.x - aroundBeingPos.x) +
- abs((int) pos.y - aroundBeingPos.y);
-
- if ((being->getType() == type || type == Being::UNKNOWN)
- && (d < dist || closestBeing == NULL) // it is closer
- && being->mAction != Being::DEAD // no dead beings
- && being != aroundBeing
- )
- {
- dist = d;
- closestBeing = being;
- }
- }
-
- return (maxdist >= dist) ? NULL : closestBeing;
+ return findNearestLivingBeing((int) aroundBeingPos.x,(int) aroundBeingPos.y,maxdist,type);
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 77fd5b90..68648d74 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -52,7 +52,6 @@ LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer():
Player(65535, 0, NULL),
- mAttackRange(0),
mInventory(new Inventory),
mEquipment(new Equipment),
mAttributeBase(NB_CHARACTER_ATTRIBUTES, -1),
@@ -510,3 +509,16 @@ std::pair<int, int> LocalPlayer::getExperience(int skill)
{
return std::pair<int, int> (mExpCurrent.at(skill), mExpNext.at(skill));
}
+
+int LocalPlayer::getAttackRange()
+{
+ Item *weapon = mEquipment->getEquipment(EQUIP_FIGHT1_SLOT);
+ if(weapon)
+ {
+ const ItemInfo info = weapon->getInfo();
+ return info.getAttackRange();
+ }
+ return 32; //unarmed range
+
+}
+
diff --git a/src/localplayer.h b/src/localplayer.h
index 0b4b66ed..7d6f3862 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -199,14 +199,9 @@ class LocalPlayer : public Player
void pickUp(FloorItem *item);
/**
- * Sets the attack range.
- */
- void setAttackRange(int range) { mAttackRange = range; }
-
- /**
* Gets the attack range.
*/
- int getAttackRange() const { return mAttackRange; }
+ int getAttackRange();
/**
* Sents a trade request to the given being.
@@ -279,8 +274,6 @@ class LocalPlayer : public Player
int getMaxHP() const
{ return mMaxHP; }
- Uint16 mAttackRange;
-
void setHP(int value)
{ mHP = value; }
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 0f89f444..306c0e5a 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -135,6 +135,7 @@ void ItemDB::load()
std::string image = XML::getProperty(node, "image", "");
std::string description = XML::getProperty(node, "description", "");
int weaponType = weaponTypeFromString(XML::getProperty(node, "weapon-type", ""));
+ int attackRange = XML::getProperty(node, "attack-range", 0);
ItemInfo *itemInfo = new ItemInfo;
itemInfo->setImageName(image);
@@ -144,6 +145,7 @@ void ItemDB::load()
itemInfo->setView(view);
itemInfo->setWeight(weight);
itemInfo->setWeaponType(weaponType);
+ itemInfo->setAttackRange(attackRange);
std::string effect;
for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i)
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 43047094..a8e9f2e4 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -38,6 +38,36 @@ enum EquipmentSoundEvent
EQUIP_EVENT_HIT
};
+enum EquipmentSlot
+{
+ // Equipment rules:
+ // 1 Brest equipment
+ EQUIP_TORSO_SLOT = 0,
+ // 1 arms equipment
+ EQUIP_ARMS_SLOT = 1,
+ // 1 head equipment
+ EQUIP_HEAD_SLOT = 2,
+ // 1 legs equipment
+ EQUIP_LEGS_SLOT = 3,
+ // 1 feet equipment
+ EQUIP_FEET_SLOT = 4,
+ // 2 rings
+ EQUIP_RING1_SLOT = 5,
+ EQUIP_RING2_SLOT = 6,
+ // 1 necklace
+ EQUIP_NECKLACE_SLOT = 7,
+ // Fight:
+ // 2 one-handed weapons
+ // or 1 two-handed weapon
+ // or 1 one-handed weapon + 1 shield.
+ EQUIP_FIGHT1_SLOT = 8,
+ EQUIP_FIGHT2_SLOT = 9,
+ // Projectile:
+ // this item does not amount to one, it only indicates the chosen projectile.
+ EQUIP_PROJECTILE_SLOT = 10,
+};
+
+
/**
* Enumeration of available Item types.
*/
@@ -143,6 +173,12 @@ class ItemInfo
SpriteAction getAttackType() const
{ return mAttackType; }
+ int getAttackRange() const
+ { return mAttackRange; }
+
+ void setAttackRange(int r)
+ { mAttackRange = r; }
+
void addSound(EquipmentSoundEvent event, const std::string &filename);
const std::string& getSound(EquipmentSoundEvent event) const;
@@ -158,6 +194,7 @@ class ItemInfo
// Equipment related members
SpriteAction mAttackType; /**< Attack type, in case of weapon. */
+ int mAttackRange; /**< Attack range, will be zero if non weapon. */
/** Maps gender to sprite filenames. */
std::map<int, std::string> mAnimationFiles;