- hooked up the secret hint system

This commit is contained in:
Christoph Oelckers 2019-11-13 00:44:33 +01:00
parent 35bc7f56fc
commit 8055d10362
5 changed files with 92 additions and 27 deletions

View file

@ -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;

View file

@ -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<int> 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)
{
}
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);
SECRET_Load(FileReader &fil)
{
}
}
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;
}
SECRET_Trigger(int num)
{
}
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);
}

View file

@ -1,7 +1,8 @@
#pragma once
#include "files.h"
SECRET_Save(FileWriter &fil);
SECRET_Load(FileReader &fil);
SECRET_Trigger(int num);
void SECRET_Save(FileWriter &fil);
bool SECRET_Load(FileReader &fil);
void SECRET_SetMapName(const char *filename, const char *maptitle);
void SECRET_Trigger(int num);

View file

@ -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;

View file

@ -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;