1 /*
2  *  This file is part of Dune Legacy.
3  *
4  *  Dune Legacy 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  *  Dune Legacy 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 Dune Legacy.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef DATATYPES_H
19 #define DATATYPES_H
20 
21 #include <Definitions.h>
22 
23 // Libraries
24 #include <SDL.h>
25 #include <string>
26 
27 
28 class Coord {
29 public:
Coord()30     Coord()
31      : x(0), y(0) {
32     }
33 
Coord(int x,int y)34     Coord(int x,int y)
35      : x(x), y(y)
36     {
37     }
38 
39     inline bool operator==(const Coord& c) const {
40         return (x == c.x && y == c.y);
41     }
42 
43     inline bool operator!=(const Coord& c) const {
44         return !operator==(c);
45     }
46 
47     inline Coord& operator+=(const Coord& c) {
48         x += c.x;
49         y += c.y;
50         return *this;
51     }
52 
53     inline Coord operator+(const Coord& c) const {
54         Coord ret = *this;
55         ret += c;
56         return ret;
57     }
58 
59     inline Coord& operator-=(const Coord& c) {
60         x -= c.x;
61         y -= c.y;
62         return *this;
63     }
64 
65     inline Coord operator-(const Coord& c) const {
66         Coord ret = *this;
67         ret -= c;
68         return ret;
69     }
70 
71     inline Coord& operator*=(int c) {
72         x *= c;
73         y *= c;
74         return *this;
75     }
76 
77     inline Coord operator*(int c) const {
78         Coord ret = *this;
79         ret *= c;
80         return ret;
81     }
82 
83     inline Coord& operator/=(int c) {
84         x /= c;
85         y /= c;
86         return *this;
87     }
88 
89     inline Coord operator/(int c) const {
90         Coord ret = *this;
91         ret /= c;
92         return ret;
93     }
94 
invalidate()95     inline void invalidate() {
96         x = INVALID_POS;
97         y = INVALID_POS;
98     }
99 
isValid()100     inline bool isValid() const {
101         return ((x != INVALID_POS) && (y != INVALID_POS));
102     }
103 
isInvalid()104     inline bool isInvalid() const {
105         return ((x == INVALID_POS) || (y == INVALID_POS));
106     }
107 
Invalid()108     static inline const Coord Invalid() {
109         return Coord(INVALID_POS, INVALID_POS);
110     }
111 
112     inline operator bool() const {
113         return isValid();
114     };
115 
116 public:
117     int x;
118     int y;
119 };
120 
121 typedef enum {
122     ATTACKMODE_INVALID = -1,
123     GUARD = 0,      ///< The unit will attack enemy units but will not move or follow enemy units.
124     AREAGUARD = 1,  ///< Area Guard is the most common command for pre-placed AI units. They will scan for targets in a relatively large radius, and return to their original position after their target was either destroyed or left the immediate area.
125     AMBUSH = 2,     ///< Ambush means a unit will remain in position until sighted by the enemy, and then proceed to attack any enemy units it might find on the map.
126     HUNT = 3,       ///< Hunt makes a unit start from its position towards enemy units, even if the player has not sighted the AI (normally the AI will not attack until there has been a contact between the player's and the AI's units). Also works for human units, they'll go towards any enemy units on the map just as the mission starts.
127     HARVEST = 4,    ///< Only used by the map editor
128     SABOTAGE = 5,   ///< Only used by the map editor
129     STOP = 6,
130     CAPTURE = 7,    ///< Capture is only used for infantry units when ordered to capture a building
131     CARRYALLREQUESTED = 8, ///< This allows a unit to keep requesting a carryall even if one isn't available right now
132     RETREAT = 9,           ///< Ignore other units
133     ATTACKMODE_MAX
134 } ATTACKMODE;
135 
136 enum class GameState {
137     Start,
138     Loading,
139     Running,
140     Deinitialize
141 };
142 
143 enum class GameType {
144     Invalid           = -1,
145     LoadSavegame      = 0,
146     Campaign          = 1,
147     CustomGame        = 2,
148     Skirmish          = 3,
149     CustomMultiplayer = 4,
150     LoadMultiplayer   = 5
151 };
152 
153 
154 class SettingsClass
155 {
156 public:
157     class GeneralClass {
158     public:
159         bool            playIntro;          ///< Play the intro when starting the game?
160         std::string     playerName;         ///< The name of the player used for multiplayer games
161         std::string     language;           ///< Language code: "en" = English, "fr" = French, "de" = German
162         int             scrollSpeed;        ///< Scroll speed in pixels
163         bool            showTutorialHints;  ///< If true, tutorial hints are shown during the game
164     } general;
165 
166     class VideoClass {
167     public:
168         bool        fullscreen;
169         int         physicalWidth;
170         int         physicalHeight;
171         int         width;
172         int         height;
173         bool        frameLimit;
174         int         preferredZoomLevel;
175         std::string scaler;
176     } video;
177 
178     class AudioClass {
179     public:
180         bool        playSFX;
181         int         sfxVolume;
182         bool        playMusic;
183         int         musicVolume;
184         std::string musicType;
185     } audio;
186 
187     class NetworkClass {
188     public:
189         int         serverPort;
190         std::string metaServer;
191         bool        debugNetwork;
192     } network;
193 
194     class AIClass {
195     public:
196         std::string campaignAI;
197     } ai;
198 
199     class GameOptionsClass {
200     public:
GameOptionsClass()201         GameOptionsClass()
202          : gameSpeed(GAMESPEED_DEFAULT), concreteRequired(true), structuresDegradeOnConcrete(true), fogOfWar(false),
203            startWithExploredMap(false), instantBuild(false), onlyOnePalace(false), rocketTurretsNeedPower(false),
204            sandwormsRespawn(false), killedSandwormsDropSpice(false), manualCarryallDrops(false), maximumNumberOfUnitsOverride(-1)  {
205         }
206 
207 
208         bool operator==(const GameOptionsClass& goc) const {
209             return (gameSpeed == goc.gameSpeed)
210                     && (concreteRequired == goc.concreteRequired)
211                     && (structuresDegradeOnConcrete == goc.structuresDegradeOnConcrete)
212                     && (fogOfWar == goc.fogOfWar)
213                     && (startWithExploredMap == goc.startWithExploredMap)
214                     && (instantBuild == goc.instantBuild)
215                     && (onlyOnePalace == goc.onlyOnePalace)
216                     && (rocketTurretsNeedPower == goc.rocketTurretsNeedPower)
217                     && (sandwormsRespawn == goc.sandwormsRespawn)
218                     && (killedSandwormsDropSpice == goc.killedSandwormsDropSpice)
219                     && (manualCarryallDrops == goc.manualCarryallDrops)
220                     && (maximumNumberOfUnitsOverride == goc.maximumNumberOfUnitsOverride);
221         }
222 
223         bool operator!=(const GameOptionsClass& goc) const {
224             return !this->operator==(goc);
225         }
226 
227         int         gameSpeed;
228         bool        concreteRequired;
229         bool        structuresDegradeOnConcrete;
230         bool        fogOfWar;
231         bool        startWithExploredMap;
232         bool        instantBuild;
233         bool        onlyOnePalace;
234         bool        rocketTurretsNeedPower;
235         bool        sandwormsRespawn;
236         bool        killedSandwormsDropSpice;
237         bool        manualCarryallDrops;
238         int         maximumNumberOfUnitsOverride;
239     } gameOptions;
240 };
241 
242 typedef enum
243 {
244     HOUSE_UNUSED    = -2,
245     HOUSE_INVALID   = -1,
246     HOUSE_HARKONNEN =  0,
247     HOUSE_ATREIDES  =  1,
248     HOUSE_ORDOS     =  2,
249     HOUSE_FREMEN    =  3,
250     HOUSE_SARDAUKAR =  4,
251     HOUSE_MERCENARY =  5,
252     NUM_HOUSES
253 } HOUSETYPE;
254 
255 typedef enum {
256     RIGHT,
257     RIGHTUP,
258     UP,
259     LEFTUP,
260     LEFT,
261     LEFTDOWN,
262     DOWN,
263     RIGHTDOWN,
264     NUM_ANGLES
265 } ANGLETYPE;
266 
267 typedef enum  {
268     Drop_Invalid = -1,
269     Drop_North,         ///< unit will appear at a random position at the top of the map
270     Drop_East,          ///< unit will appear at a random position on the right side of the map
271     Drop_South,         ///< unit will appear at a random position at the bottom of the map
272     Drop_West,          ///< unit will appear at a random position on the left side of the map
273     Drop_Air,           ///< unit will be dropped at a random position
274     Drop_Visible,       ///< unit will be dropped at a random position in the middle of the map
275     Drop_Enemybase,     ///< unit will be dropped near the enemy base
276     Drop_Homebase       ///< unit will be dropped near the base of the owner of the new unit
277 } DropLocation;
278 
279 typedef enum {
280     TeamBehavior_Invalid = -1,
281     TeamBehavior_Normal,            ///< Attack units and/or structures when building up the team is complete
282     TeamBehavior_Guard,             ///< Same as TeamBehavior_Normal
283     TeamBehavior_Kamikaze,          ///< Directly attack structures when building up the team is complete
284     TeamBehavior_Staging,           ///< A team in the process of being built up
285     TeamBehavior_Flee               ///< Do nothing (Unimplemented in Dune II?)
286 } TeamBehavior;
287 
288 typedef enum {
289     TeamType_Invalid = -1,
290     TeamType_Foot,
291     TeamType_Wheeled,
292     TeamType_Tracked,
293     TeamType_Winged,
294     TeamType_Slither,
295     TeamType_Harvester
296 } TeamType;
297 
298 #endif //DATATYPES_H
299