Use lua for special level files

Game is playable, and should compile on linux and Windows.
Assumes you have a lua 5.3 library available.

Removes level compiler and associated files.
Replaces special level des-files with lua scripts.
Exposes some NetHack internals to lua:
 - des-table with commands to create special levels
 - nh-table with NetHack core commands
 - nhc-table with some constants
 - u-table with some player-specific data (u-struct)
 - selection userdata

Adds some rudimentary tests.

Adds new extended command #wizloadlua to run a specific script,
and #wizloaddes to run a specific level-creation script.

nhlib.lua is loaded for every lua script.

Download and untar lua:
  mkdir lib
  cd lib
  curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
  tar zxf lua-5.3.5.tar.gz

Then make nethack normally.
This commit is contained in:
Pasi Kallinen
2019-05-10 21:11:50 +03:00
parent 3e029d2900
commit fd55d9118e
189 changed files with 16653 additions and 27346 deletions

View File

@@ -19,9 +19,6 @@ all: $(VARDAT) spec_levs quest_levs dungeon
../util/dgn_comp:
(cd ../util ; $(MAKE) dgn_comp)
../util/lev_comp:
(cd ../util ; $(MAKE) lev_comp)
../util/tile2x11:
(cd ../util ; $(MAKE) tile2x11)
@@ -126,39 +123,10 @@ options: ../util/makedefs
../util/makedefs -v
spec_levs: ../util/lev_comp \
bigroom.des castle.des endgame.des gehennom.des knox.des medusa.des \
mines.des oracle.des sokoban.des tower.des yendor.des
../util/lev_comp bigroom.des
../util/lev_comp castle.des
../util/lev_comp endgame.des
../util/lev_comp gehennom.des
../util/lev_comp knox.des
../util/lev_comp medusa.des
../util/lev_comp mines.des
../util/lev_comp oracle.des
../util/lev_comp sokoban.des
../util/lev_comp tower.des
../util/lev_comp yendor.des
spec_levs:
touch spec_levs
quest_levs: ../util/lev_comp \
Arch.des Barb.des Caveman.des Healer.des Knight.des Monk.des \
Priest.des Ranger.des Rogue.des Samurai.des Tourist.des Valkyrie.des \
Wizard.des
../util/lev_comp Arch.des
../util/lev_comp Barb.des
../util/lev_comp Caveman.des
../util/lev_comp Healer.des
../util/lev_comp Knight.des
../util/lev_comp Monk.des
../util/lev_comp Priest.des
../util/lev_comp Ranger.des
../util/lev_comp Rogue.des
../util/lev_comp Samurai.des
../util/lev_comp Tourist.des
../util/lev_comp Valkyrie.des
../util/lev_comp Wizard.des
quest_levs:
touch quest_levs
dungeon: dungeon.def ../util/makedefs ../util/dgn_comp

View File

