Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Add (example) script to generate a patched nhdat.
Browse files Browse the repository at this point in the history
This creates a copy of the oracle level on dungeon level 1.
  • Loading branch information
Heinrich Kuttler committed Sep 23, 2020
1 parent 68d3997 commit 280bc03
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
11 changes: 7 additions & 4 deletions nle/nethack/nethack.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@ def __init__(
options=None,
copy=False,
wizard=False,
hackdir=HACKDIR,
):
self._copy = copy

if not os.path.exists(HACKDIR) or not os.path.exists(
os.path.join(HACKDIR, "sysconf")
if not os.path.exists(hackdir) or not os.path.exists(
os.path.join(hackdir, "sysconf")
):
raise FileNotFoundError("Couldn't find NetHack installation.")
raise FileNotFoundError(
"Couldn't find NetHack installation at '%s'." % hackdir
)

# Create a HACKDIR for us.
self._vardir = tempfile.mkdtemp(prefix="nle")

# Symlink a few files.
for fn in ["nhdat", "sysconf"]:
os.symlink(os.path.join(HACKDIR, fn), os.path.join(self._vardir, fn))
os.symlink(os.path.join(hackdir, fn), os.path.join(self._vardir, fn))
# Touch a few files.
for fn in ["perm", "logfile", "xlogfile"]:
os.close(os.open(os.path.join(self._vardir, fn), os.O_CREAT))
Expand Down
55 changes: 55 additions & 0 deletions nle/scripts/patch_nhdat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
set -euo pipefail

ORIGDIR=$(pwd)

HACKDIR=$(python -c 'import pkg_resources; print(pkg_resources.resource_filename("nle", "nethackdir"), end="")')

TMPDIR=$(mktemp -d)

echo $TMPDIR

mkdir $TMPDIR/dat
cd $TMPDIR/dat
cp $HACKDIR/dat/dungeon.def .
patch --ignore-whitespace <<'EOF'
--- dungeon.def 2019-03-01 15:21:08.000000000 +0100
+++ dungeon.def 2020-09-23 19:17:51.000000000 +0200
@@ -15,6 +15,7 @@
#
DUNGEON: "The Dungeons of Doom" "D" (25, 5)
+LEVEL: "mylevel" "none" @ (1,1)
ALIGNMENT: unaligned
BRANCH: "The Gnomish Mines" @ (2, 3)
LEVEL: "rogue" "R" @ (15, 4)
EOF
$HACKDIR/makedefs -e # Looks for ../dat/dungeon.def.
$HACKDIR/dgn_comp dungeon.pdf

cp $HACKDIR/dat/oracle.des mylevel.des
patch --ignore-whitespace <<'EOF'
--- mylevel.des 2019-03-01 15:21:08.000000000 +0100
+++ mylevel.des 2020-09-23 19:01:56.000000000 +0200
@@ -5,7 +5,7 @@
# Oracle level
#
-LEVEL: "oracle"
+LEVEL: "mylevel"
ROOM: "ordinary" , lit, (3,3), (center,center), (11,9) {
OBJECT:('`',"statue"),(0,0),montype:'C',1
EOF
$HACKDIR/lev_comp mylevel.des

mkdir $TMPDIR/contents
cd $TMPDIR/contents
$HACKDIR/dlb xf $HACKDIR/nhdat
cp -f ../dat/dungeon ../dat/mylevel.lev .
$HACKDIR/dlb cf nhdat *
cp nhdat $ORIGDIR

cd $ORIGDIR

rm -rf $TMPDIR

0 comments on commit 280bc03

Please sign in to comment.