I currently have a functor that finds the closest entity (by calculated distance) to the current entity. (Vector3 is just a 3D coordinate class)
template<typename T>
class MinDistanceBGE
{
private:
Vector3 v; // The location of the 'asking' entity.
public:
MinDistanceBGE(Vector3 vInput):v(vInput) {}
bool operator()(T t1, T t2) const
{
return v.squaredDistance(t1->GetPosition()) < v.squaredDistance(t2->GetPosition());
}
};
// And used like this:
it = min_element(enemyArmy->begin(), enemyArmy->end(), MinDistanceBGE<BaseGameEntity*>(a->GetPosition()));
This works beautifully... BUT... I would like to attach a condition:-
- Return the nearest T that is also T->NotRetreating() // returns a bool
It seems wrong to change the return statement to:
return (t1->NotRetreating()) && (v.squaredDistance(t1->GetPosition()) < v.squaredDistance(t2->GetPosition()));
As this isn't technically a sort any longer. But is this in fact the right way to do it?