Overhauled detection of TEX/TXB files for Briefings and Endings

This commit is contained in:
zicodxx 2010-08-24 14:02:38 +00:00
parent c1c60ab68b
commit 9eb82f312b
4 changed files with 63 additions and 47 deletions

View file

@ -1,5 +1,9 @@
D1X-Rebirth Changelog
20100824
--------
main/mission.c, main/mission.h, main/titles.c: Overhauled detection of TEX/TXB files for Briefings and Endings
20100822
--------
main/net_ipx.c, main/net_udp.c: Moved levelnum-sanity-check in game_param_handler so it will be checked when screen is changed to allow entry of secret levels; added menu item START GAME for consistency and added proper subtitle for game setup page

View file

@ -519,37 +519,64 @@ int load_mission(mle *mission)
if (cfexist(buf))
cfile_init(buf, 0);
snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.tex",Current_mission_filename);
if (!cfexist(Briefing_text_filename))
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 (!cfexist(Ending_text_filename))
snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename);
while (cfgets(buf,80,mfile)) {
if (istok(buf,"type"))
continue; //already have name, go to next line
else if (istok(buf,"hog")) {
char *bufp = buf;
while (*(bufp++) != '=')
;
if (*bufp == ' ')
while (*(++bufp) == ' ')
;
cfile_init(bufp, 0);
}
else if (istok(buf,"briefing")) {
if ((v = get_value(buf)) != NULL) {
add_term(v);
if (strlen(v) < 13 && strlen(v) > 0)
if (strrchr(v, '.'))
if (!stricmp(strrchr(v, '.'), ".tex") || !stricmp(strrchr(v, '.'), ".txb"))
strcpy(Briefing_text_filename,v);
if (strlen(v) < FILENAME_LEN && strlen(v) > 0)
{
char *tmp, *ptr;
MALLOC(tmp, char, FILENAME_LEN);
snprintf(tmp, FILENAME_LEN, 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 (cfexist(tmp)) // check if this file exists ...
snprintf(Briefing_text_filename, FILENAME_LEN, tmp); // ... and apply ...
else // ... otherwise ...
{
if ((ptr = strrchr(tmp, '.')))
*ptr = '\0';
strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension
if (cfexist(tmp)) // check if this file exists ...
snprintf(Briefing_text_filename, FILENAME_LEN, tmp); // ... and apply ...
}
d_free(tmp);
}
}
}
else if (istok(buf,"ending")) {
if ((v = get_value(buf)) != NULL) {
add_term(v);
if (strlen(v) < 13 && strlen(v) > 0)
if (strrchr(v, '.'))
if (!stricmp(strrchr(v, '.'), ".tex") || !stricmp(strrchr(v, '.'), ".txb"))
strcpy(Ending_text_filename,v);
if (strlen(v) < FILENAME_LEN && strlen(v) > 0)
{
char *tmp, *ptr;
MALLOC(tmp, char, FILENAME_LEN);
snprintf(tmp, FILENAME_LEN, 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 (cfexist(tmp)) // check if this file exists ...
snprintf(Briefing_text_filename, FILENAME_LEN, tmp); // ... and apply ...
else // ... otherwise ...
{
if ((ptr = strrchr(tmp, '.')))
*ptr = '\0';
strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension
if (cfexist(tmp)) // check if this file exists ...
snprintf(Ending_text_filename, FILENAME_LEN, tmp); // ... and apply ...
}
d_free(tmp);
}
}
}
else if (istok(buf,"num_levels")) {

View file

@ -80,10 +80,10 @@ extern Mission *Current_mission; // current mission
#define BIMD1_LAST_LEVEL 27
#define BIMD1_LAST_SECRET_LEVEL -3
#define BIMD1_BRIEFING_FILE "briefing.tex"
#define BIMD1_ENDING_FILE "endreg.tex"
#define BIMD1_ENDING_FILE_OEM "endsat.tex"
#define BIMD1_ENDING_FILE_SHARE "ending.tex"
#define BIMD1_BRIEFING_FILE "briefing.txb"
#define BIMD1_ENDING_FILE "endreg.txb"
#define BIMD1_ENDING_FILE_OEM "endsat.txb"
#define BIMD1_ENDING_FILE_SHARE "ending.txb"
//loads the named mission if it exists.
//Returns true if mission loaded ok, else false.

View file

@ -402,34 +402,19 @@ void briefing_init(briefing *br, short level_num)
int load_screen_text(char *filename, char **buf)
{
CFILE *tfile;
CFILE *ifile;
int len;
int have_binary = 0;
if ((tfile = cfopen(filename,"rb")) == NULL) {
char nfilename[30], *ptr;
strcpy(nfilename, filename);
if ((ptr = strrchr(nfilename, '.')))
*ptr = '\0';
strcat(nfilename, ".txb");
if ((ifile = cfopen(nfilename, "rb")) == NULL) {
return (0);
//Error("Cannot open file %s or %s", filename, nfilename);
}
if (!stricmp(strrchr(filename, '.'), ".txb"))
have_binary = 1;
if ((tfile = cfopen(filename, "rb")) == NULL)
return (0);
len = cfilelength(ifile);
MALLOC(*buf, char, len+1);
cfread(*buf, 1, len, ifile);
cfclose(ifile);
} else {
len = cfilelength(tfile);
MALLOC(*buf, char, len+1);
cfread(*buf, 1, len, tfile);
cfclose(tfile);
}
len = cfilelength(tfile);
MALLOC(*buf, char, len+1);
cfread(*buf, 1, len, tfile);
cfclose(tfile);
if (have_binary)
decode_text(*buf, len);