1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef MAP_INFO_H
4 #define MAP_INFO_H
5 
6 #include "System/float3.h"
7 #include "System/float4.h"
8 
9 #include <string>
10 #include <vector>
11 
12 class LuaTable;
13 class MapParser;
14 #if !defined(HEADLESS) && !defined(NO_SOUND)
15 	struct EAXSfxProps;
16 #endif
17 
18 
19 class CMapInfo
20 {
21 public:
22 	/** Terrain type, there can be 256 of these:
23 	    "MAP\TerrainType0" up to "MAP\TerrainType255" */
24 	static const int NUM_TERRAIN_TYPES = 256;
25 
26 	/**
27 	 * @param mapInfoFile mapinfo file, aka sm3 / smf (full path)
28 	 * @param mapName human readable mapname e.g. DeltaSiegeDry
29 	 */
30 	CMapInfo(const std::string& mapInfoFile, const std::string& mapName);
31 	~CMapInfo();
32 
33 	/* The settings are just public members because:
34 
35 	   1) it's quite some work to encapsulate all of them, and
36 	   2) nothing too bad happens if you modify them, there are no complex
37 	      pointer members that really beg for encapsulation.
38 
39 	   Instead of encapsulation it is as effective and much easier make the
40 	   global mapInfo const, ie. const CMapInfo* mapInfo;
41 	 */
42 
43 	/* Note: this could (should) have been anonymous structures if only MSVC 8
44 	   didn't crap out on it.  Specifically, it craps out on any class with at
45 	   least 1 user defined non-inline constructor and at least 2 anonymous
46 	   structures, each with at least 1 object with a constructor in it.
47 	   In other words, it probably assigns the same name to each anonymous
48 	   structure, and later gets confused by that.
49 
50 	   This sample code triggers the problem in MSVC:
51 
52 		class A {
53 			A::A();
54 			struct { std::string s1; } a1;
55 			struct { std::string s2; } a2;
56 		};
57 		A::A() {}
58 	 */
59 
60 	std::string GetStringValue(const std::string& key) const; // can be used before Load()
61 
62 	/** Global settings, ie. from "MAP" section. */
63 	struct map_t {
64 		std::string name;        ///< The filename as passed to the constructor.
65 		std::string description; ///< "MAP\\Description"
66 		std::string author;
67 		float hardness;          ///< "MAP\\MapHardness"
68 		bool  notDeformable;
69 		/** Stores the gravity as a negative number in units/frame^2
70 		    (NOT positive units/second^2 as in the mapfile) */
71 		float gravity;
72 		float tidalStrength;
73 		float maxMetal;        ///< what metal value 255 in the metal map is worth
74 		float extractorRadius; ///< extraction radius for mines
75 		float voidAlphaMin;
76 		bool  voidWater;
77 		bool  voidGround;
78 	} map;
79 
80 	/** GUI settings (used by CGuiHandler) */
81 	struct gui_t {
82 		bool autoShowMetal;
83 	} gui;
84 
85 	/** settings read from "MAP\ATMOSPHERE" section */
86 	struct atmosphere_t {
87 		float  fluidDensity; ///< in kg/m^3
88 		float  cloudDensity;
89 		float  fogStart;
90 		float  fogEnd;
91 		float4 fogColor;
92 		float3 skyColor;
93 		float3 skyDir;
94 		float3 sunColor;
95 		float3 cloudColor;
96 		float  minWind;
97 		float  maxWind;
98 		std::string skyBox;
99 	} atmosphere;
100 
101 	/** settings read from "MAP\SPLATS" section */
102 	struct splats_t {
103 		float4 texScales;
104 		float4 texMults;
105 	} splats;
106 
107 	/** settings read from "MAP\GRASS" section */
108 	struct grass_t {
109 		float bladeWaveScale; //! how strongly wind affects grass-blade waving (if 0, disables vertex animation)
110 		float bladeWidth;
111 		float bladeHeight;    //! actual blades will be (bladeHeight + randf(0, bladeHeight)) tall
112 		float bladeAngle;
113 		int maxStrawsPerTurf;
114 		float3 color;
115 		std::string bladeTexName;    // defaults to internally-generated texture
116 	} grass;
117 
118 	/** settings read from "MAP\LIGHT" section */
119 	struct light_t {
120 		float4 sunDir;     ///< Holds vector for the direction of the sun
121 		float sunOrbitTime;
122 		float sunStartAngle;
123 		float3 groundAmbientColor;
124 		float3 groundSunColor;
125 		float3 groundSpecularColor;
126 		float  groundShadowDensity;
127 		float4 unitAmbientColor;
128 		float4 unitSunColor;
129 		float  unitShadowDensity;
130 		float3 unitSpecularColor;
131 		float  specularExponent;
132 	} light;
133 
134 	/** settings read from "MAP\WATER" section
135 	    prefix their name with "Water" to get the TDF variable */
136 	struct water_t {
137 		float  fluidDensity;      ///< in kg/m^3
138 		float  repeatX;           ///< (calculated default is in IWater)
139 		float  repeatY;           ///< (calculated default is in IWater)
140 		float  damage;
141 		float3 absorb;
142 		float3 baseColor;
143 		float3 minColor;
144 		float3 surfaceColor;
145 		float  surfaceAlpha;
146 		float4 planeColor;
147 		float3 diffuseColor;
148 		float3 specularColor;
149 		float  ambientFactor;
150 		float  diffuseFactor;
151 		float  specularFactor;
152 		float  specularPower;
153 		float  fresnelMin;
154 		float  fresnelMax;
155 		float  fresnelPower;
156 		float  reflDistortion;
157 		float  blurBase;
158 		float  blurExponent;
159 		float  perlinStartFreq;
160 		float  perlinLacunarity;
161 		float  perlinAmplitude;
162 		float  windSpeed;
163 		bool   shoreWaves;
164 		bool   forceRendering;    ///< if false the renderers will render it only if currentMinMapHeight<0
165 		bool   hasWaterPlane;     ///< true if "MAP\WATER\WaterPlaneColor" is set
166 		unsigned char numTiles;
167 		std::string texture;
168 		std::string foamTexture;
169 		std::string normalTexture;
170 		std::vector<std::string> causticTextures;
171 	} water;
172 
173 	/** SMF specific settings */
174 	struct smf_t {
175 		std::string detailTexName;        ///< "MAP\DetailTex"
176 		std::string specularTexName;      ///< "MAP\SpecularTex"
177 		std::string splatDistrTexName;
178 		std::string splatDetailTexName;
179 		std::string grassShadingTexName;  // defaults to minimap texture
180 		std::string skyReflectModTexName;
181 		std::string detailNormalTexName;
182 		std::string lightEmissionTexName;
183 		std::string parallaxHeightTexName;
184 
185 		float minHeight;
186 		bool  minHeightOverride;
187 		float maxHeight;
188 		bool  maxHeightOverride;
189 
190 		std::vector<std::string> smtFileNames;
191 	} smf;
192 
193 	/** SM3 specific settings
194 	    This is NOT complete, SM3 stores so much in the map settings
195 	    that it really isn't a good idea to put them here. */
196 	struct sm3_t {
197 		std::string minimap; ///< "MAP\minimap"
198 	} sm3;
199 
200 	struct pfs_t {
201 		struct legacy_constants_t {
202 		} legacy_constants;
203 
204 		struct qtpfs_constants_t {
205 			unsigned int layersPerUpdate;
206 			unsigned int maxTeamSearches;
207 			unsigned int minNodeSizeX;
208 			unsigned int minNodeSizeZ;
209 			unsigned int maxNodeDepth;
210 			unsigned int numSpeedModBins;
211 			float        minSpeedModVal;
212 			float        maxSpeedModVal;
213 		} qtpfs_constants;
214 	} pfs;
215 
216 
217 	struct TerrainType {
218 		std::string name;
219 		float hardness;
220 		float tankSpeed;   ///< "TankMoveSpeed"
221 		float kbotSpeed;   ///< "KbotMoveSpeed"
222 		float hoverSpeed;  ///< "HoverMoveSpeed"
223 		float shipSpeed;   ///< "ShipMoveSpeed"
224 		bool receiveTracks;
225 	};
226 
227 	TerrainType terrainTypes[NUM_TERRAIN_TYPES];
228 
229 	/**
230 	 * Sound EFX param structure
231 	 */
232 #if !defined(HEADLESS) && !defined(NO_SOUND)
233 	EAXSfxProps* efxprops;
234 #endif
235 
236 private:
237 	void ReadGlobal();
238 	void ReadGui();
239 	void ReadAtmosphere();
240 	void ReadSplats();
241 	void ReadGrass();
242 	void ReadLight();
243 	void ReadWater();
244 	void ReadSMF();
245 	void ReadSM3();
246 	void ReadTerrainTypes();
247 	void ReadPFSConstants();
248 	void ReadSound();
249 
250 	MapParser* parser; // map       parser root table
251 	LuaTable* resRoot; // resources parser root table
252 };
253 
254 extern const CMapInfo* mapInfo;
255 
256 #endif // MAP_INFO_H
257