From fc1108e7b611d670e64a65481664642cfbc69836 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Sat, 12 Jan 2013 13:23:28 +0800 Subject: [PATCH] Increased the maximum number of levels and secret levels per mission to 127 each, using MALLOC'd arrays; defined 'd_fname' type (mainly for my pointers to arrays of 13 character filenames, but could be convenient elsewhere) --- CHANGELOG.txt | 3 +- main/inferno.h | 3 ++ main/mission.c | 117 +++++++++++++++++++++++++++++++++++++++++++++---- main/mission.h | 20 ++++----- 4 files changed, 124 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 93a0e2e8d..8069cce7f 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,7 +2,8 @@ D1X-Rebirth Changelog 20130112 -------- -arch/carbon/conf.h: Use new D1XMAJORi / D1XMINORi / D1XMICROi version constants for Mac +arch/carbon/conf.h: Used new D1XMAJORi / D1XMINORi / D1XMICROi version constants for Mac +main/inferno.h, main/mission.c, main/mission.h: Increased the maximum number of levels and secret levels per mission to 127 each, using MALLOC'd arrays; defined 'd_fname' type (mainly for my pointers to arrays of 13 character filenames, but could be convenient elsewhere) 20130108 -------- diff --git a/main/inferno.h b/main/inferno.h index a477cd9d9..9f7346661 100644 --- a/main/inferno.h +++ b/main/inferno.h @@ -42,6 +42,9 @@ struct d_event; // the maximum length of a filename #define FILENAME_LEN 13 +// a filename, useful for declaring arrays of filenames +typedef char d_fname[FILENAME_LEN]; + /** ** Global variables **/ diff --git a/main/mission.c b/main/mission.c index 462ed6574..d36ca1fea 100644 --- a/main/mission.c +++ b/main/mission.c @@ -37,6 +37,13 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #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 @@ -44,17 +51,36 @@ typedef struct mle { char mission_name[MISSION_NAME_LEN+1]; ubyte anarchy_only_flag; // if true, mission is anarchy only char *path; // relative file path - int location; // see defines below + enum mle_loc location; // where the mission is } mle; -//values that describe where a mission is located -#define ML_CURDIR 0 -#define ML_MISSIONDIR 1 - -int num_missions = -1; +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 // @@ -71,6 +97,12 @@ int load_mission_d1(void) Last_level = 7; Last_secret_level = 0; + + if (!allocate_levels()) + { + free_mission(); + return 0; + } //build level names for (i=0;ipath && !PLAYING_BUILTIN_MISSION) { char hogpath[PATH_MAX]; sprintf(hogpath, MISSION_DIR "%s.hog", Current_mission->path); PHYSFSX_contfile_close(hogpath); } - d_free(Current_mission->path); + + 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); } } @@ -481,6 +541,9 @@ int load_mission(mle *mission) 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)) @@ -583,6 +646,16 @@ int load_mission(mle *mission) 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;ipath = 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/main/mission.h b/main/mission.h index 22435d444..a23834b0a 100644 --- a/main/mission.h +++ b/main/mission.h @@ -1,3 +1,4 @@ +/* $Id: mission.h,v 1.1.1.1 2006/03/17 19:55:22 zicodxx Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -7,7 +8,7 @@ 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. +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ @@ -24,9 +25,9 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "inferno.h" #define MAX_MISSIONS 5000 // ZICO - changed from 300 to get more levels in list -#define MAX_LEVELS_PER_MISSION 30 -#define MAX_SECRET_LEVELS_PER_MISSION 6 -#define MISSION_NAME_LEN 21 +#define MAX_LEVELS_PER_MISSION 127 // KREATOR - increased from 30 (e.g. Total Domain has 57) +#define MAX_SECRET_LEVELS_PER_MISSION 127 // KREATOR - increased from 6 +#define MISSION_NAME_LEN 25 #define D1_MISSION_FILENAME "" #define D1_MISSION_NAME "Descent: First Strike" @@ -51,15 +52,15 @@ typedef struct { char mission_name[MISSION_NAME_LEN+1]; ubyte anarchy_only_flag; // if true, mission is only for anarchy char *path; // relative file path - char briefing_text_filename[FILENAME_LEN]; // name of briefing file - char ending_text_filename[FILENAME_LEN]; // name of ending file + d_fname briefing_text_filename; // name of briefing file + d_fname ending_text_filename; // name of ending file ubyte last_level; sbyte last_secret_level; ubyte n_secret_levels; - ubyte secret_level_table[MAX_SECRET_LEVELS_PER_MISSION]; // originating level no for each secret level + ubyte *secret_level_table; // originating level no for each secret level // arrays of names of the level files - char level_names[MAX_LEVELS_PER_MISSION][FILENAME_LEN]; - char secret_level_names[MAX_SECRET_LEVELS_PER_MISSION][FILENAME_LEN]; + d_fname *level_names; + d_fname *secret_level_names; } Mission; extern Mission *Current_mission; // current mission @@ -101,4 +102,3 @@ void create_new_mission(void); #endif #endif -