forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonster_ai.h
78 lines (63 loc) · 1.77 KB
/
monster_ai.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef _ACTOR_H
#define _ACTOR_H
#include "creature.h"
#include "location.h"
struct MoveInfo {
double value;
function<void ()> move;
bool isValid() const {
return move != nullptr;
}
};
const MoveInfo NoMove = {0.0, nullptr};
enum MonsterAIType {
MONSTER,
WILDLIFE_NON_PREDATOR,
BIRD_FLY_AWAY,
FOLLOWER,
};
class Behaviour {
public:
Behaviour(Creature*);
virtual MoveInfo getMove() { return {0, nullptr}; }
virtual void onAttacked(const Creature* attacker) {}
virtual double itemValue(const Item*) { return 0; }
Item* getBestWeapon();
const Creature* getClosestEnemy();
MoveInfo tryToApplyItem(EffectType, double maxTurns);
virtual ~Behaviour() {}
protected:
Creature* creature;
};
class MonsterAI {
public:
void makeMove();
private:
friend class MonsterAIFactory;
MonsterAI(Creature*, const vector<Behaviour*>& behaviours, const vector<int>& weights, bool pickItems = true);
vector<PBehaviour> behaviours;
vector<int> weights;
Creature* creature;
bool pickItems;
};
class Collective;
class VillageControl;
class MonsterAIFactory {
public:
PMonsterAI getMonsterAI(Creature* c);
static MonsterAIFactory collective(Collective*);
static MonsterAIFactory villageControl(VillageControl*, Location*);
static MonsterAIFactory monster();
static MonsterAIFactory stayInLocation(Location*, bool moveRandomly = true);
static MonsterAIFactory guardSquare(Vec2 pos);
static MonsterAIFactory wildlifeNonPredator();
static MonsterAIFactory scavengerBird(Vec2 corpsePos);
static MonsterAIFactory follower(Creature*, int radius);
static MonsterAIFactory moveRandomly();
static MonsterAIFactory idle();
private:
typedef function<MonsterAI*(Creature*)> MakerFun;
MonsterAIFactory(MakerFun);
MakerFun maker;
};
#endif