- 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.
This commit is contained in:
Christoph Oelckers 2019-12-09 00:33:14 +01:00
parent a74797b97c
commit 9f25c9c117
16 changed files with 73 additions and 115 deletions

View file

@ -1357,7 +1357,7 @@ RESTART:
//} //}
if (gStartNewGame) if (gStartNewGame)
{ {
STAT_StartNewGame(gEpisodeInfo[gGameOptions.nEpisode].at0, gGameOptions.nDifficulty); STAT_StartNewGame(gVolumeNames[gGameOptions.nEpisode], gGameOptions.nDifficulty);
StartLevel(&gGameOptions); StartLevel(&gGameOptions);
} }
} }

View file

@ -235,8 +235,7 @@ void levelLoadDefaults(void)
break; break;
EPISODEINFO *pEpisodeInfo = &gEpisodeInfo[i]; EPISODEINFO *pEpisodeInfo = &gEpisodeInfo[i];
auto ep_str = BloodINI->GetKeyString(buffer, "Title", buffer); auto ep_str = BloodINI->GetKeyString(buffer, "Title", buffer);
strncpy(pEpisodeInfo->at0, ep_str, 31); gVolumeNames[i] = ep_str; // only keep one table for the names. Todo: Consolidate this across games.
gVolumeNames[i] = ep_str; // For the menu.
strncpy(pEpisodeInfo->at8f08, BloodINI->GetKeyString(buffer, "CutSceneA", ""), BMAX_PATH); strncpy(pEpisodeInfo->at8f08, BloodINI->GetKeyString(buffer, "CutSceneA", ""), BMAX_PATH);
pEpisodeInfo->at9028 = BloodINI->GetKeyInt(buffer, "CutWavA", -1); pEpisodeInfo->at9028 = BloodINI->GetKeyInt(buffer, "CutWavA", -1);
if (pEpisodeInfo->at9028 == 0) if (pEpisodeInfo->at9028 == 0)
@ -286,7 +285,7 @@ void levelAddUserMap(const char *pzMap)
if (pEpisodeInfo->nLevels == 0) if (pEpisodeInfo->nLevels == 0)
{ {
gEpisodeCount++; gEpisodeCount++;
sprintf(pEpisodeInfo->at0, "Episode %d", nEpisode); gVolumeNames[nEpisode].Format("Episode %d", nEpisode+1);
} }
nLevel = pEpisodeInfo->nLevels++; nLevel = pEpisodeInfo->nLevels++;
} }

View file

@ -84,7 +84,7 @@ struct LEVELINFO
struct EPISODEINFO struct EPISODEINFO
{ {
char at0[32]; //char at0[32]; removed, so that the global episode name table can be used for consistency
int nLevels; int nLevels;
unsigned int bloodbath : 1; unsigned int bloodbath : 1;
unsigned int cutALevel : 4; unsigned int cutALevel : 4;

View file

@ -38,12 +38,14 @@
#include "c_cvars.h" #include "c_cvars.h"
#include "configfile.h" #include "configfile.h"
#include "baselayer.h"
#include "c_console.h" #include "c_console.h"
#include "gamecvars.h" #include "gamecvars.h"
#include "cmdlib.h" #include "cmdlib.h"
#include "c_dispatch.h" #include "c_dispatch.h"
#include "printf.h" #include "printf.h"
#include "quotemgr.h"
struct FLatchedValue struct FLatchedValue
@ -1511,8 +1513,23 @@ CCMD (toggle)
val = var->GetGenericRep (CVAR_Bool); val = var->GetGenericRep (CVAR_Bool);
val.Bool = !val.Bool; val.Bool = !val.Bool;
var->SetGenericRep (val, CVAR_Bool); var->SetGenericRep (val, CVAR_Bool);
Printf ("\"%s\" = \"%s\"\n", var->GetName(), const char *statestr = argv.argc() <= 2? "*" : argv[2];
val.Bool ? "true" : "false"); 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);
}
}
} }
} }
} }

View file

