Difference between revisions of "Source diving"

From NetHackWiki
Jump to navigation Jump to search
(Fixed broken link)
(Tag: adds external links)
m (Message sources: Trim?)
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
[[Grep]], [[GEMA]], [[AWK]], and [http://www.stack.nl/~dimitri/doxygen/index.html Doxygen] are useful tools when source diving.
 
[[Grep]], [[GEMA]], [[AWK]], and [http://www.stack.nl/~dimitri/doxygen/index.html Doxygen] are useful tools when source diving.
  
==External links==
+
==Tips==
* [https://web.archive.org/web/20160802031704/http://members.shaw.ca/rob.ellwood/sources.txt Beginner's Guide to NetHack Sources]
+
===Function definitions===
 +
Most function declarations are in [[Source:NetHack_3.6.1/include/extern.h|extern.h]], sorted by the .c file they're defined in. If you're looking for a function's definition, you can search for the function name in extern.h, then scroll up to the comment giving the file name. Note that some things that look like functions, such as <code>resists_fire(mon)</code>, are actually preprocessor macros; most of those are defined in other header files such as [[Source:NetHack_3.6.1/include/youprop.h|youprop.h]] or [[Source:NetHack_3.6.1/include/mondata.h|mondata.h]].
 +
===Message sources===
 +
You can look up printed messages in the code to get an idea of what governs certain output. However, many messages are constructed using macros and/or string substitution. For example, when trying to [[riding|mount]] your steed, you may get the message: {{message|You are unable to swing your leg over.}}
 +
You won't find this exact message anywhere in the source code, because the line that produces it reads: <code>You("are unable to swing your %s over.", body_part(LEG))</code>. The macro <code>You()</code> prints a message beginning with the word "You"; there are similar macros for messages starting with "Your", "You hear", and "You feel". The "%s" in the message is replaced with the result of the next argument, <code>body_part(LEG)</code>, which resolves to a string describing the leg-analogue of your current [[polyself]], if any. In this case, one way to search for the message would be "unable to swing your %s over". In general, if any word or words in a message can vary, replace them with %s in a search; if a number varies, replace it with %ld. (Alternatively, trim to "unable to swing your", if your search mechanism may not cooperate with %s or %ld as part of a search.)
 +
 
 +
==See also==
 +
* [[Beginner's guide to NetHack sources]] -- note that the .des level file format described here has been replaced with LUA in current versions.
  
 
[[Category:Development]]
 
[[Category:Development]]

Latest revision as of 00:38, 5 July 2021

Source diving is the action of examining the source code of NetHack. A person who practices source diving is called a source diver. The source code is freely available for anyone, unlike in most commercial programs.

Source diving is usually done when someone wants to know how something really works in the game. Source divers may also program their own patches to the game. Some people may just want to look for easter eggs or interesting comments in the source.

Grep, GEMA, AWK, and Doxygen are useful tools when source diving.

Tips

Function definitions

Most function declarations are in extern.h, sorted by the .c file they're defined in. If you're looking for a function's definition, you can search for the function name in extern.h, then scroll up to the comment giving the file name. Note that some things that look like functions, such as resists_fire(mon), are actually preprocessor macros; most of those are defined in other header files such as youprop.h or mondata.h.

Message sources

You can look up printed messages in the code to get an idea of what governs certain output. However, many messages are constructed using macros and/or string substitution. For example, when trying to mount your steed, you may get the message:

You are unable to swing your leg over.

You won't find this exact message anywhere in the source code, because the line that produces it reads: You("are unable to swing your %s over.", body_part(LEG)). The macro You() prints a message beginning with the word "You"; there are similar macros for messages starting with "Your", "You hear", and "You feel". The "%s" in the message is replaced with the result of the next argument, body_part(LEG), which resolves to a string describing the leg-analogue of your current polyself, if any. In this case, one way to search for the message would be "unable to swing your %s over". In general, if any word or words in a message can vary, replace them with %s in a search; if a number varies, replace it with %ld. (Alternatively, trim to "unable to swing your", if your search mechanism may not cooperate with %s or %ld as part of a search.)

See also