diff --git a/include/nleobs.h b/include/nleobs.h index c70cd58f6..df84ca2fd 100644 --- a/include/nleobs.h +++ b/include/nleobs.h @@ -94,6 +94,10 @@ typedef struct nle_settings { * https://nethackwiki.com/wiki/Monster_creation#Random_generation */ int spawn_monsters; + /* + * Filename for nle's ttyrec*.bz2. + */ + char ttyrecname[4096]; } nle_settings; #endif /* NLEOBS_H */ diff --git a/src/nle.c b/src/nle.c index d58ec2358..e0d16f498 100644 --- a/src/nle.c +++ b/src/nle.c @@ -352,6 +352,12 @@ nle_done(int how) nle->observation->how_done = how; } +char * +nle_ttyrecname() +{ + return settings.ttyrecname; +} + int nle_spawn_monsters() { diff --git a/src/topten.c b/src/topten.c index 7515c35e3..8ed5d2f54 100644 --- a/src/topten.c +++ b/src/topten.c @@ -38,6 +38,9 @@ static long final_fpos; #define DTHSZ 100 #define ROLESZ 3 +#define NLE_XLOG_INCLUDE_FILE +extern char * FDECL(nle_ttyrecname, ()); + struct toptenentry { struct toptenentry *tt_next; #ifdef UPDATE_RECORD_IN_PLACE @@ -376,6 +379,10 @@ int how; genders[flags.initgend].filecode, XLOG_SEP, aligns[1 - u.ualignbase[A_ORIGINAL]].filecode); Fprintf(rfile, "%cflags=0x%lx", XLOG_SEP, encodexlogflags()); +#ifdef NLE_XLOG_INCLUDE_FILE + if (nle_ttyrecname()[0] != '\0') + Fprintf(rfile, "%cttyrecname=%s", XLOG_SEP, nle_ttyrecname()); +#endif Fprintf(rfile, "\n"); #undef XLOG_SEP } diff --git a/win/rl/pynethack.cc b/win/rl/pynethack.cc index 7de24aa93..8d045683e 100644 --- a/win/rl/pynethack.cc +++ b/win/rl/pynethack.cc @@ -122,6 +122,10 @@ class Nethack } strncpy(settings_.scoreprefix, scoreprefix.c_str(), scoreprefix.length()); + std::size_t found = ttyrec.rfind("/"); + if (found != std::string::npos && found + 1 < ttyrec.length()) + strncpy(settings_.ttyrecname, &ttyrec.c_str()[found + 1], + ttyrec.length() - found - 1); } Nethack(std::string dlpath, std::string hackdir, @@ -181,6 +185,12 @@ class Nethack PyErr_SetFromErrnoWithFilename(PyExc_OSError, ttyrec.c_str()); throw py::error_already_set(); } + + std::size_t found = ttyrec.rfind("/"); + if (found != std::string::npos && (found + 1) < ttyrec.length()) + strncpy(settings_.ttyrecname, &ttyrec.c_str()[found + 1], + ttyrec.length() - found - 1); + // Reset environment, then close original FILE. Cannot use freopen // as the game may still need to write to the original file but // reset() wants to get the new one already. @@ -331,6 +341,9 @@ class Nethack { py::gil_scoped_release gil; + if (!ttyrec) + strncpy(settings_.ttyrecname, "", sizeof(settings_.ttyrecname)); + if (!nle_) { nle_ = nle_start(dlpath_.c_str(), &obs_, ttyrec ? ttyrec : ttyrec_,