@ -25,6 +25,7 @@
#include "statistics.h" #include "statistics.h"
#include "menu.h" #include "menu.h"
#include "gstrings.h" #include "gstrings.h"
#include "quotemgr.h"
#ifndef NETCODE_DISABLE #ifndef NETCODE_DISABLE
#include "enet.h" #include "enet.h"
#endif #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() void SetDefaultStrings()
{ {
// Hard coded texts for the episode and skill selection menus. // Blood hard codes its skill names, so we have to define them manually.
if (g_gameType & GAMEFLAG_DUKE) if (g_gameType & GAMEFLAG_BLOOD)
{ {
gVolumeNames[0] = LOCALIZED_STRING("L.A. Meltdown"); gSkillNames[0] = "$STILL KICKING";
gVolumeNames[1] = LOCALIZED_STRING("Lunar Apocalypse"); gSkillNames[1] = "$PINK ON THE INSIDE";
gVolumeNames[2] = LOCALIZED_STRING("Shrapnel City"); gSkillNames[2] = "$LIGHTLY BROILED";
gSkillNames[0] = LOCALIZED_STRING("Piece Of Cake"); gSkillNames[3] = "$WELL DONE";
gSkillNames[1] = LOCALIZED_STRING("Let's Rock"); gSkillNames[4] = "$EXTRA CRISPY";
gSkillNames[2] = LOCALIZED_STRING("Come Get Some");
gSkillNames[3] = LOCALIZED_STRING("Damn I'm Good");
} }
else if (g_gameType & GAMEFLAG_BLOOD)
{ //Set a few quotes which are used for common handling of a few status messages
gSkillNames[0] = LOCALIZED_STRING("STILL KICKING"); quoteMgr.InitializeQuote(23, "$MESSAGES: ON");
gSkillNames[1] = LOCALIZED_STRING("PINK ON THE INSIDE"); quoteMgr.InitializeQuote(24, "$MESSAGES:OFF");
gSkillNames[2] = LOCALIZED_STRING("LIGHTLY BROILED"); quoteMgr.InitializeQuote(83, "$MAPFOLLOWOFF");
gSkillNames[3] = LOCALIZED_STRING("WELL DONE"); quoteMgr.InitializeQuote(84, "$MAPFOLLOWON");
gSkillNames[4] = LOCALIZED_STRING("EXTRA CRISPY"); quoteMgr.InitializeQuote(85, "$AUTORUNOFF");
} quoteMgr.InitializeQuote(86, "$AUTORUNON");
else if (g_gameType & GAMEFLAG_SW) #if 0 // todo: print a message
{ if (gAutoRun)
gVolumeNames[0] = LOCALIZED_STRING("Enter the Wang"); viewSetMessage("Auto run ON");
gVolumeNames[1] = LOCALIZED_STRING("Code of Honor"); else
viewSetMessage("Auto run OFF");
gVolumeSubtitles[0] = LOCALIZED_STRING("Four levels (Shareware Version)"); #endif
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");
}
} }
//========================================================================== //==========================================================================
// //
// //

View file

