1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
20 //
21 // Main-declerations, -classes and structures for the game
22 // Contains all global varaibles needed for the game
23 //
24 ///////////////////////////////////////////////////////////////////////////////
25 
26 // Hides some warnings from the eye of VS users ///////////////////////////////
27 #ifdef _MSC_VER
28 #pragma warning(disable:4996)
29 #endif
30 
31 #ifndef mainH
32 #define mainH
33 
34 // Includes ///////////////////////////////////////////////////////////////////
35 
36 #include <vector>
37 #include <SDL.h>
38 #include "utility/autosurface.h"
39 #include "defines.h"
40 #include "utility/language.h"
41 
42 // Predeclarations
43 class cPlayer;
44 class cLanguage;
45 struct sBuildingUIData;
46 struct sVehicleUIData;
47 
48 ///////////////////////////////////////////////////////////////////////////////
49 // Globals
50 // ------------------------
51 //
52 ///////////////////////////////////////////////////////////////////////////////
53 
54 // Languagepack ////////////////////////////////////////////////////////////////
55 EX cLanguage lngPack;
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 // Structures
59 // ------------------------
60 //
61 ///////////////////////////////////////////////////////////////////////////////
62 
63 struct sUnitData;
64 
65 struct sID
66 {
sIDsID67 	sID() : iFirstPart (0), iSecondPart (0) {}
68 
69 	std::string getText() const;
70 	void generate (const std::string& text);
71 
isAVehiclesID72 	bool isAVehicle() const { return iFirstPart == 0; }
isABuildingsID73 	bool isABuilding() const { return iFirstPart == 1; }
74 
75 	/** Get the basic version of a unit.
76 	 * @param Owner If Owner is given, his clan will be taken
77 	 *        into consideration for modifications of the unit's values.
78 	 * @return the sUnitData of the owner without upgrades
79 	 *         (but with the owner's clan modifications) */
80 	const sUnitData* getUnitDataOriginalVersion (const cPlayer* Owner = nullptr) const;
81 
82 	bool operator== (const sID& ID) const;
83 	bool operator!= (const sID& rhs) const { return ! (*this == rhs); }
84 	bool operator< (const sID& rhs) const { return less_vehicleFirst (rhs); }
85 	bool less_vehicleFirst (const sID& ID) const;
86 	bool less_buildingFirst (const sID& ID) const;
87 
88 public:
89 	int iFirstPart;
90 	int iSecondPart;
91 };
92 
93 enum
94 {
95 	TERRAIN_NONE = 0,
96 	TERRAIN_AIR = 1,
97 	TERRAIN_SEA = 2,
98 	TERRAIN_GROUND = 4,
99 	TERRAIN_COAST = 8,
100 	AREA_SUB = 16,
101 	AREA_EXP_MINE = 32
102 };
103 
104 ///////////////////////////////////////////////////////////////////////////////
105 // Variables-Classes
106 // ------------------------
107 // This classes are for saving global Variables needed by the game
108 ///////////////////////////////////////////////////////////////////////////////
109 
110 // GraphicsData - Class containing all normal graphic surfaces ////////////////
111 class cGraphicsData
112 {
113 public:
114 	AutoSurface gfx_Chand;
115 	AutoSurface gfx_Cno;
116 	AutoSurface gfx_Cselect;
117 	AutoSurface gfx_Cmove;
118 	AutoSurface gfx_Cmove_draft; // for shift + lmb to set a path but no move
119 	AutoSurface gfx_Chelp;
120 	AutoSurface gfx_Cattack;
121 	AutoSurface gfx_Cattackoor; // attack a unit out of range
122 	AutoSurface gfx_Cpfeil1;
123 	AutoSurface gfx_Cpfeil2;
124 	AutoSurface gfx_Cpfeil3;
125 	AutoSurface gfx_Cpfeil4;
126 	AutoSurface gfx_Cpfeil6;
127 	AutoSurface gfx_Cpfeil7;
128 	AutoSurface gfx_Cpfeil8;
129 	AutoSurface gfx_Cpfeil9;
130 	AutoSurface gfx_hud_stuff;
131 	AutoSurface gfx_shadow;
132 	AutoSurface gfx_tmp;
133 	AutoSurface gfx_context_menu;
134 	AutoSurface gfx_destruction;
135 	AutoSurface gfx_destruction_glas;
136 	AutoSurface gfx_Cband;
137 	AutoSurface gfx_band_small;
138 	AutoSurface gfx_band_big;
139 	AutoSurface gfx_band_small_org;
140 	AutoSurface gfx_band_big_org;
141 	AutoSurface gfx_big_beton_org;
142 	AutoSurface gfx_big_beton;
143 	AutoSurface gfx_Ctransf;
144 	AutoSurface gfx_Cload;
145 	AutoSurface gfx_Cactivate;
146 	AutoSurface gfx_storage;
147 	AutoSurface gfx_storage_ground;
148 	AutoSurface gfx_dialog;
149 	AutoSurface gfx_edock;
150 	AutoSurface gfx_ehangar;
151 	AutoSurface gfx_edepot;
152 	AutoSurface gfx_Cmuni;
153 	AutoSurface gfx_Crepair;
154 	AutoSurface gfx_panel_top;
155 	AutoSurface gfx_panel_bottom;
156 	AutoSurface gfx_Csteal;
157 	AutoSurface gfx_Cdisable;
158 	AutoSurface gfx_menu_stuff;
159 	AutoSurface gfx_hud_extra_players;
160 	AutoSurface gfx_player_pc;
161 	AutoSurface gfx_player_human;
162 	AutoSurface gfx_player_none;
163 	AutoSurface gfx_player_select;
164 	AutoSurface gfx_exitpoints_org;
165 	AutoSurface gfx_exitpoints;
166 	AutoSurface gfx_menu_buttons;
167 	AutoSurface gfx_player_ready;
168 	AutoSurface gfx_hud_chatbox;
169 
170 	std::string DialogPath;
171 	std::string Dialog2Path;
172 	std::string Dialog3Path;
173 } EX GraphicsData;
174 
175 // Effects - Class containing all effect surfaces /////////////////////////////
176 class cEffectsData
177 {
178 public:
179 	void load (const char* path);
180 public:
181 	AutoSurface fx_explo_big[2];
182 	AutoSurface fx_explo_small[2];
183 	AutoSurface fx_explo_water[2];
184 	AutoSurface fx_explo_air[2];
185 	AutoSurface fx_muzzle_big[2];
186 	AutoSurface fx_muzzle_small[2];
187 	AutoSurface fx_muzzle_med[2];
188 	AutoSurface fx_hit[2];
189 	AutoSurface fx_smoke[2];
190 	AutoSurface fx_rocket[2];
191 	AutoSurface fx_dark_smoke[2];
192 	AutoSurface fx_tracks[2];
193 	AutoSurface fx_corpse[2];
194 	AutoSurface fx_absorb[2];
195 } EX EffectsData;
196 
197 // ResourceData - Class containing all resource surfaces //////////////////////
198 class cResourceData
199 {
200 public:
201 	void load (const char* path);
202 public:
203 	AutoSurface res_metal_org;
204 	AutoSurface res_metal;
205 	AutoSurface res_oil_org;
206 	AutoSurface res_oil;
207 	AutoSurface res_gold_org;
208 	AutoSurface res_gold;
209 } EX ResourceData;
210 
211 // UnitsData - Class containing all building/vehicle surfaces & data ///////////////
212 class cUnitsData
213 {
214 public:
215 	cUnitsData();
216 
217 	void initializeIDData();
218 
219 	int getBuildingIndexBy (sID id) const;
220 	int getVehicleIndexBy (sID id) const;
221 
222 	const sBuildingUIData* getBuildingUI (sID id) const;
223 	const sVehicleUIData* getVehicleUI (sID id) const;
224 
225 	// clan = -1: without clans
226 	const sUnitData& getVehicle (int nr, int clan = -1);
227 	const sUnitData& getBuilding (int nr, int clan = -1);
228 	const sUnitData& getUnit (const sID& id, int clan = -1);
229 
230 	// clan = -1: without clans
231 	const std::vector<sUnitData>& getUnitData_Vehicles (int clan);
232 	const std::vector<sUnitData>& getUnitData_Buildings (int clan);
233 
234 	unsigned int getNrVehicles() const;
235 	unsigned int getNrBuildings() const;
236 
getConstructorID()237 	const sID& getConstructorID() const { return constructorID; }
getEngineerID()238 	const sID& getEngineerID() const { return engineerID; }
getSurveyorID()239 	const sID& getSurveyorID() const { return surveyorID; }
240 
241 	void scaleSurfaces (float zoomFactor);
242 
243 private:
244 	void initializeClanUnitData();
245 
246 public: // TODO: private
247 	// Vehicles
248 	// the standard version without clan modifications
249 	std::vector<sUnitData> svehicles;
250 	std::vector<sVehicleUIData> vehicleUIs;
251 
252 	// Buildings
253 	// the standard version without clan modifications
254 	std::vector<sUnitData> sbuildings;
255 	std::vector<sBuildingUIData> buildingUIs;
256 
257 	AutoSurface dirt_small_org;
258 	AutoSurface dirt_small;
259 	AutoSurface dirt_small_shw_org;
260 	AutoSurface dirt_small_shw;
261 	AutoSurface dirt_big_org;
262 	AutoSurface dirt_big;
263 	AutoSurface dirt_big_shw_org;
264 	AutoSurface dirt_big_shw;
265 
266 	// direct pointer on some of the building graphics
267 	SDL_Surface* ptr_small_beton;
268 	SDL_Surface* ptr_small_beton_org;
269 	SDL_Surface* ptr_connector;
270 	SDL_Surface* ptr_connector_org;
271 	SDL_Surface* ptr_connector_shw;
272 	SDL_Surface* ptr_connector_shw_org;
273 
274 private:
275 	// contains the modified versions for the clans
276 	std::vector<std::vector<sUnitData> > clanUnitDataVehicles;
277 	// contains the modified versions for the clans
278 	std::vector<std::vector<sUnitData> > clanUnitDataBuildings;
279 	bool initializedClanUnitData;
280 
281 	sID constructorID;
282 	sID engineerID;
283 	sID surveyorID;
284 public: // TODO : private
285 	sID specialIDLandMine;
286 	sID specialIDSeaMine;
287 	sID specialIDMine;
288 	sID specialIDSmallGen;
289 	sID specialIDConnector;
290 	sID specialIDSmallBeton;
291 } EX UnitsData;
292 
293 enum eFreezeMode
294 {
295 	FREEZE_WAIT_FOR_SERVER,    // waiting response from server
296 	FREEZE_WAIT_FOR_OTHERS,    // waiting for the others turn, in turn based mode
297 	FREEZE_PAUSE,              // pause, because... pause
298 	FREEZE_WAIT_FOR_RECONNECT, // game is paused, because the connection to a player is lost
299 	FREEZE_WAIT_FOR_TURNEND,   // server is processing the turn end
300 	FREEZE_WAIT_FOR_PLAYER     // waiting for response from a client
301 };
302 
303 class sFreezeModes
304 {
305 public:
306 	sFreezeModes();
307 
308 	void disable (eFreezeMode mode);
309 	void enable (eFreezeMode mode, int playerNumber);
310 	bool isEnable (eFreezeMode mode) const;
getPlayerNumber()311 	int getPlayerNumber() const { return playerNumber; }
312 	bool isFreezed() const;
313 public:
314 	bool waitForOthers;    // waiting for the others turn, in turn based mode
315 	bool waitForServer;    // waiting response from server
316 	bool waitForReconnect; // paused, because the connection to a player is lost
317 	bool waitForTurnEnd;   // server is processing the turn end
318 	bool pause;            // pause, because... pause
319 	bool waitForPlayer;    // waiting for response from a client
320 private:
321 	int playerNumber;
322 };
323 
324 // OtherData - Class containing the rest of surfaces //////////////////////////
325 class cOtherData
326 {
327 public:
328 	void loadWayPoints();
329 public:
330 	AutoSurface WayPointPfeile[8][60];
331 	AutoSurface WayPointPfeileSpecial[8][60];
332 } EX OtherData;
333 
334 ///////////////////////////////////////////////////////////////////////////////
335 // Predeclerations
336 // ------------------------
337 //
338 ///////////////////////////////////////////////////////////////////////////////
339 
340 /**
341  * Return if it is the main thread.
342  * @note: should be called by main once by the main thread to initialize.
343  */
344 bool is_main_thread();
345 
346 /**Converts integer to string
347 */
348 std::string iToStr (int x);
349 /**Converts integer to string in hex representation
350 */
351 std::string iToHex (unsigned int x);
352 /**Converts float to string
353 */
354 std::string fToStr (float x);
355 /**Converts pointer to string
356 */
357 std::string pToStr (const void* x);
358 /**Converts bool to string
359 */
360 std::string bToStr (bool x);
361 
362 /**
363 * Rounds given param num to specified position after decimal point<br>
364 * Example:<br>
365 * num := 3,234<br>
366 * n := 2<br>
367 * >>>>>>> Result = 3,23<br>
368 *
369 *@author MM
370 *@param num number to round up
371 *@param n the position after decimal point in dValueToRound,
372 *         that will be rounded
373 *@return rounded num
374 */
375 float Round (float num, unsigned int n);
376 
377 
378 template <typename T>
Square(T v)379 T Square (T v) { return v * v; }
380 
381 /**
382 * Rounds given param num without numbers after decimal point<br>
383 * Example:<br>
384 * num := 3,234<br>
385 * >>>>>>> Result = 3<br>
386 *
387 *@author beko
388 *@param num number to round up
389 *@return rounded num
390 */
391 int Round (float num);
392 
393 void Quit();
394 
395 #endif
396