summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-12-30 13:29:03 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-12-30 13:29:03 +0000
commit7d23129b8f16dfa73e3842ac8e91c61e5a3393aa (patch)
tree49132223612cd4286fbf265b9b61bcc8d756f1ea /src/being.cpp
parent6134c13fbbaf2e5516dd924425352416f66ece9b (diff)
downloadmanaserv-7d23129b8f16dfa73e3842ac8e91c61e5a3393aa.tar.gz
manaserv-7d23129b8f16dfa73e3842ac8e91c61e5a3393aa.tar.bz2
manaserv-7d23129b8f16dfa73e3842ac8e91c61e5a3393aa.tar.xz
manaserv-7d23129b8f16dfa73e3842ac8e91c61e5a3393aa.zip
Made attack code pixel-based and faster. Split State::update. Improved
interface of MapComposite iterators.
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp105
1 files changed, 40 insertions, 65 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 6f8b7028..cece203a 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -21,7 +21,7 @@
*/
#include "being.h"
-#include "mapcomposite.h"
+#include "game-server/mapcomposite.hpp"
#include "utils/logger.h"
void Being::damage(Damage damage)
@@ -35,78 +35,53 @@ void Being::damage(Damage damage)
LOG_DEBUG("Being " << getPublicID() << " got hit", 0);
}
-void Being::performAttack(MapComposite* map)
+void Being::performAttack(MapComposite *map)
{
- std::list<ObjectPtr> victimList;
- std::list<Point> attackZone;
+ int SHORT_RANGE = 32;
+ Point ppos = getPosition();
+ int dir = getDirection();
- Point attackPoint = getPosition();
+ /* TODO: calculate real attack power and damage properties based on
+ character equipment and stats. */
+ Damage damage = 1;
- unsigned char direction = getDirection();
- if (direction & UP)
+ for (MovingObjectIterator i(map->getAroundObjectIterator(this, SHORT_RANGE)); i; ++i)
{
- attackPoint.y -= 32;
- attackPoint.x -= 32;
- attackZone.push_back(attackPoint);
- attackPoint.x += 32;
- attackZone.push_back(attackPoint);
- attackPoint.x += 32;
- attackZone.push_back(attackPoint);
- }
- else if (direction & RIGHT)
- {
- attackPoint.x += 32;
- attackPoint.y -= 32;
- attackZone.push_back(attackPoint);
- attackPoint.y += 32;
- attackZone.push_back(attackPoint);
- attackPoint.y += 32;
- attackZone.push_back(attackPoint);
- }
- else if (direction & DOWN)
- {
- attackPoint.y += 32;
- attackPoint.x -= 32;
- attackZone.push_back(attackPoint);
- attackPoint.x += 32;
- attackZone.push_back(attackPoint);
- attackPoint.x += 32;
- attackZone.push_back(attackPoint);
- }
- else {
- attackPoint.x -= 32;
- attackPoint.y -= 32;
- attackZone.push_back(attackPoint);
- attackPoint.y += 32;
- attackZone.push_back(attackPoint);
- attackPoint.y += 32;
- attackZone.push_back(attackPoint);
- }
-
- attackZone.push_back(attackPoint); // point player is facing
-
- // get enemies to hurt
- for (std::list<Point>::iterator i = attackZone.begin(),
- i_end = attackZone.end(); i != i_end; ++i)
- {
- std::list<ObjectPtr> newVictimList = map->getObjectsOnTile((*i));
- victimList.splice(victimList.end(), newVictimList);
- }
+ MovingObject *o = *i;
+ if (o == this)
+ {
+ continue;
+ }
- // apply damage to victims
- Damage damage;
+ int type = o->getType();
+ Point opos = o->getPosition();
+ int dx = opos.x - ppos.x, dy = opos.y - ppos.y;
- /* TODO: calculate real attack power and damage properties based on
- * character equipment and stats
- */
- damage = 1;
+ if ((type != OBJECT_PLAYER && type != OBJECT_MONSTER) ||
+ (std::abs(dx) > SHORT_RANGE || std::abs(dy) > SHORT_RANGE))
+ {
+ continue;
+ }
- for (std::list<ObjectPtr>::iterator i = victimList.begin(),
- i_end = victimList.end(); i != i_end; ++i)
- {
- if ((*i)->getType() == OBJECT_PLAYER || (*i)->getType() == OBJECT_MONSTER)
+ // basic triangle-shaped damage zone
+ switch (dir)
{
- static_cast<Being*>(&**i)->damage(damage);
+ case DIRECTION_UP:
+ if (!(dy <= dx && dx <= -dy)) continue;
+ break;
+ case DIRECTION_DOWN:
+ if (!(-dy <= dx && dx <= dy)) continue;
+ break;
+ case DIRECTION_LEFT:
+ if (!(dx <= dy && dy <= -dx)) continue;
+ break;
+ case DIRECTION_RIGHT:
+ if (!(-dx <= dy && dy <= dx)) continue;
+ break;
+ default:
+ break;
}
+
+ static_cast< Being * >(o)->damage(damage);
}
}