Skip to content

Commit

Permalink
Update TARGETSEARCH_NEAREST to use Manhattan distance
Browse files Browse the repository at this point in the history
Fixes typo (NEAREAST -> NEAREST).

Related issue: #1206
  • Loading branch information
marksamman committed Feb 18, 2015
1 parent d2e526c commit bc83c4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,18 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL
}

switch (searchType) {
case TARGETSEARCH_NEAREAST: {
case TARGETSEARCH_NEAREST: {
if (!resultList.empty()) {
auto it = resultList.begin();
Creature* target = *it;

if (++it != resultList.end()) {
const Position& targetPosition = target->getPosition();
int32_t minRange = std::max<int32_t>(Position::getDistanceX(myPos, targetPosition), Position::getDistanceY(myPos, targetPosition));
int32_t minRange = Position::getDistanceX(myPos, targetPosition) + Position::getDistanceY(myPos, targetPosition);
do {
const Position& pos = (*it)->getPosition();

int32_t distance = std::max<int32_t>(Position::getDistanceX(myPos, pos), Position::getDistanceY(myPos, pos));
int32_t distance = Position::getDistanceX(myPos, pos) + Position::getDistanceY(myPos, pos);
if (distance < minRange) {
target = *it;
minRange = distance;
Expand Down Expand Up @@ -888,7 +888,7 @@ void Monster::onThinkTarget(uint32_t interval)
if (mType->targetDistance <= 1) {
searchTarget(TARGETSEARCH_RANDOM);
} else {
searchTarget(TARGETSEARCH_NEAREAST);
searchTarget(TARGETSEARCH_NEAREST);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum TargetSearchType_t {
TARGETSEARCH_DEFAULT,
TARGETSEARCH_RANDOM,
TARGETSEARCH_ATTACKRANGE,
TARGETSEARCH_NEAREAST
TARGETSEARCH_NEAREST
};

class Monster final : public Creature
Expand Down

0 comments on commit bc83c4e

Please sign in to comment.