@@ -67,14 +67,12 @@ MANEXT = 6
# manual installation for most BSD-style systems
GAMEMANCREATE = cat nethack.6 | $(NHGREP) >
LEVMANCREATE = cat lev_comp.6 | $(NHGREP) >
DGNMANCREATE = cat dgn_comp.6 | $(NHGREP) >
RCVRMANCREATE = cat recover.6 | $(NHGREP) >
DLBMANCREATE = cat dlb.6 | $(NHGREP) >
MDMANCREATE = cat makedefs.6 | $(NHGREP) >
# manual installation for most SYSV-style systems
# GAMEMANCREATE = cat nethack.6 | $(NHGREP) | nroff -man - >
# LEVMANCREATE = cat lev_comp.6 | $(NHGREP) | nroff -man - >
# DGNMANCREATE = cat dgn_comp.6 | $(NHGREP) | nroff -man - >
# RCVRMANCREATE = cat recover.6 | $(NHGREP) | nroff -man - >
# DLBMANCREATE = cat dlb.6 | $(NHGREP) | nroff -man - >
@@ -82,14 +80,13 @@ MDMANCREATE = cat makedefs.6 | $(NHGREP) >
manpages:
-$(GAMEMANCREATE) $(MANDIR)/$(GAME).$(MANEXT)
-$(LEVMANCREATE) $(MANDIR)/lev_comp.$(MANEXT)
-$(DGNMANCREATE) $(MANDIR)/dgn_comp.$(MANEXT)
-$(RCVRMANCREATE) $(MANDIR)/recover.$(MANEXT)
-$(DLBMANCREATE) $(MANDIR)/dlb.$(MANEXT)
-$(MDMANCREATE) $(MANDIR)/makedefs.$(MANEXT)
# manual creation for distribution
DISTRIB = Guidebook.txt nethack.txt lev_comp.txt dgn_comp.txt recover.txt \
DISTRIB = Guidebook.txt nethack.txt dgn_comp.txt recover.txt \
dlb.txt makedefs.txt
distrib: $(DISTRIB)
@@ -100,8 +97,6 @@ Guidebook.txt : Guidebook.mn tmac.n tmac.nh
MAN2TXT = $(NHGREP) | nroff -man - | $(COLCMD)
nethack.txt : nethack.6
cat nethack.6 | $(MAN2TXT) > nethack.txt
lev_comp.txt : lev_comp.6
cat lev_comp.6 | $(MAN2TXT) > lev_comp.txt
dgn_comp.txt : dgn_comp.6
cat dgn_comp.6 | $(MAN2TXT) > dgn_comp.txt
recover.txt : recover.6

View File

@@ -49,7 +49,7 @@ SHELL=/bin/sh
# for UNIX systems
SYSSRC = ../sys/share/ioctl.c ../sys/share/unixtty.c ../sys/unix/unixmain.c \
../sys/unix/unixunix.c ../sys/unix/unixres.c
SYSOBJ = ioctl.o unixmain.o unixtty.o unixunix.o unixres.o
SYSOBJ = ioctl.o unixmain.o unixtty.o unixunix.o unixres.o liblua.a
#
# for Systos
# SYSSRC = ../sys/atari/tos.c ../sys/share/pcmain.c ../sys/share/pcsys.c \
@@ -173,6 +173,10 @@ GNOMEINC=-I/usr/lib/glib/include -I/usr/lib/gnome-libs/include -I../win/gnome
#CFLAGS = -O -I../include
#LFLAGS =
CFLAGS += -I../lib/lua-5.3.5/src
# -lm required by lua
LIBS += -lm
# The Qt and Be window systems are written in C++, while the rest of
# NetHack is standard C. If using Qt, uncomment the LINK line here to get
# the C++ libraries linked in.
@@ -360,7 +364,7 @@ WINCURSESLIB = -lncurses
# If ZLIB_COMP is defined in config.h this is necessary to link with zlib.
# LIBS = -lz
#
LIBS =
# LIBS =
# make NetHack
GAME = nethack
@@ -443,7 +447,7 @@ HACKCSRC = allmain.c alloc.c apply.c artifact.c attrib.c ball.c bones.c \
dungeon.c eat.c end.c engrave.c exper.c explode.c extralev.c \
files.c fountain.c hack.c hacklib.c invent.c isaac64.c light.c \
lock.c mail.c makemon.c mapglyph.c mcastu.c mhitm.c mhitu.c \
minion.c mklev.c mkmap.c \
minion.c mklev.c mkmap.c nhlua.c nhlsel.c \
mkmaze.c mkobj.c mkroom.c mon.c mondata.c monmove.c monst.c \
mplayer.c mthrowu.c muse.c music.c o_init.c objects.c objnam.c \
options.c pager.c pickup.c pline.c polyself.c potion.c pray.c \
@@ -487,7 +491,7 @@ CSOURCES = $(HACKCSRC) $(SYSCSRC) $(WINCSRC) $(CHAINSRC) $(GENCSRC)
# all .h files except date.h, onames.h, pm.h, and vis_tab.h which would
# cause dependency loops if run through "make depend"
# and dgn_comp.h, dgn_file.h, lev_comp.h, special level & dungeon files.
# and dgn_comp.h, dgn_file.h, special level & dungeon files.
#
HACKINCL = align.h amiconf.h artifact.h artilist.h attrib.h beconf.h botl.h \
color.h config.h config1.h context.h coord.h decl.h def_os2.h \
@@ -501,7 +505,7 @@ HACKINCL = align.h amiconf.h artifact.h artilist.h attrib.h beconf.h botl.h \
wincurs.h winX.h winprocs.h wintype.h you.h youprop.h
HSOURCES = $(HACKINCL) date.h onames.h pm.h vis_tab.h \
lev_comp.h dgn_comp.h dgn_file.h
dgn_comp.h dgn_file.h
# the following .o's _must_ be made before any others (for makedefs)
FIRSTOBJ = monst.o objects.o
@@ -512,7 +516,7 @@ HOBJ = $(FIRSTOBJ) allmain.o alloc.o apply.o artifact.o attrib.o ball.o \
drawing.o dungeon.o eat.o end.o engrave.o exper.o explode.o \
extralev.o files.o fountain.o hack.o hacklib.o invent.o isaac64.o \
light.o lock.o mail.o makemon.o mapglyph.o mcastu.o mhitm.o mhitu.o \
minion.o mklev.o mkmap.o \
minion.o mklev.o mkmap.o nhlua.o nhlsel.o \
mkmaze.o mkobj.o mkroom.o mon.o mondata.o monmove.o \
mplayer.o mthrowu.o muse.o music.o o_init.o objnam.o options.o \
pager.o pickup.o pline.o polyself.o potion.o pray.o priest.o \
@@ -1061,6 +1065,8 @@ mplayer.o: mplayer.c $(HACK_H)
mthrowu.o: mthrowu.c $(HACK_H)
muse.o: muse.c $(HACK_H)
music.o: music.c $(HACK_H) #interp.c
nhlua.o: nhlua.c $(HACK_H)
nhlsel.o: nhlsel.c $(HACK_H)
o_init.o: o_init.c $(HACK_H) ../include/lev.h
objects.o: objects.c $(CONFIG_H) ../include/obj.h ../include/objclass.h \
../include/prop.h ../include/skills.h ../include/color.h

