From d6c7b0f5ff72730f707143cc4e2bd24f2a628994 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 16 Nov 2024 00:28:30 +0100 Subject: [PATCH] added support for level stories in "docs/stories/XXX.txt" By placing a text file into "docs/stories/XXX.txt" inside the level set directory, it will be shown before starting the game. --- src/libgame/setup.c | 28 ++++++++++++++++++++++++++++ src/libgame/setup.h | 1 + src/libgame/system.h | 1 + src/screens.c | 32 +++++++++++++++++++++++++------- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/libgame/setup.c b/src/libgame/setup.c index c4be3482..f2680ef5 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -879,6 +879,15 @@ static char *getLevelInfoBasename(int level_nr) return basename; } +static char *getLevelStoryBasename(int level_nr) +{ + static char basename[32]; + + sprintf(basename, "%03d.txt", level_nr); + + return basename; +} + char *getLevelSetInfoFilename(int nr) { char *basename = getLevelSetInfoBasename(nr); @@ -951,6 +960,25 @@ char *getLevelInfoFilename(int level_nr) return NULL; } +char *getLevelStoryFilename(int level_nr) +{ + char *basename = getLevelStoryBasename(level_nr); + static char *stories_subdir = NULL; + static char *filename = NULL; + + if (stories_subdir == NULL) + stories_subdir = getPath2(DOCS_DIRECTORY, STORIES_DIRECTORY); + + checked_free(filename); + + // look for story file in the current level set's "docs/stories" sub-directory + filename = getPath3(getCurrentLevelDir(), stories_subdir, basename); + if (fileExists(filename)) + return filename; + + return NULL; +} + static char *getLevelSetTitleMessageBasename(int nr, boolean initial) { static char basename[32]; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 396eff31..bb0dd842 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -286,6 +286,7 @@ char *getHelpAnimFilename(void); char *getHelpTextFilename(void); char *getLevelSetInfoFilename(int); char *getLevelInfoFilename(int); +char *getLevelStoryFilename(int); char *getLevelSetTitleMessageFilename(int, boolean); char *getCreditsFilename(int, boolean); char *getProgramInfoFilename(int); diff --git a/src/libgame/system.h b/src/libgame/system.h index 84d401ce..277046f1 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -682,6 +682,7 @@ #define PROGRAM_INFO_DIRECTORY "program" #define LEVELSET_INFO_DIRECTORY "levelset" #define LEVEL_INFO_DIRECTORY "levels" +#define STORIES_DIRECTORY "stories" #define CACHE_DIRECTORY "cache" #define CONF_DIRECTORY "conf" #define NETWORK_DIRECTORY "network" diff --git a/src/screens.c b/src/screens.c index 43e922c4..82cb0d44 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1101,6 +1101,18 @@ static char *getLevelInfoBuffer(void) return NULL; } +static char *getLevelStoryBuffer(void) +{ + if (level.game_engine_type != GAME_ENGINE_TYPE_BD || + level.native_bd_level->cave == NULL) + return NULL; + + if (level.native_bd_level->cave->story != NULL) + return getInfoTextBuffer_BD(level.native_bd_level->cave->story); + + return NULL; +} + static boolean hasLevelSetInfo(void) { return (getLevelSetInfoFilename(0) != NULL || @@ -1113,6 +1125,12 @@ static boolean hasLevelInfo(void) getLevelInfoBuffer() != NULL); } +static boolean hasLevelStory(void) +{ + return (getLevelStoryFilename(level_nr) != NULL || + getLevelStoryBuffer() != NULL); +} + static int getTitleScreenGraphic(int nr, boolean initial) { return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr; @@ -4197,11 +4215,11 @@ static int getInfoScreenBackgroundMusic_Generic(void) static char *getInfoScreenFilename_Generic(int nr, boolean global) { - return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) : - info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) : - info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) : - info_mode == INFO_MODE_LEVEL ? getLevelInfoFilename(level_nr) : - info_mode == INFO_MODE_STORY ? getLevelInfoFilename(level_nr) : + return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) : + info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) : + info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) : + info_mode == INFO_MODE_LEVEL ? getLevelInfoFilename(level_nr) : + info_mode == INFO_MODE_STORY ? getLevelStoryFilename(level_nr) : NULL); } @@ -4209,7 +4227,7 @@ static char *getInfoScreenBuffer_Generic(void) { return (info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoBuffer() : info_mode == INFO_MODE_LEVEL ? getLevelInfoBuffer() : - info_mode == INFO_MODE_STORY ? getLevelInfoBuffer() : + info_mode == INFO_MODE_STORY ? getLevelStoryBuffer() : NULL); } @@ -4632,7 +4650,7 @@ void DrawInfoScreen_FromInitGame(int nr) boolean ShowStoryScreen_FromInitGame(void) { - if (!hasLevelInfo()) + if (!hasLevelStory()) return FALSE; if (setup.show_level_story == STATE_FALSE || -- 2.34.1