summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-01 04:56:47 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-01 04:56:47 +0000
commit2fd66a97ffceb05ab0020545b81f5e5a8de06c13 (patch)
tree95c16082909ee1249f697320d25e65ab48ae7059 /src
parent423e581faf19977c2797d2c90fc65730142ed6a4 (diff)
downloadmanaserv-2fd66a97ffceb05ab0020545b81f5e5a8de06c13.tar.gz
manaserv-2fd66a97ffceb05ab0020545b81f5e5a8de06c13.tar.bz2
manaserv-2fd66a97ffceb05ab0020545b81f5e5a8de06c13.tar.xz
manaserv-2fd66a97ffceb05ab0020545b81f5e5a8de06c13.zip
Implemented priority of different monster attacks.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/monster.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 81cf29c2..10bc2b30 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -215,7 +215,8 @@ void Monster::update()
{
//check which attacks have a chance to hit the target
MonsterAttacks allAttacks = mSpecy->getAttacks();
- MonsterAttacks workingAttacks; //TODO: maybe another container than vector is better - reevaluate when implementing priority
+ std::map<int, MonsterAttack *> workingAttacks;
+ int prioritySum = 0;
for (MonsterAttacks::iterator i = allAttacks.begin();
i != allAttacks.end();
@@ -234,18 +235,22 @@ void Monster::update()
bestAttackTarget->getPosition(), bestAttackTarget->getSize(),
getPosition(), (*i)->range, (*i)->angle, attackAngle))
{
- workingAttacks.push_back((*i));
+ prioritySum += (*i)->priority;
+ workingAttacks[prioritySum] = (*i);
}
}
- if (workingAttacks.empty())
+ if (workingAttacks.empty() || !prioritySum)
{ //when no attack can hit move closer to attack position
setDestination(bestAttackPosition);
}
else
{
+ //stop movement
setDestination(getPosition());
+ //turn into direction of enemy
setDirection(bestAttackDirection);
- mCurrentAttack = workingAttacks.at(rand()%workingAttacks.size()); //TODO: this ignores priority -> fix it
+ //perform a random attack based on priority
+ mCurrentAttack = workingAttacks.upper_bound(rand()%prioritySum)->second;
mAttackTime = mCurrentAttack->preDelay + mCurrentAttack->aftDelay;
setAction(ATTACK);
raiseUpdateFlags(UPDATEFLAG_ATTACK);