@ -49,6 +49,7 @@
#include "z_music.h" #include "z_music.h"
#include "c_dispatch.h" #include "c_dispatch.h"
#include "gstrings.h" #include "gstrings.h"
#include "quotemgr.h"
/* Notes /* Notes
@ -60,23 +61,8 @@
CVARD(Bool, cl_crosshair, true, CVAR_ARCHIVE, "enable/disable crosshair"); 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 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") CVARD(Bool, cl_autorun, true, CVAR_ARCHIVE, "enable/disable autorun")
{
#if 0 // todo: print a message
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") CVARD(Bool, cl_runmode, true, CVAR_ARCHIVE, "enable/disable modernized run key operation")
bool G_CheckAutorun(bool button) 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; 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) CCMD (togglemessages)
{ {
if (hud_messages) if (hud_messages)
{ {
gi->PrintMessage(PRINT_MEDIUM, "%s\n", GStrings("MSGOFF")); gi->PrintMessage(PRINT_MEDIUM, "%s\n", quoteMgr.GetQuote(24));
hud_messages = false; hud_messages = false;
} }
else else
{ {
hud_messages = true; hud_messages = true;
gi->PrintMessage(PRINT_MEDIUM, "%s\n", GStrings("MSGON")); gi->PrintMessage(PRINT_MEDIUM, "%s\n", quoteMgr.GetQuote(23));
} }
} }

View file

@ -47,6 +47,7 @@
#include "baselayer.h" #include "baselayer.h"
#include "savegamehelp.h" #include "savegamehelp.h"
#include "sjson.h" #include "sjson.h"
#include "gstrings.h"
CVAR(Int, savestatistics, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Int, savestatistics, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(String, statfile, "demolitionstat.txt", 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) void STAT_StartNewGame(const char *episode, int skill)
{ {
StartEpisode = episode; StartEpisode = GStrings.localize(episode);
StartSkill = skill; StartSkill = skill;
LevelData.Clear(); LevelData.Clear();
LevelName = ""; LevelName = "";

View file

@ -114,14 +114,14 @@ private:
public: public:
static FString MakeMacro(const char *str) static FString MakeMacro(const char *str)
{ {
//return FStringf("${%s}", str); if (*str == '$') return str;
return str; return FString("$") + str;
} }
static FString MakeMacro(const char *str, size_t len) static FString MakeMacro(const char *str, size_t len)
{ {
//return FStringf("${%.*s}", len, str); if (*str == '$') return FString(str, len);
return FString(str, len); return "$" + FString(str, len);
} }
const char* localize(const char* str) const char* localize(const char* str)

View file

@ -212,18 +212,6 @@ void C_UndefineVolume(int32_t vol);
void C_UndefineSkill(int32_t skill); void C_UndefineSkill(int32_t skill);
void C_UndefineLevel(int32_t vol, int32_t lev); void C_UndefineLevel(int32_t vol, int32_t lev);
#if defined LUNATIC #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 #else
void C_ReportError(int error); void C_ReportError(int error);
void C_Compile(const char *filenam); void C_Compile(const char *filenam);

View file

@ -89,7 +89,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define QUOTE_RESERVED 115 #define QUOTE_RESERVED 115
#define QUOTE_RESERVED2 116 #define QUOTE_RESERVED2 116
#define QUOTE_RESERVED3 117 #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_WEAPONS NOBETAQUOTE(119)
#define QUOTE_CHEAT_ALL_INV NOBETAQUOTE(120) #define QUOTE_CHEAT_ALL_INV NOBETAQUOTE(120)
#define QUOTE_CHEAT_ALL_KEYS NOBETAQUOTE(121) #define QUOTE_CHEAT_ALL_KEYS NOBETAQUOTE(121)

View file

@ -962,7 +962,7 @@ void G_DisplayRest(int32_t smoothratio)
if (G_HaveUserMap()) if (G_HaveUserMap())
levelname = boardfilename; levelname = boardfilename;
else if (!(G_GetLogoFlags() & LOGO_HIDEEPISODE)) 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); minitext(5, a+6+6, levelname, 0, 2+8+16+256);
} }
} }

View file

@ -993,7 +993,7 @@ void G_DisplayRest(int32_t smoothratio)
else else
{ {
if (!G_HaveUserMap()) 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); minitext(5, a+6+6, g_mapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name, 0, 2+8+16+256);
} }
} }

View file

@ -926,9 +926,13 @@ void InitGame()
LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file
LoadPLockFromScript("swplock.txt"); // Get Parental Lock setup info 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) 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"); if (!loaddefinitionsfile(G_DefFile())) buildputs("Definitions file loaded.\n");
userConfig.AddDefs.reset(); userConfig.AddDefs.reset();
@ -1044,28 +1048,6 @@ int ThemeTrack[6] =
2,3,13,13,13,14 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) void InitNewGame(void)
{ {
int i, ready_bak; int i, ready_bak;

View file

@ -960,11 +960,6 @@ extern const char *ThemeSongs[6]; //
#define MAX_EPISODE_NAME_LEN 24 #define MAX_EPISODE_NAME_LEN 24
extern char EpisodeNames[3][MAX_EPISODE_NAME_LEN+2]; 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 #define MAX_FORTUNES 16
extern const char *ReadFortune[MAX_FORTUNES]; extern const char *ReadFortune[MAX_FORTUNES];

View file

@ -39,6 +39,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "jsector.h" #include "jsector.h"
#include "parent.h" #include "parent.h"
#include "scriptfile.h" #include "scriptfile.h"
#include "menu/menu.h"
BEGIN_SW_NS BEGIN_SW_NS
@ -723,18 +724,14 @@ void LoadCustomInfoFromScript(const char *filename)
{ {
char *t; char *t;
if (scriptfile_getstring(script, &t)) break; if (scriptfile_getstring(script, &t)) break;
gVolumeNames[curmap] = t;
strncpy(&EpisodeNames[curmap][1], t, MAX_EPISODE_NAME_LEN);
EpisodeNames[curmap][MAX_EPISODE_NAME_LEN+1] = 0;
break; break;
} }
case CM_SUBTITLE: case CM_SUBTITLE:
{ {
char *t; char *t;
if (scriptfile_getstring(script, &t)) break; if (scriptfile_getstring(script, &t)) break;
gVolumeSubtitles[curmap] = t;
strncpy(EpisodeSubtitles[curmap], t, MAX_EPISODE_SUBTITLE_LEN);
EpisodeSubtitles[curmap][MAX_EPISODE_SUBTITLE_LEN] = 0;
break; break;
} }
default: default:
@ -775,8 +772,7 @@ void LoadCustomInfoFromScript(const char *filename)
char *t; char *t;
if (scriptfile_getstring(script, &t)) break; if (scriptfile_getstring(script, &t)) break;
strncpy(&SkillNames[curmap][1], t, MAX_SKILL_NAME_LEN); gSkillNames[curmap] = t;
SkillNames[curmap][MAX_SKILL_NAME_LEN+1] = 0;
break; break;
} }
default: default:

View file

@ -35,7 +35,7 @@ LAlt "+Strafe"
RAlt "+Strafe" RAlt "+Strafe"
LShift "+Run" LShift "+Run"
RShift "+Run" RShift "+Run"
Capslock "+AutoRun" Capslock "toggle autorun 85"
PgUp "+Look_Up" PgUp "+Look_Up"
PgDn "+Look_Down" PgDn "+Look_Down"
Home "+Aim_Up" Home "+Aim_Up"