1 /**
2  ** frflags.h - Frame- and quality-based flags from 'shape_info.txt'.
3  **
4  ** Written: 06/01/2008 - Marzo
5  **/
6 
7 #ifndef INCL_FRFLAGS_H
8 #define INCL_FRFLAGS_H  1
9 
10 /*
11 Copyright (C) 2008 The Exult Team
12 
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
17 
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU General Public License for more details.
22 
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26 */
27 
28 #include "baseinf.h"
29 #include "exult_constants.h"
30 
31 #include <iosfwd>
32 
33 class Shape_info;
34 
35 /*
36  *  Information about frame names.
37  *  This is meant to be stored in a totally ordered vector.
38  */
39 
40 namespace Frame_flags {
41 enum Enum_Frame_power_flags {
42     fp_poison_safe = 0,
43     fp_charm_safe,
44     fp_sleep_safe,
45     fp_paralysis_safe,
46     fp_curse_safe,
47     fp_power_safe,
48     fp_death_safe,
49     fp_cant_die,
50     fp_cold_immune,
51     fp_doesnt_eat,
52     fp_swamp_safe,
53     fp_force_usecode,
54     fp_infinite_reagents
55 };
56 enum Enum_Frame_Flags {
57     poison_safe = (1u << fp_poison_safe),
58     charm_safe = (1u << fp_charm_safe),
59     sleep_safe = (1u << fp_sleep_safe),
60     paralysis_safe = (1u << fp_paralysis_safe),
61     curse_safe = (1u << fp_curse_safe),
62     power_safe = (1u << fp_power_safe),
63     death_safe = (1u << fp_death_safe),
64     cant_die = (1u << fp_cant_die),
65     cold_immune = (1u << fp_cold_immune),
66     doesnt_eat = (1u << fp_doesnt_eat),
67     swamp_safe = (1u << fp_swamp_safe),
68     force_usecode = (1u << fp_force_usecode),
69     infinite_reagents = (1u << fp_infinite_reagents)
70 };
71 }
72 
73 class Frame_flags_info : public Base_info {
74 	short           frame;      // Frame for which this applies or -1 for any.
75 	short           quality;    // Quality for which this applies or -1 for any.
76 	unsigned int    m_flags;    // Bit field with the relevant flags.
77 public:
78 	friend class Shape_info;
79 	Frame_flags_info() = default;
80 	Frame_flags_info(short fr, short q, unsigned int fl, bool p = false,
81 	                 bool m = false, bool s = false, bool inv = false) {
82 		set(fr, q, fl, p, m, s, inv);
83 	}
Frame_flags_info(const Frame_flags_info & other)84 	Frame_flags_info(const Frame_flags_info &other)
85 		: Base_info(other), frame(other.frame), quality(other.quality), m_flags(other.m_flags) {
86 		info_flags = other.info_flags;
87 	}
88 	// Read in from file.
89 	bool read(std::istream &in, int version, Exult_Game game);
90 	// Write out.
91 	void write(std::ostream &out, int shapenum, Exult_Game game);
92 	void set(short fr, short q, unsigned int fl, bool p = false,
93 	         bool m = false, bool s = false, bool inv = false) {
94 		frame = fr;
95 		quality = q;
96 		m_flags = fl;
97 		set_patch(p);
98 		set_modified(m);
99 		set_static(s);
100 		set_invalid(inv);
101 	}
invalidate()102 	void invalidate() {
103 		m_flags = 0;
104 		set_invalid(true);
105 	}
get_frame()106 	int get_frame() const {
107 		return frame;
108 	}
get_quality()109 	int get_quality() const {
110 		return quality;
111 	}
get_flag(int tf)112 	bool get_flag(int tf) const {
113 		return (m_flags & (1 << tf)) != 0;
114 	}
get_flags()115 	int get_flags() const {
116 		return m_flags;
117 	}
set_flags(unsigned int fl)118 	void set_flags(unsigned int fl) {
119 		if (m_flags != fl) {
120 			set_modified(true);
121 			m_flags = fl;
122 		}
123 	}
124 	bool operator<(const Frame_flags_info &other) const {
125 		auto qual1 = static_cast<unsigned short>(quality);
126 		auto qual2 = static_cast<unsigned short>(other.quality);
127 		auto frame1 = static_cast<unsigned short>(frame);
128 		auto frame2 = static_cast<unsigned short>(other.frame);
129 		return (frame1 == frame2 && qual1 < qual2) || (frame1 < frame2);
130 	}
131 	bool operator==(const Frame_flags_info &other) const {
132 		return this == &other || (!(*this < other) && !(other < *this));
133 	}
134 	bool operator!=(const Frame_flags_info &other) const {
135 		return !(*this == other);
136 	}
137 	Frame_flags_info &operator=(const Frame_flags_info &other) {
138 		if (this != &other) {
139 			frame = other.frame;
140 			quality = other.quality;
141 			m_flags = other.m_flags;
142 			info_flags = other.info_flags;
143 		}
144 		return *this;
145 	}
set(const Frame_flags_info & other)146 	void set(const Frame_flags_info &other) {
147 		// Assumes *this == other.
148 		// No need to guard against self-assignment.
149 		// Do NOT copy modified or static flags.
150 		set_patch(other.from_patch());
151 		set_invalid(other.is_invalid());
152 		set_flags(other.m_flags);
153 	}
154 	enum { is_binary = 0, entry_size = 0 };
155 };
156 
157 #endif
158