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_CONFIG_H
11 #define AAI_CONFIG_H
12 
13 #include "LegacyCpp/IAICallback.h"
14 
15 #include <stdio.h>
16 #include <list>
17 #include <vector>
18 
19 using std::string;
20 using std::list;
21 using std::vector;
22 
23 class AAI;
24 namespace springLegacyAI {
25 	struct UnitDef;
26 }
27 
28 using namespace springLegacyAI;
29 
30 struct CostMultiplier
31 {
32 	int id;
33 	float multiplier;
34 };
35 
36 /// Converts a string to one that can be used in a file name (eg. "Abc.123 $%^*" -> "Abc.123_____")
37 std::string MakeFileSystemCompatible(const std::string& str);
38 
39 class AAIConfig
40 {
41 public:
42 	AAIConfig(void);
43 
44 	void LoadConfig(AAI *ai);
45 
46 	bool initialized;
47 
48 	// constants (will be loaded in aaiconfig)
49 
50 	// mod specific
51 	float SECTOR_SIZE;
52 	int MIN_ENERGY;  // min energy make value to be considered beeing a power plant
53 	int MAX_UNITS;
54 	int MAX_SCOUTS;
55 	int MAX_XROW;
56 	int MAX_YROW;
57 	int X_SPACE;
58 	int Y_SPACE;
59 	int MAX_GROUP_SIZE;
60 	int MAX_AIR_GROUP_SIZE;
61 	int MAX_SUBMARINE_GROUP_SIZE;
62 	int MAX_NAVAL_GROUP_SIZE;
63 	int MAX_ANTI_AIR_GROUP_SIZE;
64 	int MAX_ARTY_GROUP_SIZE;
65 	float MIN_EFFICIENCY;
66 
67 	int MAX_BUILDERS_PER_TYPE; // max builders of same unit type
68 	int MAX_FACTORIES_PER_TYPE;
69 	int MAX_BUILDQUE_SIZE;
70 	int MAX_ASSISTANTS;
71 	int MIN_ASSISTANCE_BUILDTIME;
72 	int MAX_BASE_SIZE;
73 	float SCOUT_SPEED;
74 	float GROUND_ARTY_RANGE;
75 	float SEA_ARTY_RANGE;
76 	float HOVER_ARTY_RANGE;
77 	float STATIONARY_ARTY_RANGE;
78 	int AIRCRAFT_RATE;
79 	int HIGH_RANGE_UNITS_RATE;
80 	int FAST_UNITS_RATE;
81 	int SIDES;
82 	int MIN_ENERGY_STORAGE;
83 	int MIN_METAL_STORAGE;
84 	int MAX_METAL_COST;
85 	int MAX_AIR_TARGETS;
86 	std::vector<std::string> START_UNITS;
87 	std::vector<std::string> SIDE_NAMES;
88 
89 	list<int> SCOUTS;
90 	list<int> ATTACKERS;
91 	list<int> TRANSPORTERS;
92 	list<int> METAL_MAKERS;
93 	list<int> DONT_BUILD;
94 
95 	//float KBOT_MAX_SLOPE;
96 	//float VEHICLE_MAX_SLOPE;
97 	//float HOVER_MAX_SLOPE;
98 	float NON_AMPHIB_MAX_WATERDEPTH;
99 	float METAL_ENERGY_RATIO;
100 	int MAX_DEFENCES;
101 	int MAX_STAT_ARTY;
102 	int MAX_AIR_BASE;
103 	bool AIR_ONLY_MOD;
104 	int MAX_STORAGE;
105 	int MAX_MEX_DISTANCE;
106 	int MAX_MEX_DEFENCE_DISTANCE;
107 	float MIN_METAL_MAKER_ENERGY;
108 	int MIN_FACTORIES_FOR_DEFENCES;
109 	int MIN_FACTORIES_FOR_STORAGE;
110 	float MIN_AIR_SUPPORT_EFFICIENCY;
111 	int UNIT_SPEED_SUBGROUPS;
112 	float MAX_COST_LIGHT_ASSAULT;
113 	float MAX_COST_MEDIUM_ASSAULT;
114 	float MAX_COST_HEAVY_ASSAULT;
115 	int MAX_ATTACKS;
116 
117 	vector<CostMultiplier> cost_multipliers;
118 
119 	// combat behaviour
120 	float FALLBACK_DIST_RATIO;	// units will try to fall back if enemy is closer than ratio of weapons range of the unit
121 	float MIN_FALLBACK_RANGE;	// units with lower weapons' range will not fall back
122 	float MAX_FALLBACK_RANGE;	// maximum distance units will try to keep to their enemies
123 	float MIN_FALLBACK_TURNRATE; // units with lower turnrate will not try to fall back
124 
125 	// internal
126 	float CLIFF_SLOPE;  // cells with greater slope will be considered to be cliffs
127 	int MAX_SECTOR_IMPORTANCE;
128 
129 	// game specific
130 	int SCOUT_UPDATE_FREQUENCY;
131 	float SCOUTING_MEMORY_FACTOR;
132 	float LEARN_SPEED;
133 	int LEARN_RATE;
134 	int GAME_PERIODS;
135 
136 	/**
137 	 * open a file in springs data directory
138 	 * @param filename relative path of the file in the spring data dir
139 	 * @param mode mode file to open, see manpage of fopen
140 	 */
141 	std::string GetFileName(const std::string& filename, const std::string& prefix = "", const std::string& suffix = "", bool write = false) const;
142 	std::string getUniqueName(bool game, bool gamehash, bool map, bool maphash) const;
143 
144 private:
145 	~AAIConfig(void);
146 
147 	const UnitDef* GetUnitDef(const std::string& name);
148 	int GetInt(FILE* file);
149 	float GetFloat(FILE* file);
150 	std::string GetString(FILE* file);
151 
152 	AAI *ai;
153 	int CONSTRUCTION_TIMEOUT;
154 	float WATER_MAP_RATIO;
155 	float LAND_WATER_MAP_RATIO;
156 	float LIGHT_ASSAULT_RATIO;
157 	int MIN_FACTORIES_FOR_RADAR_JAMMER;
158 //	int MAX_MEX_DEFENCE_COST;
159 	int MAX_METAL_MAKERS;
160 	float MIN_SECTOR_THREAT;
161 //	float SHIP_MIN_WATERDEPTH;
162 	int MIN_AIR_ATTACK_COST;
163 	int MAX_BUILDERS;
164 	int MIN_ASSISTANCE_BUILDSPEED;
165 	int AIR_DEFENCE;
166 	float MEDIUM_ASSAULT_RATIO;
167 	float HEAVY_ASSAULT_RATIO;
168 	float SUPER_HEAVY_ASSAULT_RATIO;
169 	int MIN_SUBMARINE_WATERLINE;
170 
171 };
172 
173 extern AAIConfig *cfg;
174 
175 
176 #endif
177 
178