2006-03-20 17:12:09 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING . txt .
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below .
* See COPYING . txt for license details .
2006-03-20 17:12:09 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ( " PARALLAX " ) . PARALLAX , IN DISTRIBUTING THE CODE TO
END - USERS , AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN , GRANTS A
ROYALTY - FREE , PERPETUAL LICENSE TO SUCH END - USERS FOR USE BY SUCH END - USERS
IN USING , DISPLAYING , AND CREATING DERIVATIVE WORKS THEREOF , SO LONG AS
SUCH USE , DISPLAY OR CREATION IS FOR NON - COMMERCIAL , ROYALTY OR REVENUE
FREE PURPOSES . IN NO EVENT SHALL THE END - USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE - BEARING PURPOSES . THE END - USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE .
COPYRIGHT 1993 - 1999 PARALLAX SOFTWARE CORPORATION . ALL RIGHTS RESERVED .
*/
/*
*
* Code to handle multiple missions
*
*/
2012-11-11 22:12:51 +00:00
# include <algorithm>
2014-08-15 22:59:54 +00:00
# include <vector>
2006-03-20 17:12:09 +00:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <limits.h>
# include "pstypes.h"
# include "strutil.h"
# include "inferno.h"
2016-10-27 07:22:41 +00:00
# include "window.h"
2006-03-20 17:12:09 +00:00
# include "mission.h"
2016-11-12 07:38:38 +00:00
# include "gamesave.h"
2015-07-25 23:10:45 +00:00
# include "piggy.h"
2015-07-25 23:10:45 +00:00
# include "console.h"
2014-11-23 04:36:58 +00:00
# include "polyobj.h"
2012-07-07 18:35:06 +00:00
# include "dxxerror.h"
2006-03-20 17:12:09 +00:00
# include "config.h"
# include "newmenu.h"
# include "text.h"
# include "u_mem.h"
# include "ignorecase.h"
2012-11-11 00:14:30 +00:00
# include "physfsx.h"
2015-04-26 20:15:50 +00:00
# include "physfs_list.h"
2015-10-09 02:46:10 +00:00
# include "event.h"
2012-11-11 00:14:30 +00:00
# if defined(DXX_BUILD_DESCENT_II)
# include "movie.h"
# endif
2015-04-26 20:15:51 +00:00
# include "null_sentinel_iterator.h"
2006-03-20 17:12:09 +00:00
2019-06-20 04:02:27 +00:00
# include "compiler-poison.h"
2014-08-15 22:59:54 +00:00
# include "compiler-range_for.h"
2018-06-18 04:11:39 +00:00
# include "d_enumerate.h"
2021-11-01 03:37:19 +00:00
# include "d_zip.h"
2020-05-02 21:18:43 +00:00
# include <memory>
2014-08-24 03:36:35 +00:00
2017-08-11 23:43:52 +00:00
# define BIMD1_BRIEFING_FILE "briefing.txb"
2012-11-11 22:12:51 +00:00
using std : : min ;
2015-10-11 22:21:00 +00:00
# define MISSION_EXTENSION_DESCENT_I ".msn"
# if defined(DXX_BUILD_DESCENT_II)
# define MISSION_EXTENSION_DESCENT_II ".mn2"
# endif
2013-01-12 10:53:43 +00:00
2020-01-18 21:57:39 +00:00
# define CON_PRIORITY_DEBUG_MISSION_LOAD CON_DEBUG
2015-08-12 03:11:46 +00:00
namespace {
2020-05-02 21:18:42 +00:00
using mission_candidate_search_path = std : : array < char , PATH_MAX > ;
2020-01-18 21:57:39 +00:00
}
namespace dsx {
namespace {
struct mle ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
using mission_list_type = std : : vector < mle > ;
2015-10-11 22:21:00 +00:00
2015-01-13 04:19:42 +00:00
//mission list entry
2015-01-15 04:30:03 +00:00
struct mle : Mission_path
2015-01-13 04:19:42 +00:00
{
2006-03-20 17:12:09 +00:00
int builtin_hogsize ; // if it's the built-in mission, used for determining the version
2018-06-27 03:34:34 +00:00
ntstring < 75 > mission_name ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2015-10-18 21:01:18 +00:00
descent_version_type descent_version ; // descent 1 or descent 2?
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
ubyte anarchy_only_flag ; // if true, mission is anarchy only
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
mission_list_type directory ;
mle ( Mission_path & & m ) :
Mission_path ( std : : move ( m ) )
{
}
mle ( const char * const name , std : : vector < mle > & & d ) ;
2013-12-22 22:03:07 +00:00
} ;
2006-03-20 17:12:09 +00:00
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
struct mission_subdir_stats
{
std : : size_t immediate_directories = 0 , immediate_missions = 0 , total_missions = 0 ;
static std : : size_t count_missions ( const mission_list_type & directory )
{
std : : size_t total_missions = 0 ;
range_for ( auto & & i , directory )
{
if ( i . directory . empty ( ) )
+ + total_missions ;
else
total_missions + = count_missions ( i . directory ) ;
}
return total_missions ;
}
void count ( const mission_list_type & directory )
{
range_for ( auto & & i , directory )
{
if ( i . directory . empty ( ) )
{
+ + total_missions ;
+ + immediate_missions ;
}
else
{
+ + immediate_directories ;
total_missions + = count_missions ( i . directory ) ;
}
}
}
} ;
2020-01-18 21:57:39 +00:00
struct mission_name_and_version
{
# if defined(DXX_BUILD_DESCENT_II)
2020-04-26 17:26:23 +00:00
const Mission : : descent_version_type descent_version = { } ;
2020-01-18 21:57:39 +00:00
# endif
2020-04-26 17:26:23 +00:00
char * const name = nullptr ;
mission_name_and_version ( ) = default ;
2020-01-18 21:57:39 +00:00
mission_name_and_version ( Mission : : descent_version_type , char * ) ;
} ;
mission_name_and_version : : mission_name_and_version ( Mission : : descent_version_type const v , char * const n ) :
# if defined(DXX_BUILD_DESCENT_II)
descent_version ( v ) ,
# endif
name ( n )
{
# if defined(DXX_BUILD_DESCENT_I)
( void ) v ;
# endif
}
2020-05-02 21:18:42 +00:00
const char * prepare_mission_list_count_dirbuf ( std : : array < char , 12 > & dirbuf , const std : : size_t immediate_directories )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
2020-05-17 23:35:25 +00:00
/* Limit the count of directories to what can be formatted
* successfully without truncation . If a user has more than this
* many directories , an empty string will be used instead of showing
* the actual count .
*/
if ( immediate_directories & & immediate_directories < = 99999 )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
2018-08-03 04:08:12 +00:00
snprintf ( dirbuf . data ( ) , dirbuf . size ( ) , " DIR:%zu; " , immediate_directories ) ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
return dirbuf . data ( ) ;
}
return " " ;
}
mle : : mle ( const char * const name , std : : vector < mle > & & d ) :
Mission_path ( name , 0 ) , directory ( std : : move ( d ) )
{
mission_subdir_stats ss ;
ss . count ( directory ) ;
2020-05-02 21:18:42 +00:00
std : : array < char , 12 > dirbuf ;
2018-08-03 04:08:12 +00:00
snprintf ( mission_name . data ( ) , mission_name . size ( ) , " %s/ [%sMSN:L%zu;T%zu] " , name , prepare_mission_list_count_dirbuf ( dirbuf , ss . immediate_directories ) , ss . immediate_missions , ss . total_missions ) ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
}
2015-08-12 03:11:46 +00:00
2020-01-18 21:57:39 +00:00
static const mle * compare_mission_predicate_to_leaf ( const mission_entry_predicate mission_predicate , const mle & candidate , const char * candidate_filesystem_name )
{
# if defined(DXX_BUILD_DESCENT_II)
if ( mission_predicate . check_version & & mission_predicate . descent_version ! = candidate . descent_version )
{
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " mission version check requires %u, but found %u; skipping string comparison for mission \" %s \" " ) , static_cast < unsigned > ( mission_predicate . descent_version ) , static_cast < unsigned > ( candidate . descent_version ) , candidate . path . data ( ) ) ;
return nullptr ;
}
# endif
if ( ! d_stricmp ( mission_predicate . filesystem_name , candidate_filesystem_name ) )
{
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " found mission \" %s \" [ \" %s \" ] at %p " ) , candidate . path . data ( ) , & * candidate . filename , & candidate ) ;
return & candidate ;
}
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " want mission \" %s \" , no match for mission \" %s \" [ \" %s \" ] at %p " ) , mission_predicate . filesystem_name , candidate . path . data ( ) , & * candidate . filename , & candidate ) ;
return nullptr ;
}
static const mle * compare_mission_by_guess ( const mission_entry_predicate mission_predicate , const mle & candidate )
{
if ( candidate . directory . empty ( ) )
return compare_mission_predicate_to_leaf ( mission_predicate , candidate , & * candidate . filename ) ;
{
const unsigned long size = candidate . directory . size ( ) ;
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " want mission \" %s \" , check %lu missions under \" %s \" " ) , mission_predicate . filesystem_name , size , candidate . path . data ( ) ) ;
}
range_for ( auto & i , candidate . directory )
{
if ( const auto r = compare_mission_by_guess ( mission_predicate , i ) )
return r ;
}
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " no matches under \" %s \" " ) , candidate . path . data ( ) ) ;
return nullptr ;
}
static const mle * compare_mission_by_pathname ( const mission_entry_predicate mission_predicate , const mle & candidate )
{
if ( candidate . directory . empty ( ) )
return compare_mission_predicate_to_leaf ( mission_predicate , candidate , candidate . path . data ( ) ) ;
const auto mission_name = mission_predicate . filesystem_name ;
const auto path_length = candidate . path . size ( ) ;
if ( ! strncmp ( mission_name , candidate . path . data ( ) , path_length ) & & mission_name [ path_length ] = = ' / ' )
{
{
const unsigned long size = candidate . directory . size ( ) ;
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " want mission pathname \" %s \" , check %lu missions under \" %s \" " ) , mission_predicate . filesystem_name , size , candidate . path . data ( ) ) ;
}
range_for ( auto & i , candidate . directory )
{
if ( const auto r = compare_mission_by_pathname ( mission_predicate , i ) )
return r ;
}
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " no matches under \" %s \" " ) , candidate . path . data ( ) ) ;
}
else
con_printf ( CON_PRIORITY_DEBUG_MISSION_LOAD , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " want mission pathname \" %s \" , ignore non-matching directory \" %s \" " ) , mission_predicate . filesystem_name , candidate . path . data ( ) ) ;
return nullptr ;
}
}
2021-06-28 03:37:49 +00:00
Mission_ptr Current_mission ; // currently loaded mission
2016-05-22 17:49:32 +00:00
}
2006-03-20 17:12:09 +00:00
2021-06-28 03:37:49 +00:00
namespace {
2006-03-20 17:12:09 +00:00
2015-01-12 00:26:03 +00:00
static bool null_or_space ( char c )
{
return ! c | | isspace ( static_cast < unsigned > ( c ) ) ;
}
2021-11-01 03:37:19 +00:00
// Allocate the Current_mission->level_names, Current_mission->secret_level_names and Current_mission->secret_level_table arrays
2021-11-01 03:37:19 +00:00
static void allocate_levels ( const unsigned count_regular_level , const unsigned count_secret_level )
2013-01-12 10:53:43 +00:00
{
2021-11-01 03:37:19 +00:00
Current_mission - > level_names = std : : make_unique < d_fname [ ] > ( count_regular_level ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > last_level = count_regular_level ;
2021-11-01 03:37:19 +00:00
Current_mission - > n_secret_levels = count_secret_level ;
2021-11-01 03:37:19 +00:00
Current_mission - > last_secret_level = - static_cast < signed > ( count_secret_level ) ;
2021-11-01 03:37:19 +00:00
if ( count_secret_level )
2013-01-12 10:53:43 +00:00
{
2021-11-01 03:37:19 +00:00
auto secret_level_names = std : : make_unique < d_fname [ ] > ( count_secret_level ) ;
auto secret_level_table = std : : make_unique < uint8_t [ ] > ( count_secret_level ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names = std : : move ( secret_level_names ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table = std : : move ( secret_level_table ) ;
2013-01-12 10:53:43 +00:00
}
}
2021-11-01 03:37:19 +00:00
static void allocate_shareware_levels ( const unsigned count_regular_level , const unsigned count_secret_level )
{
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = BIMD1_BRIEFING_FILE ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = BIMD1_ENDING_FILE_SHARE ;
2021-11-01 03:37:19 +00:00
allocate_levels ( count_regular_level , count_secret_level ) ;
//build level names
2021-11-01 03:37:19 +00:00
for ( const auto & & [ idx , name ] : enumerate ( unchecked_partial_range ( Current_mission - > level_names . get ( ) , count_regular_level ) , 1u ) )
2021-11-01 03:37:19 +00:00
snprintf ( & name [ 0u ] , name . size ( ) , " level%02u.sdl " , idx ) ;
}
static void build_rdl_regular_level_names ( const unsigned count_regular_level , std : : unique_ptr < d_fname [ ] > & names )
{
for ( auto & & [ idx , name ] : enumerate ( unchecked_partial_range ( names . get ( ) , count_regular_level ) , 1u ) )
snprintf ( & name [ 0u ] , name . size ( ) , " level%02u.rdl " , idx ) ;
}
static void build_rdl_secret_level_names ( const unsigned count_secret_level , std : : unique_ptr < d_fname [ ] > & names )
{
for ( auto & & [ idx , name ] : enumerate ( unchecked_partial_range ( names . get ( ) , count_secret_level ) , 1u ) )
snprintf ( & name [ 0u ] , name . size ( ) , " levels%1u.rdl " , idx ) ;
}
2006-03-20 17:12:09 +00:00
//
// Special versions of mission routines for d1 builtins
//
2021-11-01 03:37:19 +00:00
static void load_mission_d1 ( )
2006-03-20 17:12:09 +00:00
{
2011-06-01 07:59:55 +00:00
switch ( PHYSFSX_fsize ( " descent.hog " ) )
2007-10-29 21:40:49 +00:00
{
case D1_SHAREWARE_MISSION_HOGSIZE :
case D1_SHAREWARE_10_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
allocate_shareware_levels ( 7 , 0 ) ;
2007-10-29 21:40:49 +00:00
break ;
case D1_MAC_SHARE_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
allocate_shareware_levels ( 3 , 0 ) ;
2007-10-29 21:40:49 +00:00
break ;
case D1_OEM_MISSION_HOGSIZE :
case D1_OEM_10_MISSION_HOGSIZE :
2018-08-26 18:10:36 +00:00
{
constexpr unsigned last_level = 15 ;
2021-11-01 03:37:19 +00:00
constexpr unsigned last_secret_level = 1 ;
allocate_levels ( last_level , last_secret_level ) ;
2007-10-29 21:40:49 +00:00
//build level names
2021-11-01 03:37:19 +00:00
build_rdl_regular_level_names ( last_level - 1 , Current_mission - > level_names ) ;
2018-08-26 18:10:36 +00:00
{
2021-11-01 03:37:19 +00:00
auto & ln = Current_mission - > level_names [ last_level - 1 ] ;
2018-08-26 18:10:36 +00:00
snprintf ( & ln [ 0u ] , ln . size ( ) , " saturn%02d.rdl " , last_level ) ;
}
2021-11-01 03:37:19 +00:00
build_rdl_secret_level_names ( last_secret_level , Current_mission - > secret_level_names ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table [ 0 ] = 10 ;
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = " briefsat.txb " ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = BIMD1_ENDING_FILE_OEM ;
2018-08-26 18:10:36 +00:00
}
2007-10-29 21:40:49 +00:00
break ;
default :
2019-04-04 04:29:03 +00:00
Int3 ( ) ;
2022-01-09 15:25:42 +00:00
[[fallthrough]] ;
2007-10-29 21:40:49 +00:00
case D1_MISSION_HOGSIZE :
2015-02-15 17:24:55 +00:00
case D1_MISSION_HOGSIZE2 :
2007-10-29 21:40:49 +00:00
case D1_10_MISSION_HOGSIZE :
case D1_MAC_MISSION_HOGSIZE :
2018-08-26 18:10:36 +00:00
{
2021-11-01 03:37:19 +00:00
constexpr unsigned last_level = 27 ;
constexpr unsigned last_secret_level = 3 ;
allocate_levels ( last_level , last_secret_level ) ;
2013-01-12 10:53:43 +00:00
2007-10-29 21:40:49 +00:00
//build level names
2021-11-01 03:37:19 +00:00
build_rdl_regular_level_names ( last_level , Current_mission - > level_names ) ;
2021-11-01 03:37:19 +00:00
build_rdl_secret_level_names ( last_secret_level , Current_mission - > secret_level_names ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table [ 0 ] = 10 ;
Current_mission - > secret_level_table [ 1 ] = 21 ;
Current_mission - > secret_level_table [ 2 ] = 24 ;
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = BIMD1_BRIEFING_FILE ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = " endreg.txb " ;
2007-10-29 21:40:49 +00:00
break ;
2018-08-26 18:10:36 +00:00
}
2006-03-20 17:12:09 +00:00
}
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
//
// Special versions of mission routines for shareware
//
2021-11-01 03:37:19 +00:00
static void load_mission_shareware ( )
2006-03-20 17:12:09 +00:00
{
2014-12-22 04:35:48 +00:00
Current_mission - > mission_name . copy_if ( SHAREWARE_MISSION_NAME ) ;
2016-03-06 05:01:41 +00:00
Current_mission - > descent_version = Mission : : descent_version_type : : descent2 ;
2006-03-20 17:12:09 +00:00
Current_mission - > anarchy_only_flag = 0 ;
2013-01-12 10:53:43 +00:00
switch ( Current_mission - > builtin_hogsize )
{
case MAC_SHARE_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
allocate_levels ( 4 , 1 ) ;
2013-01-12 10:53:43 +00:00
// mac demo is using the regular hog and rl2 files
2021-11-01 03:37:19 +00:00
Current_mission - > level_names [ 0 ] = " d2leva-1.rl2 " ;
Current_mission - > level_names [ 1 ] = " d2leva-2.rl2 " ;
Current_mission - > level_names [ 2 ] = " d2leva-3.rl2 " ;
Current_mission - > level_names [ 3 ] = " d2leva-4.rl2 " ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names [ 0 ] = " d2leva-s.rl2 " ;
2013-01-12 10:53:43 +00:00
break ;
default :
2019-04-04 04:29:03 +00:00
Int3 ( ) ;
2022-01-09 15:25:42 +00:00
[[fallthrough]] ;
2013-01-12 10:53:43 +00:00
case SHAREWARE_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
allocate_levels ( 3 , 0 ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > level_names [ 0 ] = " d2leva-1.sl2 " ;
Current_mission - > level_names [ 1 ] = " d2leva-2.sl2 " ;
Current_mission - > level_names [ 2 ] = " d2leva-3.sl2 " ;
2021-11-01 03:37:19 +00:00
break ;
2006-03-20 17:12:09 +00:00
}
}
//
// Special versions of mission routines for Diamond/S3 version
//
2021-11-01 03:37:19 +00:00
static void load_mission_oem ( )
2006-03-20 17:12:09 +00:00
{
2014-12-22 04:35:48 +00:00
Current_mission - > mission_name . copy_if ( OEM_MISSION_NAME ) ;
2016-03-06 05:01:41 +00:00
Current_mission - > descent_version = Mission : : descent_version_type : : descent2 ;
2006-03-20 17:12:09 +00:00
Current_mission - > anarchy_only_flag = 0 ;
2021-11-01 03:37:19 +00:00
allocate_levels ( 8 , 2 ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > level_names [ 0 ] = " d2leva-1.rl2 " ;
Current_mission - > level_names [ 1 ] = " d2leva-2.rl2 " ;
Current_mission - > level_names [ 2 ] = " d2leva-3.rl2 " ;
Current_mission - > level_names [ 3 ] = " d2leva-4.rl2 " ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names [ 0 ] = " d2leva-s.rl2 " ;
2021-11-01 03:37:19 +00:00
Current_mission - > level_names [ 4 ] = " d2levb-1.rl2 " ;
Current_mission - > level_names [ 5 ] = " d2levb-2.rl2 " ;
Current_mission - > level_names [ 6 ] = " d2levb-3.rl2 " ;
Current_mission - > level_names [ 7 ] = " d2levb-4.rl2 " ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names [ 1 ] = " d2levb-s.rl2 " ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table [ 0 ] = 1 ;
Current_mission - > secret_level_table [ 1 ] = 5 ;
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
//compare a string for a token. returns true if match
2013-10-27 22:00:14 +00:00
static int istok ( const char * buf , const char * tok )
2006-03-20 17:12:09 +00:00
{
2012-05-18 23:36:43 +00:00
return d_strnicmp ( buf , tok , strlen ( tok ) ) = = 0 ;
2006-03-20 17:12:09 +00:00
}
//returns ptr to string after '=' & white space, or NULL if no '='
//adds 0 after parm at first white space
2013-10-27 22:00:14 +00:00
static char * get_value ( char * buf )
2006-03-20 17:12:09 +00:00
{
2014-07-20 20:56:39 +00:00
char * t = strchr ( buf , ' = ' ) ;
2006-03-20 17:12:09 +00:00
if ( t ) {
2014-07-20 20:56:39 +00:00
while ( isspace ( static_cast < unsigned > ( * + + t ) ) ) ;
2006-03-20 17:12:09 +00:00
if ( * t )
return t ;
}
return NULL ; //error!
}
2020-01-18 21:57:39 +00:00
static mission_name_and_version get_any_mission_type_name_value ( PHYSFSX_gets_line_t < 80 > & buf , PHYSFS_File * const f , const Mission : : descent_version_type descent_version )
2006-03-20 17:12:09 +00:00
{
2013-11-23 00:13:36 +00:00
if ( ! PHYSFSX_fgets ( buf , f ) )
2020-01-18 21:57:39 +00:00
return { } ;
if ( istok ( buf , " name " ) )
return { descent_version , get_value ( buf ) } ;
# if defined(DXX_BUILD_DESCENT_II)
if ( descent_version = = Mission : : descent_version_type : : descent1 )
/* If reading a Descent 1 `.msn` file, do not check for the
* extended mission types . D1X - Rebirth would ignore them , so
* D2X - Rebirth should also ignore them .
*/
return { } ;
struct name_type_pair
{
/* std::pair cannot be used here because direct initialization
* from a string literal fails to compile .
*/
char name [ 7 ] ;
Mission : : descent_version_type descent_version ;
} ;
static constexpr name_type_pair mission_name_type_values [ ] = {
{ " xname " , Mission : : descent_version_type : : descent2x } , // enhanced mission
{ " zname " , Mission : : descent_version_type : : descent2z } , // super-enhanced mission
{ " !name " , Mission : : descent_version_type : : descent2a } , // extensible-enhanced mission
} ;
2021-11-01 03:37:20 +00:00
for ( auto & & [ name , descent_version ] : mission_name_type_values )
2020-01-18 21:57:39 +00:00
{
2021-11-01 03:37:20 +00:00
if ( istok ( buf , name ) )
return { descent_version , get_value ( buf ) } ;
2020-01-18 21:57:39 +00:00
}
# endif
return { } ;
2006-03-20 17:12:09 +00:00
}
2014-08-30 22:38:26 +00:00
static bool ml_sort_func ( const mle & e0 , const mle & e1 )
2006-03-20 17:12:09 +00:00
{
2019-11-17 01:42:09 +00:00
const auto d0 = e0 . directory . empty ( ) ;
const auto d1 = e1 . directory . empty ( ) ;
if ( d0 ! = d1 )
/* If d0 is a directory and d1 is a mission, or if d0 is a
* mission and d1 is a directory , then apply a special case .
*
* Consider d0 to be less ( and therefore ordered earlier ) if d1
* is a mission . This moves directories to the top of the list .
*/
return d1 ;
/* If both d0 and d1 are directories, or if both are missions, then
* apply the usual sorting rule . This makes directories sort
* as usual relative to each other .
*/
2014-08-30 22:38:26 +00:00
return d_stricmp ( e0 . mission_name , e1 . mission_name ) < 0 ;
2006-03-20 17:12:09 +00:00
}
2021-06-28 03:37:49 +00:00
}
2006-03-20 17:12:09 +00:00
//returns 1 if file read ok, else 0
2016-08-25 04:05:32 +00:00
namespace dsx {
2021-06-28 03:37:49 +00:00
namespace {
2016-05-22 17:49:32 +00:00
static int read_mission_file ( mission_list_type & mission_list , mission_candidate_search_path & pathname )
2006-03-20 17:12:09 +00:00
{
2021-07-25 23:00:56 +00:00
if ( const auto mfile = PHYSFSX_openReadBuffered ( pathname . data ( ) ) . first )
2015-01-17 18:31:42 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
std : : string str_pathname = pathname . data ( ) ;
const auto idx_last_slash = str_pathname . find_last_of ( ' / ' ) ;
const auto idx_filename = ( idx_last_slash = = str_pathname . npos ) ? 0 : idx_last_slash + 1 ;
const auto idx_file_extension = str_pathname . find_first_of ( ' . ' , idx_filename ) ;
if ( idx_file_extension = = str_pathname . npos )
2006-03-20 17:12:09 +00:00
return 0 ; //missing extension
2020-01-18 21:57:39 +00:00
if ( idx_file_extension > = DXX_MAX_MISSION_PATH_LENGTH )
return 0 ; // path too long, would be truncated in save game files
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
str_pathname . resize ( idx_file_extension ) ;
mission_list . emplace_back ( Mission_path ( std : : move ( str_pathname ) , idx_filename ) ) ;
2014-08-15 22:59:54 +00:00
mle * mission = & mission_list . back ( ) ;
2020-01-18 21:57:39 +00:00
# if defined(DXX_BUILD_DESCENT_I)
constexpr auto descent_version = Mission : : descent_version_type : : descent1 ;
# elif defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
// look if it's .mn2 or .msn
2020-01-18 21:57:39 +00:00
auto descent_version = ( pathname [ idx_file_extension + 3 ] = = MISSION_EXTENSION_DESCENT_II [ 3 ] )
2016-03-06 05:01:41 +00:00
? Mission : : descent_version_type : : descent2
: Mission : : descent_version_type : : descent1 ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
mission - > anarchy_only_flag = 0 ;
2014-09-07 19:48:10 +00:00
PHYSFSX_gets_line_t < 80 > buf ;
2020-01-18 21:57:39 +00:00
const auto & & nv = get_any_mission_type_name_value ( buf , mfile , descent_version ) ;
2006-03-20 17:12:09 +00:00
2020-04-26 17:26:23 +00:00
if ( const auto p = nv . name ) {
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2020-04-26 17:26:23 +00:00
mission - > descent_version = nv . descent_version ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
char * t ;
if ( ( t = strchr ( p , ' ; ' ) ) ! = NULL )
2020-01-18 21:57:39 +00:00
{
2006-03-20 17:12:09 +00:00
* t = 0 ;
2020-01-18 21:57:39 +00:00
- - t ;
}
else
t = p + strlen ( p ) - 1 ;
while ( isspace ( static_cast < unsigned > ( * t ) ) )
2006-03-20 17:12:09 +00:00
* t - - = 0 ; // remove trailing whitespace
2014-12-22 04:35:48 +00:00
mission - > mission_name . copy_if ( p , mission - > mission_name . size ( ) - 1 ) ;
2006-03-20 17:12:09 +00:00
}
else {
2014-08-15 22:59:54 +00:00
mission_list . pop_back ( ) ;
2006-03-20 17:12:09 +00:00
return 0 ;
}
2014-09-07 19:48:10 +00:00
{
PHYSFSX_gets_line_t < 4096 > temp ;
2012-07-15 18:07:50 +00:00
if ( PHYSFSX_fgets ( temp , mfile ) )
{
if ( istok ( temp , " type " ) )
{
2020-01-18 21:57:39 +00:00
const auto p = get_value ( temp ) ;
2012-07-15 18:07:50 +00:00
//get mission type
if ( p )
mission - > anarchy_only_flag = istok ( p , " anarchy " ) ;
}
}
2014-09-07 19:48:10 +00:00
}
2006-03-20 17:12:09 +00:00
return 1 ;
}
return 0 ;
}
2016-05-22 17:49:32 +00:00
static void add_d1_builtin_mission_to_list ( mission_list_type & mission_list )
2006-03-20 17:12:09 +00:00
{
int size ;
2011-06-01 07:59:55 +00:00
size = PHYSFSX_fsize ( " descent.hog " ) ;
2007-05-20 02:00:57 +00:00
if ( size = = - 1 )
return ;
2006-03-20 17:12:09 +00:00
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
mission_list . emplace_back ( Mission_path ( D1_MISSION_FILENAME , 0 ) ) ;
2014-08-15 22:59:54 +00:00
mle * mission = & mission_list . back ( ) ;
2006-03-20 17:12:09 +00:00
switch ( size ) {
case D1_SHAREWARE_MISSION_HOGSIZE :
case D1_SHAREWARE_10_MISSION_HOGSIZE :
case D1_MAC_SHARE_MISSION_HOGSIZE :
2014-12-22 04:35:48 +00:00
mission - > mission_name . copy_if ( D1_SHAREWARE_MISSION_NAME ) ;
2006-03-20 17:12:09 +00:00
mission - > anarchy_only_flag = 0 ;
break ;
case D1_OEM_MISSION_HOGSIZE :
case D1_OEM_10_MISSION_HOGSIZE :
2014-12-22 04:35:48 +00:00
mission - > mission_name . copy_if ( D1_OEM_MISSION_NAME ) ;
2006-03-20 17:12:09 +00:00
mission - > anarchy_only_flag = 0 ;
break ;
default :
Warning ( " Unknown D1 hogsize %d \n " , size ) ;
Int3 ( ) ;
2022-01-09 15:25:42 +00:00
[[fallthrough]] ;
2006-03-20 17:12:09 +00:00
case D1_MISSION_HOGSIZE :
2008-05-19 12:45:33 +00:00
case D1_MISSION_HOGSIZE2 :
2006-03-20 17:12:09 +00:00
case D1_10_MISSION_HOGSIZE :
case D1_MAC_MISSION_HOGSIZE :
2014-12-22 04:35:48 +00:00
mission - > mission_name . copy_if ( D1_MISSION_NAME ) ;
2006-03-20 17:12:09 +00:00
mission - > anarchy_only_flag = 0 ;
break ;
}
mission - > anarchy_only_flag = 0 ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
mission - > builtin_hogsize = size ;
# elif defined(DXX_BUILD_DESCENT_II)
2016-03-06 05:01:41 +00:00
mission - > descent_version = Mission : : descent_version_type : : descent1 ;
2006-03-20 17:12:09 +00:00
mission - > builtin_hogsize = 0 ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2014-08-15 22:59:54 +00:00
template < std : : size_t N1 , std : : size_t N2 >
2016-05-22 17:49:32 +00:00
static void set_hardcoded_mission ( mission_list_type & mission_list , const char ( & path ) [ N1 ] , const char ( & mission_name ) [ N2 ] )
2014-08-15 22:59:54 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
mission_list . emplace_back ( Mission_path ( path , 0 ) ) ;
2014-08-15 22:59:54 +00:00
mle * mission = & mission_list . back ( ) ;
2014-12-22 04:35:48 +00:00
mission - > mission_name . copy_if ( mission_name ) ;
2014-08-15 22:59:54 +00:00
mission - > anarchy_only_flag = 0 ;
}
2016-05-22 17:49:32 +00:00
static void add_builtin_mission_to_list ( mission_list_type & mission_list , d_fname & name )
2006-03-20 17:12:09 +00:00
{
2011-06-01 07:59:55 +00:00
int size = PHYSFSX_fsize ( " descent2.hog " ) ;
2006-03-20 17:12:09 +00:00
if ( size = = - 1 )
2011-06-01 07:59:55 +00:00
size = PHYSFSX_fsize ( " d2demo.hog " ) ;
2006-03-20 17:12:09 +00:00
switch ( size ) {
case SHAREWARE_MISSION_HOGSIZE :
case MAC_SHARE_MISSION_HOGSIZE :
2014-08-15 22:59:54 +00:00
set_hardcoded_mission ( mission_list , SHAREWARE_MISSION_FILENAME , SHAREWARE_MISSION_NAME ) ;
2006-03-20 17:12:09 +00:00
break ;
case OEM_MISSION_HOGSIZE :
2014-08-15 22:59:54 +00:00
set_hardcoded_mission ( mission_list , OEM_MISSION_FILENAME , OEM_MISSION_NAME ) ;
2006-03-20 17:12:09 +00:00
break ;
default :
2015-10-11 22:21:00 +00:00
Warning ( " Unknown hogsize %d, trying %s \n " , size , FULL_MISSION_FILENAME MISSION_EXTENSION_DESCENT_II ) ;
2019-04-04 04:29:03 +00:00
Int3 ( ) ;
2022-01-09 15:25:42 +00:00
[[fallthrough]] ;
2006-03-20 17:12:09 +00:00
case FULL_MISSION_HOGSIZE :
case FULL_10_MISSION_HOGSIZE :
case MAC_FULL_MISSION_HOGSIZE :
2015-10-11 22:21:00 +00:00
{
mission_candidate_search_path full_mission_filename = { { FULL_MISSION_FILENAME MISSION_EXTENSION_DESCENT_II } } ;
if ( ! read_mission_file ( mission_list , full_mission_filename ) )
Error ( " Could not find required mission file <%s> " , FULL_MISSION_FILENAME MISSION_EXTENSION_DESCENT_II ) ;
}
2006-03-20 17:12:09 +00:00
}
2014-08-15 22:59:54 +00:00
mle * mission = & mission_list . back ( ) ;
2014-08-16 03:59:14 +00:00
name . copy_if ( mission - > path . c_str ( ) , FILENAME_LEN ) ;
2006-03-20 17:12:09 +00:00
mission - > builtin_hogsize = size ;
2016-03-06 05:01:41 +00:00
mission - > descent_version = Mission : : descent_version_type : : descent2 ;
2006-03-20 17:12:09 +00:00
mission - > anarchy_only_flag = 0 ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2020-01-18 21:57:39 +00:00
static void add_missions_to_list ( mission_list_type & mission_list , mission_candidate_search_path & path , const mission_candidate_search_path : : iterator rel_path , const mission_filter_mode mission_filter )
2006-03-20 17:12:09 +00:00
{
2015-10-11 22:21:00 +00:00
/* rel_path must point within the array `path`.
* rel_path must point to the null that follows a possibly empty
* directory prefix .
* If the directory prefix is not empty , it must end with a PHYSFS
* path separator , which is always slash , even on Windows .
*
* If any of these assertions fail , then the path transforms used to
* recurse into subdirectories and to open individual missions will
* not work correctly .
*/
2019-06-20 04:02:27 +00:00
assert ( std : : distance ( path . begin ( ) , rel_path ) < path . size ( ) - 1 ) ;
2015-10-11 22:21:00 +00:00
assert ( ! * rel_path ) ;
assert ( path . begin ( ) = = rel_path | | * std : : prev ( rel_path ) = = ' / ' ) ;
const std : : size_t space_remaining = std : : distance ( rel_path , path . end ( ) ) ;
2019-06-20 04:02:27 +00:00
* rel_path = ' . ' ;
* std : : next ( rel_path ) = 0 ;
2015-10-11 22:21:00 +00:00
range_for ( const auto i , PHYSFSX_uncounted_list { PHYSFS_enumerateFiles ( path . data ( ) ) } )
2006-03-20 17:12:09 +00:00
{
2015-10-11 22:21:00 +00:00
/* Add 1 to include the terminating null. */
const std : : size_t il = strlen ( i ) + 1 ;
2019-06-20 04:02:27 +00:00
/* Add 2 for the slash+dot in case it is a directory. */
if ( il + 2 > = space_remaining )
2006-03-20 17:12:09 +00:00
continue ; // path is too long
2015-10-11 22:21:00 +00:00
auto j = std : : copy_n ( i , il , rel_path ) ;
const char * ext ;
if ( PHYSFS_isDirectory ( path . data ( ) ) )
2006-03-20 17:12:09 +00:00
{
2019-06-20 04:02:27 +00:00
const auto null = std : : prev ( j ) ;
2015-10-11 22:21:00 +00:00
* j = 0 ;
* null = ' / ' ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
mission_list_type sublist ;
2020-01-18 21:57:39 +00:00
add_missions_to_list ( sublist , path , j , mission_filter ) ;
2015-10-11 22:21:00 +00:00
* null = 0 ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
const auto found = sublist . size ( ) ;
if ( ! found )
{
/* Ignore empty directories */
}
else if ( found = = 1 )
{
/* If only one found, promote it up to the next level so
* the user does not need to navigate into a
* single - element directory .
*/
auto & sli = sublist . front ( ) ;
mission_list . emplace_back ( std : : move ( sli ) ) ;
}
else
2019-11-17 01:35:08 +00:00
{
std : : sort ( sublist . begin ( ) , sublist . end ( ) , ml_sort_func ) ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
mission_list . emplace_back ( path . data ( ) , std : : move ( sublist ) ) ;
2019-11-17 01:35:08 +00:00
}
2006-03-20 17:12:09 +00:00
}
2015-10-11 22:21:00 +00:00
else if ( il > 5 & &
( ( ext = & i [ il - 5 ] , ! d_strnicmp ( ext , MISSION_EXTENSION_DESCENT_I ) )
# if defined(DXX_BUILD_DESCENT_II)
| | ! d_strnicmp ( ext , MISSION_EXTENSION_DESCENT_II )
# endif
) )
if ( read_mission_file ( mission_list , path ) )
2006-03-20 17:12:09 +00:00
{
2020-01-18 21:57:39 +00:00
if ( mission_filter ! = mission_filter_mode : : exclude_anarchy | | ! mission_list . back ( ) . anarchy_only_flag )
2006-03-20 17:12:09 +00:00
{
2014-08-15 22:59:54 +00:00
mission_list . back ( ) . builtin_hogsize = 0 ;
2006-03-20 17:12:09 +00:00
}
else
2014-08-15 22:59:54 +00:00
mission_list . pop_back ( ) ;
2006-03-20 17:12:09 +00:00
}
2014-08-15 22:59:54 +00:00
if ( mission_list . size ( ) > = MAX_MISSIONS )
2006-03-20 17:12:09 +00:00
{
break ;
}
2015-10-11 22:21:00 +00:00
* rel_path = 0 ; // chop off the entry
2019-06-20 04:02:27 +00:00
DXX_POISON_MEMORY ( std : : next ( rel_path ) , path . end ( ) , 0xcc ) ;
2006-03-20 17:12:09 +00:00
}
}
2021-06-28 03:37:49 +00:00
}
2016-08-25 04:05:32 +00:00
}
2006-03-20 17:12:09 +00:00
2021-06-28 03:37:49 +00:00
namespace {
2006-03-20 17:12:09 +00:00
/* move <mission_name> to <place> on mission list, increment <place> */
2016-05-22 17:49:32 +00:00
static void promote ( mission_list_type & mission_list , const char * const name , std : : size_t & top_place )
2006-03-20 17:12:09 +00:00
{
2014-08-15 22:59:54 +00:00
range_for ( auto & i , partial_range ( mission_list , top_place , mission_list . size ( ) ) )
2014-08-16 03:59:14 +00:00
if ( ! d_stricmp ( & * i . filename , name ) ) {
2006-03-20 17:12:09 +00:00
//swap mission positions
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
auto & j = mission_list [ top_place + + ] ;
if ( & j ! = & i )
std : : swap ( j , i ) ;
2006-03-20 17:12:09 +00:00
break ;
}
}
2021-06-28 03:37:49 +00:00
}
2014-08-16 04:22:01 +00:00
Mission : : ~ Mission ( )
2006-03-20 17:12:09 +00:00
{
// May become more complex with the editor
2014-08-16 03:59:14 +00:00
if ( ! path . empty ( ) & & builtin_hogsize = = 0 )
2007-05-27 05:48:16 +00:00
{
char hogpath [ PATH_MAX ] ;
2016-12-17 18:39:18 +00:00
snprintf ( hogpath , sizeof ( hogpath ) , " %s.hog " , path . c_str ( ) ) ;
PHYSFSX_removeRelFromSearchPath ( hogpath ) ;
2007-05-27 05:48:16 +00:00
}
2006-03-20 17:12:09 +00:00
}
//fills in the global list of missions. Returns the number of missions
//in the list. If anarchy_mode is set, then also add anarchy-only missions.
2016-08-25 04:05:32 +00:00
namespace dsx {
2006-03-20 17:12:09 +00:00
2021-06-28 03:37:49 +00:00
namespace {
2020-01-18 21:57:39 +00:00
static mission_list_type build_mission_list ( const mission_filter_mode mission_filter )
{
2006-03-20 17:12:09 +00:00
//now search for levels on disk
//@@Took out this code because after this routine was called once for
//@@a list of single-player missions, a subsequent call for a list of
//@@anarchy missions would not scan again, and thus would not find the
//@@anarchy-only missions. If we retain the minimum level of install,
//@@we may want to put the code back in, having it always scan for all
//@@missions, and have the code that uses it sort out the ones it wants.
//@@ if (num_missions != -1) {
//@@ if (Current_mission_num != 0)
//@@ load_mission(0); //set built-in mission as default
//@@ return num_missions;
//@@ }
2016-05-22 17:49:32 +00:00
mission_list_type mission_list ;
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2014-08-16 04:20:48 +00:00
d_fname builtin_mission_filename ;
2014-08-15 22:59:54 +00:00
add_builtin_mission_to_list ( mission_list , builtin_mission_filename ) ; //read built-in first
2013-03-03 01:03:33 +00:00
# endif
2014-08-15 22:59:54 +00:00
add_d1_builtin_mission_to_list ( mission_list ) ;
2015-10-11 22:21:00 +00:00
mission_candidate_search_path search_str = { { MISSION_DIR } } ;
2019-06-20 04:02:27 +00:00
DXX_POISON_MEMORY ( std : : next ( search_str . begin ( ) , sizeof ( MISSION_DIR ) ) , search_str . end ( ) , 0xcc ) ;
2020-01-18 21:57:39 +00:00
add_missions_to_list ( mission_list , search_str , search_str . begin ( ) + sizeof ( MISSION_DIR ) - 1 , mission_filter ) ;
2006-03-20 17:12:09 +00:00
// move original missions (in story-chronological order)
// to top of mission list
2014-08-15 22:59:54 +00:00
std : : size_t top_place = 0 ;
2015-10-11 22:21:00 +00:00
promote ( mission_list , D1_MISSION_FILENAME , top_place ) ; // original descent 1 mission
# if defined(DXX_BUILD_DESCENT_II)
2014-08-15 22:59:54 +00:00
promote ( mission_list , builtin_mission_filename , top_place ) ; // d2 or d2demo
promote ( mission_list , " d2x " , top_place ) ; // vertigo
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2014-08-15 22:59:54 +00:00
if ( mission_list . size ( ) > top_place )
std : : sort ( next ( begin ( mission_list ) , top_place ) , end ( mission_list ) , ml_sort_func ) ;
2006-03-20 17:12:09 +00:00
return mission_list ;
}
2021-06-28 03:37:49 +00:00
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
//values for built-in mission
2013-04-06 21:24:40 +00:00
int load_mission_ham ( )
{
2019-08-13 19:31:41 +00:00
read_hamfile ( ) ; // intentionally can also read from the HOG
2019-08-15 01:34:22 +00:00
2019-08-13 19:31:41 +00:00
if ( Piggy_hamfile_version > = 3 )
{
// re-read sounds in case mission has custom .sXX
Num_sound_files = 0 ;
2021-07-25 23:00:56 +00:00
read_sndfile ( 0 ) ;
2019-08-13 19:31:41 +00:00
piggy_read_sounds ( ) ;
}
2016-03-06 05:01:41 +00:00
if ( Current_mission - > descent_version = = Mission : : descent_version_type : : descent2a & &
2016-01-09 16:38:09 +00:00
Current_mission - > alternate_ham_file )
{
2013-04-06 21:24:40 +00:00
/*
* If an alternate HAM is specified , map a HOG of the same name
* ( if it exists ) so that users can reference a HAM within a
* HOG . This is required to let users reference the D2X . HAM
* file provided by Descent II : Vertigo .
*
* Try both plain NAME and missions / NAME , in that order .
*/
2014-07-23 01:52:10 +00:00
auto & altham = Current_mission - > alternate_ham_file ;
2013-04-06 21:24:40 +00:00
unsigned l = strlen ( * altham ) ;
char althog [ PATH_MAX ] ;
2014-07-23 02:27:22 +00:00
snprintf ( althog , sizeof ( althog ) , MISSION_DIR " %.*s.hog " , l - 4 , static_cast < const char * > ( * altham ) ) ;
2013-04-06 21:24:40 +00:00
char * p = althog + sizeof ( MISSION_DIR ) - 1 ;
2021-06-28 03:37:49 +00:00
const auto mount_hog = make_PHYSFSX_ComputedPathMount ( p , althog , physfs_search_path : : prepend ) ;
2016-03-06 05:01:41 +00:00
bm_read_extra_robots ( * altham , Mission : : descent_version_type : : descent2z ) ;
2013-04-06 21:24:40 +00:00
return 1 ;
2016-01-09 16:38:09 +00:00
}
2016-03-06 05:01:41 +00:00
else if ( Current_mission - > descent_version = = Mission : : descent_version_type : : descent2a | |
Current_mission - > descent_version = = Mission : : descent_version_type : : descent2z | |
Current_mission - > descent_version = = Mission : : descent_version_type : : descent2x )
2016-01-09 16:38:09 +00:00
{
2013-04-06 21:24:40 +00:00
char t [ 50 ] ;
2020-01-18 21:57:39 +00:00
snprintf ( t , sizeof ( t ) , " %s.ham " , & * Current_mission - > filename ) ;
2016-01-09 16:38:09 +00:00
bm_read_extra_robots ( t , Current_mission - > descent_version ) ;
2013-04-06 21:24:40 +00:00
return 1 ;
} else
return 0 ;
}
2013-03-03 01:03:33 +00:00
# endif
2020-01-18 21:57:39 +00:00
}
2013-04-06 21:24:40 +00:00
2021-06-28 03:37:49 +00:00
namespace {
2015-01-18 01:58:31 +00:00
# define tex ".tex"
static void set_briefing_filename ( d_fname & f , const char * const v , std : : size_t d )
{
f . copy_if ( v , d ) ;
f . copy_if ( d , tex ) ;
if ( ! PHYSFSX_exists ( static_cast < const char * > ( f ) , 1 ) & & ! ( f . copy_if ( + + d , " txb " ) , PHYSFSX_exists ( static_cast < const char * > ( f ) , 1 ) ) ) // check if this file exists ...
f = { } ;
}
2014-07-23 02:27:22 +00:00
static void set_briefing_filename ( d_fname & f , const char * const v )
{
using std : : next ;
2014-12-08 03:54:11 +00:00
auto a = [ ] ( char c ) {
return ! c | | c = = ' . ' ;
} ;
2015-01-18 01:58:30 +00:00
auto i = std : : find_if ( v , next ( v , f . size ( ) - sizeof ( tex ) ) , a ) ;
std : : size_t d = std : : distance ( v , i ) ;
2015-01-18 01:58:31 +00:00
set_briefing_filename ( f , v , d ) ;
2014-07-23 02:27:22 +00:00
}
2020-05-02 21:18:42 +00:00
static void record_briefing ( d_fname & f , std : : array < char , PATH_MAX > & buf )
2014-07-23 02:27:22 +00:00
{
2014-12-20 04:36:10 +00:00
const auto v = get_value ( buf . data ( ) ) ;
2018-06-13 02:02:58 +00:00
if ( ! v )
return ;
const std : : size_t d = std : : distance ( v , std : : find_if ( v , buf . end ( ) , null_or_space ) ) ;
if ( d > = FILENAME_LEN )
return ;
{
2015-01-18 01:58:31 +00:00
set_briefing_filename ( f , v , std : : min ( d , f . size ( ) - sizeof ( tex ) ) ) ;
2018-06-13 02:02:58 +00:00
}
2014-07-23 02:27:22 +00:00
}
2015-01-18 01:58:31 +00:00
# undef tex
2014-07-23 02:27:22 +00:00
2021-06-28 03:37:49 +00:00
}
2006-03-20 17:12:09 +00:00
//loads the specfied mission from the mission list.
//build_mission_list() must have been called.
//Returns true if mission loaded ok, else false.
2016-08-25 04:05:32 +00:00
namespace dsx {
2018-07-03 05:59:39 +00:00
2021-06-28 03:37:49 +00:00
namespace {
2018-07-03 05:59:39 +00:00
static const char * load_mission ( const mle * const mission )
2006-03-20 17:12:09 +00:00
{
2016-05-22 17:49:31 +00:00
char * v ;
2006-03-20 17:12:09 +00:00
2020-05-02 21:18:42 +00:00
Current_mission = std : : make_unique < Mission > ( static_cast < const Mission_path & > ( * mission ) ) ;
2013-08-18 20:58:52 +00:00
Current_mission - > builtin_hogsize = mission - > builtin_hogsize ;
2018-06-27 03:34:34 +00:00
Current_mission - > mission_name . copy_if ( mission - > mission_name ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-08-18 20:58:52 +00:00
Current_mission - > descent_version = mission - > descent_version ;
2013-03-03 01:03:33 +00:00
# endif
2013-08-18 20:58:52 +00:00
Current_mission - > anarchy_only_flag = mission - > anarchy_only_flag ;
2008-03-08 22:37:09 +00:00
Current_mission - > n_secret_levels = 0 ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-04-06 21:24:40 +00:00
Current_mission - > alternate_ham_file = NULL ;
2013-03-03 01:03:33 +00:00
# endif
2007-04-04 07:40:13 +00:00
2010-03-04 17:19:47 +00:00
//init vars
2021-11-01 03:37:19 +00:00
Current_mission - > last_level = 0 ;
2021-11-01 03:37:19 +00:00
Current_mission - > last_secret_level = 0 ;
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = { } ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = { } ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table . reset ( ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > level_names . reset ( ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names . reset ( ) ;
2010-03-04 17:19:47 +00:00
2008-01-23 17:28:28 +00:00
// for Descent 1 missions, load descent.hog
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
if ( EMULATING_D1 )
# endif
{
2021-06-28 03:37:49 +00:00
std : : array < char , PATH_MAX > pathname ;
2021-07-25 23:00:56 +00:00
if ( const auto r = PHYSFSX_addRelToSearchPath ( " descent.hog " , pathname , physfs_search_path : : prepend ) ; r ! = PHYSFS_ERR_OK )
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
2021-07-25 23:00:56 +00:00
Error ( " descent.hog not available! \n %s " , PHYSFS_getErrorByCode ( r ) ) ;
2013-03-03 01:03:33 +00:00
# elif defined(DXX_BUILD_DESCENT_II)
2021-07-25 23:00:56 +00:00
Warning ( " descent.hog not available! \n %s \n This mission may be missing some files required for briefings and exit sequence \n " , PHYSFS_getErrorByCode ( r ) ) ;
2013-03-03 01:03:33 +00:00
# endif
2020-01-18 21:57:39 +00:00
if ( ! d_stricmp ( Current_mission - > path . c_str ( ) , D1_MISSION_FILENAME ) )
2021-11-01 03:37:19 +00:00
{
load_mission_d1 ( ) ;
return nullptr ;
}
2008-01-23 17:28:28 +00:00
}
2015-01-30 23:18:22 +00:00
# if defined(DXX_BUILD_DESCENT_II)
else
2021-07-25 23:00:56 +00:00
PHYSFSX_removeRelFromSearchPath ( " descent.hog " ) ;
2015-01-30 23:18:22 +00:00
# endif
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2008-01-23 17:28:28 +00:00
if ( PLAYING_BUILTIN_MISSION ) {
2006-03-20 17:12:09 +00:00
switch ( Current_mission - > builtin_hogsize ) {
case SHAREWARE_MISSION_HOGSIZE :
case MAC_SHARE_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = " brief2.txb " ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = BIMD2_ENDING_FILE_SHARE ;
2021-11-01 03:37:19 +00:00
load_mission_shareware ( ) ;
return nullptr ;
2006-03-20 17:12:09 +00:00
case OEM_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = " brief2o.txb " ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = BIMD2_ENDING_FILE_OEM ;
2021-11-01 03:37:19 +00:00
load_mission_oem ( ) ;
return nullptr ;
2006-03-20 17:12:09 +00:00
default :
2019-04-04 04:29:03 +00:00
Int3 ( ) ;
2022-01-09 15:25:42 +00:00
[[fallthrough]] ;
2006-03-20 17:12:09 +00:00
case FULL_MISSION_HOGSIZE :
case FULL_10_MISSION_HOGSIZE :
case MAC_FULL_MISSION_HOGSIZE :
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = " robot.txb " ;
2006-03-20 17:12:09 +00:00
// continue on... (use d2.mn2 from hogfile)
break ;
}
2008-01-23 17:28:28 +00:00
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
//read mission from file
2014-08-16 03:59:14 +00:00
auto & msn_extension =
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2020-01-18 21:57:39 +00:00
( mission - > descent_version ! = Mission : : descent_version_type : : descent1 ) ? MISSION_EXTENSION_DESCENT_II :
2013-03-03 01:03:33 +00:00
# endif
2015-10-11 22:21:00 +00:00
MISSION_EXTENSION_DESCENT_I ;
2020-05-02 21:18:42 +00:00
std : : array < char , PATH_MAX > mission_filename ;
2016-05-22 17:49:31 +00:00
snprintf ( mission_filename . data ( ) , mission_filename . size ( ) , " %s%s " , mission - > path . c_str ( ) , msn_extension ) ;
2006-03-20 17:12:09 +00:00
2016-05-22 17:49:31 +00:00
PHYSFSEXT_locateCorrectCase ( mission_filename . data ( ) ) ;
2006-03-20 17:12:09 +00:00
2021-07-25 23:00:56 +00:00
auto & & [ mfile , physfserr ] = PHYSFSX_openReadBuffered ( mission_filename . data ( ) ) ;
2015-01-17 18:31:42 +00:00
if ( ! mfile ) {
2014-07-20 22:13:25 +00:00
Current_mission . reset ( ) ;
2021-07-25 23:00:56 +00:00
con_printf ( CON_NORMAL , DXX_STRINGIZE_FL ( __FILE__ , __LINE__ , " error: failed to open mission \" %s \" : %s " ) , mission_filename . data ( ) , PHYSFS_getErrorByCode ( physfserr ) ) ;
2018-07-03 05:59:39 +00:00
return " Failed to open mission file " ; //error!
2006-03-20 17:12:09 +00:00
}
2008-01-23 17:28:28 +00:00
//for non-builtin missions, load HOG
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2020-01-18 21:57:39 +00:00
Current_mission - > descent_version = mission - > descent_version ;
2008-01-23 17:28:28 +00:00
if ( ! PLAYING_BUILTIN_MISSION )
2013-03-03 01:03:33 +00:00
# endif
2008-01-23 17:28:28 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
strcpy ( & mission_filename [ mission - > path . size ( ) + 1 ] , " hog " ) ; //change extension
2021-06-28 03:37:49 +00:00
std : : array < char , PATH_MAX > pathname ;
PHYSFSX_addRelToSearchPath ( mission_filename . data ( ) , pathname , physfs_search_path : : prepend ) ;
2021-11-01 03:37:19 +00:00
set_briefing_filename ( Current_mission - > briefing_text_filename , & * Current_mission - > filename ) ;
Current_mission - > ending_text_filename = Current_mission - > briefing_text_filename ;
2008-01-23 17:28:28 +00:00
}
2006-03-20 17:12:09 +00:00
2014-10-19 17:17:54 +00:00
for ( PHYSFSX_gets_line_t < PATH_MAX > buf ; PHYSFSX_fgets ( buf , mfile ) ; )
2014-09-07 19:48:10 +00:00
{
2013-03-03 01:03:33 +00:00
if ( istok ( buf , " type " ) )
2006-03-20 17:12:09 +00:00
continue ; //already have name, go to next line
else if ( istok ( buf , " briefing " ) ) {
2021-11-01 03:37:19 +00:00
record_briefing ( Current_mission - > briefing_text_filename , buf ) ;
2006-03-20 17:12:09 +00:00
}
else if ( istok ( buf , " ending " ) ) {
2021-11-01 03:37:19 +00:00
record_briefing ( Current_mission - > ending_text_filename , buf ) ;
2006-03-20 17:12:09 +00:00
}
else if ( istok ( buf , " num_levels " ) ) {
if ( ( v = get_value ( buf ) ) ! = NULL ) {
2015-01-11 05:08:30 +00:00
char * ip ;
2016-07-30 21:56:31 +00:00
const auto n_levels = strtoul ( v , & ip , 10 ) ;
2013-01-12 10:53:43 +00:00
Assert ( n_levels < = MAX_LEVELS_PER_MISSION ) ;
2016-07-30 21:56:31 +00:00
if ( n_levels > MAX_LEVELS_PER_MISSION )
continue ;
if ( * ip )
{
while ( isspace ( static_cast < unsigned > ( * ip ) ) )
+ + ip ;
if ( * ip & & * ip ! = ' ; ' )
continue ;
}
2021-11-01 03:37:19 +00:00
auto names = std : : make_unique < d_fname [ ] > ( n_levels ) ;
uint8_t level_names_loaded = 0 ;
for ( auto & i : unchecked_partial_range ( names . get ( ) , n_levels ) )
2015-01-11 05:08:30 +00:00
{
2015-01-12 00:26:03 +00:00
if ( ! PHYSFSX_fgets ( buf , mfile ) )
break ;
auto & line = buf . line ( ) ;
auto s = std : : find_if ( line . begin ( ) , line . end ( ) , null_or_space ) ;
if ( i . copy_if ( buf . line ( ) , std : : distance ( line . begin ( ) , s ) ) )
2015-01-11 05:08:30 +00:00
{
2021-11-01 03:37:19 +00:00
+ + level_names_loaded ;
2006-03-20 17:12:09 +00:00
}
else
break ;
}
2021-11-01 03:37:19 +00:00
Current_mission - > last_level = level_names_loaded ;
2021-11-01 03:37:19 +00:00
Current_mission - > level_names = std : : move ( names ) ;
2006-03-20 17:12:09 +00:00
}
}
else if ( istok ( buf , " num_secrets " ) ) {
if ( ( v = get_value ( buf ) ) ! = NULL ) {
2015-01-12 00:26:03 +00:00
char * ip ;
2016-07-30 21:56:31 +00:00
const auto n_levels = strtoul ( v , & ip , 10 ) ;
2015-01-12 00:26:03 +00:00
Assert ( n_levels < = MAX_SECRET_LEVELS_PER_MISSION ) ;
2016-07-30 21:56:31 +00:00
if ( n_levels > MAX_SECRET_LEVELS_PER_MISSION )
continue ;
if ( * ip )
{
while ( isspace ( static_cast < unsigned > ( * ip ) ) )
+ + ip ;
if ( * ip & & * ip ! = ' ; ' )
continue ;
}
2021-11-01 03:37:19 +00:00
Current_mission - > n_secret_levels = n_levels ;
2021-11-01 03:37:19 +00:00
uint8_t level_names_loaded = 0 ;
auto names = std : : make_unique < d_fname [ ] > ( n_levels ) ;
auto table = std : : make_unique < uint8_t [ ] > ( n_levels ) ;
for ( auto & & [ name , table_cell ] : zip ( unchecked_partial_range ( names . get ( ) , n_levels ) , unchecked_partial_range ( table . get ( ) , n_levels ) ) )
{
2015-01-12 00:26:03 +00:00
if ( ! PHYSFSX_fgets ( buf , mfile ) )
2006-03-20 17:12:09 +00:00
break ;
2015-01-12 00:26:03 +00:00
const auto & line = buf . line ( ) ;
const auto lb = line . begin ( ) ;
2015-01-14 02:26:20 +00:00
/* No auto: returned value must be type const char*
* Modern glibc maintains const - ness of the input .
* Apple libc + + and mingw32 do not .
*/
const char * const t = strchr ( lb , ' , ' ) ;
2015-01-12 00:26:03 +00:00
if ( ! t )
break ;
auto a = [ ] ( char c ) {
return isspace ( static_cast < unsigned > ( c ) ) ;
} ;
auto s = std : : find_if ( lb , t , a ) ;
2021-11-01 03:37:19 +00:00
if ( name . copy_if ( line , std : : distance ( lb , s ) ) )
2015-01-12 00:26:03 +00:00
{
unsigned long ls = strtoul ( t + 1 , & ip , 10 ) ;
2021-11-01 03:37:19 +00:00
if ( ls < 1 | | ls > Current_mission - > last_level )
2006-03-20 17:12:09 +00:00
break ;
2021-11-01 03:37:19 +00:00
table_cell = ls ;
+ + level_names_loaded ;
2006-03-20 17:12:09 +00:00
}
else
break ;
}
2021-11-01 03:37:19 +00:00
Current_mission - > last_secret_level = - static_cast < signed > ( level_names_loaded ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names = std : : move ( names ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table = std : : move ( table ) ;
2006-03-20 17:12:09 +00:00
}
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2016-03-06 05:01:41 +00:00
else if ( Current_mission - > descent_version = = Mission : : descent_version_type : : descent2a & & buf [ 0 ] = = ' ! ' ) {
2013-04-06 21:24:40 +00:00
if ( istok ( buf + 1 , " ham " ) ) {
2020-05-02 21:18:42 +00:00
Current_mission - > alternate_ham_file = std : : make_unique < d_fname > ( ) ;
2013-04-06 21:24:40 +00:00
if ( ( v = get_value ( buf ) ) ! = NULL ) {
unsigned l = strlen ( v ) ;
if ( l < = 4 )
2014-08-16 03:59:14 +00:00
con_printf ( CON_URGENT , " Mission %s has short HAM \" %s \" . " , Current_mission - > path . c_str ( ) , v ) ;
2013-04-06 21:24:40 +00:00
else if ( l > = sizeof ( * Current_mission - > alternate_ham_file ) )
2014-08-16 03:59:14 +00:00
con_printf ( CON_URGENT , " Mission %s has excessive HAM \" %s \" . " , Current_mission - > path . c_str ( ) , v ) ;
2013-04-06 21:24:40 +00:00
else {
2014-07-23 02:27:22 +00:00
Current_mission - > alternate_ham_file - > copy_if ( v , l + 1 ) ;
2014-08-16 03:59:14 +00:00
con_printf ( CON_VERBOSE , " Mission %s will use HAM %s. " , Current_mission - > path . c_str ( ) , static_cast < const char * > ( * Current_mission - > alternate_ham_file ) ) ;
2013-04-06 21:24:40 +00:00
}
}
else
2014-08-16 03:59:14 +00:00
con_printf ( CON_URGENT , " Mission %s has no HAM. " , Current_mission - > path . c_str ( ) ) ;
2013-04-06 21:24:40 +00:00
}
else {
2014-12-20 04:36:10 +00:00
con_printf ( CON_URGENT , " Mission %s uses unsupported critical directive \" %s \" . " , Current_mission - > path . c_str ( ) , static_cast < const char * > ( buf ) ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > last_level = 0 ;
2013-04-06 21:24:40 +00:00
break ;
}
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
}
2015-01-17 18:31:42 +00:00
mfile . reset ( ) ;
2021-11-01 03:37:19 +00:00
if ( Current_mission - > last_level < = 0 )
{
2014-07-20 22:13:25 +00:00
Current_mission . reset ( ) ; //no valid mission loaded
2018-07-03 05:59:39 +00:00
return " Failed to parse mission file " ;
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2011-04-20 17:42:02 +00:00
// re-read default HAM file, in case this mission brings it's own version of it
2020-08-24 01:31:28 +00:00
free_polygon_models ( LevelSharedPolygonModelState ) ;
2011-04-20 17:42:02 +00:00
2013-04-06 21:24:40 +00:00
if ( load_mission_ham ( ) )
2021-06-28 03:37:49 +00:00
Current_mission - > extra_robot_movie = init_extra_robot_movie ( & * Current_mission - > filename ) ;
2013-03-03 01:03:33 +00:00
# endif
2018-07-03 05:59:39 +00:00
return nullptr ;
2006-03-20 17:12:09 +00:00
}
2018-07-03 05:59:39 +00:00
2021-06-28 03:37:49 +00:00
}
2006-03-20 17:12:09 +00:00
//loads the named mission if exists.
2018-07-03 05:59:39 +00:00
//Returns nullptr if mission loaded ok, else error string.
2020-01-18 21:57:39 +00:00
const char * load_mission_by_name ( const mission_entry_predicate mission_name , const mission_name_type name_match_mode )
2006-03-20 17:12:09 +00:00
{
2020-01-18 21:57:39 +00:00
auto & & mission_list = build_mission_list ( mission_filter_mode : : include_anarchy ) ;
2020-01-18 21:57:39 +00:00
{
range_for ( auto & i , mission_list )
{
switch ( name_match_mode )
{
case mission_name_type : : basename :
if ( ! d_stricmp ( mission_name . filesystem_name , & * i . filename ) )
return load_mission ( & i ) ;
continue ;
case mission_name_type : : pathname :
case mission_name_type : : guess :
if ( const auto r = compare_mission_by_pathname ( mission_name , i ) )
return load_mission ( r ) ;
continue ;
default :
return " Unhandled load mission type " ;
}
}
}
if ( name_match_mode = = mission_name_type : : guess )
{
const auto p = strrchr ( mission_name . filesystem_name , ' / ' ) ;
const auto & guess_predicate = p
? mission_name . with_filesystem_name ( p + 1 )
: mission_name ;
range_for ( auto & i , mission_list )
{
if ( const auto r = compare_mission_by_guess ( guess_predicate , i ) )
{
con_printf ( CON_NORMAL , " %s:%u: request for guessed mission name \" %s \" found \" %s \" " , __FILE__ , __LINE__ , mission_name . filesystem_name , r - > path . c_str ( ) ) ;
return load_mission ( r ) ;
}
}
}
2020-01-06 01:25:35 +00:00
return " No matching mission found in \n installed mission list. " ;
2006-03-20 17:12:09 +00:00
}
2020-01-18 21:57:39 +00:00
}
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
namespace {
2020-12-26 21:17:29 +00:00
template < typename tag >
class unique_menu_tagged_string : std : : unique_ptr < char [ ] >
{
public :
unique_menu_tagged_string ( std : : unique_ptr < char [ ] > p ) :
std : : unique_ptr < char [ ] > ( std : : move ( p ) )
{
}
using std : : unique_ptr < char [ ] > : : get ;
operator menu_tagged_string < tag > ( ) const &
{
return { get ( ) } ;
}
operator menu_tagged_string < tag > ( ) const & & = delete ;
} ;
2020-12-27 22:03:09 +00:00
struct mission_menu : listbox
2010-03-18 07:02:38 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
static constexpr char listbox_go_up [ ] = " <..> " ;
2018-06-18 04:11:39 +00:00
using callback_type = window_event_result ( * ) ( void ) ;
2020-12-27 22:03:09 +00:00
/* The top level menu stores the mission data in a member variable.
* When this class is the base of toplevel_mission_menu , this
* reference points to that member variable in
* toplevel_mission_menu .
*
* Subdirectory menus do not store a copy of the mission data , and
* instead store a reference to the mission data in the top level
* menu . When this class is the base of subdirectory_mission_menu ,
* this reference points to the member variable in the
* toplevel_mission_menu that created this subdirectory_mission_menu .
*
* The data is not reference counted , because the top level menu
* always outlives the subdirectory menus .
*/
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
const mission_list_type & ml ;
2020-12-27 22:03:09 +00:00
/* listbox stores an unowned pointer to the string pointers that it
* uses . This member variable stores an owned pointer to the same
* string pointers , so that the string pointers persist for the life
* of the listbox . The strings are stored elsewhere .
*/
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
const std : : unique_ptr < const char * [ ] > listbox_strings ;
2020-12-27 22:03:09 +00:00
/* listbox stores an unowned pointer to the title string, since some
* listboxes use statically allocated strings . This member variable
* owns the storage for this listbox ' s title .
*/
2020-12-26 21:17:29 +00:00
const unique_menu_tagged_string < menu_title_tag > title ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
const callback_type when_selected ;
2020-12-27 22:03:09 +00:00
virtual window_event_result callback_handler ( const d_event & , window_event_result ) override ;
mission_menu ( const mission_list_type & rml , std : : unique_ptr < const char * [ ] > & & name_pointer_strings , const char * const message , callback_type when_selected , mission_menu * const parent , const int default_item , grs_canvas & canvas ) :
mission_menu ( rml , std : : move ( name_pointer_strings ) , prepare_title ( message , rml ) , when_selected , parent , default_item , canvas )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
}
2020-12-27 22:03:09 +00:00
protected :
mission_menu * parent = nullptr ;
mission_menu ( const mission_list_type & rml , std : : unique_ptr < const char * [ ] > & & name_pointer_strings , unique_menu_tagged_string < menu_title_tag > title_parameter , callback_type when_selected , mission_menu * const parent , const int default_item , grs_canvas & canvas ) :
listbox ( default_item , rml . size ( ) , name_pointer_strings . get ( ) , title_parameter , canvas , 1 ) ,
ml ( rml ) , listbox_strings ( std : : move ( name_pointer_strings ) ) ,
title ( std : : move ( title_parameter ) ) ,
when_selected ( when_selected ) , parent ( parent )
2018-06-18 04:11:39 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
}
2020-12-26 21:17:29 +00:00
static unique_menu_tagged_string < menu_title_tag > prepare_title ( const char * const message , const mission_list_type & ml )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
mission_subdir_stats ss ;
ss . count ( ml ) ;
2020-05-02 21:18:42 +00:00
std : : array < char , 12 > dirbuf ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
char buf [ 128 ] ;
2020-12-26 21:17:29 +00:00
const auto r = 1u + std : : snprintf ( buf , sizeof ( buf ) , " %s \n [%sMSN:LOCAL %zu; TOTAL %zu] " , message , prepare_mission_list_count_dirbuf ( dirbuf , ss . immediate_directories ) , ss . immediate_missions , ss . total_missions ) ;
unique_menu_tagged_string < menu_title_tag > p = std : : make_unique < char [ ] > ( r ) ;
std : : memcpy ( p . get ( ) , buf , r ) ;
return p ;
2018-06-18 04:11:39 +00:00
}
2013-12-22 22:03:07 +00:00
} ;
2010-03-18 07:02:38 +00:00
2020-12-27 22:03:09 +00:00
struct toplevel_mission_menu_storage
{
protected :
const mission_list_type mission_list_storage ;
toplevel_mission_menu_storage ( mission_list_type & & rml ) :
mission_list_storage ( std : : move ( rml ) )
{
}
} ;
struct toplevel_mission_menu : toplevel_mission_menu_storage , mission_menu
{
public :
toplevel_mission_menu ( mission_list_type & & rml , std : : unique_ptr < const char * [ ] > & & name_pointer_strings , const char * const message , callback_type when_selected , const int default_item , grs_canvas & canvas ) :
toplevel_mission_menu_storage ( std : : move ( rml ) ) ,
mission_menu ( mission_list_storage , std : : move ( name_pointer_strings ) , message , when_selected , nullptr /* no parent for toplevel menu */ , default_item , canvas )
{
}
} ;
struct subdirectory_mission_menu : mission_menu
{
using mission_menu : : mission_menu ;
} ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
constexpr char mission_menu : : listbox_go_up [ ] ;
struct mission_menu_create_state
{
std : : unique_ptr < const char * [ ] > listbox_strings ;
unsigned initial_selection = UINT_MAX ;
std : : unique_ptr < mission_menu_create_state > submenu ;
mission_menu_create_state ( const std : : size_t len ) :
2020-05-02 21:18:42 +00:00
listbox_strings ( std : : make_unique < const char * [ ] > ( len ) )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
}
mission_menu_create_state ( mission_menu_create_state & & ) = default ;
} ;
}
2020-12-27 22:03:09 +00:00
window_event_result mission_menu : : callback_handler ( const d_event & event , window_event_result )
2010-03-18 07:02:38 +00:00
{
2014-10-04 21:47:13 +00:00
switch ( event . type )
2010-03-18 07:02:38 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
case EVENT_WINDOW_CREATED :
break ;
2010-03-18 07:02:38 +00:00
case EVENT_NEWMENU_SELECTED :
2015-02-28 22:34:07 +00:00
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
const auto raw_citem = static_cast < const d_select_event & > ( event ) . citem ;
auto citem = raw_citem ;
2020-12-27 22:03:09 +00:00
if ( parent )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
if ( citem = = 0 )
{
/* Clear parent pointer so that the parent window is
* not implicitly closed during handling of
* EVENT_WINDOW_CLOSE .
*/
2020-12-27 22:03:09 +00:00
parent = nullptr ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
return window_event_result : : close ;
}
/* Adjust for the "Go up" placeholder item */
- - citem ;
}
2010-03-18 07:02:38 +00:00
if ( citem > = 0 )
{
2020-12-27 22:03:09 +00:00
auto & mli = ml [ citem ] ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
if ( ! mli . directory . empty ( ) )
{
2020-05-02 21:18:42 +00:00
auto listbox_strings = std : : make_unique < const char * [ ] > ( mli . directory . size ( ) + 1 ) ;
2020-12-27 22:03:09 +00:00
listbox_strings [ 0 ] = listbox_go_up ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
const auto a = [ ] ( const mle & m ) - > const char * {
return m . mission_name ;
} ;
std : : transform ( mli . directory . begin ( ) , mli . directory . end ( ) , & listbox_strings [ 1 ] , a ) ;
2021-06-13 08:15:26 +00:00
auto submm = window_create < subdirectory_mission_menu > ( mli . directory , std : : move ( listbox_strings ) , mli . path . c_str ( ) , when_selected , this , 0 , grd_curscreen - > sc_canvas ) ;
2020-12-27 22:03:09 +00:00
( void ) submm ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
return window_event_result : : handled ;
}
2010-03-18 07:02:38 +00:00
// Chose a mission
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
else if ( const auto errstr = load_mission ( & mli ) )
2010-03-18 07:02:38 +00:00
{
2020-12-19 16:13:26 +00:00
nm_messagebox ( menu_title { nullptr } , 1 , TXT_OK , " %s \n \n %s \n \n %s " , TXT_MISSION_ERROR , errstr , mli . path . c_str ( ) ) ;
2016-10-27 07:22:41 +00:00
return window_event_result : : handled ; // stay in listbox so user can select another one
2010-03-18 07:02:38 +00:00
}
2020-12-27 22:03:09 +00:00
CGameCfg . LastMission . copy_if ( listbox_strings [ raw_citem ] ) ;
2010-03-18 07:02:38 +00:00
}
2020-12-27 22:03:09 +00:00
return ( * when_selected ) ( ) ;
2015-02-28 22:34:07 +00:00
}
2010-03-18 07:02:38 +00:00
case EVENT_WINDOW_CLOSE :
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
/* If the user dismisses the listbox by pressing ESCAPE,
* do not close the parent listbox .
*/
2020-12-27 22:03:09 +00:00
if ( listbox_get_citem ( * this ) ! = - 1 )
if ( parent )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
2020-12-27 22:03:09 +00:00
window_close ( parent ) ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
}
2010-03-18 07:02:38 +00:00
break ;
default :
break ;
}
2016-10-27 07:22:41 +00:00
return window_event_result : : ignored ;
2010-03-18 07:02:38 +00:00
}
2021-06-28 03:37:49 +00:00
namespace {
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
using mission_menu_create_state_ptr = std : : unique_ptr < mission_menu_create_state > ;
static mission_menu_create_state_ptr prepare_mission_menu_state ( const mission_list_type & mission_list , const char * const LastMission , const std : : size_t extra_strings )
{
auto mission_name_to_select = LastMission ;
2020-05-02 21:18:42 +00:00
auto p = std : : make_unique < mission_menu_create_state > ( mission_list . size ( ) + extra_strings ) ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
auto & create_state = * p . get ( ) ;
auto listbox_strings = create_state . listbox_strings . get ( ) ;
std : : fill_n ( listbox_strings , extra_strings , nullptr ) ;
listbox_strings + = extra_strings ;
2021-06-28 03:37:50 +00:00
for ( auto & & [ idx , mli ] : enumerate ( mission_list ) )
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
{
const char * const mission_name = mli . mission_name ;
* listbox_strings + + = mission_name ;
if ( ! mission_name_to_select )
continue ;
if ( ! mli . directory . empty ( ) )
{
auto & & substate = prepare_mission_menu_state ( mli . directory , mission_name_to_select , 1 ) ;
if ( substate - > initial_selection = = UINT_MAX )
continue ;
substate - > listbox_strings [ 0 ] = mission_menu : : listbox_go_up ;
create_state . submenu = std : : move ( substate ) ;
}
else if ( strcmp ( mission_name , mission_name_to_select ) )
continue ;
2021-06-28 03:37:50 +00:00
create_state . initial_selection = idx ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
mission_name_to_select = nullptr ;
}
2018-10-20 17:25:59 +00:00
return p ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
}
2021-06-28 03:37:49 +00:00
}
2020-01-18 21:57:39 +00:00
namespace dsx {
2020-12-26 21:17:29 +00:00
int select_mission ( const mission_filter_mode mission_filter , const menu_title message , window_event_result ( * when_selected ) ( void ) )
2006-03-20 17:12:09 +00:00
{
2020-01-18 21:57:39 +00:00
auto & & mission_list = build_mission_list ( mission_filter ) ;
2006-03-20 17:12:09 +00:00
int new_mission_num ;
2014-08-15 22:59:54 +00:00
if ( mission_list . size ( ) < = 1 )
2010-03-18 07:02:38 +00:00
{
2018-07-03 05:59:39 +00:00
new_mission_num = ! mission_list . empty ( ) & & ! load_mission ( & mission_list . front ( ) ) ? 0 : - 1 ;
2010-03-18 07:02:38 +00:00
( * when_selected ) ( ) ;
return ( new_mission_num > = 0 ) ;
}
else
{
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
auto & & create_state_ptr = prepare_mission_menu_state ( mission_list , CGameCfg . LastMission , 0 ) ;
auto & create_state = * create_state_ptr . get ( ) ;
mission_menu * parent_mission_menu ;
2010-03-18 07:02:38 +00:00
{
2020-12-27 22:03:09 +00:00
auto mm = window_create < toplevel_mission_menu > ( std : : move ( mission_list ) , std : : move ( create_state . listbox_strings ) , message , when_selected , create_state . initial_selection = = UINT_MAX ? 0 : create_state . initial_selection , grd_curscreen - > sc_canvas ) ;
parent_mission_menu = mm ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
}
for ( auto parent_state = & create_state ; const auto substate = parent_state - > submenu . get ( ) ; parent_state = substate )
{
const auto parent_initial_selection = parent_state - > initial_selection ;
const auto parent_mission_list_size = parent_mission_menu - > ml . size ( ) ;
assert ( parent_initial_selection < parent_mission_list_size ) ;
if ( parent_initial_selection > = parent_mission_list_size )
break ;
const auto & substate_mission_list = parent_mission_menu - > ml [ parent_initial_selection ] ;
2020-12-27 22:03:09 +00:00
auto submm = window_create < subdirectory_mission_menu > ( substate_mission_list . directory , std : : move ( substate - > listbox_strings ) , substate_mission_list . path . c_str ( ) , when_selected , parent_mission_menu , 0 , grd_curscreen - > sc_canvas ) ;
parent_mission_menu = submm ;
Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog. This was substantially more trouble than it should have been,
but the result is good.
Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.
Now:
- Empty directories are hidden entirely. There is nothing for the user
to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
parent, since there is no ambiguity about what the user would want.
If the parent in turn has only that one promoted element when the scan
of the parent finishes, then the element can be promoted up again.
This continues until the root is reached or until a level has more
than one entry. For this purpose, both missions and directories count
as entries.
- Directory entries are decorated to inform the user how many
immediate subdirectories are present, how many missions are present
immediately in the directory, and how many missions total are present,
counting all subdirectories. If there are zero immediate
subdirectories, then the directory count is not shown. For this
purpose, directories that were hidden due to a lack of missions are
not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
sub-dialog, appropriate sub-dialogs are opened so that the last played
mission can be pre-selected.
Currently, there is no in-game override to return to the prior rollup
rules.
Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
}
2006-03-20 17:12:09 +00:00
}
2010-03-18 07:02:38 +00:00
return 1 ; // presume success
2006-03-20 17:12:09 +00:00
}
2012-04-17 09:37:15 +00:00
2016-09-11 18:49:16 +00:00
# if DXX_USE_EDITOR
2016-11-15 07:03:34 +00:00
static int write_mission ( void )
2016-11-14 13:42:35 +00:00
{
auto & msn_extension =
# if defined(DXX_BUILD_DESCENT_II)
2016-11-15 07:03:34 +00:00
( Current_mission - > descent_version ! = Mission : : descent_version_type : : descent1 ) ? MISSION_EXTENSION_DESCENT_II :
2016-11-14 13:42:35 +00:00
# endif
MISSION_EXTENSION_DESCENT_I ;
2020-05-02 21:18:42 +00:00
std : : array < char , PATH_MAX > mission_filename ;
2016-11-14 13:42:35 +00:00
snprintf ( mission_filename . data ( ) , mission_filename . size ( ) , " %s%s " , Current_mission - > path . c_str ( ) , msn_extension ) ;
2021-07-25 23:00:56 +00:00
auto & & mfile = PHYSFSX_openWriteBuffered ( mission_filename . data ( ) ) . first ;
2016-11-14 13:42:35 +00:00
if ( ! mfile )
{
PHYSFS_mkdir ( MISSION_DIR ) ; //try making directory - in *write* path
2021-07-25 23:00:56 +00:00
mfile = PHYSFSX_openWriteBuffered ( mission_filename . data ( ) ) . first ;
2016-11-14 13:42:35 +00:00
if ( ! mfile )
return 0 ;
}
2016-11-15 07:03:34 +00:00
const char * prefix = " " ;
2016-11-14 13:42:35 +00:00
# if defined(DXX_BUILD_DESCENT_II)
switch ( Current_mission - > descent_version )
{
case Mission : : descent_version_type : : descent2x :
2016-11-15 07:03:34 +00:00
prefix = " x " ;
2016-11-14 13:42:35 +00:00
break ;
case Mission : : descent_version_type : : descent2z :
2016-11-15 07:03:34 +00:00
prefix = " z " ;
2016-11-14 13:42:35 +00:00
break ;
case Mission : : descent_version_type : : descent2a :
2016-11-15 07:03:34 +00:00
prefix = " ! " ;
2016-11-14 13:42:35 +00:00
break ;
default :
break ;
}
# endif
2016-11-15 07:03:34 +00:00
PHYSFSX_printf ( mfile , " %sname = %s \n " , prefix , static_cast < const char * > ( Current_mission - > mission_name ) ) ;
2016-11-14 13:42:35 +00:00
PHYSFSX_printf ( mfile , " type = %s \n " , Current_mission - > anarchy_only_flag ? " anarchy " : " normal " ) ;
2021-11-01 03:37:19 +00:00
if ( Current_mission - > briefing_text_filename [ 0 ] )
PHYSFSX_printf ( mfile , " briefing = %s \n " , static_cast < const char * > ( Current_mission - > briefing_text_filename ) ) ;
2016-11-14 13:42:35 +00:00
2021-11-01 03:37:19 +00:00
if ( Current_mission - > ending_text_filename [ 0 ] )
PHYSFSX_printf ( mfile , " ending = %s \n " , static_cast < const char * > ( Current_mission - > ending_text_filename ) ) ;
2016-11-14 13:42:35 +00:00
2021-11-01 03:37:19 +00:00
PHYSFSX_printf ( mfile , " num_levels = %i \n " , Current_mission - > last_level ) ;
2016-11-14 13:42:35 +00:00
2021-11-01 03:37:20 +00:00
for ( const char * const i : unchecked_partial_range ( Current_mission - > level_names . get ( ) , Current_mission - > last_level ) )
PHYSFSX_printf ( mfile , " %s \n " , i ) ;
2016-11-14 13:42:35 +00:00
2021-11-01 03:37:20 +00:00
if ( const auto n_secret_levels = Current_mission - > n_secret_levels )
2016-11-14 13:42:35 +00:00
{
2021-11-01 03:37:20 +00:00
PHYSFSX_printf ( mfile , " num_secrets = %i \n " , n_secret_levels ) ;
for ( const auto & & [ name , table_cell ] : zip ( unchecked_partial_range ( Current_mission - > secret_level_names . get ( ) , n_secret_levels ) , unchecked_partial_range ( Current_mission - > secret_level_table . get ( ) , n_secret_levels ) ) )
PHYSFSX_printf ( mfile , " %s,%i \n " , static_cast < const char * > ( name ) , table_cell ) ;
2016-11-14 13:42:35 +00:00
}
# if defined(DXX_BUILD_DESCENT_II)
if ( Current_mission - > alternate_ham_file )
PHYSFSX_printf ( mfile , " ham = %s \n " , static_cast < const char * > ( * Current_mission - > alternate_ham_file . get ( ) ) ) ;
# endif
return 1 ;
}
2012-04-17 09:37:15 +00:00
void create_new_mission ( void )
{
2020-05-02 21:18:42 +00:00
Current_mission = std : : make_unique < Mission > ( Mission_path ( MISSION_DIR " new_miss " , sizeof ( MISSION_DIR ) - 1 ) ) ; // limited to eight characters because of savegame format
2016-11-14 13:42:35 +00:00
Current_mission - > mission_name . copy_if ( " Untitled " ) ;
2016-11-12 07:38:38 +00:00
Current_mission - > builtin_hogsize = 0 ;
2016-11-14 13:42:35 +00:00
Current_mission - > anarchy_only_flag = 0 ;
2012-04-17 09:37:15 +00:00
2021-11-01 03:37:19 +00:00
Current_mission - > level_names = std : : make_unique < d_fname [ ] > ( 1 ) ;
if ( ! Current_mission - > level_names )
2013-01-12 10:53:43 +00:00
{
2014-07-20 22:13:25 +00:00
Current_mission . reset ( ) ;
2013-01-12 10:53:43 +00:00
return ;
}
2021-11-01 03:37:19 +00:00
Current_mission - > level_names [ 0 ] = " GAMESAVE.LVL " ;
2021-11-01 03:37:19 +00:00
Current_mission - > last_level = 1 ;
2021-11-01 03:37:19 +00:00
Current_mission - > n_secret_levels = 0 ;
2021-11-01 03:37:19 +00:00
Current_mission - > last_secret_level = 0 ;
2021-11-01 03:37:19 +00:00
Current_mission - > briefing_text_filename = { } ;
2021-11-01 03:37:19 +00:00
Current_mission - > ending_text_filename = { } ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_table . reset ( ) ;
2021-11-01 03:37:19 +00:00
Current_mission - > secret_level_names . reset ( ) ;
2016-11-14 13:42:35 +00:00
2016-11-12 07:38:38 +00:00
# if defined(DXX_BUILD_DESCENT_II)
if ( Gamesave_current_version > 3 )
Current_mission - > descent_version = Mission : : descent_version_type : : descent2 ; // custom ham not supported in editor (yet)
else
Current_mission - > descent_version = Mission : : descent_version_type : : descent1 ;
2016-11-14 13:42:35 +00:00
Current_mission - > alternate_ham_file = nullptr ;
2016-11-12 07:38:38 +00:00
# endif
2016-11-14 13:42:35 +00:00
write_mission ( ) ;
2012-04-17 09:37:15 +00:00
}
# endif
2020-01-18 21:57:39 +00:00
}