View File

@@ -80,18 +80,19 @@ VARDAT = $(VARDATD) $(VARDATND)
DATHELP = help hh cmdhelp keyhelp history opthelp wizhelp
SPEC_LEVS = asmodeus.lev baalz.lev bigrm-*.lev castle.lev fakewiz?.lev \
juiblex.lev knox.lev medusa-?.lev minend-?.lev minefill.lev \
minetn-?.lev oracle.lev orcus.lev sanctum.lev soko?-?.lev \
tower?.lev valley.lev wizard?.lev \
astral.lev air.lev earth.lev fire.lev water.lev
QUEST_LEVS = ???-goal.lev ???-fil?.lev ???-loca.lev ???-strt.lev
SPEC_LEVS = asmodeus.lua baalz.lua bigrm-*.lua castle.lua fakewiz?.lua \
juiblex.lua knox.lua medusa-?.lua minend-?.lua minefill.lua \
minetn-?.lua oracle.lua orcus.lua sanctum.lua soko?-?.lua \
tower?.lua valley.lua wizard?.lua nhlib.lua \
astral.lua air.lua earth.lua fire.lua water.lua
QUEST_LEVS = ???-goal.lua ???-fil?.lua ???-loca.lua ???-strt.lua
DATNODLB = $(VARDATND) license symbols
DATDLB = $(DATHELP) dungeon tribute $(SPEC_LEVS) $(QUEST_LEVS) $(VARDATD)
DAT = $(DATNODLB) $(DATDLB)
$(GAME):
( cd lib/lua-5.3.5/src && make a && cp liblua.a ../../../src/ )
( cd src ; $(MAKE) )
all: $(GAME) recover Guidebook $(VARDAT) dungeon spec_levs check-dlb
@@ -133,7 +134,6 @@ quest.dat: $(GAME)
( cd dat ; $(MAKE) quest.dat )
spec_levs: dungeon
( cd util ; $(MAKE) lev_comp )
( cd dat ; $(MAKE) spec_levs )
( cd dat ; $(MAKE) quest_levs )
@@ -288,6 +288,7 @@ clean:
( cd src ; $(MAKE) clean )
( cd util ; $(MAKE) clean )
( cd doc ; $(MAKE) clean )
( cd lib/lua-5.3.5/src && $(MAKE) clean )
# 'make spotless' returns the source tree to near-distribution condition.
# it removes .o files, executables, and compiled data files

