Playing for Keeps

NetHack is one of the oldest open source games around. But a few avid players have modernized -- or modded, as gamers would say -- the Unix classic, adding bitmapped graphics, sound effects, and music. Meet the developers of Slash'EM and Falcon's Eye -- some programmers that work hard and play harder.

Like certain models of cars, some computer games inspire avid players to dream up mods, or ways to modify and enhance the games. NetHack (http://www.nethack.org), a free, open source dungeon exploration game that’s nearly eighteen years old, is just such a game.

Over the years, NetHack fans with programming talent have dreamed up and realized all kinds of clever ways to enhance the basic game, including adding player character races, monsters, and spells. Other fans with a more artistic bent have also upgraded the original game’s minimalist graphics, replacing its baroque palette of ASCII symbols — @ for your character, $ for gold, and = for a ring — with bitmap images.

Two notable projects that enhance gameplay and graphics are Slash’EM and Falcon’s Eye. Slash’EM (http://slashem.sourceforge.net) is unique because it combines the best patches and upgrades that others have made to NetHack and runs the game in a graphical window interface. Falcon’s Eye (http://falconseye.sourceforge.net) goes even further, adding a graphical, SimCity-like, isometric perspective to game play.

Let’s take a look at Slash’EM and Falcon’s Eye, and in the process, follow the labyrinthine twists and turns of NetHack history.

Exploring NetHack

NetHack began simply as “Hack,” a dungeon exploration game modeled after another dungeon exploration game, rogue, developed at the University of California, Berkeley to run on BSD Unix. Early in the course of its evolution, “Net” was eventually added to “Hack.” “Net” isn’t a reference to the gameplay — NetHack isn’t played on a network, it’s a solo-player adventure — but to the Internet, through which dozens of contributors have collaborated to refine the game over the years. Figure Four shows the genealogy of NetHack.

Here’s the gist of NetHack: you’re a dungeon adventurer and treasure seeker. While there are hordes of monsters to battle, the emphasis is on exploration instead of outright hacking, slashing, and killing. In fact, going on a DOOM-like killing spree is a surefire way to lose real fast. You can pick your character’s race (human, orc, elf, dwarf, or gnome) and choose a role (the possibilities include knight, ranger, rogue, and wizard).

Dungeon maps feature doorways, traps, ladders, and stairs. Some of the many items to be found are weapons, armors, spellbooks, amulets, gems, and gold stashes. Keeping the game play fresh, every session of NetHack is unique: the code cranks out a randomly-generated dungeon map whenever you start a new game.

Figure One: The simple graphics of the original NetHack

The design philosophy of NetHack is to maintain a deceptively simple looking, minimalist appearance, but offer underlying gameplay that’s incredibly deep and rich. (Yes, NetHack can be maddeningly complex to learn how to play.) Thus, the code is not weighed down by extraneous material like graphics, sound or elaborate user input code. This approach helps to insure that NetHack’s source remains readily portable: NetHack runs on virtually any platform (Linux, UNIX, Windows, DOS, Macintosh, BeOS, OS/2 and so on) with minimal hassle. NetHack presents the player with no flash. No dazzle. Just “pure” gameplay. Figure One captures the simple graphics of NetHack.

Yet NetHack’s code modularity has enabled many programmers, most of whom aren’t among the official NetHack development team, to upgrade it with added gameplay features or lay fancy multimedia elements over the basic “engine” of the game. Figure Four shows the genealogy of NetHack and other variants.

Mash ‘em to Make Slash’EM

“It’s overstating it to say that Slash’EM includes virtually every [NetHack] patch — probably about half of [all patches] eventually make it into Slash’EM,” says J. Ali Harlow, 36, a programmer from London, England, and one of the current maintainers of Slash’EM.

Slash’EM is written in C, and its Qt window interface in C++. Of course, because of its NetHack lineage, it contains lots of code that the present team supporting it didn’t originally develop. Normally, incorporating code from outside a project can be a hassle due to incompatibilities among various open source licenses. Fortunately, Harlow says things work differently within the NetHack community because code is shared among different projects. “There’s no such problem with code that’s been written to be used with NetHack. We seek to use the best of these whenever possible.”

Slash’EM’s origins date back to 1996 when Warren Cheung first tried to merge a variant of NetHack called Slash with the popular Wizard Patch. At the time, Cheung — now 23 and a computer research assistant in Vancouver, British Columbia, Canada — had no prior knowledge of C and had never compiled anything before. Thus, his initial attempt at combining the two failed. A year went by before he gave the idea another shot, and finally, after applying “… a small amount of additional knowledge, a healthy portion of luck, and … simple stubbornness,” according to Cheung, Slash’EM was born. A screenshot of Slash’EM is shown in Figure Two.

Figure Two: Slash’EM in action

Interestingly, few technical conflicts arose in blending the separate Slash and Wizard Patch code. This is partly because the design of each of those code sets was different from the other’s: Slash’s code added new gameplay elements — such as more monsters and objects. The Wizard Patch primarily dealt with upgrading the spellcasting component of the game, which is largely untouched by Slash.

After Slash and the Wizard Patch were melded, code from several other NetHack variants and patches — including AllegroHack, glHack, and the Lethe Patch — were added to the mix. But, all throughout, the Slash’EM developers found that they didn’t have to alter the code of these patches much either to get them to work together. “True conflicts only occur when two patches change the same aspect of the code — do we keep the original, one of the patches, or somehow make everyone ‘play ball’?” says Cheung.

Thus, because of NetHack’s code modularity, integrating so many patches to create Slash’EM has been relatively “simple.” Harlow says that integrating GTK+ was pretty easy, too: “I don’t recall any problems with doing that, although over the years I have slowly re-written the interface for various reasons until the current version is very different from [the author's] original. It still looks much the same, though.”

“Knock-on Consequences”

That’s not to imply that there are no technical issues when merging different NetHack flavors under the Slash’EM banner. The strength of NetHack’s code lies in the huge range of interactions it allows between objects in the game and the consistency it maintains while doing this. Complex interactions have a downside, as Harlow describes: “As soon as you change one thing, you need to think very carefully about what else needs changing to keep consistency.”

One example of this problem is lava. Harlow wanted to alter the gameplay so that objects are vulnerable to damage by lava pools (represented by a } in NetHack). Doing this was straightforward, until Harlow realized that he also had to consider what should happen to containers, another element in the game that’s damaged by lava. Ultimately, he decided all containers, except ice boxes, would be destroyed by lava and their contents damaged.

Adding any new interactive feature in NetHack has a trickle-down effect throughout its gaming environment, and these effects need to make logical sense in terms of gameplay. “Every change has knock-on consequences, and the hardest thing is working through them and making the right judgment calls so that the end result is a better game,” says Harlow.

Then there’s the process of incorporating NetHack itself. Whenever a new version of the (core) game is released, the Slash’EM developers have to choose what immediate elements of their code should be altered to accommodate the latest NetHack. A new release of NetHack generally results in what Cheung describes as a gargantuan patch that modifies almost every file within Slash’EM. From there, the team must slog through a 5-10 MB patch file and integrate the changes.

“Most of it is an all-or-nothing deal — you either change everything or only change a very small part of the code,” says Cheung. “This made the upgrade to NetHack 3.3 fairly scary. There was a period of three months where Slash’EM was basically dead while I slowly whittled away at the patch file. The massive effort that tackled NetHack 3.4 (of which I was only a small part) impressed me to no end. That one focused, coordinated effort finished the entire merge in little more than a week.”

Of Windows and Keyboards

Beyond code merging, one of the significant technical challenges in developing Slash’EM has been perfecting its proxy window interface. The concept of a proxy window interface is rather simple: the game runs as one process while the window interface runs as another, separate process — each may even run on different machines. But the two must communicate with one another using a protocol that’s understood by the proxy window interface.

Harlow’s been been working on this element. The major challenge has been to design a protocol independent of machine architecture (Harlow settled on RFC 1014, XDR: External Data Representation Standard) and doesn’t require much overhead. He says, “I’m still working on fine-tuning the protocol to reduce overhead. One obvious improvement would be to move to an asynchronous protocol, rather than the current, simple synchronous protocol.”

(An advantage of the synchronous protocol is that both the client and server know whether they should be reading or writing. Because NhExt packets contain a length field in the header, the proxy interface can issue a read call without worrying about the fact that it may block. With an asynchronous protocol, the proxy interface has to be able to issue non-blocking read calls. There also needs to be a system for tracking packets so that replies can be associated with requests. “Of course, none of these problems are new and, in particular, have been solved in the X11 protocol, which I am hoping to use as a pattern [for Slash'EM],” Harlow says.)

The Slash’EM window interfaces pose another problem: while NetHack has a well-defined API for use when the game calls a window interface, it has very little in the way of an API for a window interface to use when querying back to the game, which is what the Slash’EM interface needs to do. The solution to this had to be designed from scratch.

“The process is complicated by the fact that we need to be flexible enough that future window interfaces will have everything they need, but not so flexible that an external window interface could be used to cheat when playing with an official binary,” says Harlow. “I believe I’ve achieved the latter, but I’m still a long way from achieving the former. What we need to do is examine the state information that the game holds and decide which parts should be made available to external interfaces. Once this is established, new remote procedures can be designed to provide the information to prospective external interfaces.”

Piling on so many gameplay features has posed a new quandary: figuring out the best way to assign key commands. Most of the letters on the keyboard have already been assigned to control the many functions assembled from so many NetHack variants. “Adding new actions isn’t quite as simple as it used to be,” says Cheung. “Part of the challenge is trying to figure out a way to do what you want without radically changing the current interface.”

A New (Isometric) Perspective on NetHack

“Text-based games may not seem so appealing to computer gamers nowadays. On the other hand, I knew that NetHack’s game content was varied and interesting. It seemed natural to upgrade the graphics to better appreciate the gameplay,” says Jaakko Peltonen, a 25-year-old from Helsinki, Finland, who works as a neural network researcher. He created Falcon’s Eye (http://falconseye.sourceforge.net), perhaps the most sophisticated makeover of NetHack yet.

Falcon’s Eye overlays NetHack’s ASCII characters with detailed graphics presented in an isometric, “two-and-a-half dimensions” perspective, and adds sound effects and music. It also adds mouse support, shortcuts for several keyboard commands, and many customization options. Falcon’s Eye coats NetHack with so much eye candy that it makes the originally minimalist game look, sound, and play almost like a commercially produced role-playing title. A picture of Falcon’s Eye is shown in Figure Three.

Figure Three: The 3D isometric eye candy of Falcon’s Eye

Falcon’s Eye itself does not alter NetHack’s gameplay. Instead, it adds some helpful features, like a path-finding algorithm to navigate the player’s character on “autopilot” over long distances in a dungeon map. Otherwise, this graphical window interface remains strictly compatible with the official releases of NetHack. “NetHack has been developed over many years. Many people prefer the gameplay in its current form,” Peltonen explains his reasoning.

Still, Falcon’s Eye’s pretty graphics alter the NetHack gaming experience. One issue in early versions was the visibility of the map. Most NetHack enthusiasts prefer to see the entire level of the dungeon at once, but Falcon’s Eye only shows a small portion of the map on-screen as a scrollable area. Given feedback from players, Peltonen compromised by adding a radar-like mini-map — a separate top-down map window — in one corner of the screen.

Peltonen originally developed a self-standing engine for displaying isometric graphics, then grafted it onto NetHack so he could utilize his other creative skills — drawing and sound composing. In terms of its design, artwork and programming, Falcon’s Eye has mainly been his work. However, many other people have sent him suggestions, bug reports, and fixes. Others submit art and sound effects, which are usually added to the latest releases.

Falcon’s Eye is programmed in C, with a few system-dependent functions in C++. It uses an outside graphics, sound, and input library — namely, the Simple DirectMedia Layer (http://www.libsdl.org). Aside from this, the rest of the code was written by Peltonen.

Implementing something as “simple” as the mouse interface, however, was a challenge. The NetHack game control scheme is designed for the keyboard, so Peltonen had to incorporate “work-arounds” into Falcon’s Eye’s code to make the mouse controls work. “If you right-click an in-game creature or item, Falcon’s Eye opens a context menu with possible actions, such as ‘Open’ or ‘Kick.’ NetHack doesn’t have built-in support for such menus, so Falcon’s Eye creates them on its own, and translates your choices to keyboard commands,” Peltonen says.

Falcon’s Eye’s graphics currently do not feature animation, but lots of people have asked for it. Peltonen is considering adding “static” animation like flickering torches or flowing water fountains. “Dynamic” animation, like characters walking, is more difficult to implement. “First, to work well, it needs separate animations for each movement direction,” says Peltonen. “Second, the interface then needs to find out what happened between turns — NetHack doesn’t provide this by default. Neither is impossible to solve, but they do require more background logic for the interface.”

Peltonen did consider using 3D models for his NetHack window interface’s graphics. This would have made putting in such animated sequences in Falcon’s Eye far easier, since each animation frame for a 3D model is just a set of object positions. In a 2D game, the frames are separate images that take up more memory and disk space.

“This would be rather easy programming, since only the actual tile drawing would change — most other graphics and background logic would be the same. I intended to add artificial elevation differences, just to make the levels look more interesting,” Peltonen says. However, each dungeon level in NetHack is a 2D plane. Adding elevation differences, such as rising and falling floors that would affect combat justified the use of 3D graphics, but he ultimately elected against doing this because he felt that such alterations would make the gameplay confusing and stray from the essence of NetHack.

Overall, he was pleasantly surprised to discover how well NetHack’s code had been designed to accommodate different user interfaces. NetHack doesn’t assume much about what the user interface will be like: the game tells what dungeon maps and messages to display and what to ask from the player, but the details about how to do these things are left up to the interface.

This separation and modularity of NetHack’s display and game logic aided the development of Falcon’s Eye. “NetHack only has a few files for the display functions of each interface, and its internal data representation is generally display-independent. This versatility helped a lot to create Falcon’s Eye. If NetHack had been tied to a character-based interface, I might have needed to work around it a lot. Thankfully, this was not the case,” Peltonen says.

Building Your Own Variant of NetHack

When it comes to creating a graphical window interface for NetHack or for another kind of game also with very minimal graphics, Peltonen came to a few specific conclusions from his experience with Falcon’s Eye.

Determine what the exact purpose of the interface is and how it can convey the gameplay in very clear, specific ways. Too many graphical effects can make a game’s GUI appear cluttered.

For input, the keyboard is probably still the best bet.

Simply adding on-screen buttons in place of keyboard key presses doesn’t improve game play and may actually worsen it. “Instead, one should consider how the mouse can best be used in tandem with the keyboard,” Peltonen says. “The GUI should work in concert with the keyboard interface. Especially with widely used programs, users have learned how to use the character interface quickly, and changing this functionality probably adds an unnecessary learning step. The GUI should instead provide alternatives — some users may eventually use a combination midway between the old and new interfaces. Allowing this can sometimes mean making several different ways to do a task, which takes much work (in both design and implementation), but I believe it is well worth the trouble.”

Figure Four: The NetHack family tree leading to Slash’EM

Advising those who want to develop yet another flavor of NetHack or a patch, Slash’EM’s Cheung suggests, “Start with a small modification, then work out all the ramifications. It’s amazing how everything in NetHack can interact, and the player can do almost any action with any object. So one simple addition can lead to many more ideas that are interconnected. NetHack is an amazingly complex program, and small changes can have far-reaching, unexpected effects.”

But don’t all these extensions and added graphics to NetHack get away from the heart of the game? Consider Falcon’s Eye: it doesn’t just show a different “view” of NetHack. Though the gameplay itself is technically the same, you have to keep reminding yourself of this as you play because it simply “feels” different from NetHack. The candy-colored coating alters a player’s perception of the game being played. NetHack is loved by its ardent fans for focusing squarely on its computer gaming minimalism — right down to the #‘s, $‘s, and ^‘s. With NetHack enhancements like Slash’EM, Falcon’s Eye and others, how much is too much?

“The overall experience is what matters,” says Peltonen. “I believe the graphical overlays are a useful middle ground, each with different amounts of changes. All [of them] leave room for the player’s imagination as well.”

Howard Wen (http://www.howardwen.com) has written about the video game industry over the years for several publications, including
Salon, Wired and Playboy.com. Sections of this article originally appeared in a series of articles he wrote for oreilly.com.

Comments are closed.