1 // -------------------------------------------------------------------------
2 // AAI
3 //
4 // A skirmish AI for the Spring engine.
5 // Copyright Alexander Seizinger
6 //
7 // Released under GPL license: see LICENSE.html for more information.
8 // -------------------------------------------------------------------------
9 
10 #ifndef AAI_GROUP_H
11 #define AAI_GROUP_H
12 
13 #include "System/type2.h"
14 #include "aidef.h"
15 
16 enum GroupTask {GROUP_IDLE, GROUP_ATTACKING, GROUP_DEFENDING, GROUP_PATROLING, GROUP_BOMBING, GROUP_RETREATING};
17 
18 namespace springLegacyAI {
19 	struct UnitDef;
20 	struct Command;
21 }
22 #include "LegacyCpp/Command.h"
23 using namespace springLegacyAI;
24 
25 #include <vector>
26 #include <list>
27 using namespace std;
28 
29 class AAI;
30 class AAIBuildTable;
31 class AAIAttack;
32 class AAISector;
33 
34 class AAIGroup
35 {
36 public:
37 	AAIGroup(AAI* ai, const UnitDef *def, UnitType unit_type, int continent_id);
38 	~AAIGroup(void);
39 
40 	bool AddUnit(int unit_id, int def_id, UnitType type, int continent_id);
41 
42 	bool RemoveUnit(int unit, int attacker);
43 
44 	void GiveOrder(Command *c, float importance, UnitTask task, const char *owner);
45 
46 	void AttackSector(AAISector *dest, float importance);
47 
48 	// defend unit vs enemy (0; zerovector if enemy unknown)
49 	void Defend(int unit, float3 *enemy_pos, int importance);
50 
51 	// retreat combat groups to pos
52 	void Retreat(float3 *pos);
53 
54 	// bombs target (only for bomber groups)
55 	void BombTarget(int target_id, float3 *target_pos);
56 
57 	// orders fighters to defend air space
58 	void DefendAirSpace(float3 *pos);
59 
60 	// orders air units to attack
61 	void AirRaidUnit(int unit_id);
62 
63 	int GetRandomUnit();
64 
65 	void Update();
66 
67 	void TargetUnitKilled();
68 
69 	// checks current rally point and chooses new one if necessary
70 	void UpdateRallyPoint();
71 
72 	// gets a new rally point and orders units to get there
73 	void GetNewRallyPoint();
74 
75 	void UnitIdle(int unit);
76 
77 	float GetCombatPowerVsCategory(int assault_cat_id);
78 
79 	void GetCombatPower(vector<float> *combat_power);
80 
81 	float3 GetGroupPos();
82 
83 	// checks if the group may participate in an attack (= idle, sufficient combat power, etc.)
84 	bool AvailableForAttack();
85 
86 	int maxSize;
87 	int size;
88 
89 	float avg_speed;
90 	list<int2> units;
91 
92 
93 	float task_importance;	// importance of current task
94 
95 	GroupTask task;
96 
97 	UnitCategory category;
98 	int combat_category;
99 
100 	UnitType group_unit_type;
101 
102 	unsigned int group_movement_type;
103 
104 	// attack the group takes part in
105 	AAIAttack *attack;
106 
107 	// rally point of the group, ZeroVector if none...
108 	float3 rally_point;
109 
110 	// id of the continent the units of this group are stationed on (only matters if group_movement_type is continent bound)
111 	int continent;
112 
113 private:
114 	// returns true if group is strong enough to attack
115 	bool SufficientAttackPower();
116 	int lastCommandFrame;
117 	Command lastCommand;
118 	int speed_group;
119 
120 	AAI* ai;
121 	AAISector *target_sector;
122 
123 };
124 
125 #endif
126 
127