From 9f25c9c1178607e2d935c5e6a0be94622af05c08 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 9 Dec 2019 00:33:14 +0100 Subject: [PATCH] - some string rework * removed temporary placeholder content from string init function. All this gets properly read from definition files now. * preinitialize a few quotes that are used for status display purposes and are needed in all games * only use the global episode name table in Blood to avoid redundancy * let SW's swcustom parser write to the global tables instead of local ones. --- source/blood/src/blood.cpp | 2 +- source/blood/src/levels.cpp | 5 +-- source/blood/src/levels.h | 2 +- source/common/console/c_cvars.cpp | 21 ++++++++- source/common/gamecontrol.cpp | 56 +++++++++++------------- source/common/gamecvars.cpp | 24 +++------- source/common/statistics.cpp | 3 +- source/common/utility/stringtable.h | 8 ++-- source/duke3d/src/gamedef.h | 12 ----- source/duke3d/src/quotes.h | 2 +- source/duke3d/src/screens.cpp | 2 +- source/rr/src/screens.cpp | 2 +- source/sw/src/game.cpp | 30 +++---------- source/sw/src/game.h | 5 --- source/sw/src/scrip2.cpp | 12 ++--- wadsrc/static/demolition/commonbinds.txt | 2 +- 16 files changed, 73 insertions(+), 115 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 3ae6eb9a5..019e48fc6 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -1357,7 +1357,7 @@ RESTART: //} if (gStartNewGame) { - STAT_StartNewGame(gEpisodeInfo[gGameOptions.nEpisode].at0, gGameOptions.nDifficulty); + STAT_StartNewGame(gVolumeNames[gGameOptions.nEpisode], gGameOptions.nDifficulty); StartLevel(&gGameOptions); } } diff --git a/source/blood/src/levels.cpp b/source/blood/src/levels.cpp index 0ca5672f6..7cc35c58f 100644 --- a/source/blood/src/levels.cpp +++ b/source/blood/src/levels.cpp @@ -235,8 +235,7 @@ void levelLoadDefaults(void) break; EPISODEINFO *pEpisodeInfo = &gEpisodeInfo[i]; auto ep_str = BloodINI->GetKeyString(buffer, "Title", buffer); - strncpy(pEpisodeInfo->at0, ep_str, 31); - gVolumeNames[i] = ep_str; // For the menu. + gVolumeNames[i] = ep_str; // only keep one table for the names. Todo: Consolidate this across games. strncpy(pEpisodeInfo->at8f08, BloodINI->GetKeyString(buffer, "CutSceneA", ""), BMAX_PATH); pEpisodeInfo->at9028 = BloodINI->GetKeyInt(buffer, "CutWavA", -1); if (pEpisodeInfo->at9028 == 0) @@ -286,7 +285,7 @@ void levelAddUserMap(const char *pzMap) if (pEpisodeInfo->nLevels == 0) { gEpisodeCount++; - sprintf(pEpisodeInfo->at0, "Episode %d", nEpisode); + gVolumeNames[nEpisode].Format("Episode %d", nEpisode+1); } nLevel = pEpisodeInfo->nLevels++; } diff --git a/source/blood/src/levels.h b/source/blood/src/levels.h index eb4223f9b..e0b5bb9d7 100644 --- a/source/blood/src/levels.h +++ b/source/blood/src/levels.h @@ -84,7 +84,7 @@ struct LEVELINFO struct EPISODEINFO { - char at0[32]; + //char at0[32]; removed, so that the global episode name table can be used for consistency int nLevels; unsigned int bloodbath : 1; unsigned int cutALevel : 4; diff --git a/source/common/console/c_cvars.cpp b/source/common/console/c_cvars.cpp index 89d3aeee0..195bfe51a 100644 --- a/source/common/console/c_cvars.cpp +++ b/source/common/console/c_cvars.cpp @@ -38,12 +38,14 @@ #include "c_cvars.h" #include "configfile.h" +#include "baselayer.h" #include "c_console.h" #include "gamecvars.h" #include "cmdlib.h" #include "c_dispatch.h" #include "printf.h" +#include "quotemgr.h" struct FLatchedValue @@ -1511,8 +1513,23 @@ CCMD (toggle) val = var->GetGenericRep (CVAR_Bool); val.Bool = !val.Bool; var->SetGenericRep (val, CVAR_Bool); - Printf ("\"%s\" = \"%s\"\n", var->GetName(), - val.Bool ? "true" : "false"); + const char *statestr = argv.argc() <= 2? "*" : argv[2]; + if (*statestr == '*') + { + gi->PrintMessage(PRINT_MEDIUM, "\"%s\" = \"%s\"\n", var->GetName(), val.Bool ? "true" : "false"); + } + else + { + int state = (int)strtoll(argv[2], nullptr, 0); + if (state != 0) + { + // Order of Duke's quote string varies, some have on first, some off, so use the sign of the parameter to decide. + // Positive means Off/On, negative means On/Off + int quote = state > 0? state + val.Bool : -(state + val.Bool); + auto text = quoteMgr.GetQuote(quote); + if (text) gi->PrintMessage(PRINT_MEDIUM, "%s\n", text); + } + } } } } diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index b086ab39a..8258acb2a 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -25,6 +25,7 @@ #include "statistics.h" #include "menu.h" #include "gstrings.h" +#include "quotemgr.h" #ifndef NETCODE_DISABLE #include "enet.h" #endif @@ -263,47 +264,40 @@ int GameMain() //========================================================================== // -// Try to keep all initializations of global string variables in this one place +// // //========================================================================== -#define LOCALIZED_STRING(s) s // change to "${" s "}" later, once all text output functions can replace text macros +#define LOCALIZED_STRING(s) "$" s void SetDefaultStrings() { - // Hard coded texts for the episode and skill selection menus. - if (g_gameType & GAMEFLAG_DUKE) + // Blood hard codes its skill names, so we have to define them manually. + if (g_gameType & GAMEFLAG_BLOOD) { - gVolumeNames[0] = LOCALIZED_STRING("L.A. Meltdown"); - gVolumeNames[1] = LOCALIZED_STRING("Lunar Apocalypse"); - gVolumeNames[2] = LOCALIZED_STRING("Shrapnel City"); - gSkillNames[0] = LOCALIZED_STRING("Piece Of Cake"); - gSkillNames[1] = LOCALIZED_STRING("Let's Rock"); - gSkillNames[2] = LOCALIZED_STRING("Come Get Some"); - gSkillNames[3] = LOCALIZED_STRING("Damn I'm Good"); + gSkillNames[0] = "$STILL KICKING"; + gSkillNames[1] = "$PINK ON THE INSIDE"; + gSkillNames[2] = "$LIGHTLY BROILED"; + gSkillNames[3] = "$WELL DONE"; + gSkillNames[4] = "$EXTRA CRISPY"; } - else if (g_gameType & GAMEFLAG_BLOOD) - { - gSkillNames[0] = LOCALIZED_STRING("STILL KICKING"); - gSkillNames[1] = LOCALIZED_STRING("PINK ON THE INSIDE"); - gSkillNames[2] = LOCALIZED_STRING("LIGHTLY BROILED"); - gSkillNames[3] = LOCALIZED_STRING("WELL DONE"); - gSkillNames[4] = LOCALIZED_STRING("EXTRA CRISPY"); - } - else if (g_gameType & GAMEFLAG_SW) - { - gVolumeNames[0] = LOCALIZED_STRING("Enter the Wang"); - gVolumeNames[1] = LOCALIZED_STRING("Code of Honor"); + + //Set a few quotes which are used for common handling of a few status messages + quoteMgr.InitializeQuote(23, "$MESSAGES: ON"); + quoteMgr.InitializeQuote(24, "$MESSAGES:OFF"); + quoteMgr.InitializeQuote(83, "$MAPFOLLOWOFF"); + quoteMgr.InitializeQuote(84, "$MAPFOLLOWON"); + quoteMgr.InitializeQuote(85, "$AUTORUNOFF"); + quoteMgr.InitializeQuote(86, "$AUTORUNON"); + #if 0 // todo: print a message + if (gAutoRun) + viewSetMessage("Auto run ON"); + else + viewSetMessage("Auto run OFF"); - gVolumeSubtitles[0] = LOCALIZED_STRING("Four levels (Shareware Version)"); - gVolumeSubtitles[1] = LOCALIZED_STRING("Eighteen levels (Full Version Only)"); - - gSkillNames[0] = LOCALIZED_STRING("Tiny grasshopper"); - gSkillNames[1] = LOCALIZED_STRING("I Have No Fear"); - gSkillNames[2] = LOCALIZED_STRING("Who Wants Wang"); - gSkillNames[3] = LOCALIZED_STRING("No Pain, No Gain"); - } + #endif } + //========================================================================== // // diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index c82ce8cca..5a4674b13 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -49,6 +49,7 @@ #include "z_music.h" #include "c_dispatch.h" #include "gstrings.h" +#include "quotemgr.h" /* Notes @@ -60,23 +61,8 @@ CVARD(Bool, cl_crosshair, true, CVAR_ARCHIVE, "enable/disable crosshair"); CVARD(Bool, cl_automsg, false, CVAR_ARCHIVE, "enable/disable automatically sending messages to all players") // Not implemented for Blood -CUSTOM_CVARD(Bool, cl_autorun, true, CVAR_ARCHIVE, "enable/disable autorun") -{ -#if 0 // todo: print a message +CVARD(Bool, cl_autorun, true, CVAR_ARCHIVE, "enable/disable autorun") - if (gAutoRun) - viewSetMessage("Auto run ON"); - else - viewSetMessage("Auto run OFF"); - - - RUN MODE OFF - RUN MODE ON - cl_autorun= 1-cl_autorun; - P_DoQuote(QUOTE_RUN_MODE_OFF + cl_autorun, &myplayer); - } -#endif -} CVARD(Bool, cl_runmode, true, CVAR_ARCHIVE, "enable/disable modernized run key operation") bool G_CheckAutorun(bool button) @@ -259,18 +245,18 @@ CUSTOM_CVARD(Int, hud_messages, 1, CVAR_ARCHIVE, "enable/disable showing message if (self < 0 || self > 2) self = 1; } - +// This cannot be done with the 'toggle' CCMD because it needs to control itself when to output the message CCMD (togglemessages) { if (hud_messages) { - gi->PrintMessage(PRINT_MEDIUM, "%s\n", GStrings("MSGOFF")); + gi->PrintMessage(PRINT_MEDIUM, "%s\n", quoteMgr.GetQuote(24)); hud_messages = false; } else { hud_messages = true; - gi->PrintMessage(PRINT_MEDIUM, "%s\n", GStrings("MSGON")); + gi->PrintMessage(PRINT_MEDIUM, "%s\n", quoteMgr.GetQuote(23)); } } diff --git a/source/common/statistics.cpp b/source/common/statistics.cpp index 58ebf0e1c..cbe336141 100644 --- a/source/common/statistics.cpp +++ b/source/common/statistics.cpp @@ -47,6 +47,7 @@ #include "baselayer.h" #include "savegamehelp.h" #include "sjson.h" +#include "gstrings.h" CVAR(Int, savestatistics, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(String, statfile, "demolitionstat.txt", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -354,7 +355,7 @@ static void LevelStatEntry(FSessionStatistics *es, const char *level, const char void STAT_StartNewGame(const char *episode, int skill) { - StartEpisode = episode; + StartEpisode = GStrings.localize(episode); StartSkill = skill; LevelData.Clear(); LevelName = ""; diff --git a/source/common/utility/stringtable.h b/source/common/utility/stringtable.h index f18c5315a..5849d2b2c 100644 --- a/source/common/utility/stringtable.h +++ b/source/common/utility/stringtable.h @@ -114,14 +114,14 @@ private: public: static FString MakeMacro(const char *str) { - //return FStringf("${%s}", str); - return str; + if (*str == '$') return str; + return FString("$") + str; } static FString MakeMacro(const char *str, size_t len) { - //return FStringf("${%.*s}", len, str); - return FString(str, len); + if (*str == '$') return FString(str, len); + return "$" + FString(str, len); } const char* localize(const char* str) diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index a9aa67294..f46bc8df0 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -212,18 +212,6 @@ void C_UndefineVolume(int32_t vol); void C_UndefineSkill(int32_t skill); void C_UndefineLevel(int32_t vol, int32_t lev); #if defined LUNATIC -void C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5]); -void C_DefineQuote(int32_t qnum, const char *qstr); -void C_DefineVolumeName(int32_t vol, const char *name); -void C_DefineSkillName(int32_t skill, const char *name); -void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn, - int32_t partime, int32_t designertime, - const char *levelname); -void C_DefineGameFuncName(int32_t idx, const char *name); -void C_DefineGameType(int32_t idx, int32_t flags, const char *name); -int32_t C_SetDefName(const char *name); -void C_DefineProjectile(int32_t j, int32_t what, int32_t val); -void C_SetCfgName(const char *cfgname); #else void C_ReportError(int error); void C_Compile(const char *filenam); diff --git a/source/duke3d/src/quotes.h b/source/duke3d/src/quotes.h index ae5078a16..50b9dc1c2 100644 --- a/source/duke3d/src/quotes.h +++ b/source/duke3d/src/quotes.h @@ -89,7 +89,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define QUOTE_RESERVED 115 #define QUOTE_RESERVED2 116 #define QUOTE_RESERVED3 117 -#define QUOTE_SAVE_DEAD NOBETAQUOTE(118) +#define QUOTE_SAVE_DEAD 118 #define QUOTE_CHEAT_ALL_WEAPONS NOBETAQUOTE(119) #define QUOTE_CHEAT_ALL_INV NOBETAQUOTE(120) #define QUOTE_CHEAT_ALL_KEYS NOBETAQUOTE(121) diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index ea8f64505..df1cd1f4a 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -962,7 +962,7 @@ void G_DisplayRest(int32_t smoothratio) if (G_HaveUserMap()) levelname = boardfilename; else if (!(G_GetLogoFlags() & LOGO_HIDEEPISODE)) - minitext(5, a+6, gVolumeNames[ud.volume_number], 0, 2+8+16+256); + minitext(5, a+6, GStrings.localize(gVolumeNames[ud.volume_number]), 0, 2+8+16+256); minitext(5, a+6+6, levelname, 0, 2+8+16+256); } } diff --git a/source/rr/src/screens.cpp b/source/rr/src/screens.cpp index 557beea8b..769b26a2a 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -993,7 +993,7 @@ void G_DisplayRest(int32_t smoothratio) else { if (!G_HaveUserMap()) - minitext(5, a+6, gVolumeNames[ud.volume_number], 0, 2+8+16+256); + minitext(5, a+6, GStrings.localize(gVolumeNames[ud.volume_number]), 0, 2+8+16+256); minitext(5, a+6+6, g_mapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name, 0, 2+8+16+256); } } diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index a82731778..5214778ee 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -926,9 +926,13 @@ void InitGame() LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file LoadPLockFromScript("swplock.txt"); // Get Parental Lock setup info + + LoadCustomInfoFromScript("demolition/swcustom.txt"); // load the internal definitions. These also apply to the shareware version. if (!SW_SHAREWARE) - LoadCustomInfoFromScript("swcustom.txt"); // Load user customisation information - + { + LoadCustomInfoFromScript("swcustom.txt"); // Load user customisation information + } + if (!loaddefinitionsfile(G_DefFile())) buildputs("Definitions file loaded.\n"); userConfig.AddDefs.reset(); @@ -1044,28 +1048,6 @@ int ThemeTrack[6] = 2,3,13,13,13,14 }; -char EpisodeNames[3][MAX_EPISODE_NAME_LEN+2] = -{ - "^Enter the Wang", - "^Code of Honor", - "^User Maps", -}; - -char EpisodeSubtitles[3][MAX_EPISODE_SUBTITLE_LEN+1] = -{ - "Four levels (Shareware Version)", - "Eighteen levels (Full Version Only)", - "Select a user map to play", -}; - -char SkillNames[4][MAX_SKILL_NAME_LEN+2] = -{ - "^Tiny grasshopper", - "^I Have No Fear", - "^Who Wants Wang", - "^No Pain, No Gain" -}; - void InitNewGame(void) { int i, ready_bak; diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 21ec3146e..80bb812b7 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -960,11 +960,6 @@ extern const char *ThemeSongs[6]; // #define MAX_EPISODE_NAME_LEN 24 extern char EpisodeNames[3][MAX_EPISODE_NAME_LEN+2]; -#define MAX_EPISODE_SUBTITLE_LEN 40 -extern char EpisodeSubtitles[3][MAX_EPISODE_SUBTITLE_LEN+1]; - -#define MAX_SKILL_NAME_LEN 24 -extern char SkillNames[4][MAX_SKILL_NAME_LEN+2]; #define MAX_FORTUNES 16 extern const char *ReadFortune[MAX_FORTUNES]; diff --git a/source/sw/src/scrip2.cpp b/source/sw/src/scrip2.cpp index ba19d1e30..f9598e064 100644 --- a/source/sw/src/scrip2.cpp +++ b/source/sw/src/scrip2.cpp @@ -39,6 +39,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "jsector.h" #include "parent.h" #include "scriptfile.h" +#include "menu/menu.h" BEGIN_SW_NS @@ -723,18 +724,14 @@ void LoadCustomInfoFromScript(const char *filename) { char *t; if (scriptfile_getstring(script, &t)) break; - - strncpy(&EpisodeNames[curmap][1], t, MAX_EPISODE_NAME_LEN); - EpisodeNames[curmap][MAX_EPISODE_NAME_LEN+1] = 0; + gVolumeNames[curmap] = t; break; } case CM_SUBTITLE: { char *t; if (scriptfile_getstring(script, &t)) break; - - strncpy(EpisodeSubtitles[curmap], t, MAX_EPISODE_SUBTITLE_LEN); - EpisodeSubtitles[curmap][MAX_EPISODE_SUBTITLE_LEN] = 0; + gVolumeSubtitles[curmap] = t; break; } default: @@ -775,8 +772,7 @@ void LoadCustomInfoFromScript(const char *filename) char *t; if (scriptfile_getstring(script, &t)) break; - strncpy(&SkillNames[curmap][1], t, MAX_SKILL_NAME_LEN); - SkillNames[curmap][MAX_SKILL_NAME_LEN+1] = 0; + gSkillNames[curmap] = t; break; } default: diff --git a/wadsrc/static/demolition/commonbinds.txt b/wadsrc/static/demolition/commonbinds.txt index 23cdfddc2..9c45bf0a3 100644 --- a/wadsrc/static/demolition/commonbinds.txt +++ b/wadsrc/static/demolition/commonbinds.txt @@ -35,7 +35,7 @@ LAlt "+Strafe" RAlt "+Strafe" LShift "+Run" RShift "+Run" -Capslock "+AutoRun" +Capslock "toggle autorun 85" PgUp "+Look_Up" PgDn "+Look_Down" Home "+Aim_Up"