ManaPlus
Public Member Functions | Data Fields
SortBeingFunctor Class Reference

Public Member Functions

bool operator() (const Being *const being1, const Being *const being2) const
 

Data Fields

StringIntMapattackBeings
 
StringIntMappriorityBeings
 
int x
 
int y
 
int defaultAttackIndex
 
int defaultPriorityIndex
 
int attackRange
 
bool specialDistance
 

Detailed Description

Definition at line 129 of file actormanager.cpp.

Member Function Documentation

◆ operator()()

bool SortBeingFunctor::operator() ( const Being *const  being1,
const Being *const  being2 
) const
inline

Definition at line 134 of file actormanager.cpp.

136  {
137  if ((being1 == nullptr) || (being2 == nullptr))
138  return false;
139 
140  if (priorityBeings != nullptr)
141  {
142  int w1 = defaultPriorityIndex;
143  int w2 = defaultPriorityIndex;
144  const StringIntMapCIter it1 = priorityBeings->find(
145  being1->getName());
146  const StringIntMapCIter it2 = priorityBeings->find(
147  being2->getName());
148  if (it1 != priorityBeings->end())
149  w1 = (*it1).second;
150  if (it2 != priorityBeings->end())
151  w2 = (*it2).second;
152 
153  if (w1 != w2)
154  return w1 < w2;
155  }
156  if (being1->getDistance() != being2->getDistance())
157  {
158  if (specialDistance && being1->getDistance() <= 2
159  && being2->getDistance() <= attackRange
160  && being2->getDistance() > 2)
161  {
162  return false;
163  }
164  else if (specialDistance && being2->getDistance() <= 2
165  && being1->getDistance() <= attackRange
166  && being1->getDistance() > 2)
167  {
168  return true;
169  }
170  return being1->getDistance() < being2->getDistance();
171  }
172 
173  const int d1 = abs(being1->getTileX() - x)
174  + abs(being1->getTileY() - y);
175  const int d2 = abs(being2->getTileX() - x)
176  + abs(being2->getTileY() - y);
177 
178  if (d1 != d2)
179  return d1 < d2;
180  if (attackBeings != nullptr)
181  {
182  int w1 = defaultAttackIndex;
183  int w2 = defaultAttackIndex;
184  const StringIntMapCIter it1 = attackBeings->find(
185  being1->getName());
186  const StringIntMapCIter it2 = attackBeings->find(
187  being2->getName());
188  if (it1 != attackBeings->end())
189  w1 = (*it1).second;
190  if (it2 != attackBeings->end())
191  w2 = (*it2).second;
192 
193  if (w1 != w2)
194  return w1 < w2;
195  }
196 
197  return being1->getName() < being2->getName();
198  }
int getTileX() const
Definition: being.h:168
int getTileY() const
Definition: being.h:174
const std::string & getName() const
Definition: being.h:232
int getDistance() const
Definition: being.h:552
StringIntMap * priorityBeings
StringIntMap * attackBeings
StringIntMap::const_iterator StringIntMapCIter
Definition: stringmap.h:30

References attackBeings, attackRange, defaultAttackIndex, defaultPriorityIndex, priorityBeings, specialDistance, x, and y.

Field Documentation

◆ attackBeings

StringIntMap* SortBeingFunctor::attackBeings

Definition at line 199 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ attackRange

int SortBeingFunctor::attackRange

Definition at line 205 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ defaultAttackIndex

int SortBeingFunctor::defaultAttackIndex

Definition at line 203 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ defaultPriorityIndex

int SortBeingFunctor::defaultPriorityIndex

Definition at line 204 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ priorityBeings

StringIntMap* SortBeingFunctor::priorityBeings

Definition at line 200 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ specialDistance

bool SortBeingFunctor::specialDistance

Definition at line 206 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ x

int SortBeingFunctor::x

Definition at line 201 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().

◆ y

int SortBeingFunctor::y

Definition at line 202 of file actormanager.cpp.

Referenced by ActorManager::findNearestLivingBeing(), and operator()().


The documentation for this class was generated from the following file: