1 #ifndef KAIK_ATTACKHANDLER_HDR
2 #define KAIK_ATTACKHANDLER_HDR
3 
4 #include <list>
5 #include <utility>
6 #include <vector>
7 
8 class CAttackGroup;
9 struct AIClasses;
10 
11 class CAttackHandler {
12 public:
13 	CR_DECLARE(CAttackHandler)
14 
15 	CAttackHandler(AIClasses* ai);
16 	~CAttackHandler(void);
17 
18 	void AddUnit(int unitID);
19 	void Update(int);
20 	void UnitDestroyed(int unitID);
21 
22 	// K-means functions are placed here for now
23 	std::vector<float3> KMeansIteration(std::vector<float3> means, std::vector<float3> unitPositions, int newK);
24 	float DistanceToBase(float3 pos);
25 	float3 GetClosestBaseSpot(float3 pos);
26 	bool PlaceIdleUnit(int unit);
27 
28 	// for use for builders
29 	bool IsSafeBuildSpot(float3 mypos);
30 
31 	float3 FindSafeSpot(float3 myPos, float minSafety, float maxSafety);
32 	float3 FindSafeArea(float3 pos);
33 	float3 FindVerySafeArea(float3 pos);
34 	float3 FindUnsafeArea(float3 pos);
35 
36 	void AirAttack(int);
37 	void AirPatrol(int);
38 
39 	void UpdateKMeans(void);
40 	void UpdateAir(int);
41 	void UpdateSea(int);
42 
43 	// nuke-related functions
44 	void UpdateNukeSilos(int);
45 	int PickNukeSiloTarget(std::vector<std::pair<int, float> >&);
46 	void GetNukeSiloTargets(std::vector<std::pair<int, float> >&);
47 
48 	void AssignTargets(int);
49 	void AssignTarget(CAttackGroup* group);
50 
51 	bool UnitGroundAttackFilter(int unit);
52 	bool UnitBuildingFilter(const UnitDef* ud);
53 	bool UnitReadyFilter(int unit);
54 
55 	void CombineGroups(void);
56 
57 private:
58 	AIClasses* ai;
59 
60 	std::list<int> attackUnits;
61 	std::list< std::pair<int, float3> > stuckUnits;
62 	// TODO: should be sets
63 	std::list<int> unarmedAirUnits;
64 	std::list<int> armedAirUnits;
65 
66 	bool airIsAttacking;
67 	bool airPatrolOrdersGiven;
68 	int airTarget;
69 
70 	int newGroupID;
71 
72 	std::list<CAttackGroup> attackGroups;
73 //	std::list<CAttackGroup> defenseGroups;
74 
75 	std::vector<float3> kMeansBase;
76 	std::vector<float3> kMeansEnemyBase;
77 	int kMeansK;
78 	int kMeansEnemyK;
79 };
80 
81 #endif
82