Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  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. #include "fwd-window.h"
  36.  
  37. #include "ntstring.h"
  38.  
  39. #define MAX_MISSIONS                    5000 // ZICO - changed from 300 to get more levels in list
  40. // KREATOR - increased from 30 (limited by Demo and Multiplayer code)
  41. constexpr std::integral_constant<uint8_t, 127> MAX_LEVELS_PER_MISSION{};
  42. constexpr std::integral_constant<uint8_t, 127> MAX_SECRET_LEVELS_PER_MISSION{}; // KREATOR - increased from 6 (limited by Demo and Multiplayer code)
  43. #define MISSION_NAME_LEN                25
  44.  
  45. #if defined(DXX_BUILD_DESCENT_I)
  46. #define D1_MISSION_FILENAME             ""
  47. #elif defined(DXX_BUILD_DESCENT_II)
  48. #define D1_MISSION_FILENAME             "descent"
  49. #endif
  50. #define D1_MISSION_NAME                 "Descent: First Strike"
  51. #define D1_MISSION_HOGSIZE              6856701 // v1.4 - 1.5
  52. #define D1_MISSION_HOGSIZE2             6856183 // v1.4 - 1.5 - different patch-way
  53. #define D1_10_MISSION_HOGSIZE           7261423 // v1.0
  54. #define D1_MAC_MISSION_HOGSIZE          7456179
  55. #define D1_OEM_MISSION_NAME             "Destination Saturn"
  56. #define D1_OEM_MISSION_HOGSIZE          4492107 // v1.4a
  57. #define D1_OEM_10_MISSION_HOGSIZE       4494862 // v1.0
  58. #define D1_SHAREWARE_MISSION_NAME       "Descent Demo"
  59. #define D1_SHAREWARE_MISSION_HOGSIZE    2339773 // v1.4
  60. #define D1_SHAREWARE_10_MISSION_HOGSIZE 2365676 // v1.0 - 1.2
  61. #define D1_MAC_SHARE_MISSION_HOGSIZE    3370339
  62.  
  63. #if defined(DXX_BUILD_DESCENT_II)
  64. #define SHAREWARE_MISSION_FILENAME  "d2demo"
  65. #define SHAREWARE_MISSION_NAME      "Descent 2 Demo"
  66. #define SHAREWARE_MISSION_HOGSIZE   2292566 // v1.0 (d2demo.hog)
  67. #define MAC_SHARE_MISSION_HOGSIZE   4292746
  68.  
  69. #define OEM_MISSION_FILENAME        "d2"
  70. #define OEM_MISSION_NAME            "D2 Destination:Quartzon"
  71. #define OEM_MISSION_HOGSIZE         6132957 // v1.1
  72.  
  73. #define FULL_MISSION_FILENAME       "d2"
  74. #define FULL_MISSION_HOGSIZE        7595079 // v1.1 - 1.2
  75. #define FULL_10_MISSION_HOGSIZE     7107354 // v1.0
  76. #define MAC_FULL_MISSION_HOGSIZE    7110007 // v1.1 - 1.2
  77. #endif
  78.  
  79. //where the missions go
  80. #define MISSION_DIR "missions/"
  81.  
  82. constexpr std::integral_constant<std::size_t, 128> DXX_MAX_MISSION_PATH_LENGTH{};
  83.  
  84. /* Path and filename must be kept in sync. */
  85. class Mission_path
  86. {
  87. public:
  88.         Mission_path(const Mission_path &m) :
  89.                 path(m.path),
  90.                 filename(std::next(path.cbegin(), std::distance(m.path.cbegin(), m.filename)))
  91.         {
  92.         }
  93.         Mission_path &operator=(const Mission_path &m)
  94.         {
  95.                 path = m.path;
  96.                 filename = std::next(path.begin(), std::distance(m.path.cbegin(), m.filename));
  97.                 return *this;
  98.         }
  99.         Mission_path(std::string &&p, const std::size_t offset) :
  100.                 path(std::move(p)),
  101.                 filename(std::next(path.cbegin(), offset))
  102.         {
  103.         }
  104.         Mission_path(Mission_path &&m) :
  105.                 Mission_path(std::move(m).path, std::distance(m.path.cbegin(), m.filename))
  106.         {
  107.         }
  108.         Mission_path &operator=(Mission_path &&rhs)
  109.         {
  110.                 std::size_t offset = std::distance(rhs.path.cbegin(), rhs.filename);
  111.                 path = std::move(rhs.path);
  112.                 filename = std::next(path.begin(), offset);
  113.                 return *this;
  114.         }
  115.         /* Must be in this order for move constructor to work properly */
  116.         std::string path;                               // relative file path
  117.         std::string::const_iterator filename;          // filename without extension
  118.         enum class descent_version_type : uint8_t
  119.         {
  120. #if defined(DXX_BUILD_DESCENT_II)
  121.                 /* These values are written to the binary savegame as part of
  122.                  * the mission name.  If the values are reordered or renumbered,
  123.                  * old savegames will be unable to find the matching mission
  124.                  * file.
  125.                  */
  126.                 descent2a,      // !name
  127.                 descent2z,      // zname
  128.                 descent2x,      // xname
  129.                 descent2,
  130. #endif
  131.                 descent1,
  132.         };
  133. };
  134.  
  135. #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
  136. struct Mission : Mission_path
  137. {
  138.         std::unique_ptr<ubyte[]>        secret_level_table; // originating level no for each secret level
  139.         // arrays of names of the level files
  140.         std::unique_ptr<d_fname[]>      level_names;
  141.         std::unique_ptr<d_fname[]>      secret_level_names;
  142.         int     builtin_hogsize;    // the size of the hogfile for a builtin mission, and 0 for an add-on mission
  143.         ntstring<MISSION_NAME_LEN> mission_name;
  144.         d_fname briefing_text_filename; // name of briefing file
  145.         d_fname ending_text_filename; // name of ending file
  146.         ubyte   anarchy_only_flag;  // if true, mission is only for anarchy
  147.         ubyte   last_level;
  148.         sbyte   last_secret_level;
  149.         ubyte   n_secret_levels;
  150. #if defined(DXX_BUILD_DESCENT_II)
  151.         descent_version_type descent_version;   // descent 1 or descent 2?
  152.         std::unique_ptr<d_fname> alternate_ham_file;
  153. #endif
  154.         /* Explicitly default move constructor and move operator=
  155.          *
  156.          * Without this, gcc (tested gcc-4.9, gcc-5) tries to use
  157.          * a synthetic operator=(const Mission &) to implement `instance =
  158.          * {};`, which fails because Mission contains std::unique_ptr, a
  159.          * movable but noncopyable type.
  160.          *
  161.          * With the explicit default, gcc uses operator=(Mission &&), which
  162.          * works.
  163.          *
  164.          * Explicitly delete copy constructor and copy operator= for
  165.          * thoroughness.
  166.          */
  167.         Mission(Mission &&) = default;
  168.         Mission &operator=(Mission &&) = default;
  169.         Mission(const Mission &) = delete;
  170.         Mission &operator=(const Mission &) = delete;
  171.         explicit Mission(const Mission_path &m) :
  172.                 Mission_path(m)
  173.         {
  174.         }
  175.         explicit Mission(Mission_path &&m) :
  176.                 Mission_path(std::move(m))
  177.         {
  178.         }
  179.         ~Mission();
  180. };
  181.  
  182. typedef std::unique_ptr<Mission> Mission_ptr;
  183. extern Mission_ptr Current_mission; // current mission
  184.  
  185. #define Current_mission_longname        Current_mission->mission_name
  186. #define Briefing_text_filename          Current_mission->briefing_text_filename
  187. #define Ending_text_filename            Current_mission->ending_text_filename
  188. #define Last_level                      Current_mission->last_level
  189. #define Last_secret_level               Current_mission->last_secret_level
  190. #define N_secret_levels                 Current_mission->n_secret_levels
  191. #define Secret_level_table              Current_mission->secret_level_table
  192. #define Level_names                     Current_mission->level_names
  193. #define Secret_level_names              Current_mission->secret_level_names
  194.  
  195. #if defined(DXX_BUILD_DESCENT_II)
  196. /* Wrap in parentheses to avoid precedence problems.  Put constant on
  197.  * the left to silence clang's overzealous -Wparentheses-equality messages.
  198.  */
  199. #define is_SHAREWARE (SHAREWARE_MISSION_HOGSIZE == Current_mission->builtin_hogsize)
  200. #define is_MAC_SHARE (MAC_SHARE_MISSION_HOGSIZE == Current_mission->builtin_hogsize)
  201. #define is_D2_OEM (OEM_MISSION_HOGSIZE == Current_mission->builtin_hogsize)
  202.  
  203. #define EMULATING_D1            (Mission::descent_version_type::descent1 == Current_mission->descent_version)
  204. #endif
  205. #define PLAYING_BUILTIN_MISSION (Current_mission->builtin_hogsize != 0)
  206. #define ANARCHY_ONLY_MISSION    (1 == Current_mission->anarchy_only_flag)
  207.  
  208. namespace dcx {
  209.  
  210. enum class mission_filter_mode
  211. {
  212.         exclude_anarchy,
  213.         include_anarchy,
  214. };
  215.  
  216. }
  217. #endif
  218.  
  219. //values for d1 built-in mission
  220. #define BIMD1_LAST_LEVEL                27
  221. #define BIMD1_LAST_SECRET_LEVEL         -3
  222. #define BIMD1_ENDING_FILE_OEM           "endsat.txb"
  223. #define BIMD1_ENDING_FILE_SHARE         "ending.txb"
  224.  
  225. #ifdef dsx
  226.  
  227. namespace dcx {
  228.  
  229. enum class mission_name_type
  230. {
  231.         basename,
  232.         pathname,
  233.         guess,
  234. };
  235.  
  236. }
  237.  
  238. namespace dsx {
  239.  
  240. #if defined(DXX_BUILD_DESCENT_II)
  241. //values for d2 built-in mission
  242. #define BIMD2_ENDING_FILE_OEM           "end2oem.txb"
  243. #define BIMD2_ENDING_FILE_SHARE         "ending2.txb"
  244.  
  245. int load_mission_ham();
  246. void bm_read_extra_robots(const char *fname, Mission::descent_version_type type);
  247. #endif
  248.  
  249. struct mission_entry_predicate
  250. {
  251.         /* May be a basename or may be a path relative to the root of the
  252.          * PHYSFS virtual filesystem, depending on what the caller provides.
  253.          *
  254.          * In both cases, the file extension is omitted.
  255.          */
  256.         const char *filesystem_name;
  257. #if defined(DXX_BUILD_DESCENT_II)
  258.         bool check_version;
  259.         Mission::descent_version_type descent_version;
  260. #endif
  261.         mission_entry_predicate with_filesystem_name(const char *fsname) const
  262.         {
  263.                 mission_entry_predicate m = *this;
  264.                 m.filesystem_name = fsname;
  265.                 return m;
  266.         }
  267. };
  268.  
  269. //loads the named mission if it exists.
  270. //Returns nullptr if mission loaded ok, else error string.
  271. const char *load_mission_by_name (mission_entry_predicate mission_name, mission_name_type);
  272.  
  273. //Handles creating and selecting from the mission list.
  274. //Returns 1 if a mission was loaded.
  275. int select_mission (mission_filter_mode anarchy_mode, const char *message, window_event_result (*when_selected)(void));
  276.  
  277. #if DXX_USE_EDITOR
  278. void create_new_mission(void);
  279. #endif
  280.  
  281. }
  282.  
  283. #endif
  284.  
  285. #endif
  286.