Debian Codegraph @

common/main/mission.h

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * Header for mission.h
23 *
24 */
25
26 #ifndef _MISSION_H
27 #define _MISSION_H
28
29 #include <memory>
30 #include <string>
31 #include "pstypes.h"
32 #include "inferno.h"
33 #include "dxxsconf.h"
34 #include "dsx-ns.h"
35
36 #include "ntstring.h"
37
38 constexpr unsigned MAX_MISSIONS{5000}; // ZICO - changed from 300 to get more levels in list
39 // KREATOR - increased from 30 (limited by Demo and Multiplayer code)
40 constexpr std::integral_constant<uint8_t, 127> MAX_LEVELS_PER_MISSION{};
41 constexpr std::integral_constant<uint8_t, 127> MAX_SECRET_LEVELS_PER_MISSION{}; // KREATOR - increased from 6 (limited by Demo and Multiplayer code)
42 #define MISSION_NAME_LEN 25
43
44 #ifdef DXX_BUILD_DESCENT
45 #if DXX_BUILD_DESCENT == 1
46 #define D1_MISSION_FILENAME ""
47 #elif DXX_BUILD_DESCENT == 2
48 #define D1_MISSION_FILENAME "descent"
49 #endif
50 #endif
51 #define D1_MISSION_NAME "Descent: First Strike"
52 #define D1_OEM_MISSION_NAME "Destination Saturn"
53 #define D1_SHAREWARE_MISSION_NAME "Descent Demo"
54
55 #ifdef DXX_BUILD_DESCENT
56 namespace dsx {
57
58 enum class descent_hog_size : int
59 {
60 None = 0,
61 pc_retail_v15 = 6856701, // v1.4 - 1.5
62 pc_retail_v15_alt1 = 6856183, // v1.4 - 1.5 - different patch-way
63 pc_retail_v10 = 7261423, // v1.0
64 mac_retail = 7456179,
65 pc_oem_v14 = 4492107, // v1.4a
66 pc_oem_v10 = 4494862, // v1.0
67 pc_shareware_v14 = 2339773, // v1.4
68 pc_shareware_v10 = 2365676, // v1.0 - 1.2
69 mac_shareware = 3370339,
70 #if DXX_BUILD_DESCENT == 2
71 #define SHAREWARE_MISSION_FILENAME "d2demo"
72 #define SHAREWARE_MISSION_NAME "Descent 2 Demo"
73 d2_shareware = 2292566, // v1.0 (d2demo.hog)
74 d2_mac_shareware = 4292746,
75 d2_oem_v11 = 6132957, // v1.1
76 d2_full = 7595079, // v1.1 - 1.2
77 d2_full_v10 = 7107354, // v1.0
78 d2_mac_full = 7110007, // v1.1 - 1.2
79
80 #define OEM_MISSION_FILENAME "d2"
81 #define OEM_MISSION_NAME "D2 Destination:Quartzon"
82
83 #define FULL_MISSION_FILENAME "d2"
84 #endif
85 };
86
87 }
88
89 #if DXX_BUILD_DESCENT == 2
90 #include "movie.h"
91 #endif
92
93 #endif
94
95 //where the missions go
96 #define MISSION_DIR "missions/"
97
98 constexpr std::integral_constant<std::size_t, 128> DXX_MAX_MISSION_PATH_LENGTH{};
99
100 #ifdef DXX_BUILD_DESCENT
101 /* Path and filename must be kept in sync. */
102 class Mission_path
103 {
104 public:
105 Mission_path(const Mission_path &m) :
106 path{m.path},
107 filename{std::next(path.cbegin(), std::distance(m.path.cbegin(), m.filename))}
108 {
109 }
110 Mission_path &operator=(const Mission_path &m)
111 {
112 path = m.path;
113 filename = std::next(path.begin(), std::distance(m.path.cbegin(), m.filename));
114 return *this;
115 }
116 Mission_path(std::string_view p, const std::ptrdiff_t offset) :
117 path{p},
118 filename{std::next(path.cbegin(), {offset})}
119 {
120 }
121 Mission_path(Mission_path &&m) :
122 Mission_path{std::move(m).path, std::distance(m.path.cbegin(), m.filename)}
123 {
124 }
125 Mission_path &operator=(Mission_path &&rhs)
126 {
127 const auto offset{std::distance(rhs.path.cbegin(), rhs.filename)};
128 path = std::move(rhs.path);
129 filename = std::next(path.begin(), {offset});
130 return *this;
131 }
132 /* Must be in this order for move constructor to work properly */
133 std::string path; // relative file path
134 std::string::const_iterator filename; // filename without extension
135 enum class descent_version_type : uint8_t
136 {
137 #if DXX_BUILD_DESCENT == 2
138 /* These values are written to the binary savegame as part of
139 * the mission name. If the values are reordered or renumbered,
140 * old savegames will be unable to find the matching mission
141 * file.
142 */
143 descent2a, // !name
144 descent2z, // zname
145 descent2x, // xname
146 descent2,
147 #endif
148 descent1,
149 };
150 };
151
152 namespace dsx {
153
154 struct Mission : Mission_path
155 {
156 enum class anarchy_only_level : bool
157 {
158 allow_any_game,
159 only_anarchy_games,
160 };
161 std::unique_ptr<ubyte[]> secret_level_table; // originating level no for each secret level
162 // arrays of names of the level files
163 std::unique_ptr<d_fname[]> level_names;
164 std::unique_ptr<d_fname[]> secret_level_names;
165 descent_hog_size builtin_hogsize; // the size of the hogfile for a builtin mission, and 0 for an add-on mission
166 ntstring<MISSION_NAME_LEN> mission_name;
167 d_fname briefing_text_filename{}; // name of briefing file
168 d_fname ending_text_filename{}; // name of ending file
169 anarchy_only_level anarchy_only_flag; // if true, mission is only for anarchy
170 uint8_t last_level{};
171 int8_t last_secret_level{};
172 uint8_t n_secret_levels{};
173 #if DXX_BUILD_DESCENT == 2
174 descent_version_type descent_version; // descent 1 or descent 2?
175 std::unique_ptr<d_fname> alternate_ham_file;
176 std::unique_ptr<LoadedMovieWithResolution> extra_robot_movie;
177 #endif
178 Mission(Mission &&) = default;
179 Mission &operator=(Mission &&) = default;
180 Mission(const Mission &) = delete;
181 Mission &operator=(const Mission &) = delete;
182 explicit Mission(const Mission_path &m) :
183 Mission_path{m}
184 {
185 }
186 explicit Mission(Mission_path &&m) :
187 Mission_path{std::move(m)}
188 {
189 }
190 ~Mission();
191 };
192
193 typedef std::unique_ptr<Mission> Mission_ptr;
194 extern Mission_ptr Current_mission; // current mission
195
196 #if DXX_BUILD_DESCENT == 2
197 /* Wrap in parentheses to avoid precedence problems. Put constant on
198 * the left to silence clang's overzealous -Wparentheses-equality messages.
199 */
200 #define is_SHAREWARE (descent_hog_size::d2_shareware == Current_mission->builtin_hogsize)
201 #define is_MAC_SHARE (descent_hog_size::d2_mac_shareware == Current_mission->builtin_hogsize)
202 #define is_D2_OEM (descent_hog_size::d2_oem_v11 == Current_mission->builtin_hogsize)
203
204 #define EMULATING_D1 (Mission::descent_version_type::descent1 == Current_mission->descent_version)
205 #endif
206 #define PLAYING_BUILTIN_MISSION (Current_mission->builtin_hogsize != descent_hog_size::None)
207 #define ANARCHY_ONLY_MISSION (Mission::anarchy_only_level::only_anarchy_games == Current_mission->anarchy_only_flag)
208
209 }
210
211 //values for d1 built-in mission
212 #define BIMD1_ENDING_FILE_OEM "endsat.txb"
213 #define BIMD1_ENDING_FILE_SHARE "ending.txb"
214
215 namespace dcx {
216
217 enum class mission_name_type
218 {
219 basename,
220 pathname,
221 guess,
222 };
223
224 extern char descent_hog_basename[12];
225
226 }
227
228 namespace dsx {
229
230 #if DXX_BUILD_DESCENT == 2
231 //values for d2 built-in mission
232 #define BIMD2_ENDING_FILE_OEM "end2oem.txb"
233 #define BIMD2_ENDING_FILE_SHARE "ending2.txb"
234
235 int load_mission_ham();
236 void bm_read_extra_robots(const char *fname, Mission::descent_version_type type);
237 #endif
238
239 struct mission_entry_predicate
240 {
241 /* May be a basename or may be a path relative to the root of the
242 * PHYSFS virtual filesystem, depending on what the caller provides.
243 *
244 * In both cases, the file extension is omitted.
245 */
246 const char *filesystem_name;
247 #if DXX_BUILD_DESCENT == 2
248 bool check_version;
249 Mission::descent_version_type descent_version;
250 #endif
251 mission_entry_predicate with_filesystem_name(const char *fsname) const
252 {
253 mission_entry_predicate m = *this;
254 m.filesystem_name = fsname;
255 return m;
256 }
257 };
258
259 //loads the named mission if it exists.
260 //Returns nullptr if mission loaded ok, else error string.
261 const char *load_mission_by_name (mission_entry_predicate mission_name, mission_name_type);
262
263 #if DXX_USE_EDITOR
264 void create_new_mission(void);
265 #endif
266
267 extern char descent2_hog_basename[13];
268 extern char d2demo_hog_basename[11];
269
270 }
271
272 #endif
273
274 #endif