View File

@@ -97,6 +97,9 @@ NHSROOT=..
#CFLAGS = -O -I../include
#LFLAGS =
CFLAGS += -I../lib/lua-5.3.5/src
LFLAGS += -lm
# we specify C preprocessor flags via CFLAGS; files built with default rules
# might include $(CPPFLAGS) which could get a value from user's environment;
# we avoid that by forcing it empty rather than by overriding default rules
@@ -183,11 +186,10 @@ HACK_H = ../src/hack.h-t
# utility .c files
MAKESRC = makedefs.c
SPLEVSRC = lev_yacc.c lev_lex.c lev_main.c
DGNCOMPSRC = dgn_yacc.c dgn_lex.c dgn_main.c
RECOVSRC = recover.c
DLBSRC = dlb_main.c
UTILSRCS = $(MAKESRC) panic.c $(SPLEVSRC) $(DGNCOMPSRC) $(RECOVSRC) $(DLBSRC)
UTILSRCS = $(MAKESRC) panic.c $(DGNCOMPSRC) $(RECOVSRC) $(DLBSRC)
READTAGSSRC = readtags.c
# files that define all monsters and objects
@@ -203,9 +205,6 @@ OALLOC = $(OBJDIR)/alloc.o panic.o
# object files for makedefs
MAKEOBJS = makedefs.o $(OMONOBJ)
# object files for special levels compiler
SPLEVOBJS = lev_yacc.o lev_lex.o lev_main.o $(OALLOC) $(ONAMING)
# object files for dungeon compiler
DGNCOMPOBJS = dgn_yacc.o dgn_lex.o dgn_main.o $(OALLOC)
@@ -268,52 +267,6 @@ lintdefs:
panic.o: panic.c $(CONFIG_H)
# dependencies for lev_comp
#
lev_comp: $(SPLEVOBJS)
$(CC) $(LFLAGS) -o lev_comp $(SPLEVOBJS) $(LIBS)
lev_yacc.o: lev_yacc.c $(HACK_H) ../include/sp_lev.h
lev_main.o: lev_main.c $(HACK_H) ../include/sp_lev.h ../include/tcap.h \
../include/date.h
# see lev_comp.l for WEIRD_LEX discussion
# egrep will return failure if it doesn't find anything, but we know there
# is one "_cplusplus" inside a comment
lev_lex.o: lev_lex.c $(HACK_H) ../include/lev_comp.h ../include/sp_lev.h
$(CC) -c $(CFLAGS) -DWEIRD_LEX=`egrep -c _cplusplus lev_lex.c` lev_lex.c
# '$(YACC) -d' generates both $(YTABC) and $(YTABH) in one run
../include/lev_comp.h: lev_yacc.c
lev_yacc.c: lev_comp.y
$(YACC) $(YACCDIST) -d lev_comp.y
sed -e 's#"$(YTABC)"#"$@"#' -e 's#$(YTABC):#$@:#' $(YTABC) > $@ \
&& rm $(YTABC)
sed -e 's#"$(YTABH)"#"lev_comp.h"#' $(YTABH) > ../include/lev_comp.h \
&& rm $(YTABH)
lev_lex.c: lev_comp.l
$(LEX) $(FLEXDIST) lev_comp.l
sed -e 's#"$(LEXYYC)"#"$@"#' -e 's# *$$##' \
-e 's#static void yyunput#void yyunput#' $(LEXYYC) > $@ \
&& rm $(LEXYYC)
# note: flex code construction using m4 macros results in some trailing
# spaces; <space><space><star> is basic RE substitute for <space><plus>
# and we don't bother stripping trailing tabs because that gets messy;
# make expands <dollar><dollar> into <dollar> which is RE end-of-line.
# flex also creates yyunput() as a static routine, but lev_comp doesn't
# use it so compiler complaints can ensue; recent flex versions honor
# NO_YY_UNPUT to suppress it, but older ones don't; making it global to
# avoid an "unused function" warning is simpler than trying to remove
# the whole thing (although full 'lint' may still complain).
# with all of extern.h's functions to complain about, we drown in
# 'defined but not used' without -u
lintlev:
@lint -axhu -I../include -DLINT $(SPLEVSRC) $(CALLOC) $(CNAMING) | sed '/_flsbuf/d'
# dependencies for dgn_comp
#
dgn_comp: $(DGNCOMPOBJS)
@@ -550,12 +503,6 @@ $(CONFIG_H): ../include/config.h
# 'make dist' => put generated lex and yacc sources into place for distribution
SYSSHARE=../sys/share/
$(SYSSHARE)lev_lex.c: lev_lex.c
cp lev_lex.c $@
$(SYSSHARE)lev_yacc.c: lev_yacc.c
cp lev_yacc.c $@
$(SYSSHARE)lev_comp.h: ../include/lev_comp.h
cp ../include/lev_comp.h $@
$(SYSSHARE)dgn_lex.c: dgn_lex.c
cp dgn_lex.c $@
$(SYSSHARE)dgn_yacc.c: dgn_yacc.c
@@ -563,8 +510,7 @@ $(SYSSHARE)dgn_yacc.c: dgn_yacc.c
$(SYSSHARE)dgn_comp.h: ../include/dgn_comp.h
cp ../include/dgn_comp.h $@
dist: $(SYSSHARE)lev_lex.c $(SYSSHARE)lev_yacc.c $(SYSSHARE)lev_comp.h \
$(SYSSHARE)dgn_lex.c $(SYSSHARE)dgn_yacc.c $(SYSSHARE)dgn_comp.h
dist: $(SYSSHARE)dgn_lex.c $(SYSSHARE)dgn_yacc.c $(SYSSHARE)dgn_comp.h
@echo 'pre-generated lex and yacc sources are in place in sys/share'
tags: $(UTILSRCS)
@@ -574,9 +520,9 @@ clean:
-rm -f *.o
spotless: clean
-rm -f lev_lex.c lev_yacc.c dgn_lex.c dgn_yacc.c
-rm -f ../include/lev_comp.h ../include/dgn_comp.h
-rm -f dgn_lex.c dgn_yacc.c
-rm -f ../include/dgn_comp.h
-rm -f ../include/tile.h tiletxt.c
-rm -f makedefs lev_comp dgn_comp recover dlb
-rm -f makedefs dgn_comp recover dlb
-rm -f gif2txt txt2ppm tile2x11 tile2img.ttp xpm2img.ttp \
tilemap tileedit tile2bmp

View File

@@ -20,7 +20,8 @@ VARDIR = $(HACKDIR)
POSTINSTALL=cp -n sys/unix/sysconf $(INSTDIR)/sysconf; $(CHOWN) $(GAMEUID) $(INSTDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(INSTDIR)/sysconf; chmod $(VARFILEPERM) $(INSTDIR)/sysconf;
CFLAGS=-g -O -I../include -DNOTPARMDECL -DDLB
CFLAGS=-g -O -I../include -DNOTPARMDECL
CFLAGS+=-DDLB
CFLAGS+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\"
CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE
CFLAGS+=-DTIMED_DELAY
@@ -33,7 +34,6 @@ CFLAGS+=-DCURSES_GRAPHICS
#CFLAGS+=-DSCORE_ON_BOTL
#CFLAGS+=-DMSGHANDLER
#CFLAGS+=-DTTY_TILES_ESCCODES
#CFLAGS+=-DDLB
LINK=$(CC)
# Only needed for GLIBC stack trace: