_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

settings.h
Go to the documentation of this file.
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 //
12 //
13 // (c) Copyright 2000-2006 by Andreas Arens and Jimmy Salmon
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 __SETTINGS_H__
31 #define __SETTINGS_H__
32 
33 /*
34  * This header file defines all the structures that need to be consistent for replays, savegame loading, and
35  * multiplayer games.
36  */
37 
39 
40 #include <bitset>
41 #include <stdint.h>
42 #include <string>
43 #include <vector>
44 #include <functional>
45 #include <variant>
46 
47 /*----------------------------------------------------------------------------
48 -- TODO: Remove this once we move off of tolua++ and can properly support strongly typed enums
49 ----------------------------------------------------------------------------*/
50 #define USING_TOLUAPP 1
51 #if USING_TOLUAPP
52 // using tolua++
53 #define ENUM_CLASS enum
54 #else
55 #define ENUM_CLASS enum class
56 #endif
57 
58 /*----------------------------------------------------------------------------
59 -- Some limits
60 ----------------------------------------------------------------------------*/
61 
62 constexpr unsigned char PlayerMax = 16;
63 constexpr unsigned short UnitTypeMax = 2048;
64 constexpr unsigned short UpgradeMax = 2048;
65 constexpr unsigned char MAX_RACES = 8;
66 constexpr unsigned char PlayerNumNeutral = PlayerMax - 1;
67 
69 constexpr unsigned char FRAMES_PER_SECOND = 30; // 1/30s
71 constexpr unsigned char CYCLES_PER_SECOND = 30; // 1/30s 0.33ms
72 
73 /*----------------------------------------------------------------------------
74 -- Settings
75 ----------------------------------------------------------------------------*/
76 
77 constexpr int8_t SettingsPresetMapDefault = -1;
78 
117 ENUM_CLASS PlayerTypes : int8_t {
126 };
127 
128 extern std::string PlayerTypeNames[static_cast<int>(PlayerTypes::PlayerRescueActive) + 1];
129 
130 static_assert(MAX_RACES < 256, "Race selection needs to fit into 8 bits");
131 static_assert(PlayerMax < 256, "Team number must fit into 8 bits");
132 
134  int8_t PlayerColor;
135  std::string AIScript;
136  int8_t Race;
137  int8_t Team;
139 
140  void Save(const std::function <void (std::string)>& f) {
141  f(std::string("PlayerColor = ") + std::to_string(PlayerColor));
142  f(std::string("AIScript = \"") + AIScript + "\"");
143  f(std::string("Race = ") + std::to_string(Race));
144  f(std::string("Team = ") + std::to_string(Team));
145  f(std::string("Type = ") + std::to_string(static_cast<int>(Type)));
146  }
147 
148  void Init() {
149  PlayerColor = 0;
150  AIScript = "ai-passive";
153  Type = PlayerTypes::MapDefault;
154  }
155 
156  bool operator==(const SettingsPresets &other) const {
157  return PlayerColor == other.PlayerColor &&
158  AIScript == other.AIScript &&
159  Race == other.Race &&
160  Team == other.Team &&
161  Type == other.Type;
162  }
163 };
164 
165 ENUM_CLASS RevealTypes : uint8_t {
166  cNoRevelation,
169 };
170 
174 ENUM_CLASS NetGameTypes : uint8_t {
175  SettingsSinglePlayerGame,
177  Unset
178 };
179 
183 ENUM_CLASS GameTypes : int8_t {
184  SettingsGameTypeMapDefault = SettingsPresetMapDefault,
193 
194  // Future game type ideas
195 #if 0
196  SettingsGameTypeOneOnOne,
197  SettingsGameTypeCaptureTheFlag,
198  SettingsGameTypeGreed,
199  SettingsGameTypeSlaughter,
200  SettingsGameTypeSuddenDeath,
201  SettingsGameTypeTeamMelee,
202  SettingsGameTypeTeamCaptureTheFlag
203 #endif
204 };
205 
208 ENUM_CLASS MapRevealModes : uint8_t {
209  cHidden = 0,
213 };
214 
215 ENUM_CLASS FieldOfViewTypes : uint8_t {
216  cShadowCasting,
218  NumOfTypes
219 };
220 
230 struct Settings {
232 
233  // Individual presets:
234  // For single-player game only Presets[0] will be used..
236 
237  // Common settings:
238  int8_t Resources;
239  int8_t NumUnits;
240  int8_t Opponents;
241  int8_t Difficulty;
246  union {
247  struct {
248  unsigned NoFogOfWar:1;
249  unsigned Inside:1;
250  unsigned AiExplores:1;
252  unsigned AiChecksDependencies:1;
253  unsigned UserGameSettings:27;
254  };
255  uint32_t _Bitfield;
256  };
257 
258  bool GetUserGameSetting(int i) {
259  return std::bitset<27>(UserGameSettings).test(i);
260  }
261 
262  void SetUserGameSetting(int i, bool v) {
263  std::bitset<27> bs(UserGameSettings);
264  bs.set(i, v);
265  UserGameSettings = bs.to_ulong();
266  }
267 
268  bool operator==(const Settings &other) const {
269  for (int i = 0; i < PlayerMax; i++) {
270  if (Presets[i] == other.Presets[i]) {
271  continue;
272  } else {
273  return false;
274  }
275  }
276  return NetGameType == other.NetGameType &&
277  Resources == other.Resources &&
278  NumUnits == other.NumUnits &&
279  Opponents == other.Opponents &&
280  Difficulty == other.Difficulty &&
281  GameType == other.GameType &&
282  FoV == other.FoV &&
283  RevealMap == other.RevealMap &&
284  DefeatReveal == other.DefeatReveal &&
285  _Bitfield == other._Bitfield;
286  }
287 
288  void Save(const std::function <void (std::string)>& f, bool withPlayers = true) {
289  f(std::string("NetGameType = ") + std::to_string(static_cast<int>(NetGameType)));
290  if (withPlayers) {
291  for (int i = 0; i < PlayerMax; ++i) {
292  Presets[i].Save([&] (std::string field) {
293  f(std::string("Presets[") + std::to_string(i) + "]." + field);
294  });
295  }
296  }
297  f(std::string("Resources = ") + std::to_string(Resources));
298  f(std::string("NumUnits = ") + std::to_string(NumUnits));
299  f(std::string("Opponents = ") + std::to_string(Opponents));
300  f(std::string("Difficulty = ") + std::to_string(Difficulty));
301  f(std::string("GameType = ") + std::to_string(static_cast<int>(GameType)));
302  f(std::string("FoV = ") + std::to_string(static_cast<int>(FoV)));
303  f(std::string("RevealMap = ") + std::to_string(static_cast<int>(RevealMap)));
304  f(std::string("DefeatReveal = ") + std::to_string(static_cast<int>(DefeatReveal)));
305  f(std::string("Flags = ") + std::to_string(_Bitfield));
306  }
307 
308  bool SetField(std::string field, int value) {
309  if (field == "NetGameType") {
310  NetGameType = static_cast<NetGameTypes>(value);
311  } else if (field == "Resources") {
312  Resources = value;
313  } else if (field == "NumUnits") {
314  NumUnits = value;
315  } else if (field == "Opponents") {
316  Opponents = value;
317  } else if (field == "Difficulty") {
318  Difficulty = value;
319  } else if (field == "GameType") {
320  GameType = static_cast<GameTypes>(value);
321  } else if (field == "FoV") {
322  FoV = static_cast<FieldOfViewTypes>(value);
323  } else if (field == "RevealMap") {
324  RevealMap = static_cast<MapRevealModes>(value);
325  } else if (field == "DefeatReveal") {
326  DefeatReveal = static_cast<RevealTypes>(value);
327  } else if (field == "Flags") {
328  _Bitfield = value;
329  } else {
330  return false;
331  }
332  return true;
333  }
334 
335  void Init() {
336  NetGameType = NetGameTypes::SettingsSinglePlayerGame;
337  for (int i = 0; i < PlayerMax; ++i) {
338  Presets[i].Init();
339  Presets[i].PlayerColor = i;
340  }
345  GameType = GameTypes::SettingsGameTypeMapDefault;
347  RevealMap = MapRevealModes::cHidden;
349  NoFogOfWar = 0;
350  Inside = 0;
351  AiExplores = 1;
354  UserGameSettings = 0;
355  }
356 };
357 
358 /*----------------------------------------------------------------------------
359 -- Variables
360 ----------------------------------------------------------------------------*/
361 
362 extern Settings GameSettings;
363 
364 /*----------------------------------------------------------------------------
365 -- Functions
366 ----------------------------------------------------------------------------*/
367 
369 extern void InitSettings();
370 
372 
373 #endif // !__SETTINGS_H__
InitSettings
void InitSettings()
Game settings.
Definition: game.cpp:1082
Settings::AiExplores
unsigned AiExplores
if game uses interior tileset or is generally "inside" for the purpose of obstacles
Definition: settings.h:250
NetGameTypes
ENUM_CLASS NetGameTypes
Revelation types.
Definition: settings.h:175
NumOfTypes
ENUM_CLASS NumOfTypes
Definition: settings.h:219
UpgradeMax
constexpr unsigned short UpgradeMax
How many unit types supported.
Definition: settings.h:64
SettingsGameTypeMelee
ENUM_CLASS SettingsGameTypeMelee
Definition: settings.h:185
SettingsGameTypeManVsMachine
ENUM_CLASS SettingsGameTypeManVsMachine
Definition: settings.h:189
Settings::GameType
GameTypes GameType
Terrain type (summer,winter,...)
Definition: settings.h:242
cNumOfModes
ENUM_CLASS cNumOfModes
Definition: settings.h:213
Settings::NetGameType
NetGameTypes NetGameType
Definition: settings.h:231
PlayerNumNeutral
constexpr unsigned char PlayerNumNeutral
Definition: settings.h:66
SettingsGameTypeManTeamVsMachine
ENUM_CLASS SettingsGameTypeManTeamVsMachine
Definition: settings.h:190
Unset
ENUM_CLASS Unset
Definition: settings.h:178
SettingsGameTypeMachineVsMachineTraining
ENUM_CLASS SettingsGameTypeMachineVsMachineTraining
Definition: settings.h:204
Settings::Difficulty
int8_t Difficulty
Preset # of ai-opponents.
Definition: settings.h:241
Settings::_Bitfield
uint32_t _Bitfield
Definition: settings.h:255
Settings::RevealMap
MapRevealModes RevealMap
Which field of view is used - important to be shared for unit sight.
Definition: settings.h:244
SettingsPresets::Team
int8_t Team
Race of the player.
Definition: settings.h:137
GameTypes
ENUM_CLASS GameTypes
Definition: settings.h:184
PlayerRescueActive
ENUM_CLASS PlayerRescueActive
rescued passive
Definition: settings.h:125
cExplored
ENUM_CLASS cExplored
Definition: settings.h:211
Settings::Init
void Init()
Definition: settings.h:335
SettingsPresets::PlayerColor
int8_t PlayerColor
Definition: settings.h:134
RevealTypes
ENUM_CLASS RevealTypes
Definition: settings.h:166
SettingsPresets::operator==
bool operator==(const SettingsPresets &other) const
Definition: settings.h:156
cSimpleRadial
ENUM_CLASS cSimpleRadial
Definition: settings.h:217
Settings::UserGameSettings
unsigned UserGameSettings
If false, the AI can do upgrades even if the dependencies are not met. This can be desirable to simpl...
Definition: settings.h:253
FRAMES_PER_SECOND
constexpr unsigned char FRAMES_PER_SECOND
this is the neutral player slot
Definition: settings.h:69
Settings::AiChecksDependencies
unsigned AiChecksDependencies
Use alternate target choosing algorithm for auto attack mode (idle, attack-move, patrol,...
Definition: settings.h:252
SettingsPresets::Race
int8_t Race
AI script for computer to use.
Definition: settings.h:136
PlayerPerson
ENUM_CLASS PlayerPerson
computer player
Definition: settings.h:123
FieldOfViewTypes
ENUM_CLASS FieldOfViewTypes
Definition: settings.h:216
SettingsGameTypeMachineVsMachine
ENUM_CLASS SettingsGameTypeMachineVsMachine
Definition: settings.h:191
CYCLES_PER_SECOND
constexpr unsigned char CYCLES_PER_SECOND
Game cycles per second to simulate (original 30-40)
Definition: settings.h:71
Settings::Opponents
int8_t Opponents
Preset # of units.
Definition: settings.h:240
Settings::operator==
bool operator==(const Settings &other) const
Definition: settings.h:268
Settings::Presets
SettingsPresets Presets[PlayerMax]
Multiplayer or single player.
Definition: settings.h:235
PlayerComputer
ENUM_CLASS PlayerComputer
unused slot
Definition: settings.h:122
PlayerUnset
ENUM_CLASS PlayerUnset
use default
Definition: settings.h:119
PlayerMax
constexpr unsigned char PlayerMax
Definition: settings.h:62
SettingsGameTypeFreeForAll
ENUM_CLASS SettingsGameTypeFreeForAll
Definition: settings.h:186
Settings::DefeatReveal
RevealTypes DefeatReveal
Reveal map kind.
Definition: settings.h:245
cAllUnits
ENUM_CLASS cAllUnits
Definition: settings.h:167
Settings::NoFogOfWar
unsigned NoFogOfWar
Definition: settings.h:248
MapRevealModes
ENUM_CLASS MapRevealModes
Definition: settings.h:209
SettingsPresets::Type
PlayerTypes Type
Team of player.
Definition: settings.h:138
Settings
Definition: settings.h:230
cBuildingsOnly
ENUM_CLASS cBuildingsOnly
Definition: settings.h:169
Settings::Inside
unsigned Inside
if dynamic fog of war is disabled
Definition: settings.h:249
SettingsMultiPlayerGame
ENUM_CLASS SettingsMultiPlayerGame
Definition: settings.h:176
SettingsGameTypeLeftVsRight
ENUM_CLASS SettingsGameTypeLeftVsRight
Definition: settings.h:188
PlayerRescuePassive
ENUM_CLASS PlayerRescuePassive
human player
Definition: settings.h:124
cKnown
ENUM_CLASS cKnown
Definition: settings.h:210
Settings::FoV
FieldOfViewTypes FoV
Game type (melee, free for all,...)
Definition: settings.h:243
SettingsPresets::Save
void Save(const std::function< void(std::string)> &f)
Type of player (for network games)
Definition: settings.h:140
Settings::GetUserGameSetting
bool GetUserGameSetting(int i)
Definition: settings.h:258
Settings::Save
void Save(const std::function< void(std::string)> &f, bool withPlayers=true)
Definition: settings.h:288
PlayerTypeNames
std::string PlayerTypeNames[static_cast< int >(PlayerTypes::PlayerRescueActive)+1]
Definition: game.cpp:280
Settings::Resources
int8_t Resources
Definition: settings.h:238
Settings::SetField
bool SetField(std::string field, int value)
Definition: settings.h:308
Settings::NumUnits
int8_t NumUnits
Preset resource factor.
Definition: settings.h:239
Settings::SimplifiedAutoTargeting
unsigned SimplifiedAutoTargeting
If true, AI sends explorers to search for resources (almost useless thing)
Definition: settings.h:251
SettingsPresets
Definition: settings.h:133
MAX_RACES
constexpr unsigned char MAX_RACES
How many upgrades supported.
Definition: settings.h:65
Settings::SetUserGameSetting
void SetUserGameSetting(int i, bool v)
Definition: settings.h:262
UnitTypeMax
constexpr unsigned short UnitTypeMax
How many players are supported.
Definition: settings.h:63
PlayerNobody
ENUM_CLASS PlayerNobody
neutral
Definition: settings.h:121
SettingsPresetMapDefault
constexpr int8_t SettingsPresetMapDefault
Definition: settings.h:77
PlayerNeutral
ENUM_CLASS PlayerNeutral
not set
Definition: settings.h:120
GameSettings
Settings GameSettings
Definition: game.cpp:87
SettingsPresets::Init
void Init()
Definition: settings.h:148
SettingsGameTypeTopVsBottom
ENUM_CLASS SettingsGameTypeTopVsBottom
Definition: settings.h:187
PlayerTypes
ENUM_CLASS PlayerTypes
Special: Use map supplied.
Definition: settings.h:118
SettingsPresets::AIScript
std::string AIScript
Color of a player.
Definition: settings.h:135
ENUM_CLASS
#define ENUM_CLASS
Definition: settings.h:53
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.