diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a82881cb6..8f77aa379 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: rev: v0.6.13 - hooks: - description: Format files with clang-format - entry: clang-format + entry: clang-format -i files: ^(src\/nle|include\/nle|win\/rl|sys\/unix\/nle).*\.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$ id: clang-format language: system diff --git a/CMakeLists.txt b/CMakeLists.txt index 0337a7eb5..2b97cdecb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +message(NOTICE "*** CMakeLists.txt: ${CMAKE_CURRENT_LIST_FILE}") + cmake_minimum_required(VERSION 3.28) if(NOT DEFINED NLE_VERSION) if(DEFINED SKBUILD_PROJECT_VERSION) @@ -93,7 +95,8 @@ add_compile_definitions( HACKDIR="${HACKDIR}" DEFAULT_WINDOW_SYS="rl" DLB - NOCWD_ASSUMPTIONS) + NOCWD_ASSUMPTIONS + NO_TERMCAP_HEADERS) set(NLE_SRC ${nle_SOURCE_DIR}/src) set(NLE_INC ${nle_SOURCE_DIR}/include) @@ -108,10 +111,49 @@ set(NLE_INC_GEN ${nle_BINARY_DIR}/include) set(NLE_DAT_GEN ${nle_BINARY_DIR}/dat) set(NLE_UTIL_GEN ${nle_BINARY_DIR}/util) +# TODO: NH5 - Sometimes the other CMakeLists.txt executions will not detect this +# setting. Why is this? +set(LUA_INCLUDE ${nle_BINARY_DIR}/lua/src/fetch-lua/src) +message(NOTICE "-- LUA_INCLUDE: ${LUA_INCLUDE}") + set(CMAKE_INSTALL_MESSAGE LAZY) # Don't tell us about up-to-date files. add_subdirectory(util) add_subdirectory(dat) +# Lua. +set(LUA_VERSION 5.4.3) +include(ExternalProject) +ExternalProject_Add( + fetch-lua + PREFIX "lua" + URL http://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz + URL_HASH + SHA512=3a1a3ee8694b72b4ec9d3ce76705fe179328294353604ca950c53f41b41161b449877d43318ef4501fee44ecbd6c83314ce7468d7425ba9b2903c9c32a28bbc0 + BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND "" + BUILD_COMMAND make + BUILD_BYPRODUCTS /src/liblua.a + INSTALL_COMMAND "" + STEP_TARGETS build) + +ExternalProject_Get_Property(fetch-lua BINARY_DIR) +set(TOPLUALIB ${BINARY_DIR}/src/liblua.a) + +add_custom_command( + OUTPUT ${NLE_INC_GEN}/nhlua.h + COMMAND ${CMAKE_COMMAND} -E echo "/* nhlua.h - generated by top Makefile */" > + ${NLE_INC_GEN}/nhlua.h + COMMAND ${CMAKE_COMMAND} -E echo "#include \"lua.h\"" >> + ${NLE_INC_GEN}/nhlua.h + COMMAND ${CMAKE_COMMAND} -E echo "#include \"lualib.h\"" >> + ${NLE_INC_GEN}/nhlua.h + COMMAND ${CMAKE_COMMAND} -E echo "#include \"lauxlib.h\"" >> + ${NLE_INC_GEN}/nhlua.h + COMMAND ${CMAKE_COMMAND} -E echo "/*nhlua.h*/" >> ${NLE_INC_GEN}/nhlua.h + VERBATIM) + +add_custom_target(lua_support DEPENDS fetch-lua-build ${NLE_INC_GEN}/nhlua.h) + file( GLOB NETHACK_SRC @@ -152,22 +194,24 @@ set_target_properties(tmt PROPERTIES C_STANDARD 11) # libnethack library add_library(nethack SHARED ${NETHACK_SRC}) -add_dependencies(nethack util dat) +add_dependencies(nethack util dat lua_support) set_target_properties(nethack PROPERTIES CXX_STANDARD 14 SUFFIX ".so") target_compile_options( nethack PRIVATE -Wno-deprecated-non-prototype - PRIVATE -Wno-unused-variable) + PRIVATE -Wno-unused-variable + PRIVATE -fPIC) target_include_directories( nethack PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${NLE_INC_GEN} /usr/local/include - ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt ${bzip2_SOURCE_DIR}) + ${LUA_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt + ${bzip2_SOURCE_DIR}) # target_link_directories(nethack PUBLIC /usr/local/lib) # Careful with -DMONITOR_HEAP: Ironically, it fails to fclose FILE* heaplog. # target_compile_definitions(nethack PUBLIC "$<$:MONITOR_HEAP>") -target_link_libraries(nethack PUBLIC m fcontext bz2_static tmt) +target_link_libraries(nethack PUBLIC m fcontext bz2_static tmt ${TOPLUALIB}) # dlopen wrapper library add_library(nethackdl STATIC "sys/unix/nledl.c") @@ -180,7 +224,7 @@ target_link_libraries(nethackdl PUBLIC dl) add_executable(rlmain "sys/unix/rlmain.cc") set_target_properties(rlmain PROPERTIES CXX_STANDARD 11) target_link_libraries(rlmain PUBLIC nethackdl) -target_include_directories(rlmain PUBLIC ${NLE_INC_GEN}) +target_include_directories(rlmain PUBLIC ${NLE_INC_GEN} ${LUA_INCLUDE}) add_dependencies(rlmain util) # For pm.h. # pybind11 core python library. @@ -194,7 +238,8 @@ pybind11_add_module( $) target_link_libraries(_pynethack PUBLIC nethackdl) set_target_properties(_pynethack PROPERTIES CXX_STANDARD 14) -target_include_directories(_pynethack PUBLIC ${NLE_INC_GEN} ${NLE_WIN}/share) +target_include_directories(_pynethack PUBLIC ${NLE_INC_GEN} ${NLE_WIN}/share + ${LUA_INCLUDE}) # add_dependencies(_pynethack util tile) # For pm.h. # ttyrec converter library diff --git a/dat/CMakeLists.txt b/dat/CMakeLists.txt index a860180d7..a2140e7a7 100644 --- a/dat/CMakeLists.txt +++ b/dat/CMakeLists.txt @@ -5,47 +5,57 @@ set(DATHELP keyhelp history opthelp + optmenu wizhelp) -set(SPECIAL_LEVELS - bigroom.des - castle.des - endgame.des - gehennom.des - knox.des - medusa.des - mines.des - oracle.des - sokoban.des - tower.des - yendor.des) - -set(QUEST_LEVELS - 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) +file( + GLOB SPECIAL_LEVELS + RELATIVE ${NH_DAT} + 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 + nhcore.lua + nhlib.lua + themerms.lua + astral.lua + air.lua + earth.lua + fire.lua + water.lua) + +file( + GLOB QUEST_LEVELS + RELATIVE ${NH_DAT} + ???-goal.lua ???-fil?.lua ???-loca.lua ???-strt.lua) set(DATDLB ${DATHELP} - dungeon + dungeon.lua tribute + ${SPECIAL_LEVELS} + ${QUEST_LEVELS} bogusmon data engrave epitaph oracles options - quest.dat + quest.lua rumors) file(MAKE_DIRECTORY ${NLE_DAT_GEN}) @@ -57,11 +67,11 @@ set(ALL_DAT_NOTGEN ${QUEST_LEVELS} bogusmon.txt data.base - dungeon.def + dungeon.lua engrave.txt epitaph.txt oracles.txt - quest.txt + quest.lua rumors.fal rumors.tru tribute) @@ -74,129 +84,6 @@ endforeach(filename) # Dat files that are not inputs to any tools. set(ALL_DAT_NOTGEN ${ALL_DAT_NOTGEN} license symbols) -# Result of running lev_comp. -set(LEVS_GEN - Arc-fila.lev - Arc-filb.lev - Arc-goal.lev - Arc-loca.lev - Arc-strt.lev - Bar-fila.lev - Bar-filb.lev - Bar-goal.lev - Bar-loca.lev - Bar-strt.lev - Cav-fila.lev - Cav-filb.lev - Cav-goal.lev - Cav-loca.lev - Cav-strt.lev - Hea-fila.lev - Hea-filb.lev - Hea-goal.lev - Hea-loca.lev - Hea-strt.lev - Kni-fila.lev - Kni-filb.lev - Kni-goal.lev - Kni-loca.lev - Kni-strt.lev - Mon-fila.lev - Mon-filb.lev - Mon-goal.lev - Mon-loca.lev - Mon-strt.lev - Pri-fila.lev - Pri-filb.lev - Pri-goal.lev - Pri-loca.lev - Pri-strt.lev - Ran-fila.lev - Ran-filb.lev - Ran-goal.lev - Ran-loca.lev - Ran-strt.lev - Rog-fila.lev - Rog-filb.lev - Rog-goal.lev - Rog-loca.lev - Rog-strt.lev - Sam-fila.lev - Sam-filb.lev - Sam-goal.lev - Sam-loca.lev - Sam-strt.lev - Tou-fila.lev - Tou-filb.lev - Tou-goal.lev - Tou-loca.lev - Tou-strt.lev - Val-fila.lev - Val-filb.lev - Val-goal.lev - Val-loca.lev - Val-strt.lev - Wiz-fila.lev - Wiz-filb.lev - Wiz-goal.lev - Wiz-loca.lev - Wiz-strt.lev - air.lev - asmodeus.lev - astral.lev - baalz.lev - bigrm-1.lev - bigrm-10.lev - bigrm-2.lev - bigrm-3.lev - bigrm-4.lev - bigrm-5.lev - bigrm-6.lev - bigrm-7.lev - bigrm-8.lev - bigrm-9.lev - castle.lev - earth.lev - fakewiz1.lev - fakewiz2.lev - fire.lev - juiblex.lev - knox.lev - medusa-1.lev - medusa-2.lev - medusa-3.lev - medusa-4.lev - minefill.lev - minend-1.lev - minend-2.lev - minend-3.lev - minetn-1.lev - minetn-2.lev - minetn-3.lev - minetn-4.lev - minetn-5.lev - minetn-6.lev - minetn-7.lev - oracle.lev - orcus.lev - sanctum.lev - soko1-1.lev - soko1-2.lev - soko2-1.lev - soko2-2.lev - soko3-1.lev - soko3-2.lev - soko4-1.lev - soko4-2.lev - tower1.lev - tower2.lev - tower3.lev - valley.lev - water.lev - wizard1.lev - wizard2.lev - wizard3.lev) - add_custom_command( DEPENDS $ bogusmon.txt engrave.txt epitaph.txt OUTPUT bogusmon epitaph engrave @@ -224,25 +111,10 @@ add_custom_command( # Hack: Depend on date.h to avoid race. add_custom_command( - DEPENDS $ ${NLE_INC_GEN}/date.h + DEPENDS $ generate_date_h OUTPUT options COMMAND makedefs ARGS -v) -# Hack: Depend on bogusmon to avoid race wrt. makedef's grep.tmp file. Best to -# be defensive about the paths (matters if NetHack's make install was run). -add_custom_command( - DEPENDS $ $ - ${NLE_DAT_GEN}/dungeon.def ${NLE_DAT_GEN}/bogusmon - OUTPUT dungeon dungeon.pdf - COMMAND makedefs ARGS -e - COMMAND dgn_comp ARGS dungeon.pdf) - -add_custom_command( - DEPENDS lev_comp - OUTPUT ${LEVS_GEN} - COMMAND lev_comp ${SPECIAL_LEVELS} - COMMAND lev_comp ${QUEST_LEVELS}) - add_custom_command( OUTPUT perm record logfile xlogfile COMMAND ${CMAKE_COMMAND} -E touch perm record logfile xlogfile) @@ -250,13 +122,11 @@ add_custom_command( # Defensive dependencies for when we also build NetHack with make/make install. list(TRANSFORM DATDLB PREPEND ${NLE_DAT_GEN}/ OUTPUT_VARIABLE NLE_DAT_GEN_DATDLB) -list(TRANSFORM LEVS_GEN PREPEND ${NLE_DAT_GEN}/ OUTPUT_VARIABLE - NLE_DAT_GEN_LEVS_GEN) add_custom_command( - DEPENDS dlb ${NLE_DAT_GEN_DATDLB} ${NLE_DAT_GEN_LEVS_GEN} + DEPENDS dlb ${NLE_DAT_GEN_DATDLB} OUTPUT nhdat - COMMAND LC_ALL=C $ ARGS cf nhdat ${DATDLB} ${LEVS_GEN}) + COMMAND LC_ALL=C $ ARGS cf nhdat ${DATDLB}) set(ALL_DAT_GEN nhdat perm record logfile xlogfile) list(TRANSFORM ALL_DAT_GEN PREPEND ${NLE_DAT_GEN}/) diff --git a/include/winprocs.h b/include/winprocs.h index 7ec7de01a..122a86798 100644 --- a/include/winprocs.h +++ b/include/winprocs.h @@ -16,6 +16,10 @@ enum wp_ids { wp_tty = 1, wp_X11, wp_Qt, wp_mswin, wp_curses, #if defined(AMIGA) wp_amii, wp_amiv, #endif +/* NLE: add our windowport */ +#if defined(RL_GRAPHICS) + wp_rl, +#endif #ifdef OUTDATED_STUFF wp_mac, wp_Gem, wp_Gnome, #endif diff --git a/include/wintty.h b/include/wintty.h index 8240101a5..9f6d5cc19 100644 --- a/include/wintty.h +++ b/include/wintty.h @@ -365,7 +365,7 @@ extern void video_update_positionbar(char *); #undef fflush extern int nle_putchar(int); extern int nle_puts(const char *); -extern int nle_xputs(const char *); +extern void nle_xputs(const char *); extern int nle_fflush(FILE *); #define putchar nle_putchar diff --git a/src/calendar.c b/src/calendar.c index 7c74b1521..827995801 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -5,6 +5,9 @@ /* NetHack may be freely redistributed. See license for details. */ #include "hack.h" +#include "nletypes.h" +#include "nlernd.h" +extern nle_settings settings; /* * Time routines @@ -50,7 +53,7 @@ getlt(void) * and seeds have been set. Otherwise fall back to real system time. * The actual RNG work is done by nle_fill_fixed_tm() in nlernd.c. */ -STATIC_OVL struct tm * +static struct tm * nle_getlt_maybe_fixed() { static struct tm fixed_tm; diff --git a/src/cmd.c b/src/cmd.c index 0ad65d3a0..fff005366 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1659,6 +1659,27 @@ do_repeat(void) return res; } +/* NLE: Replacement commands*/ +int nle_dosave() { + pline("You get the feeling there's only one way to save yourself..."); + return 1; +} + +int nle_done2() { + pline("You can't quit now, you're having so much fun!"); + return 1; +} + +int nle_doset() { + pline("The options are already set perfectly for you!"); + return 1; +} + +int nle_noop() { + pline("Noop"); + return 1; +} + /* extcmdlist: full command list, ordered by command name; commands with no keystroke or with only a meta keystroke generally need to be flagged as autocomplete and ones with a regular keystroke @@ -2557,26 +2578,6 @@ extcmds_match(const char *findstr, int ecmflags, int **matchlist) return mi; } -int nle_dosave() { - pline("You get the feeling there's only one way to save yourself..."); - return 1; -} - -int nle_done2() { - pline("You can't quit now, you're having so much fun!"); - return 1; -} - -int nle_doset() { - pline("The options are already set perfectly for you!"); - return 1; -} - -int nle_noop() { - pline("Noop"); - return 1; -} - const char * key2extcmddesc(uchar key) { diff --git a/src/nle.c b/src/nle.c index 07f315083..bb272c6be 100644 --- a/src/nle.c +++ b/src/nle.c @@ -12,6 +12,11 @@ #endif #include "hack.h" +/* */ +// #include "decl.h" +/* needed for term_start_screen & term_end_screen */ +#include "wintty.h" + #include "dlb.h" #include "nle.h" @@ -199,16 +204,16 @@ mainloop(fcontext_transfer_t ctx_transfer) char *scoreprefix = (settings.scoreprefix[0] != '\0') ? settings.scoreprefix : settings.hackdir; - fqn_prefix[SYSCONFPREFIX] = settings.hackdir; - fqn_prefix[CONFIGPREFIX] = settings.hackdir; - fqn_prefix[HACKPREFIX] = settings.hackdir; - fqn_prefix[SAVEPREFIX] = settings.hackdir; - fqn_prefix[LEVELPREFIX] = settings.hackdir; - fqn_prefix[BONESPREFIX] = settings.hackdir; - fqn_prefix[SCOREPREFIX] = scoreprefix; - fqn_prefix[LOCKPREFIX] = settings.hackdir; - fqn_prefix[TROUBLEPREFIX] = settings.hackdir; - fqn_prefix[DATAPREFIX] = settings.hackdir; + gf.fqn_prefix[SYSCONFPREFIX] = settings.hackdir; + gf.fqn_prefix[CONFIGPREFIX] = settings.hackdir; + gf.fqn_prefix[HACKPREFIX] = settings.hackdir; + gf.fqn_prefix[SAVEPREFIX] = settings.hackdir; + gf.fqn_prefix[LEVELPREFIX] = settings.hackdir; + gf.fqn_prefix[BONESPREFIX] = settings.hackdir; + gf.fqn_prefix[SCOREPREFIX] = scoreprefix; + gf.fqn_prefix[LOCKPREFIX] = settings.hackdir; + gf.fqn_prefix[TROUBLEPREFIX] = settings.hackdir; + gf.fqn_prefix[DATAPREFIX] = settings.hackdir; char *argv[1] = { "nethack" }; @@ -542,7 +547,7 @@ gettty() void settty(const char *s) { - end_screen(); + term_end_screen(); if (s) raw_print(s); } @@ -550,7 +555,7 @@ settty(const char *s) void setftty() { - start_screen(); + term_start_screen(); iflags.cbreak = ON; iflags.echo = OFF; @@ -572,16 +577,16 @@ introff() int linux_flag_console = 0; -void NDECL(linux_mapon); -void NDECL(linux_mapoff); -void NDECL(check_linux_console); -void NDECL(init_linux_cons); +void linux_mapon(void); +void linux_mapoff(void); +void check_linux_console(void); +void init_linux_cons(void); void linux_mapon() { #ifdef TTY_GRAPHICS - if (WINDOWPORT("tty") && linux_flag_console) { + if (WINDOWPORT(tty) && linux_flag_console) { write(1, "\033(B", 3); } #endif @@ -591,7 +596,7 @@ void linux_mapoff() { #ifdef TTY_GRAPHICS - if (WINDOWPORT("tty") && linux_flag_console) { + if (WINDOWPORT(tty) && linux_flag_console) { write(1, "\033(U", 3); } #endif @@ -611,7 +616,7 @@ void init_linux_cons() { #ifdef TTY_GRAPHICS - if (WINDOWPORT("tty") && linux_flag_console) { + if (WINDOWPORT(tty) && linux_flag_console) { atexit(linux_mapon); linux_mapoff(); #ifdef TEXTCOLOR @@ -622,3 +627,17 @@ init_linux_cons() #endif } #endif /* __linux__ */ + +/* Taken from unixtty.c, needed by the term_start_screen +function, but we don't need to do anything */ +#ifdef ENHANCED_SYMBOLS +/* + * set in term_start_screen() and allows + * OS-specific changes that may be + * required for support of utf8. + */ +void +tty_utf8graphics_fixup(void) +{ +} +#endif \ No newline at end of file diff --git a/src/nlernd.c b/src/nlernd.c index e119f1bc8..ff81b877f 100644 --- a/src/nlernd.c +++ b/src/nlernd.c @@ -14,7 +14,7 @@ extern struct rnglist_t rnglist[]; extern int whichrng(int (*fn)(int)); /* See rnd.c. */ -extern int set_random(unsigned long, int (*fn)(int)); +extern void set_random(unsigned long, int (*fn)(int)); /* An appropriate version of this must always be provided in port-specific code somewhere. It returns a number suitable diff --git a/src/rnd.c b/src/rnd.c index 864b48cf6..50501ee14 100644 --- a/src/rnd.c +++ b/src/rnd.c @@ -6,10 +6,16 @@ #ifdef USE_ISAAC64 #include "isaac64.h" +#include "nlernd.h" +#include "nletypes.h" -staticfn int whichrng(int (*fn)(int)); +/* NLE: remove staticfn modifier as we want to access +this function from nlernd.c */ +int whichrng(int (*fn)(int)); staticfn int RND(int); -staticfn void set_random(unsigned long, int (*)(int)); +/* NLE: remove staticfn modifier as we want to access +this function from nlernd.c */ +void set_random(unsigned long, int (*)(int)); #if 0 static isaac64_ctx rng_state; @@ -30,7 +36,9 @@ struct rnglist_t rnglist[] = { { rn2_on_display_rng, FALSE, { 0 } }, /* DISP */ }; -staticfn int +/* NLE: remove staticfn modifier as we want to access +this function from nlernd.c */ +int whichrng(int (*fn)(int)) { int i; @@ -233,7 +241,13 @@ rnz(int i) /* Sets the seed for the random number generator */ #ifdef USE_ISAAC64 -staticfn void +/* NLE: Array to store seeds for each random number generator. + see nlernd.h */ +extern unsigned long nle_seeds[]; + +/* NLE: remove staticfn modifier as we want to access +this function from nlernd.c */ +void set_random(unsigned long seed, int (*fn)(int)) { @@ -245,7 +259,9 @@ set_random(unsigned long seed, #else /* USE_ISAAC64 */ /*ARGSUSED*/ -staticfn void +/* NLE: remove staticfn modifier as we want to access +this function from nlernd.c */ +void set_random(unsigned long seed, int (*fn)(int) UNUSED) { diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 4f0194b67..26be07d2e 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,49 +1,50 @@ +message(NOTICE "*** CMakeLists.txt: ${CMAKE_CURRENT_LIST_FILE}") + find_program(FLEX_EXECUTABLE NAMES flex flex.exe) find_program(BISON_EXECUTABLE NAMES bison bison.exe) -set(MAKEDEFS_SRC makedefs.c ${NLE_SRC}/monst.c ${NLE_SRC}/objects.c) - -set(DGN_COMP_SRC dgn_main.c panic.c ${NLE_SRC}/alloc.c - ${NLE_UTIL_GEN}/dgn_parser.c ${NLE_UTIL_GEN}/dgn_scanner.c) - -set(LEV_COMP_SRC - lev_main.c - panic.c - ${NLE_SRC}/decl.c +set(MAKEDEFS_SRC + makedefs.c ${NLE_SRC}/monst.c ${NLE_SRC}/objects.c ${NLE_SRC}/alloc.c - ${NLE_SRC}/drawing.c - ${NLE_UTIL_GEN}/lev_parser.c - ${NLE_UTIL_GEN}/lev_scanner.c) + ${NLE_SRC}/date.c + ${NLE_SRC}/hacklib.c + panic.c) -set(MAKEDEFS_HEADERS ${NLE_INC_GEN}/date.h ${NLE_INC_GEN}/onames.h - ${NLE_INC_GEN}/pm.h) +set(MAKEDEFS_HEADERS ${NLE_INC_GEN}/date.h ${NLE_INC_GEN}/pm.h) -set(DLB_SRC dlb_main.c ${NLE_SRC}/dlb.c panic.c ${NLE_SRC}/alloc.c) +set(DLB_SRC dlb_main.c ${NLE_SRC}/dlb.c panic.c ${NLE_SRC}/alloc.c + ${NLE_SRC}/hacklib.c) file(MAKE_DIRECTORY ${NLE_INC_GEN} ${NLE_SRC_GEN}) +message(NOTICE "-- LUA_INCLUDE: ${LUA_INCLUDE}") + add_executable(makedefs ${MAKEDEFS_SRC}) -target_include_directories(makedefs PRIVATE ${NLE_INC} ${NLE_INC_GEN} - ${NLE_UTIL_GEN}) -add_executable(dgn_comp ${DGN_COMP_SRC}) -target_include_directories(dgn_comp PRIVATE ${NLE_INC} ${NLE_INC_GEN} - ${NLE_UTIL_GEN}) -add_executable(lev_comp ${LEV_COMP_SRC}) -target_include_directories(lev_comp PRIVATE ${NLE_INC} ${NLE_INC_GEN} - ${NLE_UTIL_GEN}) +add_dependencies(makedefs lua_support) +target_include_directories( + makedefs PRIVATE ${NLE_INC} ${NLE_INC_GEN} ${NLE_UTIL_GEN} ${LUA_INCLUDE} + ${deboost_context_SOURCE_DIR}/include) + add_executable(dlb ${DLB_SRC}) -target_include_directories(dlb PRIVATE ${NLE_INC} ${NLE_INC_GEN} - ${NLE_UTIL_GEN}) -add_executable(recover recover.c) -target_include_directories(recover PRIVATE ${NLE_INC} ${NLE_INC_GEN} - ${NLE_UTIL_GEN}) +add_dependencies(dlb lua_support) +target_include_directories( + dlb PRIVATE ${NLE_INC} ${NLE_INC_GEN} ${NLE_UTIL_GEN} ${LUA_INCLUDE} + ${deboost_context_SOURCE_DIR}/include) + +add_executable(recover recover.c ${NLE_SRC}/hacklib.c ${NLE_SRC}/version.c) +add_dependencies(recover lua_support) +target_compile_definitions(recover PRIVATE -DMINIMAL_FOR_RECOVER) +target_include_directories( + recover PRIVATE ${NLE_INC} ${NLE_INC_GEN} ${NLE_UTIL_GEN} ${LUA_INCLUDE} + ${deboost_context_SOURCE_DIR}/include) add_custom_command( DEPENDS makedefs OUTPUT ${NLE_INC_GEN}/date.h COMMAND $ ARGS -v) +add_custom_target(generate_date_h DEPENDS ${NLE_INC_GEN}/date.h) add_custom_command( DEPENDS makedefs @@ -62,54 +63,29 @@ add_custom_command( COMMAND $) add_custom_target(generate_tile_c DEPENDS ${NLE_SRC_GEN}/tile.c) -add_custom_command( - OUTPUT ${NLE_UTIL_GEN}/dgn_parser.c ${NLE_UTIL_GEN}/dgn_comp.h - COMMAND bison -y --defines=${NLE_UTIL_GEN}/dgn_comp.h -o - ${NLE_UTIL_GEN}/dgn_parser.c ${NLE_UTIL}/dgn_comp.y - DEPENDS ${NLE_UTIL}/dgn_comp.y) - -add_custom_command( - OUTPUT ${NLE_UTIL_GEN}/dgn_scanner.c - COMMAND ${FLEX_EXECUTABLE} ARGS -o${NLE_UTIL_GEN}/dgn_scanner.c - ${NLE_UTIL}/dgn_comp.l - DEPENDS ${NLE_UTIL}/dgn_comp.l) - -add_custom_command( - OUTPUT ${NLE_UTIL_GEN}/lev_parser.c ${NLE_UTIL_GEN}/lev_comp.h - COMMAND ${BISON_EXECUTABLE} ARGS -y --defines=${NLE_UTIL_GEN}/lev_comp.h -o - ${NLE_UTIL_GEN}/lev_parser.c ${NLE_UTIL}/lev_comp.y - DEPENDS ${NLE_UTIL}/lev_comp.y) - -add_custom_command( - OUTPUT ${NLE_UTIL_GEN}/lev_scanner.c - COMMAND ${FLEX_EXECUTABLE} ARGS -o${NLE_UTIL_GEN}/lev_scanner.c - ${NLE_UTIL}/lev_comp.l - DEPENDS ${NLE_UTIL}/lev_comp.l) - add_custom_target(util DEPENDS ${MAKEDEFS_HEADERS} recover) -add_executable(tilemap ${NLE_WIN}/share/tilemap.c) -target_include_directories(tilemap PUBLIC ${NLE_INC} ${NLE_INC_GEN}) -add_dependencies(tilemap util) +add_executable( + tilemap ${NLE_WIN}/share/tilemap.c ${NLE_SRC}/monst.c ${NLE_SRC}/objects.c + ${NLE_SRC}/drawing.c ${NLE_SRC}/hacklib.c) +target_include_directories( + tilemap PUBLIC ${NLE_INC} ${NLE_INC_GEN} ${LUA_INCLUDE} + ${deboost_context_SOURCE_DIR}/include) +add_dependencies(tilemap util lua_support) file(GLOB NETHACK_TILE_SRC ${NLE_WIN}/rl/tile2rgb.c ${NLE_WIN}/rl/nletiletxt.c ${NLE_WIN}/share/tiletext.c) add_library(tile OBJECT ${NETHACK_TILE_SRC} ${NLE_SRC_GEN}/tile.c) target_include_directories(tile PUBLIC ${NLE_INC} ${NLE_INC_GEN} - ${NLE_WIN}/share) + ${NLE_WIN}/share ${LUA_INCLUDE}) add_dependencies(tile generate_pm_h generate_tile_c) -# NOTE: util is dependent on these two -add_dependencies(lev_comp util) -add_dependencies(dgn_comp util) - -set(MAN_PAGES ${NLE_DOC}/makedefs.6 ${NLE_DOC}/dgn_comp.6 ${NLE_DOC}/lev_comp.6 - ${NLE_DOC}/dlb.6 ${NLE_DOC}/recover.6 ${NLE_DOC}/nethack.6) +set(MAN_PAGES ${NLE_DOC}/makedefs.6 ${NLE_DOC}/dlb.6 ${NLE_DOC}/recover.6 + ${NLE_DOC}/nethack.6) -set(TXT_DOCS - ${NLE_DOC}/makedefs.txt ${NLE_DOC}/dgn_comp.txt ${NLE_DOC}/lev_comp.txt - ${NLE_DOC}/dlb.txt ${NLE_DOC}/recover.txt ${NLE_DOC}/nethack.txt) +set(TXT_DOCS ${NLE_DOC}/makedefs.txt ${NLE_DOC}/dlb.txt ${NLE_DOC}/recover.txt + ${NLE_DOC}/nethack.txt) -install(TARGETS makedefs dgn_comp lev_comp dlb recover DESTINATION ${INSTDIR}) +install(TARGETS makedefs dlb recover DESTINATION ${INSTDIR}) install(FILES ${MAN_PAGES} DESTINATION ${INSTDIR}/man) install(FILES ${TXT_DOCS} DESTINATION ${INSTDIR}/doc) diff --git a/win/rl/pynethack.cc b/win/rl/pynethack.cc index fefd99c21..5d651edc7 100644 --- a/win/rl/pynethack.cc +++ b/win/rl/pynethack.cc @@ -13,7 +13,7 @@ extern "C" { #include "hack.h" #include "permonst.h" -#include "pm.h" // File generated during NetHack compilation. +// #include "pm.h" // File generated during NetHack compilation. #include "rm.h" } @@ -37,7 +37,7 @@ extern int total_tiles_used; /* also in tile.c */ boolean In_hell(d_level *lev) { - return (boolean) (dungeons[lev->dnum].flags.hellish); + return (boolean) (svd.dungeons[lev->dnum].flags.hellish); } /* are you in the mines dungeon? */ @@ -474,7 +474,7 @@ class Nethack if (tile_index < 0 || tile_index >= total_tiles_used) { fprintf(stderr, "Invalid tile index %d for glyph %d at position " - "(%ld,%ld)\n", + "(%d,%d)\n", tile_index, glyph, tile_row, tile_col); continue; } @@ -641,28 +641,28 @@ PYBIND11_MODULE(_pynethack, m) // MAXWIN is #defined as 20 there. mn.attr("MAXWIN") = py::int_(20); - mn.attr("NUMMONS") = py::int_(NUMMONS); - mn.attr("NUM_OBJECTS") = py::int_(NUM_OBJECTS); + mn.attr("NUMMONS") = py::int_((int) NUMMONS); + mn.attr("NUM_OBJECTS") = py::int_((int) NUM_OBJECTS); // Glyph array offsets. This is what the glyph_is_* functions // are based on, see display.h. - mn.attr("GLYPH_MON_OFF") = py::int_(GLYPH_MON_OFF); - mn.attr("GLYPH_PET_OFF") = py::int_(GLYPH_PET_OFF); - mn.attr("GLYPH_INVIS_OFF") = py::int_(GLYPH_INVIS_OFF); - mn.attr("GLYPH_DETECT_OFF") = py::int_(GLYPH_DETECT_OFF); - mn.attr("GLYPH_BODY_OFF") = py::int_(GLYPH_BODY_OFF); - mn.attr("GLYPH_RIDDEN_OFF") = py::int_(GLYPH_RIDDEN_OFF); - mn.attr("GLYPH_OBJ_OFF") = py::int_(GLYPH_OBJ_OFF); - mn.attr("GLYPH_CMAP_OFF") = py::int_(GLYPH_CMAP_OFF); - mn.attr("GLYPH_EXPLODE_OFF") = py::int_(GLYPH_EXPLODE_OFF); - mn.attr("GLYPH_ZAP_OFF") = py::int_(GLYPH_ZAP_OFF); - mn.attr("GLYPH_SWALLOW_OFF") = py::int_(GLYPH_SWALLOW_OFF); - mn.attr("GLYPH_WARNING_OFF") = py::int_(GLYPH_WARNING_OFF); - mn.attr("GLYPH_STATUE_OFF") = py::int_(GLYPH_STATUE_OFF); - mn.attr("MAX_GLYPH") = py::int_(MAX_GLYPH); - - mn.attr("NO_GLYPH") = py::int_(NO_GLYPH); - mn.attr("GLYPH_INVISIBLE") = py::int_(GLYPH_INVISIBLE); + mn.attr("GLYPH_MON_OFF") = py::int_((int) GLYPH_MON_OFF); + mn.attr("GLYPH_PET_OFF") = py::int_((int) GLYPH_PET_OFF); + mn.attr("GLYPH_INVIS_OFF") = py::int_((int) GLYPH_INVIS_OFF); + mn.attr("GLYPH_DETECT_OFF") = py::int_((int) GLYPH_DETECT_OFF); + mn.attr("GLYPH_BODY_OFF") = py::int_((int) GLYPH_BODY_OFF); + mn.attr("GLYPH_RIDDEN_OFF") = py::int_((int) GLYPH_RIDDEN_OFF); + mn.attr("GLYPH_OBJ_OFF") = py::int_((int) GLYPH_OBJ_OFF); + mn.attr("GLYPH_CMAP_OFF") = py::int_((int) GLYPH_CMAP_OFF); + mn.attr("GLYPH_EXPLODE_OFF") = py::int_((int) GLYPH_EXPLODE_OFF); + mn.attr("GLYPH_ZAP_OFF") = py::int_((int) GLYPH_ZAP_OFF); + mn.attr("GLYPH_SWALLOW_OFF") = py::int_((int) GLYPH_SWALLOW_OFF); + mn.attr("GLYPH_WARNING_OFF") = py::int_((int) GLYPH_WARNING_OFF); + mn.attr("GLYPH_STATUE_OFF") = py::int_((int) GLYPH_STATUE_OFF); + mn.attr("MAX_GLYPH") = py::int_((int) MAX_GLYPH); + + mn.attr("NO_GLYPH") = py::int_((int) NO_GLYPH); + mn.attr("GLYPH_INVISIBLE") = py::int_((int) GLYPH_INVISIBLE); mn.attr("MAXEXPCHARS") = py::int_(MAXEXPCHARS); mn.attr("MAXPCHARS") = py::int_(static_cast(MAXPCHARS)); @@ -799,7 +799,19 @@ PYBIND11_MODULE(_pynethack, m) v_h.set_holder_constructed(true); }, py::detail::is_new_style_constructor()) - .def_readonly("mname", &permonst::mname) /* full name */ + /* TODO: NetHack 5 introduces gendered names for monsters. + NLE needs to be aware of this. */ + .def_static( + "mname", + [](const permonst &pm, int idx) -> const char * { + if (idx < 0 || idx >= NUM_MGENDERS) + throw std::out_of_range( + "Argument should be between 0 and NUM_MGENDERS (" + + std::to_string(NUM_MGENDERS) + ") but got " + + std::to_string(idx)); + return pm.pmnames[idx]; + }, + py::return_value_policy::reference) .def_readonly("mlet", &permonst::mlet) /* symbol */ .def_readonly("mlevel", &permonst::mlevel) /* base monster level */ .def_readonly("mmove", &permonst::mmove) /* move speed */ diff --git a/win/rl/winrl.cc b/win/rl/winrl.cc index f3159ba44..03dacb8af 100644 --- a/win/rl/winrl.cc +++ b/win/rl/winrl.cc @@ -118,32 +118,33 @@ class NetHackRL static void rl_resume_nhwindows(); static winid rl_create_nhwindow(int type); static void rl_clear_nhwindow(winid wid); - static void rl_display_nhwindow(winid wid, BOOLEAN_P block); + static void rl_display_nhwindow(winid wid, boolean block); static void rl_destroy_nhwindow(winid wid); static void rl_curs(winid wid, int x, int y); static void rl_putstr(winid wid, int attr, const char *text); - static void rl_display_file(const char *filename, BOOLEAN_P must_exist); - static void rl_start_menu(winid wid); - static void rl_add_menu(winid wid, int glyph, const ANY_P *identifier, - CHAR_P ch, CHAR_P gch, int attr, const char *str, - BOOLEAN_P presel); + static void rl_display_file(const char *filename, boolean must_exist); + static void rl_start_menu(winid wid, unsigned long mbehavior); + static void rl_add_menu(winid wid, const glyph_info *glyphinfo, + const ANY_P *identifier, char ch, char gch, + int attr, int colour, const char *str, + unsigned int presel); static void rl_end_menu(winid wid, const char *prompt); static int rl_select_menu(winid wid, int how, MENU_ITEM_P **menu_list); - static void rl_update_inventory(); static void rl_mark_synch(); static void rl_wait_synch(); static void rl_cliparound(int x, int y); - static void rl_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, - int bkglyph); + static void rl_print_glyph(winid wid, coordxy x, coordxy y, + const glyph_info *glyphinfo, + const glyph_info *bkglyphinfo); static void rl_raw_print(const char *str); static void rl_raw_print_bold(const char *str); static int rl_nhgetch(); - static int rl_nh_poskey(int *x, int *y, int *mod); + static int rl_nh_poskey(coordxy *x, coordxy *y, int *mod); static void rl_nhbell(); static int rl_doprev_message(); static char rl_yn_function(const char *question, const char *choices, - CHAR_P def); + char def); static void rl_getlin(const char *prompt, char *line); static int rl_get_ext_cmd(); static void rl_number_pad(int); @@ -151,8 +152,8 @@ class NetHackRL static void rl_start_screen(); static void rl_end_screen(); - static char *rl_getmsghistory(BOOLEAN_P init); - static void rl_putmsghistory(const char *msg, BOOLEAN_P is_restoring); + static char *rl_getmsghistory(boolean init); + static void rl_putmsghistory(const char *msg, boolean is_restoring); static void rl_outrip(winid wid, int how, time_t when); static void rl_status_init(); @@ -161,16 +162,19 @@ class NetHackRL int percent, int color, unsigned long *colormasks); + static void rl_update_inventory(int arg UNUSED); + private: struct rl_menu_item { - int glyph; /* character glyph */ - anything identifier; /* user identifier */ - long count; /* user count */ - std::string str; /* description string */ - int attr; /* string attribute */ - boolean selected; /* TRUE if selected by user */ - char selector; /* keyboard accelerator */ - char gselector; /* group accelerator */ + const glyph_info + *glyphinfo; /* glyph to display with item (not used) */ + anything identifier; /* user identifier */ + long count; /* user count */ + std::string str; /* description string */ + int attr; /* string attribute */ + unsigned int selected; /* TRUE if selected by user */ + char selector; /* keyboard accelerator */ + char gselector; /* group accelerator */ }; struct rl_window { @@ -207,7 +211,7 @@ class NetHackRL void store_glyph(XCHAR_P x, XCHAR_P y, int glyph); void store_mapped_glyph(int ch, int color, int special, XCHAR_P x, XCHAR_P y); - void store_screen_description(XCHAR_P x, XCHAR_P y, int glyph); + void store_screen_description(coordxy x, coordxy y, int glyph); void fill_obs(nle_obs *); int getch_method(); @@ -226,15 +230,16 @@ class NetHackRL std::vector inventory_; - void start_menu_method(winid wid); - void add_menu_method(winid wid, int glyph, const anything *identifier, - char ch, char gch, int attr, const char *str, - bool preselected); + void start_menu_method(winid wid, unsigned long mbehavior); + void add_menu_method(winid wid, const glyph_info *glyph, + const anything *identifier, char ch, char gch, + int attr, int colour, const char *str, + unsigned int preselected); void update_inventory_method(); winid create_nhwindow_method(int type); void clear_nhwindow_method(winid wid); - void display_nhwindow_method(winid wid, BOOLEAN_P block); + void display_nhwindow_method(winid wid, boolean block); void destroy_nhwindow_method(winid wid); }; @@ -271,15 +276,18 @@ NetHackRL::fill_obs(nle_obs *obs) } if (obs->internal) { // From do.c. sstairs is a potential "special" staircase. + /* boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair) || (u.ux == sstairs.sx && u.uy == sstairs.sy && !sstairs.up)); + */ obs->internal[0] = deepest_lev_reached(false); obs->internal[1] = in_yn_function; obs->internal[2] = in_getlin; obs->internal[3] = xwaitingforspace; - obs->internal[4] = stairs_down; + stairway *stway = stairway_at(u.ux, u.uy); + obs->internal[4] = (stway && !stway->up); obs->internal[5] = 0; /* used to be core seed */ obs->internal[6] = 0; /* used to be disp seed */ obs->internal[7] = u.uhunger; @@ -347,7 +355,7 @@ NetHackRL::fill_obs(nle_obs *obs) win->strings.back().c_str(), NLE_MESSAGE_SIZE); } else if (ttyDisplay->toplin) { // Copy toplines[], see topl.c. - std::strncpy((char *) &obs->message[0], toplines, + std::strncpy((char *) &obs->message[0], gt.toplines, NLE_MESSAGE_SIZE); } else { std::memset(obs->message, 0, NLE_MESSAGE_SIZE); @@ -364,7 +372,7 @@ NetHackRL::fill_obs(nle_obs *obs) blstats will be updated. */ blstats_[NLE_BL_X] = u.ux - 1; /* x coordinate, 1 <= ux <= cols */ blstats_[NLE_BL_Y] = u.uy; /* y coordinate, 0 <= uy < rows */ - blstats_[NLE_BL_TIME] = moves; + blstats_[NLE_BL_TIME] = svm.moves; } std::memcpy(obs->blstats, &blstats_[0], sizeof(blstats_)); } @@ -450,10 +458,11 @@ NetHackRL::update_inventory_method() list up to date via the following code adopted from display_pickinv in invent.c */ + /* TODO: Recheck this code for NetHack5 upgrade*/ struct obj *otmp; inventory_.clear(); - for (otmp = invent; otmp; otmp = otmp->nobj) { + for (otmp = gi.invent; otmp; otmp = otmp->nobj) { inventory_.emplace_back(rl_inventory_item{ shuffled_glyph(obj_to_glyph(otmp, rn2_on_display_rng)), doname(otmp), otmp->invlet, otmp->oclass, @@ -488,7 +497,7 @@ NetHackRL::store_mapped_glyph(int ch, int color, int special, XCHAR_P x, } void -NetHackRL::store_screen_description(XCHAR_P x, XCHAR_P y, int glyph) +NetHackRL::store_screen_description(coordxy x, coordxy y, int glyph) { // 1 <= x < cols, 0 <= y < rows (!) size_t i = (x - 1) % (COLNO - 1); @@ -545,7 +554,7 @@ NetHackRL::update_blstats() blstats_[NLE_BL_HP] = hitpoints; /* hitpoints */ blstats_[NLE_BL_HPMAX] = max_hitpoints; /* max_hitpoints */ blstats_[NLE_BL_DEPTH] = depth(&u.uz); /* depth */ - blstats_[NLE_BL_GOLD] = money_cnt(invent); /* gold */ + blstats_[NLE_BL_GOLD] = money_cnt(gi.invent); /* gold */ blstats_[NLE_BL_ENE] = min(u.uen, 9999); /* energy */ blstats_[NLE_BL_ENEMAX] = min(u.uenmax, 9999); /* max_energy */ blstats_[NLE_BL_AC] = u.uac; /* armor_class */ @@ -553,7 +562,7 @@ NetHackRL::update_blstats() : 0; /* monster level, hit-dice */ blstats_[NLE_BL_XP] = u.ulevel; /* experience level */ blstats_[NLE_BL_EXP] = u.uexp; /* experience points */ - blstats_[NLE_BL_TIME] = moves; /* time */ + blstats_[NLE_BL_TIME] = svm.moves; /* time */ blstats_[NLE_BL_HUNGER] = u.uhs; /* hunger state */ blstats_[NLE_BL_CAP] = near_capacity(); /* carrying capacity */ blstats_[NLE_BL_DNUM] = u.uz.dnum; /* dungeon number */ @@ -657,7 +666,7 @@ NetHackRL::clear_nhwindow_method(winid wid) } void -NetHackRL::display_nhwindow_method(winid wid, BOOLEAN_P block) +NetHackRL::display_nhwindow_method(winid wid, boolean block) { DEBUG_API("rl_display_nhwindow(wid=" << wid << ", block=" << block << ")" << std::endl); @@ -674,34 +683,37 @@ NetHackRL::destroy_nhwindow_method(winid wid) } void -NetHackRL::start_menu_method(winid wid) +NetHackRL::start_menu_method(winid wid, unsigned long mbehavior) { - DEBUG_API("rl_start_menu(wid=" << wid << ")" << std::endl); - tty_start_menu(wid); + DEBUG_API("rl_start_menu(wid=" << wid << ", mbehavior=" << mbehavior + << ")" << std::endl); + tty_start_menu(wid, mbehavior); windows_[wid]->menu_items.clear(); } void NetHackRL::add_menu_method( - winid wid, /* window to use, must be of type NHW_MENU */ - int glyph, /* glyph to display with item (not used) */ - const anything *identifier, /* what to return if selected */ - char ch, /* keyboard accelerator (0 = pick our own) */ - char gch, /* group accelerator (0 = no group) */ - int attr, /* attribute for string (like putstr()) */ - const char *str, /* menu string */ - bool preselected /* item is marked as selected */ + winid wid, /* window to use */ + const glyph_info *glyphinfo, /* glyph to display with item (not used) */ + const anything *identifier, /* what to return if selected */ + char ch, /* keyboard accelerator (0 = pick our own) */ + char gch, /* group accelerator (0 = no group) */ + int attr, /* attribute for string (like putstr()) */ + int colour, /* color for string */ + const char *str, /* menu string */ + unsigned int preselected /* item is marked as selected */ ) { DEBUG_API("rl_add_menu" << std::endl); - tty_add_menu(wid, glyph, identifier, ch, gch, attr, str, preselected); + tty_add_menu(wid, glyphinfo, identifier, ch, gch, attr, colour, str, + preselected); /* We just add the menu item here. One problem with this method is that we won't see any updates happening during tty_select_menu. We could try to inspect tty's own menu items instead? */ windows_[wid]->menu_items.emplace_back(rl_menu_item{ - glyph, *identifier, -1L, str, attr, preselected, ch, gch }); + glyphinfo, *identifier, -1L, str, attr, preselected, ch, gch }); } void @@ -787,7 +799,7 @@ NetHackRL::rl_clear_nhwindow(winid wid) -- Calling display_nhwindow(WIN_MESSAGE,???) will do a --more--, if necessary, in the tty window-port. */ void -NetHackRL::rl_display_nhwindow(winid wid, BOOLEAN_P block) +NetHackRL::rl_display_nhwindow(winid wid, boolean block) { ScopedStack s(win_proc_calls, "display_nhwindow"); instance->display_nhwindow_method(wid, block); @@ -821,7 +833,7 @@ NetHackRL::rl_putstr(winid wid, int attr, const char *text) } void -NetHackRL::rl_display_file(const char *filename, BOOLEAN_P must_exist) +NetHackRL::rl_display_file(const char *filename, boolean must_exist) { DEBUG_API("rl_display_file" << std::endl); ScopedStack s(win_proc_calls, "display_file"); @@ -829,20 +841,20 @@ NetHackRL::rl_display_file(const char *filename, BOOLEAN_P must_exist) } void -NetHackRL::rl_start_menu(winid wid) +NetHackRL::rl_start_menu(winid wid, unsigned long mbehavior) { ScopedStack s(win_proc_calls, "start_menu"); - instance->start_menu_method(wid); + instance->start_menu_method(wid, mbehavior); } void -NetHackRL::rl_add_menu(winid wid, int glyph, const ANY_P *identifier, - CHAR_P ch, CHAR_P gch, int attr, const char *str, - BOOLEAN_P presel) +NetHackRL::rl_add_menu(winid wid, const glyph_info *glyphinfo, + const ANY_P *identifier, char ch, char gch, int attr, + int colour, const char *str, unsigned int presel) { ScopedStack s(win_proc_calls, "add_menu"); - instance->add_menu_method(wid, glyph, identifier, ch, gch, attr, str, - presel); + instance->add_menu_method(wid, glyphinfo, identifier, ch, gch, attr, + colour, str, presel); } void @@ -864,7 +876,7 @@ NetHackRL::rl_select_menu(winid wid, int how, MENU_ITEM_P **menu_list) } void -NetHackRL::rl_update_inventory() +NetHackRL::rl_update_inventory(int arg UNUSED) { DEBUG_API("rl_update_inventory" << std::endl); ScopedStack s(win_proc_calls, "update_inventory"); @@ -895,7 +907,7 @@ NetHackRL::rl_cliparound(int x, int y) #endif } -/* print_glyph(window, x, y, glyph, bkglyph) +/* print_glyph(window, x, y, *glyph_info, *bkglyph_info) -- Print the glyph at (x,y) on the given window. Glyphs are integers at the interface, mapped to whatever the window- port wants (symbol, font, color, attributes, ...there's @@ -906,46 +918,44 @@ NetHackRL::rl_cliparound(int x, int y) around x,y. If bkglyph is NO_GLYPH, then the parameter should be ignored (do nothing with it). */ void -NetHackRL::rl_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, - int bkglyph) +NetHackRL::rl_print_glyph(winid wid, coordxy x, coordxy y, + const glyph_info *glyphinfo, + const glyph_info *bkglyphinfo) { - int ch; int color; - unsigned special; - - (void) mapglyph(glyph, &ch, &color, &special, x, y, 0); -#if USE_DEBUG_API - DEBUG_API("rl_print_glyph(wid=" << wid << ", x=" << x << ", y=" << y - << ", glyph=(ch='" << (char) ch - << "', color=" << color - << ", special=" << special); - int bch; - int bcolor; - unsigned bspecial; - (void) mapglyph(bkglyph, &bch, &bcolor, &bspecial, x, y, 0); - DEBUG_API("), bkglyph=(ch='" << (char) bch << "', color=" << bcolor - << ", special=" << bspecial << ")" - << std::endl); -#endif + /* TODO: Remove the comments from this #define when NetHack5 upgrade is + * complete */ + // #if USE_DEBUG_API + DEBUG_API("rl_print_glyph(wid=" + << wid << ", x=" << x << ", y=" << y << ", glyph=(ch='" + << (char) glyphinfo->ttychar + << "', color=" << glyphinfo->gm.sym.color); + DEBUG_API("), bkglyph=(ch='" << (char) bkglyphinfo->ttychar << "', color=" + << bkglyphinfo->framecolor << std::endl); + // #endif // No win_proc_calls entry here. if (wid == WIN_MAP) { - instance->store_glyph(x, y, glyph); - if (glyph != nul_glyph && color == CLR_BLACK) { + instance->store_glyph(x, y, glyphinfo->glyph); + if (glyphinfo->glyph != nul_glyph + && glyphinfo->gm.sym.color == CLR_BLACK) { /* This will be 'bright black' (or blue) on tty so we change it to * make NLE's colors and tty_colors stay compatible. */ color = iflags.wc2_darkgray ? 8 : CLR_BLUE; + } else { + color = glyphinfo->gm.sym.color; } - instance->store_mapped_glyph(ch, color, special, x, y); + instance->store_mapped_glyph(glyphinfo->ttychar, color, + glyphinfo->gm.glyphflags, x, y); if (nle_get_obs()->screen_descriptions) { - instance->store_screen_description(x, y, glyph); + instance->store_screen_description(x, y, glyphinfo->glyph); } } else { DEBUG_API("Window id is " << wid << ". This shouldn't happen." << std::endl); } - tty_print_glyph(wid, x, y, glyph, bkglyph); + tty_print_glyph(wid, x, y, glyphinfo, bkglyphinfo); } void NetHackRL::rl_raw_print(const char *str) @@ -980,7 +990,7 @@ NetHackRL::rl_nhgetch() } int -NetHackRL::rl_nh_poskey(int *x, int *y, int *mod) +NetHackRL::rl_nh_poskey(coordxy *x, coordxy *y, int *mod) { nhUse(x); nhUse(y); @@ -1012,7 +1022,7 @@ NetHackRL::rl_doprev_message() char NetHackRL::rl_yn_function(const char *question_, const char *choices, - CHAR_P def) + char def) { DEBUG_API("rl_yn_function" << std::endl); ScopedStack s(win_proc_calls, "yn_function"); @@ -1054,7 +1064,7 @@ NetHackRL::rl_delay_output() DEBUG_API("rl_delay_output" << std::endl); // No call to tty_delay_output() as we don't actually want delays. } - +/* void NetHackRL::rl_start_screen() { @@ -1076,7 +1086,7 @@ NetHackRL::rl_end_screen() // global objects. So we do it here. instance.reset(nullptr); } - +*/ void NetHackRL::rl_outrip(winid wid, int how, time_t when) { @@ -1085,14 +1095,14 @@ NetHackRL::rl_outrip(winid wid, int how, time_t when) } char * -NetHackRL::rl_getmsghistory(BOOLEAN_P init) +NetHackRL::rl_getmsghistory(boolean init) { DEBUG_API("rl_getmsghistory" << std::endl); return tty_getmsghistory(init); } void -NetHackRL::rl_putmsghistory(const char *msg, BOOLEAN_P is_restoring) +NetHackRL::rl_putmsghistory(const char *msg, boolean is_restoring) { DEBUG_API("rl_putmsghistory" << std::endl); tty_putmsghistory(msg, is_restoring); @@ -1132,7 +1142,7 @@ rl_update_positionbar(char *chrs) } // namespace nethack_rl struct window_procs rl_procs = { - "rl", + WPID(rl), (WC_COLOR | WC_HILITE_PET | WC_INVERSE | WC_EIGHT_BIT_IN | WC_PERM_INVENT), (0 @@ -1166,7 +1176,6 @@ struct window_procs rl_procs = { nethack_rl::NetHackRL::rl_end_menu, nethack_rl::NetHackRL::rl_select_menu, genl_message_menu, /* no need for X-specific handling */ - nethack_rl::NetHackRL::rl_update_inventory, nethack_rl::NetHackRL::rl_mark_synch, nethack_rl::NetHackRL::rl_wait_synch, #ifdef CLIPPING @@ -1176,7 +1185,6 @@ struct window_procs rl_procs = { nethack_rl::rl_update_positionbar, #endif nethack_rl::NetHackRL::rl_print_glyph, - // NetHackRL::rl_print_glyph_compose, nethack_rl::NetHackRL::rl_raw_print, nethack_rl::NetHackRL::rl_raw_print_bold, nethack_rl::NetHackRL::rl_nhgetch, @@ -1194,9 +1202,6 @@ struct window_procs rl_procs = { donull, donull, #endif - /* other defs that really should go away (they're tty specific) */ - nethack_rl::NetHackRL::rl_start_screen, - nethack_rl::NetHackRL::rl_end_screen, #ifdef GRAPHIC_TOMBSTONE nethack_rl::NetHackRL::rl_outrip, #else @@ -1210,4 +1215,5 @@ struct window_procs rl_procs = { tty_status_enablefield, nethack_rl::NetHackRL::rl_status_update, genl_can_suspend_yes, + nethack_rl::NetHackRL::rl_update_inventory, };