summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoderic Morris <roderic@ccs.neu.edu>2008-10-25 01:40:36 +0000
committerRoderic Morris <roderic@ccs.neu.edu>2008-10-25 01:40:36 +0000
commit796c2addfb17b57992d304667248873ee26088dc (patch)
tree8d3aaab2dd6abbc304eb9f8b70551b210894a7e2 /src
parentf8f3e17f72d1216bacd5aaa975789b0b790068f6 (diff)
downloadMana-796c2addfb17b57992d304667248873ee26088dc.tar.gz
Mana-796c2addfb17b57992d304667248873ee26088dc.tar.bz2
Mana-796c2addfb17b57992d304667248873ee26088dc.tar.xz
Mana-796c2addfb17b57992d304667248873ee26088dc.zip
attack range fixes, highlight monsters in range (by Chuck Miller)
Diffstat (limited to 'src')
-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
5 files changed, 67 insertions, 34 deletions
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;