1 /*
2  * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3  * It is copyright by its individual contributors, as recorded in the
4  * project's Git history.  See COPYING.txt at the top level for license
5  * terms and a link to the Git history.
6  */
7 
8 #pragma once
9 
10 #include <cstdint>
11 
12 #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
13 // Values for special flags
14 enum class PLAYER_FLAG : uint32_t
15 {
16 	None = 0,
17 	INVULNERABLE = 1,	// Player is invincible
18 	BLUE_KEY = 2,		// Player has blue key
19 	RED_KEY = 4,		// Player has red key
20 	GOLD_KEY = 8,		// Player has gold key
21 	MAP_ALL = 64,		// Player can see unvisited areas on map
22 	QUAD_LASERS = 1024,	// Player shoots 4 at once
23 	/* Renamed from CLOAKED due to name conflict with AI define
24 	 * `CLOAKED`.
25 	 */
26 	PLAYER_CLOAKED = 2048,		// Player is cloaked for awhile
27 #if defined(DXX_BUILD_DESCENT_II)
28 	HAS_TEAM_FLAG = 16,			// Player has his team's flag
29 	AMMO_RACK = 128,	// Player has ammo rack
30 	CONVERTER = 256,	// Player has energy->shield converter
31 	AFTERBURNER = 4096,	// Player's afterburner is engaged
32 	HEADLIGHT = 8192,	// Player has headlight boost
33 	HEADLIGHT_ON = 16384,	// is headlight on or off?
34 	HEADLIGHT_PRESENT_AND_ON = HEADLIGHT | HEADLIGHT_ON,	// required for thief
35 #endif
36 };
37 
38 constexpr PLAYER_FLAG operator~(const PLAYER_FLAG a)
39 {
40 	return static_cast<PLAYER_FLAG>(~static_cast<uint32_t>(a));
41 }
42 
43 constexpr PLAYER_FLAG operator|(const PLAYER_FLAG a, const PLAYER_FLAG b)
44 {
45 	return static_cast<PLAYER_FLAG>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
46 }
47 
48 #define PLAYER_FLAGS_INVULNERABLE	PLAYER_FLAG::INVULNERABLE
49 #define PLAYER_FLAGS_BLUE_KEY	PLAYER_FLAG::BLUE_KEY
50 #define PLAYER_FLAGS_RED_KEY	PLAYER_FLAG::RED_KEY
51 #define PLAYER_FLAGS_GOLD_KEY	PLAYER_FLAG::GOLD_KEY
52 #define PLAYER_FLAGS_MAP_ALL	PLAYER_FLAG::MAP_ALL
53 #define PLAYER_FLAGS_QUAD_LASERS	PLAYER_FLAG::QUAD_LASERS
54 #define PLAYER_FLAGS_CLOAKED	PLAYER_FLAG::PLAYER_CLOAKED
55 #if defined(DXX_BUILD_DESCENT_II)
56 #define PLAYER_FLAGS_FLAG	PLAYER_FLAG::HAS_TEAM_FLAG
57 #define PLAYER_FLAGS_AMMO_RACK	PLAYER_FLAG::AMMO_RACK
58 #define PLAYER_FLAGS_CONVERTER	PLAYER_FLAG::CONVERTER
59 #define PLAYER_FLAGS_AFTERBURNER	PLAYER_FLAG::AFTERBURNER
60 #define PLAYER_FLAGS_HEADLIGHT	PLAYER_FLAG::HEADLIGHT
61 #define PLAYER_FLAGS_HEADLIGHT_ON	PLAYER_FLAG::HEADLIGHT_ON
62 #endif
63 
64 class player_flags
65 {
66 	uint32_t flags;
67 public:
68 	void operator&() const = delete;
69 	player_flags() = default;
player_flags(const uint32_t & f)70 	explicit player_flags(const uint32_t &f) : flags(f)
71 	{
72 	}
player_flags(PLAYER_FLAG f)73 	explicit player_flags(PLAYER_FLAG f) : flags(static_cast<uint32_t>(f))
74 	{
75 	}
get_player_flags()76 	uint32_t get_player_flags() const
77 	{
78 		return flags;
79 	}
80 	player_flags &operator&=(const player_flags &rhs)
81 	{
82 		flags &= rhs.flags;
83 		return *this;
84 	}
85 	player_flags &operator|=(const player_flags &rhs)
86 	{
87 		flags |= rhs.flags;
88 		return *this;
89 	}
90 	player_flags &operator|=(const uint32_t &rhs)
91 	{
92 		flags |= rhs;
93 		return *this;
94 	}
95 	player_flags operator|(const player_flags &rhs) const
96 	{
97 		return player_flags(flags | rhs.flags);
98 	}
99 	player_flags operator~() const
100 	{
101 		return player_flags(~flags);
102 	}
103 	uint32_t operator&(const PLAYER_FLAG value) const
104 	{
105 		return flags & static_cast<uint32_t>(value);
106 	}
107 	player_flags &operator^=(const PLAYER_FLAG value)
108 	{
109 		flags ^= static_cast<uint32_t>(value);
110 		return *this;
111 	}
112 	player_flags &operator&=(const PLAYER_FLAG value)
113 	{
114 		flags &= static_cast<uint32_t>(value);
115 		return *this;
116 	}
117 	player_flags &operator|=(const PLAYER_FLAG value)
118 	{
119 		flags |= static_cast<uint32_t>(value);
120 		return *this;
121 	}
122 };
123 #endif
124