HoverRace  2.0
GameOptions.h
Go to the documentation of this file.
1 
2 // GameOptions.h
3 //
4 // Copyright (c) 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <bitset>
25 
26 #include "../Util/MR_Types.h"
27 
28 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
29 # ifdef MR_ENGINE
30 # define MR_DllDeclare __declspec( dllexport )
31 # else
32 # define MR_DllDeclare __declspec( dllimport )
33 # endif
34 #else
35 # define MR_DllDeclare
36 #endif
37 
38 namespace HoverRace {
39 namespace Model {
40 
42 {
43 public:
44  GameOptions() : weaponsEnabled(true) { }
45 
46 public:
47  char ToFlags() const;
48 
49 public:
50  enum class Craft : size_t
51  {
52  EON, CX, BI, BASIC
53  };
54 
55  static Craft PickRandomCraft();
56 
57 public:
58  //TODO: Handle this by blacklisting/allowing the list of weapon pickups.
59  bool IsWeaponsEnabled() const { return weaponsEnabled; }
60  void SetWeaponsEnabled(bool enabled) { weaponsEnabled = enabled; }
61 
66  void BlacklistCraft(Craft craft)
67  {
68  craftBlacklist[static_cast<size_t>(craft)] = 1;
69  }
70 
75  void AllowOnlyCraft(Craft craft)
76  {
77  craftBlacklist.set();
78  craftBlacklist[static_cast<size_t>(craft)] = 0;
79  }
80 
86  bool IsCraftAllowed(Craft craft) const
87  {
88  return !craftBlacklist[static_cast<size_t>(craft)];
89  }
90 
95  void BlacklistObject(MR_UInt16 classId)
96  {
97  if (classId < objectBlacklist.size()) {
98  objectBlacklist[classId] = 1;
99  }
100  }
101 
107  bool IsObjectAllowed(MR_UInt16 classId) const
108  {
109  return
110  classId >= objectBlacklist.size() ||
111  !objectBlacklist[classId];
112  }
113 
114 private:
116  std::bitset<4> craftBlacklist;
117  std::bitset<1104> objectBlacklist;
118 };
119 
120 
121 } // namespace Model
122 } // namespace HoverRace
123 
124 #undef MR_DllDeclare
uint16_t MR_UInt16
Definition: MR_Types.h:42
bool IsWeaponsEnabled() const
Definition: GameOptions.h:59
void SetWeaponsEnabled(bool enabled)
Definition: GameOptions.h:60
std::bitset< 4 > craftBlacklist
Definition: GameOptions.h:116
bool IsObjectAllowed(MR_UInt16 classId) const
Check if an object is allowed (by class ID).
Definition: GameOptions.h:107
std::bitset< 1104 > objectBlacklist
Class IDs from ObjFac1.
Definition: GameOptions.h:117
#define MR_DllDeclare
Definition: GameOptions.h:35
void AllowOnlyCraft(Craft craft)
Allow only a single craft (blacklist all other crafts).
Definition: GameOptions.h:75
Craft
Definition: GameOptions.h:50
Definition: GameOptions.h:41
bool weaponsEnabled
Definition: GameOptions.h:115
void BlacklistCraft(Craft craft)
Blacklist a craft from being selected.
Definition: GameOptions.h:66
Definition: Announcement.h:24
void BlacklistObject(MR_UInt16 classId)
Blacklists an object from spawning in the track.
Definition: GameOptions.h:95
GameOptions()
Definition: GameOptions.h:44
bool IsCraftAllowed(Craft craft) const
Check if a craft is allowed.
Definition: GameOptions.h:86