-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.hpp
91 lines (64 loc) · 2.03 KB
/
ai.hpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef AI_HPP
#define AI_HPP
#include <vector>
#include <iostream>
#include "unit.hpp"
#include "map.hpp"
#include "tile.hpp"
#include "colony.hpp"
#include "random.hpp"
namespace TerraNova {
enum AIPlan_t { PLAN_ATTACK = 0, PLAN_DEFEND = 1, PLAN_ECONOMY = 2,
PLAN_BUILDARMY = 3};
struct AIPriority {
int priority = 0;
AIPlan_t action;
Tile* target = nullptr;
AIPriority(AIPlan_t action, Tile* target = nullptr): action(action),
target(target) {}
};
class TacticalAI {
Map& map;
int faction;
WeakVector<Unit> myUnits;
WeakVector<Unit> enemyUnits;
Unit* FindNearestEnemy(const Unit& attacker);
unsigned int TargetPriority(const Unit& target,
const unsigned int distance) const;
public:
TacticalAI(Map& map, const int faction): map(map), faction(faction) {}
void AddUnit(std::shared_ptr<Unit> newUnit);
void StartTurn();
void EndTurn();
void GiveOrders();
};
class AIPlayer {
Map& map;
int faction;
std::vector<TacticalAI> tacticalAIs; // one for each dynamic theater
std::vector<AIPriority> priorities;
std::vector<std::weak_ptr<Colony>> myWeakColonies;
std::vector<Colony*> myColonies;
std::vector<std::weak_ptr<Unit>> myWeakUnits;
std::vector<Unit*> myUnits;
int ColonyDefensePriority(const Colony& colony);
int ColonyAttackPriority(const Colony& colony);
int UnitAttackPriority(const Unit& unit);
int DevelopmentPriority(const Colony& colony);
// i.e. compare friendly and enemy forces nearby, return a positive value
// for favorable fight conditions, negative value for unfavorable ones
int ForceComparison(const Colony& colony);
// compute strength based on attack & defense, then weight by distance away
int WeightedUnitStrength(const Unit& unit);
//int MeleeStrength(const Region& region);
//std::vector<Unit*> FindMeleeToTransfer(const Region& region);
Colony* FindBestPlaceToBuild(const UnitType& type);
public:
AIPlayer(Map& map, const int faction);
void AddUnit(std::shared_ptr<Unit> newUnit);
void StartTurn();
void EndTurn();
void GiveOrders();
};
} // namespace TerraNova
#endif