From 1fd1aa05bc0eb1ffd3f7fde10757998fcd416a37 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 3 Mar 2013 01:03:33 +0000 Subject: [PATCH] Move */main/mission.c -> similar/main/mission.c --- SConstruct | 3 +- d1x-rebirth/main/mission.c | 867 ------------------------ {d2x-rebirth => similar}/main/mission.c | 58 +- 3 files changed, 53 insertions(+), 875 deletions(-) delete mode 100644 d1x-rebirth/main/mission.c rename {d2x-rebirth => similar}/main/mission.c (96%) diff --git a/SConstruct b/SConstruct index 6c10c87e3..89df4c6e9 100644 --- a/SConstruct +++ b/SConstruct @@ -773,6 +773,7 @@ class DXXProgram(DXXCommon): 'main/kmatrix.c', 'main/lighting.c', 'main/mglobal.c', +'main/mission.c', 'main/morph.c', 'main/multi.c', 'main/multibot.c', @@ -1025,7 +1026,6 @@ class D1XProgram(DXXProgram): 'main/hostage.c', 'main/laser.c', 'main/menu.c', -'main/mission.c', 'main/newdemo.c', 'main/piggy.c', 'main/playsave.c', @@ -1101,7 +1101,6 @@ class D2XProgram(DXXProgram): 'main/gameseq.c', 'main/laser.c', 'main/menu.c', -'main/mission.c', 'main/movie.c', 'main/newdemo.c', 'main/piggy.c', diff --git a/d1x-rebirth/main/mission.c b/d1x-rebirth/main/mission.c deleted file mode 100644 index 31e1f6286..000000000 --- a/d1x-rebirth/main/mission.c +++ /dev/null @@ -1,867 +0,0 @@ -/* -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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - -/* - * - * Code to handle multiple missions - * - */ - -#include -#include -#include -#include -#include - -#include "pstypes.h" -#include "strutil.h" -#include "inferno.h" -#include "mission.h" -#include "gameseq.h" -#include "titles.h" -#include "songs.h" -#include "dxxerror.h" -#include "config.h" -#include "newmenu.h" -#include "text.h" -#include "u_mem.h" -#include "ignorecase.h" - -//values that describe where a mission is located -enum mle_loc -{ - ML_CURDIR = 0, - ML_MISSIONDIR = 1 -}; - -//mission list entry -typedef struct mle { - char *filename; // filename without extension - int builtin_hogsize; // if it's the built-in mission, used for determining the version - char mission_name[MISSION_NAME_LEN+1]; - ubyte anarchy_only_flag; // if true, mission is anarchy only - char *path; // relative file path - enum mle_loc location; // where the mission is -} mle; - -static int num_missions = -1; - -Mission *Current_mission = NULL; // currently loaded mission - -// Allocate the Level_names, Secret_level_names and Secret_level_table arrays -static int allocate_levels(void) -{ - MALLOC(Level_names, d_fname, Last_level); - if (!Level_names) - return 0; - - if (Last_secret_level) - { - N_secret_levels = -Last_secret_level; - - MALLOC(Secret_level_names, d_fname, N_secret_levels); - if (!Secret_level_names) - return 0; - - MALLOC(Secret_level_table, ubyte, N_secret_levels); - if (!Secret_level_table) - return 0; - } - - return 1; -} - -// -// Special versions of mission routines for d1 builtins -// - -int load_mission_d1(void) -{ - int i; - - switch (PHYSFSX_fsize("descent.hog")) - { - case D1_SHAREWARE_MISSION_HOGSIZE: - case D1_SHAREWARE_10_MISSION_HOGSIZE: - N_secret_levels = 0; - - Last_level = 7; - Last_secret_level = 0; - - if (!allocate_levels()) - { - free_mission(); - return 0; - } - - //build level names - for (i=0;imission_name,e1->mission_name); - -} - -//returns 1 if file read ok, else 0 -int read_mission_file(mle *mission, char *filename, int location) -{ - char filename2[100]; - PHYSFS_file *mfile; - - switch (location) { - case ML_MISSIONDIR: - strcpy(filename2,MISSION_DIR); - break; - - default: - Int3(); //fall through - - case ML_CURDIR: - strcpy(filename2,""); - break; - } - strcat(filename2,filename); - - mfile = PHYSFSX_openReadBuffered(filename2); - - if (mfile) { - char *p; - char temp[PATH_MAX], *ext; - - strcpy(temp,filename); - p = strrchr(temp, '/'); // get the filename at the end of the path - if (!p) - p = temp; - else p++; - - if ((ext = strchr(p, '.')) == NULL) - return 0; //missing extension - - *ext = 0; //kill extension - - mission->path = d_strdup(temp); - mission->anarchy_only_flag = 0; - mission->filename = mission->path + (p - temp); - mission->location = location; - - p = get_parm_value("name",mfile); - - if (p) { - char *t; - if ((t=strchr(p,';'))!=NULL) - *t=0; - t = p + strlen(p)-1; - while (isspace(*t)) - *t-- = 0; // remove trailing whitespace - if (strlen(p) > MISSION_NAME_LEN) - p[MISSION_NAME_LEN] = 0; - strncpy(mission->mission_name, p, MISSION_NAME_LEN + 1); - } - else { - PHYSFS_close(mfile); - d_free(mission->path); - return 0; - } - - p = get_parm_value("type",mfile); - - //get mission type - if (p) - mission->anarchy_only_flag = istok(p,"anarchy"); - - PHYSFS_close(mfile); - - return 1; - } - - return 0; -} - -void add_d1_builtin_mission_to_list(mle *mission) -{ - int size; - - size = PHYSFSX_fsize("descent.hog"); - if (size == -1) - return; - - switch (size) { - case D1_SHAREWARE_MISSION_HOGSIZE: - case D1_SHAREWARE_10_MISSION_HOGSIZE: - case D1_MAC_SHARE_MISSION_HOGSIZE: - mission->filename = d_strdup(D1_MISSION_FILENAME); - strcpy(mission->mission_name, D1_SHAREWARE_MISSION_NAME); - mission->anarchy_only_flag = 0; - break; - case D1_OEM_MISSION_HOGSIZE: - case D1_OEM_10_MISSION_HOGSIZE: - mission->filename = d_strdup(D1_MISSION_FILENAME); - strcpy(mission->mission_name, D1_OEM_MISSION_NAME); - mission->anarchy_only_flag = 0; - break; - default: - Warning("Unknown D1 hogsize %d\n", size); - Int3(); - // fall through - case D1_MISSION_HOGSIZE: - case D1_MISSION_HOGSIZE2: - case D1_10_MISSION_HOGSIZE: - case D1_MAC_MISSION_HOGSIZE: - mission->filename = d_strdup(D1_MISSION_FILENAME); - strcpy(mission->mission_name, D1_MISSION_NAME); - mission->anarchy_only_flag = 0; - break; - } - - mission->anarchy_only_flag = 0; - mission->builtin_hogsize = size; - mission->path = mission->filename; - num_missions++; -} - -void add_missions_to_list(mle *mission_list, char *path, char *rel_path, int anarchy_mode) -{ - char **find, **i, *ext; - - find = PHYSFS_enumerateFiles(path); - - for (i = find; *i != NULL; i++) - { - if (strlen(path) + strlen(*i) + 1 >= PATH_MAX) - continue; // path is too long - - strcat(rel_path, *i); - if (PHYSFS_isDirectory(path)) - { - strcat(rel_path, "/"); - add_missions_to_list(mission_list, path, rel_path, anarchy_mode); - *(strrchr(path, '/')) = 0; - } - else if ((ext = strrchr(*i, '.')) && (!d_strnicmp(ext, ".msn", 4) || !d_strnicmp(ext, ".mn2", 4))) - if (read_mission_file(&mission_list[num_missions], rel_path, ML_MISSIONDIR)) - { - if (anarchy_mode || !mission_list[num_missions].anarchy_only_flag) - { - mission_list[num_missions].builtin_hogsize = 0; - num_missions++; - } - else - d_free(mission_list[num_missions].path); - } - - if (num_missions >= MAX_MISSIONS) - { - break; - } - - (strrchr(path, '/'))[1] = 0; // chop off the entry - } - - PHYSFS_freeList(find); -} - -/* move to on mission list, increment */ -void promote (mle *mission_list, char * mission_name, int * top_place) -{ - int i; - char name[FILENAME_LEN], * t; - strcpy(name, mission_name); - if ((t = strchr(name,'.')) != NULL) - *t = 0; //kill extension - for (i = *top_place; i < num_missions; i++) - if (!d_stricmp(mission_list[i].filename, name)) { - //swap mission positions - mle temp; - - temp = mission_list[*top_place]; - mission_list[*top_place] = mission_list[i]; - mission_list[i] = temp; - ++(*top_place); - break; - } -} - -void free_mission(void) -{ - // May become more complex with the editor - if (Current_mission) - { - if (Current_mission->path && !PLAYING_BUILTIN_MISSION) - { - char hogpath[PATH_MAX]; - - sprintf(hogpath, MISSION_DIR "%s.hog", Current_mission->path); - PHYSFSX_contfile_close(hogpath); - } - - if (Current_mission->path) - d_free(Current_mission->path); - - if (Level_names) - d_free(Level_names); - if(Secret_level_names) - d_free(Secret_level_names); - if(Secret_level_table) - d_free(Secret_level_table); - - d_free(Current_mission); - } -} - - - -//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. - -mle *build_mission_list(int anarchy_mode) -{ - mle *mission_list; - int top_place; - char search_str[PATH_MAX] = MISSION_DIR; - - //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; -//@@ } - - MALLOC(mission_list, mle, MAX_MISSIONS); - num_missions = 0; - - add_d1_builtin_mission_to_list(mission_list + num_missions); - add_missions_to_list(mission_list, search_str, search_str + strlen(search_str), anarchy_mode); - - // move original missions (in story-chronological order) - // to top of mission list - top_place = 0; - promote(mission_list, "", &top_place); // original descent 1 mission - - if (num_missions > top_place) - qsort(&mission_list[top_place], - num_missions - top_place, - sizeof(*mission_list), - (int (*)( const void *, const void * ))ml_sort_func); - - - if (num_missions > top_place) - qsort(&mission_list[top_place], - num_missions - top_place, - sizeof(*mission_list), - (int (*)( const void *, const void * ))ml_sort_func); - - return mission_list; -} - -void free_mission_list(mle *mission_list) -{ - int i; - - for (i = 0; i < num_missions; i++) - d_free(mission_list[i].path); - - d_free(mission_list); - num_missions = 0; -} - -void init_extra_robot_movie(char *filename); - -//values for built-in mission - -//loads the specfied mission from the mission list. -//build_mission_list() must have been called. -//Returns true if mission loaded ok, else false. -int load_mission(mle *mission) -{ - PHYSFS_file *mfile; - char buf[PATH_MAX], *v; - - if (Current_mission) - free_mission(); - Current_mission = d_malloc(sizeof(Mission)); - if (!Current_mission) return 0; - *(mle *) Current_mission = *mission; - Current_mission->path = d_strdup(mission->path); - Current_mission->filename = Current_mission->path + (mission->filename - mission->path); - Current_mission->n_secret_levels = 0; - - //init vars - Last_level = 0; - Last_secret_level = 0; - memset(&Briefing_text_filename, '\0', sizeof(Briefing_text_filename)); - memset(&Ending_text_filename, '\0', sizeof(Ending_text_filename)); - Secret_level_table = NULL; - Level_names = NULL; - Secret_level_names = NULL; - - // for Descent 1 missions, load descent.hog - if (!PHYSFSX_contfile_init("descent.hog", 1)) - Error("descent.hog not available!\n"); - if (!d_stricmp(Current_mission_filename, D1_MISSION_FILENAME)) - return load_mission_d1(); - - //read mission from file - - switch (mission->location) { - case ML_MISSIONDIR: - strcpy(buf,MISSION_DIR); - break; - default: - Int3(); //fall through - case ML_CURDIR: - strcpy(buf,""); - break; - } - strcat(buf, mission->path); - strcat(buf,".msn"); - - PHYSFSEXT_locateCorrectCase(buf); - - mfile = PHYSFSX_openReadBuffered(buf); - if (mfile == NULL) { - free_mission(); - return 0; //error! - } - - //for non-builtin missions, load HOG - strcpy(buf+strlen(buf)-4,".hog"); //change extension - PHYSFSEXT_locateCorrectCase(buf); - if (PHYSFSX_exists(buf,1)) - PHYSFSX_contfile_init(buf, 0); - - snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.tex",Current_mission_filename); - if (!PHYSFSX_exists(Briefing_text_filename,1)) - snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.txb",Current_mission_filename); - snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.tex",Current_mission_filename); - if (!PHYSFSX_exists(Ending_text_filename,1)) - snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename); - - while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) { - if (istok(buf,"type")) - continue; //already have name, go to next line - else if (istok(buf,"briefing")) { - if ((v = get_value(buf)) != NULL) { - add_term(v); - if (strlen(v) < FILENAME_LEN && strlen(v) > 0) - { - char *tmp, *ptr; - MALLOC(tmp, char, FILENAME_LEN); - snprintf(tmp, FILENAME_LEN, "%s", v); - if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. - *ptr = '\0'; - strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion - if (PHYSFSX_exists(tmp,1)) // check if this file exists ... - snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... - else // ... otherwise ... - { - if ((ptr = strrchr(tmp, '.'))) - *ptr = '\0'; - strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension - if (PHYSFSX_exists(tmp,1)) // check if this file exists ... - snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... - } - d_free(tmp); - } - } - } - else if (istok(buf,"ending")) { - if ((v = get_value(buf)) != NULL) { - add_term(v); - if (strlen(v) < FILENAME_LEN && strlen(v) > 0) - { - char *tmp, *ptr; - MALLOC(tmp, char, FILENAME_LEN); - snprintf(tmp, FILENAME_LEN, "%s", v); - if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. - *ptr = '\0'; - strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion - if (PHYSFSX_exists(tmp,1)) // check if this file exists ... - snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... - else // ... otherwise ... - { - if ((ptr = strrchr(tmp, '.'))) - *ptr = '\0'; - strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension - if (PHYSFSX_exists(tmp,1)) // check if this file exists ... - snprintf(Ending_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... - } - d_free(tmp); - } - } - } - else if (istok(buf,"num_levels")) { - - if ((v=get_value(buf))!=NULL) { - int n_levels,i; - - n_levels = atoi(v); - - Assert(n_levels <= MAX_LEVELS_PER_MISSION); - n_levels = min(n_levels, MAX_LEVELS_PER_MISSION); - - MALLOC(Level_names, d_fname, n_levels); - if (!Level_names) - { - free_mission(); - return 0; - } - - for (i=0;iLast_level) - break; - Last_secret_level--; - } - else - break; - } - - } - } - - } - - PHYSFS_close(mfile); - - if (Last_level <= 0) { - free_mission(); //no valid mission loaded - return 0; - } - - return 1; -} - -//loads the named mission if exists. -//Returns true if mission loaded ok, else false. -int load_mission_by_name(const char *mission_name) -{ - int i; - mle *mission_list = build_mission_list(1); - bool found = 0; - - for (i = 0; i < num_missions; i++) - if (!d_stricmp(mission_name, mission_list[i].filename)) - found = load_mission(mission_list + i); - - free_mission_list(mission_list); - return found; -} - -typedef struct mission_menu -{ - mle *mission_list; - int (*when_selected)(void); -} mission_menu; - -int mission_menu_handler(listbox *lb, d_event *event, mission_menu *mm) -{ - char **list = listbox_get_items(lb); - int citem = listbox_get_citem(lb); - - switch (event->type) - { - case EVENT_NEWMENU_SELECTED: - if (citem >= 0) - { - // Chose a mission - strcpy(GameCfg.LastMission, list[citem]); - - if (!load_mission(mm->mission_list + citem)) - { - nm_messagebox( NULL, 1, TXT_OK, TXT_MISSION_ERROR); - return 1; // stay in listbox so user can select another one - } - } - return !(*mm->when_selected)(); - break; - - case EVENT_WINDOW_CLOSE: - free_mission_list(mm->mission_list); - d_free(list); - d_free(mm); - break; - - default: - break; - } - - return 0; -} - -int select_mission(int anarchy_mode, const char *message, int (*when_selected)(void)) -{ - mle *mission_list = build_mission_list(anarchy_mode); - int new_mission_num; - - if (num_missions <= 1) - { - new_mission_num = load_mission(mission_list) ? 0 : -1; - free_mission_list(mission_list); - (*when_selected)(); - - return (new_mission_num >= 0); - } - else - { - mission_menu *mm; - int i, default_mission; - char **m; - - MALLOC(m, char *, num_missions); - if (!m) - { - free_mission_list(mission_list); - return 0; - } - - MALLOC(mm, mission_menu, 1); - if (!mm) - { - d_free(m); - free_mission_list(mission_list); - return 0; - } - - mm->mission_list = mission_list; - mm->when_selected = when_selected; - - default_mission = 0; - for (i = 0; i < num_missions; i++) { - m[i] = mission_list[i].mission_name; - if ( !d_stricmp( m[i], GameCfg.LastMission ) ) - default_mission = i; - } - - newmenu_listbox1( message, num_missions, m, 1, default_mission, (int (*)(listbox *, d_event *, void *))mission_menu_handler, mm ); - } - - return 1; // presume success -} - -#ifdef EDITOR -void create_new_mission(void) -{ - if (Current_mission) - free_mission(); - - Current_mission = d_malloc(sizeof(Mission)); - if (!Current_mission) - return; - memset(Current_mission, 0, sizeof(Mission)); - - Current_mission->path = d_strdup("new_mission"); - if (!Current_mission->path) - { - free_mission(); - return; - } - - Current_mission->filename = Current_mission->path; - - MALLOC(Level_names, d_fname, 1); - if (!Level_names) - { - free_mission(); - return; - } - - strcpy(Level_names[0], "GAMESAVE.LVL"); -} -#endif diff --git a/d2x-rebirth/main/mission.c b/similar/main/mission.c similarity index 96% rename from d2x-rebirth/main/mission.c rename to similar/main/mission.c index fbd4ec674..3ebbfed23 100644 --- a/d2x-rebirth/main/mission.c +++ b/similar/main/mission.c @@ -49,7 +49,9 @@ typedef struct mle { char *filename; // filename without extension int builtin_hogsize; // if it's the built-in mission, used for determining the version char mission_name[MISSION_NAME_LEN+1]; +#if defined(DXX_BUILD_DESCENT_II) ubyte descent_version; // descent 1 or descent 2? +#endif ubyte anarchy_only_flag; // if true, mission is anarchy only char *path; // relative file path enum mle_loc location; // where the mission is @@ -194,7 +196,7 @@ int load_mission_d1(void) return 1; } - +#if defined(DXX_BUILD_DESCENT_II) // // Special versions of mission routines for shareware // @@ -289,7 +291,7 @@ int load_mission_oem(void) return 1; } - +#endif //compare a string for a token. returns true if match int istok(char *buf,char *tok) @@ -378,8 +380,10 @@ int read_mission_file(mle *mission, char *filename, int location) if ((ext = strchr(p, '.')) == NULL) return 0; //missing extension +#if defined(DXX_BUILD_DESCENT_II) // look if it's .mn2 or .msn mission->descent_version = (ext[3] == '2') ? 2 : 1; +#endif *ext = 0; //kill extension mission->path = d_strdup(temp); @@ -389,6 +393,7 @@ int read_mission_file(mle *mission, char *filename, int location) p = get_parm_value("name",mfile); +#if defined(DXX_BUILD_DESCENT_II) if (!p) { //try enhanced mission PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value("xname",mfile); @@ -403,6 +408,7 @@ int read_mission_file(mle *mission, char *filename, int location) PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value("!name",mfile); } +#endif if (p) { char *t; @@ -471,14 +477,18 @@ void add_d1_builtin_mission_to_list(mle *mission) break; } - mission->descent_version = 1; mission->anarchy_only_flag = 0; +#if defined(DXX_BUILD_DESCENT_I) + mission->builtin_hogsize = size; +#elif defined(DXX_BUILD_DESCENT_II) + mission->descent_version = 1; mission->builtin_hogsize = 0; +#endif mission->path = mission->filename; num_missions++; } - +#if defined(DXX_BUILD_DESCENT_II) void add_builtin_mission_to_list(mle *mission, char *name) { int size = PHYSFSX_fsize("descent2.hog"); @@ -515,6 +525,7 @@ void add_builtin_mission_to_list(mle *mission, char *name) mission->anarchy_only_flag = 0; num_missions++; } +#endif void add_missions_to_list(mle *mission_list, char *path, char *rel_path, int anarchy_mode) @@ -601,8 +612,10 @@ void free_mission(void) d_free(Secret_level_names); if(Secret_level_table) d_free(Secret_level_table); +#if defined(DXX_BUILD_DESCENT_II) if (Current_mission->alternate_ham_file) d_free(Current_mission->alternate_ham_file); +#endif d_free(Current_mission); } @@ -617,7 +630,9 @@ mle *build_mission_list(int anarchy_mode) { mle *mission_list; int top_place; +#if defined(DXX_BUILD_DESCENT_II) char builtin_mission_filename[FILENAME_LEN]; +#endif char search_str[PATH_MAX] = MISSION_DIR; //now search for levels on disk @@ -637,16 +652,22 @@ mle *build_mission_list(int anarchy_mode) MALLOC(mission_list, mle, MAX_MISSIONS); num_missions = 0; +#if defined(DXX_BUILD_DESCENT_II) add_builtin_mission_to_list(mission_list + num_missions, builtin_mission_filename); //read built-in first +#endif add_d1_builtin_mission_to_list(mission_list + num_missions); add_missions_to_list(mission_list, search_str, search_str + strlen(search_str), anarchy_mode); // move original missions (in story-chronological order) // to top of mission list top_place = 0; +#if defined(DXX_BUILD_DESCENT_I) + promote(mission_list, "", &top_place); // original descent 1 mission +#elif defined(DXX_BUILD_DESCENT_II) promote(mission_list, "descent", &top_place); // original descent 1 mission promote(mission_list, builtin_mission_filename, &top_place); // d2 or d2demo promote(mission_list, "d2x", &top_place); // vertigo +#endif if (num_missions > top_place) qsort(&mission_list[top_place], @@ -676,6 +697,7 @@ void free_mission_list(mle *mission_list) } void init_extra_robot_movie(char *filename); +#if defined(DXX_BUILD_DESCENT_II) int read_hamfile(); //values for built-in mission @@ -717,6 +739,7 @@ int load_mission_ham() } else return 0; } +#endif //loads the specfied mission from the mission list. //build_mission_list() must have been called. @@ -732,13 +755,17 @@ int load_mission(mle *mission) if (!Current_mission) return 0; Current_mission->builtin_hogsize = mission->builtin_hogsize; strcpy(Current_mission->mission_name, mission->mission_name); +#if defined(DXX_BUILD_DESCENT_II) Current_mission->descent_version = mission->descent_version; +#endif Current_mission->anarchy_only_flag = mission->anarchy_only_flag; Current_mission->path = d_strdup(mission->path); Current_mission->filename = Current_mission->path + (mission->filename - mission->path); Current_mission->n_secret_levels = 0; +#if defined(DXX_BUILD_DESCENT_II) Current_mission->enhanced = 0; Current_mission->alternate_ham_file = NULL; +#endif //init vars Last_level = 0; @@ -750,13 +777,21 @@ int load_mission(mle *mission) Secret_level_names = NULL; // for Descent 1 missions, load descent.hog - if (EMULATING_D1) { +#if defined(DXX_BUILD_DESCENT_II) + if (EMULATING_D1) +#endif + { if (!PHYSFSX_contfile_init("descent.hog", 1)) +#if defined(DXX_BUILD_DESCENT_I) + Error("descent.hog not available!\n"); +#elif defined(DXX_BUILD_DESCENT_II) Warning("descent.hog not available, this mission may be missing some files required for briefings and exit sequence\n"); +#endif if (!d_stricmp(Current_mission_filename, D1_MISSION_FILENAME)) return load_mission_d1(); } +#if defined(DXX_BUILD_DESCENT_II) if (PLAYING_BUILTIN_MISSION) { switch (Current_mission->builtin_hogsize) { case SHAREWARE_MISSION_HOGSIZE: @@ -780,6 +815,7 @@ int load_mission(mle *mission) break; } } +#endif //read mission from file @@ -794,9 +830,11 @@ int load_mission(mle *mission) break; } strcat(buf, mission->path); +#if defined(DXX_BUILD_DESCENT_II) if (mission->descent_version == 2) strcat(buf,".mn2"); else +#endif strcat(buf,".msn"); PHYSFSEXT_locateCorrectCase(buf); @@ -808,7 +846,9 @@ int load_mission(mle *mission) } //for non-builtin missions, load HOG +#if defined(DXX_BUILD_DESCENT_II) if (!PLAYING_BUILTIN_MISSION) +#endif { strcpy(buf+strlen(buf)-4,".hog"); //change extension PHYSFSEXT_locateCorrectCase(buf); @@ -824,6 +864,7 @@ int load_mission(mle *mission) } while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) { +#if defined(DXX_BUILD_DESCENT_II) if (istok(buf,"name") && !Current_mission->enhanced) { Current_mission->enhanced = 0; continue; //already have name, go to next line @@ -840,7 +881,8 @@ int load_mission(mle *mission) Current_mission->enhanced = 3; continue; //already have name, go to next line } - else if (istok(buf,"type")) +#endif + if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"briefing")) { if ((v = get_value(buf)) != NULL) { @@ -967,6 +1009,7 @@ int load_mission(mle *mission) } } +#if defined(DXX_BUILD_DESCENT_II) else if (Current_mission->enhanced == 3 && buf[0] == '!') { if (istok(buf+1,"ham")) { if (!Current_mission->alternate_ham_file) { @@ -992,6 +1035,7 @@ int load_mission(mle *mission) break; } } +#endif } @@ -1002,11 +1046,13 @@ int load_mission(mle *mission) return 0; } +#if defined(DXX_BUILD_DESCENT_II) // re-read default HAM file, in case this mission brings it's own version of it free_polygon_models(); if (load_mission_ham()) init_extra_robot_movie(Current_mission_filename); +#endif return 1; }