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_BRAIN_H
11 #define AAI_BRAIN_H
12 
13 class AAI;
14 class AAIBuildTable;
15 class AAIExecute;
16 class AIIMap;
17 class AAISector;
18 
19 #include "aidef.h"
20 
21 enum SectorType {UNKNOWN_SECTOR, LAND_SECTOR, LAND_WATER_SECTOR, WATER_SECTOR};
22 
23 
24 class AAIBrain
25 {
26 public:
27 	AAIBrain(AAI *ai);
28 	~AAIBrain(void);
29 
30 	// adds/removes sector to the base
31 	void AddSector(AAISector *sector);
32 	void RemoveSector(AAISector *sector);
33 
34 	// returns dest attack sector
35 	AAISector* GetAttackDest(bool land, bool water);
36 
37 	// returns a sector to proceed with attack
38 	AAISector* GetNextAttackDest(AAISector *current_sector, bool land, bool water);
39 
40 	// checks for new neighbours (and removes old ones if necessary)
41 	void UpdateNeighbouringSectors();
42 
43 	// recalculates the center of the base
44 	void UpdateBaseCenter();
45 
46 	// updates max units spotted
47 	void UpdateMaxCombatUnitsSpotted(vector<unsigned short>& units_spotted);
48 
49 	void UpdateAttackedByValues();
50 
51 	void AttackedBy(int combat_category_id);
52 
53 	// recalculates def capabilities of all units
54 	void UpdateDefenceCapabilities();
55 
56 	// adds/subtracts def. cap. for a single unit
57 	void AddDefenceCapabilities(int def_id, UnitCategory category);
58 //	void SubtractDefenceCapabilities(int def_id, UnitCategory category);
59 
60 	// returns pos where scout schould be sent to
61 	void GetNewScoutDest(float3 *dest, int scout);
62 
63 
64 	// adds new sectors to base
65 	bool ExpandBase(SectorType sectorType);
66 
67 	// returns how much ressources can be spent for unit construction atm
68 	float Affordable();
69 
70 	// returns true if commander is allowed for construction at the specified position in the sector
71 	bool CommanderAllowedForConstructionAt(AAISector *sector, float3 *pos);
72 
73 	// returns true if AAI may build a mex in this sector (e.g. safe sector)
74 	bool MexConstructionAllowedInSector(AAISector *sector);
75 
76 	void DefendCommander(int attacker);
77 
78 	void BuildUnits();
79 
80 	// returns game period
81 	int GetGamePeriod();
82 
83 	void UpdatePressureByEnemy();
84 
85 	// returns the probability that units of specified combat category will be used to attack (determine value with respect to game period, current and learning data)
86 	float GetAttacksBy(int combat_category, int game_period);
87 
88 	//  0 = sectors the ai uses to build its base, 1 = direct neighbours etc.
89 	vector<list<AAISector*> > sectors;
90 
91 	// ratio of  flat land/water cells in all base sectors
92 	float baseLandRatio;
93 	float baseWaterRatio;
94 
95 	int max_distance;
96 
97 	// center of base (mean value of centers of all base sectors)
98 	float3 base_center;
99 
100 	// are there any free metal spots within the base
101 	bool freeBaseSpots;
102 	bool expandable;
103 
104 	// holding max number of units of a category spotted at the same time
105 	vector<float> max_combat_units_spotted;
106 
107 	// current estimations of game situation , values ranging from 0 (min) to 1 max
108 
109 	float enemy_pressure_estimation;	// how much pressure done to the ai by enemy units
110 
111 	// pos where com spawned
112 	float3 start_pos;
113 
114 private:
115 	// returns true if sufficient ressources to build unit are availbale
116 	bool RessourcesForConstr(int unit, int workertime = 175);
117 
118 	// returns true if enough metal for constr.
119 	bool MetalForConstr(int unit, int workertime = 175);
120 
121 	// returns true if enough energy for constr.
122 	bool EnergyForConstr(int unit, int wokertime = 175);
123 
124 	// returns true if sector is considered to be safe
125 	bool IsSafeSector(AAISector *sector);
126 
127 	void BuildUnitOfMovementType(unsigned int allowed_move_type, float cost, float ground_eff, float air_eff, float hover_eff, float sea_eff, float submarine_eff, float stat_eff, bool urgent);
128 	// returns ratio of cells in the current base sectors that match movement_type (e.g. 0.3 if 30% of base is covered with water and building is naval)
129 	float GetBaseBuildspaceRatio(unsigned int building_move_type);
130 	bool SectorInList(list<AAISector*> mylist, AAISector *sector);
131 	list<AAISector*> GetSectors();
132 	vector<float> defence_power_vs;
133 	vector<float> attacked_by;
134 
135 	AAI *ai;
136 };
137 
138 #endif
139 
140