0

I have been trying to learn about GUI frontends for Nethack, but I have been unable to determine how do they get the game information (map, inventory, player info, enemy locations, etc) from Nethack? As in, is there some API that allows these frontends to query these information? If so, how are they used?

I have looked up everywhere but unable to find any documentation that describes how to do so.

Pikalek
  • 12,372
  • 5
  • 43
  • 51
SargentD
  • 103
  • 2

1 Answers1

0

There are a couple of options for building a NetHack front end. Some graphical versions of NetHack are true front ends meaning they are only additions and do not modify NetHack. Others are more correctly referred to as graphical variants, they are modifications of NetHack that include changes to the source code for rendering graphics. Even though the later are not technically front ends, the differences are largely invisible to the player, so I've included information regarding both.

A note for those less familiar with older roguelike development: 'console' refers to the command line interface.

Direct Source Code Development

NetHack is open source and has been ported to a variety of languages and platforms. The most direct way to build a front end is to use the source code directly. This option provides the most flexibility as you have full access to the internal workings of the game. It's also probably the most complex, as you will need to develop a good working understanding of the source code. Essentially you:

  • determine the layout for conveying the game information to the user
  • develop your graphics
  • replace the output calls with graphical equivalents

From what I understand, this is how the Nintendo DS version works as it was ported the source was modified to support sprite output.

Note: sometimes instead of replacing the output, it is actual supplemented. That is graphics are added, but the console output is left in place as it can be useful for debugging and can reduce the number of changes (and thus opportunities for bugs) in the source. The ASCII output window can be minimized or redirected to /dev/null if needed.

Interpret NetHack's Output

It is possible to translate the console output from NetHack into graphics. This is the approach used by Necklace of the Eye (NotEye in short) - it uses a Lua script to interpret NetHack's console output and determine how to replace the ASCII text with a graphical interface. While this may be conceptually simpler than understanding the source code for the game, it still requires a complete understanding of the game itself & the possible output. Generally speaking, the steps would be something like this:

  • determine the layout for conveying the game information to the user
  • develop your graphics
  • intercept the console output
  • interpret the console output
  • display graphics
  • pass user input back into the console game

There are at least a couple of ways to implement this approach - to the best of my knowledge, they are OS family specific. At one end of the spectrum, you could use something like command line pipes. More complex solutions (like those in Necklace of the Eye) rely OS APIs, using things like getstdhandle or posix_openpt.

Modify an existing front end or variant

Instead of starting from the original source, you could modify an existing graphical variant or front end. Some are open source and can be directly changed. Others can be changed via scripts or config files. The exact steps for this route will vary greatly depending on which particular variant / front end you are attempting to change & the types of changes you are making.

Modify a tileset

The easiest, but also least flexible option is to start with a graphical version of NetHack that uses a tileset (sometimes just called tiles or sprites) and change just the graphics. Using this approach you are limited to graphical substitutions. You likely won't be able to change the location for displaying health for instance, but you could replace the sprite for an item or enemy with a different sprite.

The RogueBasin NetHack page is a good resource for NetHack variants & front ends. There's also a variety resources posted on the NetHack Wiki.

Pikalek
  • 12,372
  • 5
  • 43
  • 51
  • Yes, I am interested in the "Interpret NetHack's Output" approach. The main blind area for me is how to do so. Do I start the game in the background and simply interpret the text in STDOUT or is there a more efficient way via an API perhaps? – SargentD Feb 03 '21 at 10:03
  • I've edited to include a little bit more about the option you're interested in. The specifics of "how do I intercept text output from another program" is a big enough problem to be asked as its own question & might be better suited to Stack Overflow. – Pikalek Feb 03 '21 at 15:51
  • I have been sleeping over your response for a while and I have realized that interpreting the text output might not be enough since in Nethack characters are reused for similar type of monsters. For example, d could mean Dog, Wolf, Jackal, Fox, etc. which will not be easy to determine by simply looking at the character. However, I remember that Vulture renders the correct sprites, so I guess there must be someway to determine the type of monster that goes beyond simple text interception. – SargentD Feb 05 '21 at 09:56
  • It depends. Some consoles support color text which can be used to disambiguate reused symbols. And unless your character is blind, the look command doesn't use game time, so an interpreter could use that as needed. Looking at the source code for Vulture, I see a lot of NetHack source files, so my guess would be that they opted to use a "Direct Source Code Development" type solution. – Pikalek Feb 05 '21 at 14:55
  • Makes sense I suppose. Looks like the best solution is to deep dive Nethack's source code. – SargentD Feb 08 '21 at 10:07