From 8055d1036238dd9059d662714db665c5665a65a1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 13 Nov 2019 00:44:33 +0100 Subject: [PATCH] - hooked up the secret hint system --- source/blood/src/eventq.cpp | 3 +- source/common/secrets.cpp | 101 ++++++++++++++++++++++++++++------- source/common/secrets.h | 9 ++-- source/duke3d/src/sector.cpp | 3 +- source/rr/src/sector.cpp | 3 +- 5 files changed, 92 insertions(+), 27 deletions(-) diff --git a/source/blood/src/eventq.cpp b/source/blood/src/eventq.cpp index dc9a21e17..d09183f8b 100644 --- a/source/blood/src/eventq.cpp +++ b/source/blood/src/eventq.cpp @@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "pqueue.h" #include "triggers.h" #include "view.h" +#include "secrets.h" BEGIN_BLD_NS @@ -380,7 +381,7 @@ void evSend(int nIndex, int nType, int rxId, COMMAND_ID command, short causedBy) else viewSetSystemMessage("Invalid Total-Secrets command by xobject #%d (object type %d)", nIndex, nType); break; case kChannelSecretFound: - Printf(PRINT_NONOTIFY, "Secret trigger %d\n", nIndex * 65536 + nType); + SECRET_Trigger(nIndex + 65536 * nType); if (command >= kCmdNumberic) levelTriggerSecret(command - kCmdNumberic); else viewSetSystemMessage("Invalid Trigger-Secret command by xobject #%d (object type %d)", nIndex, nType); break; diff --git a/source/common/secrets.cpp b/source/common/secrets.cpp index 64a244e95..bbdbb628e 100644 --- a/source/common/secrets.cpp +++ b/source/common/secrets.cpp @@ -2,7 +2,45 @@ #include "cache1d.h" #include "printf.h" #include "v_text.h" +#include "tarray.h" +#include "c_cvars.h" +#include "v_font.h" +#include "v_draw.h" +// Unlike in GZDoom we have to maintain this list here, because we got different game frontents that all store this info differently. +// So the games will have to report the credited secrets so that this code can keep track of how to display them. +static TArray discovered_secrets; +CVAR(Bool, secret_notify, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); +FString mapfile, maptitle; + +//----------------------------------------------------------------------------- +// +// Print secret info (submitted by Karl Murks) +// +//----------------------------------------------------------------------------- + +static void PrintSecretString(const char *string, bool thislevel) +{ + const char *colstr = thislevel? TEXTCOLOR_YELLOW : TEXTCOLOR_CYAN; + if (string != NULL) + { + if (*string == '$') + { + if (string[1] == 'S' || string[1] == 's') + { + auto secnum = (unsigned)strtoull(string+2, (char**)&string, 10); + if (*string == ';') string++; + colstr = discovered_secrets.Find(secnum) == discovered_secrets.Size() ? TEXTCOLOR_RED : TEXTCOLOR_GREEN; + } + } + auto brok = V_BreakLines(NewConsoleFont, screen->GetWidth()*95/100, string); + + for (auto &line : brok) + { + Printf("%s%s\n", colstr, line.Text.GetChars()); + } + } +} //============================================================================ // @@ -12,14 +50,14 @@ CCMD(secret) { - const char *mapname = argv.argc() < 2? primaryLevel->MapName.GetChars() : argv[1]; - bool thislevel = !stricmp(mapname, primaryLevel->MapName); + const char *mapname = argv.argc() < 2? mapfile.GetChars() : argv[1]; + bool thislevel = !stricmp(mapname, mapfile.GetChars()); bool foundsome = false; - int lumpno=Wads.CheckNumForName("SECRETS"); + int lumpno=fileSystem.FindFile("secrets.txt"); if (lumpno < 0) return; - auto lump = Wads.OpenLumpReader(lumpno); + auto lump = fileSystem.OpenFileReader(lumpno); FString maphdr; maphdr.Format("[%s]", mapname); @@ -37,9 +75,8 @@ CCMD(secret) if (!foundsome) { FString levelname; - level_info_t *info = FindLevelInfo(mapname); - const char *ln = !(info->flags & LEVEL_LOOKUPLEVELNAME)? info->LevelName.GetChars() : GStrings[info->LevelName.GetChars()]; - levelname.Format("%s - %s", mapname, ln); + if (thislevel) levelname.Format("%s - %s", mapname, maptitle.GetChars()); + else levelname = mapname; Printf(TEXTCOLOR_YELLOW "%s\n", levelname.GetChars()); size_t llen = levelname.Len(); levelname = ""; @@ -69,16 +106,40 @@ CCMD(secret) } } - SECRET_Save(FileWriter &fil) - { - } - - SECRET_Load(FileReader &fil) - { - - } - - SECRET_Trigger(int num) - { - } - \ No newline at end of file +void SECRET_Save(FileWriter &fil) +{ + fil.Write("SECR", 4); + unsigned count = discovered_secrets.Size(); + fil.Write(&count, 4); + fil.Write(discovered_secrets.Data(), 4 * count); + fil.Write("RCES", 4); + +} + +bool SECRET_Load(FileReader &fil) +{ + char buf[4]; + unsigned count; + fil.Read(buf, 4); + if (memcmp(buf, "SECR", 4)) return false; + fil.Read(&count, 4); + discovered_secrets.Resize(count); + fil.Read(discovered_secrets.Data(), count * 4); + fil.Read(buf, 4); + if (memcmp(buf, "RCES", 4)) return false; + return true; +} + +void SECRET_SetMapName(const char *filename, const char *_maptitle) +{ + mapfile = filename; + maptitle = _maptitle; +} + +void SECRET_Trigger(int num) +{ + if (secret_notify) Printf(PRINT_NONOTIFY, "Secret #%d found\n", num); + if (discovered_secrets.Find(num) == discovered_secrets.Size()) + discovered_secrets.Push(num); +} + diff --git a/source/common/secrets.h b/source/common/secrets.h index 59382111c..bc44ddca6 100644 --- a/source/common/secrets.h +++ b/source/common/secrets.h @@ -1,7 +1,8 @@ #pragma once #include "files.h" -SECRET_Save(FileWriter &fil); -SECRET_Load(FileReader &fil); -SECRET_Trigger(int num); - \ No newline at end of file +void SECRET_Save(FileWriter &fil); +bool SECRET_Load(FileReader &fil); +void SECRET_SetMapName(const char *filename, const char *maptitle); +void SECRET_Trigger(int num); + diff --git a/source/duke3d/src/sector.cpp b/source/duke3d/src/sector.cpp index f73f0a50f..b29a9098d 100644 --- a/source/duke3d/src/sector.cpp +++ b/source/duke3d/src/sector.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "input.h" #include "printf.h" +#include "secrets.h" BEGIN_DUKE_NS @@ -3123,7 +3124,7 @@ void P_CheckSectors(int playerNum) case 32767: pSector->lotag = 0; P_DoQuote(QUOTE_FOUND_SECRET, pPlayer); - Printf(PRINT_NONOTIFY, "Secret in sector %d\n", pPlayer->cursectnum); + SECRET_Trigger(pPlayer->cursectnum); pPlayer->secret_rooms++; return; diff --git a/source/rr/src/sector.cpp b/source/rr/src/sector.cpp index d827fbe01..b716b3142 100644 --- a/source/rr/src/sector.cpp +++ b/source/rr/src/sector.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "input.h" +#include "secrets.h" BEGIN_RR_NS @@ -4284,7 +4285,7 @@ void P_CheckSectors(int playerNum) if (RR && !RRRA) g_canSeePlayer = 0; P_DoQuote(QUOTE_FOUND_SECRET, pPlayer); - Printf(PRINT_NONOTIFY, "Secret in sector %d\n", pPlayer->cursectnum); + SECRET_Trigger(pPlayer->cursectnum); pPlayer->secret_rooms++; return;