1 //       _________ __                 __
2 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
3 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
4 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
5 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
6 //             \/                  \/          \//_____/            \/
7 //  ______________________                           ______________________
8 //                        T H E   W A R   B E G I N S
9 //         Stratagus - A free fantasy real time strategy game engine
10 //
11 /**@name stratagus.h - The main header file. */
12 //
13 //      (c) Copyright 1998-2019 by Lutz Sammer, Jimmy Salmon and Andrettin
14 //
15 //      This program is free software; you can redistribute it and/or modify
16 //      it under the terms of the GNU General Public License as published by
17 //      the Free Software Foundation; only version 2 of the License.
18 //
19 //      This program is distributed in the hope that it will be useful,
20 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //      GNU General Public License for more details.
23 //
24 //      You should have received a copy of the GNU General Public License
25 //      along with this program; if not, write to the Free Software
26 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 //      02111-1307, USA.
28 //
29 
30 #ifndef __STRATAGUS_H__
31 #define __STRATAGUS_H__
32 
33 //@{
34 
35 /*============================================================================
36 ==  Config definitions
37 ============================================================================*/
38 
39 // Dynamic loading.
40 //#define DYNAMIC_LOAD
41 
42 /*============================================================================
43 ==  Compiler repairs
44 ============================================================================*/
45 
46 #ifdef _MSC_VER
47 
48 #define WIN32_LEAN_AND_MEAN
49 
50 #if _MSC_VER >= 1800
51 // From VS2013 onwards, std::min/max are only defined if algorithm is included
52 #include <algorithm>
53 #endif
54 
55 #pragma warning(disable:4244)               /// Conversion from double to uchar
56 #pragma warning(disable:4761)               /// Integral size mismatch
57 #pragma warning(disable:4786)               /// Truncated to 255 chars
58 
59 #ifndef __func__
60 #define __func__ __FUNCTION__
61 #endif
62 
63 #define snprintf _snprintf
64 #if !(_MSC_VER >= 1500 && _MSC_VER < 1600)
65 #define vsnprintf _vsnprintf
66 #endif
67 #define unlink _unlink
68 #define strdup _strdup
69 #define strcasecmp _stricmp
70 #define strncasecmp _strnicmp
71 
72 #endif  // } _MSC_VER
73 
74 
75 /*============================================================================
76 ==  Macro
77 ============================================================================*/
78 
79 // To remove warning for unused variable.
80 #ifdef __GNUC__
81 #define UNUSED(var) do {__typeof__ (&var) __attribute__ ((unused)) __tmp = &var; } while(0)
82 #else
83 #define UNUSED(var) (var)
84 #endif
85 
86 #ifdef __GNUC__
87 #define PRINTF_VAARG_ATTRIBUTE(a, b) __attribute__((format (printf, a, b)))
88 #else
89 #define PRINTF_VAARG_ATTRIBUTE(a, b)
90 #endif
91 
92 /*============================================================================
93 ==  Debug definitions
94 ============================================================================*/
95 
96 /**
97 **  This simulates vararg macros.
98 **  Example:
99 **    DebugPrint("Test %d %d\n" _C_ 1 _C_ 2);
100 */
101 #define _C_  ,    /// Debug , to simulate vararg macros
102 
103 extern void PrintLocation(const char *file, int line, const char *funcName);
104 
105 /// Print function in debug macros
106 #define PrintFunction() PrintLocation(__FILE__, __LINE__, __func__);
107 
108 extern bool EnableDebugPrint;
109 extern bool EnableAssert;
110 extern bool EnableUnitDebug;
111 
112 extern void AbortAt(const char *file, int line, const char *funcName, const char *conditionStr);
113 extern void PrintOnStdOut(const char *format, ...);
114 
115 /**
116 **  Assert a condition. If cond is not true abort with file,line.
117 */
118 #define Assert(cond) \
119 	do { if (EnableAssert && !(cond)) { AbortAt(__FILE__, __LINE__, __func__, #cond); }} while (0)
120 
121 /**
122 **  Print debug information with function name.
123 */
124 #define DebugPrint(args) \
125 	do { if (EnableDebugPrint) { PrintFunction(); PrintOnStdOut(args); } } while (0)
126 
127 /*============================================================================
128 ==  Definitions
129 ============================================================================*/
130 
131 #include <string.h>
132 
133 #ifndef __UTIL_H__
134 #include "util.h"
135 #endif
136 
new_strdup(const char * str)137 inline char *new_strdup(const char *str)
138 {
139 	int len = strlen(str) + 1;
140 	char *newstr = new char[len];
141 	strcpy_s(newstr, len, str);
142 	return newstr;
143 }
144 
145 /*----------------------------------------------------------------------------
146 --  General
147 ----------------------------------------------------------------------------*/
148 
149 /// Text string: Name, Version, Copyright
150 extern const char NameLine[];
151 
152 /*----------------------------------------------------------------------------
153 --  Some limits
154 ----------------------------------------------------------------------------*/
155 
156 //Wyrmgus start
157 //#define PlayerMax    16                 /// How many players are supported
158 #define PlayerMax    32                 /// How many players are supported
159 //Wyrmgus end
160 #define UnitTypeMax  2048                /// How many unit types supported
161 #define UpgradeMax   2048                /// How many upgrades supported
162 //Wyrmgus start
163 //#define MAX_RACES 8
164 #define MAX_RACES 128
165 #define FactionMax 128				/// Maximum number of factions a civilization can have
166 #define PlayerColorMax 32			/// How many player colors are supported
167 
168 #define AuraRange 6					/// Range of auras
169 #define PlayerHeroMax 4				/// Maximum heroes per player
170 #define PlayerMajorDeityMax 1		/// Maximum major deities per player/character
171 //#define PlayerMinorDeityMax 3		/// Maximum minor deities per player/character
172 #define PlayerMinorDeityMax 1		/// Maximum minor deities per player/character
173 #define PlayerDeityMax (PlayerMajorDeityMax + PlayerMinorDeityMax)
174 
175 #define PopulationPerUnit 1000		/// Number of people a unit represents
176 
177 #define DEFAULT_HOURS_PER_DAY 24
178 #define DEFAULT_DAYS_PER_MONTH 30
179 #define DEFAULT_DAYS_PER_YEAR 365
180 #define DEFAULT_DAYS_PER_WEEK 7
181 //Wyrmgus end
182 
183 /// Frames per second to display (original 30-40)
184 #define FRAMES_PER_SECOND  30  // 1/30s
185 /// Game cycles per second to simulate (original 30-40)
186 #define CYCLES_PER_SECOND  30  // 1/30s 0.33ms
187 #define CYCLES_PER_MINUTE  (CYCLES_PER_SECOND * 60)
188 
189 #define CYCLES_PER_IN_GAME_HOUR (CYCLES_PER_SECOND * 10) // every 10 seconds of gameplay = 1 hour for the purposes of in-game date/time
190 
191 #define DEFAULT_DAY_MULTIPLIER_PER_YEAR (DEFAULT_DAYS_PER_YEAR * DEFAULT_HOURS_PER_DAY * CYCLES_PER_IN_GAME_HOUR / CYCLES_PER_SECOND / 60 / 60) //the purpose of the day multiplier is so that we can effectively have months only taking e.g. 10 days to pass, so that we can have a day/night cycle, different days of the week and months/years, while still months and years not taking an overly long time to pass; the day multiplier should as such NOT affect the changes in day of the week; here we define the day multiplier to be such that one year equals roughly one hour of gameplay
192 
193 #define HOUR_MULTIPLIER_DIVIDER 4 //for calculating the multipliers for schedules; the maximum duration length will be the default multiplier * the HOUR_MULTIPLIER_DIVIDER
194 
195 #define HeroCooldownCycles CYCLES_PER_MINUTE	/// Cooldown (in cycles) for recruiting a hero
196 
197 #define DefaultTileMovementCost 8
198 
199 /*----------------------------------------------------------------------------
200 --  stratagus.cpp
201 ----------------------------------------------------------------------------*/
202 
203 extern std::string StratagusLibPath;        /// Location of stratagus data
204 extern std::string MenuRace;
205 //Wyrmgus start
206 extern std::string PlayerFaction;
207 //Wyrmgus end
208 
209 extern unsigned long GameCycle;				/// Game simulation cycle counter
210 extern unsigned long FastForwardCycle;		/// Game Replay Fast Forward Counter
211 
212 extern void Exit(int err);                  /// Exit
213 extern void ExitFatal(int err);             /// Exit with fatal error
214 
215 extern void UpdateDisplay();            /// Game display update
216 extern void DrawMapArea();              /// Draw the map area
217 extern void GameMainLoop();             /// Game main loop
218 extern int stratagusMain(int argc, char **argv); /// main entry
219 
220 //Wyrmgus start
221 enum Directions {
222 	North,
223 	Northeast,
224 	East,
225 	Southeast,
226 	South,
227 	Southwest,
228 	West,
229 	Northwest,
230 
231 	MaxDirections
232 };
233 
234 enum Difficulties {
235 	DifficultyNoDifficulty = 0,
236 	DifficultyEasy,
237 	DifficultyNormal,
238 	DifficultyHard,
239 	DifficultyBrutal
240 };
241 
242 enum TechLevels {
243 	NoTechLevel = 0,
244 	AgrarianBronzeTechLevel,
245 	AgrarianIronTechLevel,
246 	CivilizedBronzeTechLevel,
247 	CivilizedIronTechLevel,
248 	CivilizedGunpowderTechLevel
249 };
250 
251 #include <vec2i.h>
252 
253 extern int GetReverseDirection(int direction);
254 extern std::string GetDirectionNameById(int direction);
255 extern int GetDirectionIdByName(const std::string &direction);
256 extern int GetDirectionFromOffset(int x, int y);
257 extern Vec2i GetDirectionOffset(int direction);
258 //Wyrmgus end
259 
260 //@}
261 
262 #endif // !__STRATAGUS_H__
263