summaryrefslogtreecommitdiff
path: root/src/game-server/being.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2008-11-20 16:52:48 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2008-11-20 16:52:48 +0100
commitd9189cba9db278b20c07bcb31ae481ad9804aaa5 (patch)
treeece36de0b3a6c833f5e79dc6d4c8a22278f757d1 /src/game-server/being.cpp
parent8481413ea17177945d3d280b1518eb6f1f25cd5d (diff)
downloadmanaserv-d9189cba9db278b20c07bcb31ae481ad9804aaa5.tar.gz
manaserv-d9189cba9db278b20c07bcb31ae481ad9804aaa5.tar.bz2
manaserv-d9189cba9db278b20c07bcb31ae481ad9804aaa5.tar.xz
manaserv-d9189cba9db278b20c07bcb31ae481ad9804aaa5.zip
Added rectangular attack zones which are faster and simpler than cone-shaped ones and sufficient for most situations.
Diffstat (limited to 'src/game-server/being.cpp')
-rw-r--r--src/game-server/being.cpp66
1 files changed, 62 insertions, 4 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 8ec0ea62..c07bff71 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -136,7 +136,48 @@ void Being::performAttack(Damage const &damage, AttackZone const *attackZone)
Point ppos = getPosition();
const int attackAngle = directionToAngle(getDirection());
- std::list<Being *> victims;
+ std::list<Being *> victims;
+
+ LOG_DEBUG("Direction:"<<getDirection()<<
+ " range:"<<attackZone->range<<
+ " angle:"<<attackZone->angle);
+
+ Point attPos, attSize, defPos, defSize;
+ if (attackZone->shape == ATTZONESHAPE_RECT)
+ {
+ if (getDirection() == DIRECTION_UP)
+ {
+ attPos.x = ppos.x - attackZone->angle;
+ attPos.y = ppos.y - attackZone->range;
+ attSize.x = attackZone->angle * 2;
+ attSize.y = attackZone->range;
+ }
+ if (getDirection() == DIRECTION_DOWN)
+ {
+ attPos.x = ppos.x - attackZone->angle;
+ attPos.y = ppos.y;
+ attSize.x = attackZone->angle * 2;
+ attSize.y = attackZone->range;
+ }
+ if (getDirection() == DIRECTION_RIGHT)
+ {
+ attPos.x = ppos.x;
+ attPos.y = ppos.y - attackZone->angle;
+ attSize.x = attackZone->range;
+ attSize.y = attackZone->angle * 2;
+ }
+ if (getDirection() == DIRECTION_LEFT)
+ {
+ attPos.x = ppos.x - attackZone->range;
+ attPos.y = ppos.y - attackZone->angle;
+ attSize.x = attackZone->range;
+ attSize.y = attackZone->angle * 2;
+ }
+ /* debug effect to see when and where the server pictures the attack - should
+ * be moved to the client side when the attack detection works statisfactory.
+ */
+ Effects::show(26, getMap(), Point(attPos.x + attSize.x / 2, attPos.y + attSize.y / 2));
+ }
for (MovingObjectIterator
i(getMap()->getAroundObjectIterator(this, attackZone->range)); i; ++i)
@@ -147,9 +188,16 @@ void Being::performAttack(Damage const &damage, AttackZone const *attackZone)
if (o == this) continue;
int type = o->getType();
-
- if (type != OBJECT_CHARACTER && type != OBJECT_MONSTER) continue;
-
+ if (type != OBJECT_CHARACTER && type != OBJECT_MONSTER) continue;
+
+ LOG_DEBUG("Attack Zone:"<<
+ attPos.x<<":"<<attPos.y<<
+ " "<<
+ attSize.x<<"x"<<attSize.y);
+ LOG_DEBUG("Defender Zone:"<<
+ defPos.x<<":"<<defPos.y<<
+ " "<<
+ defSize.x<<"x"<<defSize.y);
switch (attackZone->shape)
{
@@ -161,6 +209,16 @@ void Being::performAttack(Damage const &damage, AttackZone const *attackZone)
)
{
victims.push_back(static_cast< Being * >(o));
+ }
+ break;
+ case ATTZONESHAPE_RECT:
+ defPos.x = opos.x - o->getSize();
+ defPos.y = opos.y - o->getSize();
+ defSize.x = o->getSize() * 2;
+ defSize.y = o->getSize() * 2;
+ if (Collision::rectWithRect(attPos, attSize, defPos, defSize))
+ {
+ victims.push_back(static_cast< Being * >(o));
}
break;
default: