SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
HasEnemies.h
Go to the documentation of this file.
1 
5 #pragma once
6 
8 #include "common/String.h"
9 #include "aggro/AggroMgr.h"
10 
11 namespace ai {
12 
21 class HasEnemies: public ICondition {
22 protected:
23  int _enemyCount;
24 public:
26 
27  explicit HasEnemies(const std::string& parameters) :
28  ICondition("HasEnemies", parameters) {
29  if (_parameters.empty()) {
30  _enemyCount = -1;
31  } else {
32  _enemyCount = std::stoi(_parameters);
33  }
34  }
35 
36  bool evaluate(const AIPtr& entity) override {
37  const AggroMgr& mgr = entity->getAggroMgr();
38  if (_enemyCount == -1) {
39  // TODO: check why boolean operator isn't working here
40  const bool hasEnemy = mgr.getHighestEntry() != nullptr;
41  return hasEnemy;
42  }
43  const int size = static_cast<int>(mgr.getEntries().size());
44  return size >= _enemyCount;
45  }
46 };
47 
48 }
Manages the aggro values for one AI instance. There are several ways to degrade the aggro values...
Definition: AggroMgr.h:21
A condition can be placed on a TreeNode to decide which node is going to get executed. In general they are stateless. If they are not, it should explicitly get noted.
Definition: ICondition.h:124
const Entries & getEntries() const
Definition: AggroMgr.h:176
Condition related stuff.
EntryPtr getHighestEntry() const
Get the entry with the highest aggro value.
Definition: AggroMgr.h:185
bool evaluate(const AIPtr &entity) override
Checks whether the condition evaluates to true for the given entity.
Definition: HasEnemies.h:36
#define CONDITION_FACTORY(ConditionName)
A condition factory macro to ease and unify the registration at AIRegistry.
Definition: ICondition.h:55
This condition checks whether there are enemies.
Definition: HasEnemies.h:21