From 2fd66a97ffceb05ab0020545b81f5e5a8de06c13 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sat, 1 Mar 2008 04:56:47 +0000 Subject: Implemented priority of different monster attacks. --- ChangeLog | 5 +++++ src/game-server/monster.cpp | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index ced9c664..ca2d9b17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-03-01 Philipp Sehmisch + + * src/game-server/monster.cpp: Implemented priority of different + monster attacks. + 2008-02-27 Philipp Sehmisch * src/defines.h, src/game-server/character.cpp, 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 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); -- cgit v1.2.3-60-g2f50