Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get started making a patch?

7 views
Skip to first unread message

Ed_the...@yahoo.com

unread,
Mar 12, 2007, 4:23:28 PM3/12/07
to
Well, here it is: my first post to a Usenet group!

I have a few questions on making a patch:

Assuming I have no knowledge whatsoever on programming, how can I go
about making a patch that adds, say, a new class?

If that's too complex for a patching newbie, then how about several
monsters and a couple of new rooms?

Doug Freyburger

unread,
Mar 12, 2007, 5:37:26 PM3/12/07
to
Ed_the_ro...@yahoo.com wrote:
>
> Well, here it is: my first post to a Usenet group!

Welcome.

> Assuming I have no knowledge whatsoever on programming, how can I go
> about making a patch that adds, say, a new class?
>
> If that's too complex for a patching newbie, then how about several
> monsters and a couple of new rooms?

If you don't know programming you're going to need to learn it. While
you can start by downloading the sources and traching yourself how
to build the unaltered source into a working binary, you will probably
do better by taking a couple of programming courses to get yourself
bootstrapped.

Be cautioned that nethack is written in a style of C that was common
years ago. It is very well written IMO but it takes plenty of
programming
experience even to be able to read it. Download compile, read the
sources, figure out what files you would want to change. Take your
time and have fun.

chuckcar

unread,
Mar 12, 2007, 5:46:43 PM3/12/07
to
Ed_the...@yahoo.com wrote in
news:1173731008....@q40g2000cwq.googlegroups.com:

Get a copy of Kernigan and Ritchie and work your way through it. It's
the best way. You can't write patches if you can't program in C period.
They're the same thing.

--
(setq (chuck nil) car(chuck) )

Pasi Kallinen

unread,
Mar 12, 2007, 6:19:19 PM3/12/07
to

You really need some knowledge about C coding before you can try
adding anything complex such as a new class. Adding a new special
room is easier, but still needs some code changes. Adding a new
monster is easiest of those three, if you're not adding new types
of attacks, resistances and whatnot.


Off the top of my head:


To add a new monster (only reusing existing abilities):

1. Edit src/monst.c to add the monster's data. The fields in the
gigantic array are described in include/permonst.h, and the
flags used in there are in include/monflag.h

2. Add a tile for the monster to win/share/monsters.txt


To add a new special room (like beehive and so on):

1. Edit inclde/mkroom.h and add the room number, like
#define MYROOM 14
_before_ the SHOPBASE definition, and renumbering the
room definitions that come after it.

2. Edit the levelflags struct in include/rm.h and add
Bitfield(has_myroom,1);
in it.

3. Edit check_special_room() in src/hack.c and add something
like this in there in the proper place:
case MYROOM:
You("enter a strange room!");
break;
and slightly later in the same function add something like
case MYROOM:
level.flags.has_myroom = 0;
break;

4. Edit clear_level_structures() in src/mklev.c adding
level.flags.has_myroom = 0;
somewhere near where the other lines like it are.

5. Also in src/mklev.c, near the end of makelevel(), add
something like this:
else if (u_depth > 11 && !rn2(6)) mkroom(MYROOM);
in the block where other lines like that are.
u_depth > 11 means that the dungeon level must be deeper
than 11 levels from top of dungeon and rn2(6) must be zero
before your level is created in the dungeon level.
rn2(6) returns a random value between 0 to 5, inclusive.

6. Edit mkroom() in src/mkroom.c, by adding a line like this:
case MYROOM: mkzoo(MYROOM); break;
near where there are lines like it.

7. (This is the part that requires most coding.)
Also in src/mkroom.c, edit fill_zoo() by adding cases
for your special room, so that it will get stocked with
monsters and whatever you want. Look how the other zoo-like
rooms are done in fill_zoo(). Also remember to add the
case MYROOM:
level.flags.has_myroom = 0;
break;
near the end of that function, where there are other lines like
that.

8. Edit dosounds() in src/sounds.c and add the ambient sounds when
a your room is on a level, for example:
if (level.flags.has_myroom && !rn2(400)) {
static const char * const myroom_msg[4] = {
"first random sound.",
"second random sound.",
"third random sound.",
"fourth, hallucinatory, random sound!",
};
You_hear(myroom_msg[rn2(3)+hallu]);
}

9. Edit fill_room() in src/sp_lev.c and add something like this:
case MYROOM:
level.flags.has_myroom = TRUE;
break;

10. Edit util/lev_main.c and add your room to the room_types array
for example adding a line like this in it:
{ "myroom", MYROOM },


...Hmmm, I think that's it, unless I forget something.
Not much explanations in there, but I think that shows how easy it is =)


Adding a new class is much, much more complex.


--
Pasi Kallinen
pa...@alt.org
http://bilious.homelinux.org/ -- NetHack Patch Database

John H.

unread,
Mar 12, 2007, 6:29:13 PM3/12/07
to
On Mar 12, 3:23 pm, Ed_the_ro...@yahoo.com wrote:
> Well, here it is: my first post to a Usenet group!
>
> I have a few questions on making a patch:

To start out, there are some very useful things to have.

- You'll need a means of compiling C code, of course. Cygwin is a
popular choice that's relatively easy to maintain and is free. DJGPP
is the easiest way to make DOS Nethack (still possibly the best
graphical version of the game, since it can use tiles yet the screen
still mirrors the classic UI, without obnoxious windows and scrollbars
and map windows and scrolling message buffers and bah humbug).
- You'll need the source code (from www.nethack.org). From personal
experience, it can be annoying to set up in a way that Nethack will
like it on a Windows machine. However the Devteam has shown itself to
be helpful in providing advice to OCCASIONAL questions concerning
compiling it, provided you follow the instructions on their web page
and within the source code docs exactly. Anyway, you can't really
make a patch until you get the game compiling on your system.
- After you get it compiling okay, the very next thing to do is to
make a complete copy of the source directory, and use your system's
compression program (Zip, Gzip, whatever Macs use) to make an archive
of that ready-to-compile vanilla source tree. (You should also keep
the original source, as downloaded from www.nethack.org, on hand as
well.) This is so that, if you want to start from scratch you can
just uncompress a copy of the working source and you're ready to go,
and if you want to make a patch, you'll can make the diff from your
patch's source tree and your working copy.
- You'll also need the diff, and patch, two command-line tools that
are used for making patches and applying them. Every time I figure
out how to use them I forget how I did it a couple of months later, so
I can't help much there. You can probably figure it out. If you're
using Cygwin you can use the versions available through its package
system.

When it comes to actually changing the code:
A Beginner's Guide to the Nethack Sources (http://members.shaw.ca/
rob.ellwood/sources.txt) is 12 years old but still mostly accurate,
and covers many of the easier changes to the game like making new
levels and monsters.
The Nethack Wiki (http://nethack.wikia.com/wiki/Main_Page) is an
invaluable aid to anyone with any level of interest to the game. It
has the complete source code on its pages, some of it annotated.
Pasi's Nethack Patch Database (http://bilious.homelinux.org/) has
hundreds of other user-made patches. You can use them for practice
applying patches, and resolving patch errors when they occur.
Further, you can see how other people implemented their patches: the
diff format that patches are supplied in are user-readable text files,
although depending on your code canniness it might take a little bit
of research to see how they work.
The archives of the Nethack Usenet Group (news://
rec.games.roguelike.nethack/) may also be a good place to look.
Google Groups keeps records of post going back many years. There were
a few highly useful source annotations here two or three years back.

When you finish your patch, be sure to tell us here, and to submit it
to the database so people can find it!

- John H.

Richard Bos

unread,
Mar 13, 2007, 6:16:14 PM3/13/07
to
"Doug Freyburger" <dfre...@yahoo.com> wrote:

> Ed_the_ro...@yahoo.com wrote:
> >
> > Well, here it is: my first post to a Usenet group!
>
> Welcome.
>
> > Assuming I have no knowledge whatsoever on programming, how can I go
> > about making a patch that adds, say, a new class?
> >
> > If that's too complex for a patching newbie, then how about several
> > monsters and a couple of new rooms?
>
> If you don't know programming you're going to need to learn it.

Quite. For new monsters and rooms even more than for a new class, I'd
say.
And I'd also recommend _not_ starting on C, because while it's a very
hacker-friendly language, it's not beginner-friendly. Try Pascal as a
first language.

> Be cautioned that nethack is written in a style of C that was common
> years ago.

s/years/decades/. The first ISO C Standard was published over 25 years
ago; and the NetHack source is firmly K&R 1.

Richard

ran...@pactechdata.com

unread,
Mar 15, 2007, 12:15:37 AM3/15/07
to
On Mar 13, 3:16 pm, ralt...@xs4all.nl (Richard Bos) wrote:

> "Doug Freyburger" <dfrey...@yahoo.com> wrote:
>> Be cautioned that nethack is written in a style of C that was common
>> years ago.
>
> s/years/decades/. The first ISO C Standard was published over 25 years
> ago; and the NetHack source is firmly K&R 1.

Hardly. The ANSI standard for C was adopted in 1989, the
99.99%-equivalent ISO standard was adopted in 1990, and compilers
+ libraries + linkers which actually conformed to them came later
(although fairly quickly, unlike for the subsequent 1999 standard).


MassiveProng

unread,
Mar 15, 2007, 8:42:57 PM3/15/07
to
On 12 Mar 2007 13:23:28 -0700, Ed_the...@yahoo.com Gave us:


You take a pair of old jeans, and cut out some squares and
rectangles...

Then you get yourself some thread and a needle...

Topi Linkala

unread,
Mar 14, 2007, 6:02:14 AM3/14/07
to
Richard Bos wrote:
> "Doug Freyburger" <dfre...@yahoo.com> wrote:
>
>
>>Ed_the_ro...@yahoo.com wrote:
>>
>>>Well, here it is: my first post to a Usenet group!
>>
>>Welcome.
>>
>>
>>>Assuming I have no knowledge whatsoever on programming, how can I go
>>>about making a patch that adds, say, a new class?
>>>
>>>If that's too complex for a patching newbie, then how about several
>>>monsters and a couple of new rooms?
>>
>>If you don't know programming you're going to need to learn it.
>
>
> Quite. For new monsters and rooms even more than for a new class, I'd
> say.
> And I'd also recommend _not_ starting on C, because while it's a very
> hacker-friendly language, it's not beginner-friendly. Try Pascal as a
> first language.

Don't start with Pascal. It teaches you bad habits.

Try Java.

Topi
--
"The whole problem with the world is that fools and fanatics are
always so certain of themselves, but wiser people so full of doubts."
- Bertrand Russell
"How come he didn't put 'I think' at the end of it?" - Anonymous

Janis

unread,
Mar 16, 2007, 9:36:17 AM3/16/07
to
On 14 Mrz., 11:02, Topi Linkala <n...@iki.fi> wrote:
> Richard Bos wrote:
> > "Doug Freyburger" <dfrey...@yahoo.com> wrote:
> >>Ed_the_ro...@yahoo.com wrote:
>
> >>>Well, here it is: my first post to a Usenet group!
>
> >>Welcome.
>
> >>>Assuming I have no knowledge whatsoever on programming, how can I go
> >>>about making a patch that adds, say, a new class?
>
> >>>If that's too complex for a patching newbie, then how about several
> >>>monsters and a couple of new rooms?
>
> >>If you don't know programming you're going to need to learn it.
>
> > Quite. For new monsters and rooms even more than for a new class, I'd
> > say.
> > And I'd also recommend _not_ starting on C, because while it's a very
> > hacker-friendly language, it's not beginner-friendly. Try Pascal as a
> > first language.
>
> Don't start with Pascal. It teaches you bad habits.
>
> Try Java.

Don't start with Java. It teaches you bad habbits. :-)

Try Simula.

Janis, only partly serious, but surely striving against the (main)
stream

PS: Back to on-topicness, at least in the post scriptum...
Why would anyone suggest to use a language different from the existing
huge code base if all he wants is just to extend that code base?

Arthur J. O'Dwyer

unread,
Mar 16, 2007, 12:54:48 PM3/16/07
to

On Fri, 16 Mar 2007, Janis wrote:
> On 14 Mrz., 11:02, Topi Linkala <n...@iki.fi> wrote:
>> Richard Bos wrote:
>>> "Doug Freyburger" <dfrey...@yahoo.com> wrote:
>>>> Ed_the_ro...@yahoo.com wrote:
>>>>>
>>>>> Assuming I have no knowledge whatsoever on programming, how can I go
>>>>> about making a patch that adds, say, a new class?
>>>>>
>>>>> If that's too complex for a patching newbie, then how about several
>>>>> monsters and a couple of new rooms?
>>>>
>>>> If you don't know programming you're going to need to learn it.
>>>
>>> Quite. For new monsters and rooms even more than for a new class, I'd
>>> say.
>>> And I'd also recommend _not_ starting on C, because while it's a very
>>> hacker-friendly language, it's not beginner-friendly. Try Pascal as a
>>> first language.
>>
>> Don't start with Pascal. It teaches you bad habits.
>>
>> Try Java.
>
> Don't start with Java. It teaches you bad habbits. :-)
>
> Try Simula.
>
> Janis, only partly serious, but surely striving against the (main)
> stream

Not at all. (Well, at least with the "Java is bad" part. "Simula is
good" is a new one for me. :) I don't think there's anything wrong with
Pascal, either, as long as you use something like Turbo Pascal; I guess
that Topi was thinking mainly of the lack of forward declarations and
file-inclusion, which means Pascal encourages you to write your program
"backwards", with [the equivalent of] "main" at the bottom.

> PS: Back to on-topicness, at least in the post scriptum...
> Why would anyone suggest to use a language different from the existing
> huge code base if all he wants is just to extend that code base?

Because if he's halfway good at it, then that won't be /all/ he wants
to do. It's like asking what's the best car to learn to drive to the
grocery store in. :)

Anyway, the OP could do a lot worse than starting with (ANSI) C.
Trying to start with Nethack's own brand of K&R C is almost certainly
asking for trouble; this is one of those "you must follow the rules
before you can break them" situations.

my $.02,
-Arthur

Richard Bos

unread,
Mar 16, 2007, 7:37:47 PM3/16/07
to
"Arthur J. O'Dwyer" <ajon...@andrew.cmu.edu> wrote:

>
> On Fri, 16 Mar 2007, Janis wrote:
> > On 14 Mrz., 11:02, Topi Linkala <n...@iki.fi> wrote:
> >> Richard Bos wrote:
> >>> And I'd also recommend _not_ starting on C, because while it's a very
> >>> hacker-friendly language, it's not beginner-friendly. Try Pascal as a
> >>> first language.
> >>
> >> Don't start with Pascal. It teaches you bad habits.
> >>
> >> Try Java.

*Snigger*

> > Don't start with Java. It teaches you bad habbits. :-)
> >
> > Try Simula.
> >
> > Janis, only partly serious, but surely striving against the (main)
> > stream
>
> Not at all. (Well, at least with the "Java is bad" part. "Simula is
> good" is a new one for me. :) I don't think there's anything wrong with
> Pascal, either, as long as you use something like Turbo Pascal;

*Shudder*

At least proper Pascal teaches you discipline.

> > PS: Back to on-topicness, at least in the post scriptum...
> > Why would anyone suggest to use a language different from the existing
> > huge code base if all he wants is just to extend that code base?
>
> Because if he's halfway good at it, then that won't be /all/ he wants
> to do. It's like asking what's the best car to learn to drive to the
> grocery store in. :)

Also, because if you can't program yet, learning pre-ANSI C will teach
you a lot of habits that aren't just antediluvial, but were a bad idea
even back that.

> Anyway, the OP could do a lot worse than starting with (ANSI) C.
> Trying to start with Nethack's own brand of K&R C is almost certainly
> asking for trouble; this is one of those "you must follow the rules
> before you can break them" situations.

Which is why you start with real Pascal, which forces you to learn the
rules.

Richard

Richard Bos

unread,
Mar 16, 2007, 7:37:48 PM3/16/07
to
ran...@pactechdata.com wrote:

> On Mar 13, 3:16 pm, ralt...@xs4all.nl (Richard Bos) wrote:
> > "Doug Freyburger" <dfrey...@yahoo.com> wrote:
> >> Be cautioned that nethack is written in a style of C that was common
> >> years ago.
> >
> > s/years/decades/. The first ISO C Standard was published over 25 years
> > ago; and the NetHack source is firmly K&R 1.
>
> Hardly. The ANSI standard for C was adopted in 1989,

Feh. Off-by-ten error in my brian.

Anyway, K&R C is still not the thing to learn today.

Richard

Topi Linkala

unread,
Mar 17, 2007, 5:46:32 PM3/17/07
to
Richard Bos wrote:

> "Arthur J. O'Dwyer" <ajon...@andrew.cmu.edu> wrote:
>
>
>>On Fri, 16 Mar 2007, Janis wrote:
>>
>>>On 14 Mrz., 11:02, Topi Linkala <n...@iki.fi> wrote:
>>>
>>>>Richard Bos wrote:
>>>>
>>>>>And I'd also recommend _not_ starting on C, because while it's a very
>>>>>hacker-friendly language, it's not beginner-friendly. Try Pascal as a
>>>>>first language.
>>>>
>>>>Don't start with Pascal. It teaches you bad habits.
>>>>
>>>>Try Java.
>
>
> *Snigger*
>
>
>>>Don't start with Java. It teaches you bad habbits. :-)
>>>
>>>Try Simula.
>>>
>>>Janis, only partly serious, but surely striving against the (main)
>>>stream
>>
>> Not at all. (Well, at least with the "Java is bad" part. "Simula is
>>good" is a new one for me. :) I don't think there's anything wrong with
>>Pascal, either, as long as you use something like Turbo Pascal;
>
>
> *Shudder*
>
> At least proper Pascal teaches you discipline.

Doesn't r.g.r.n FAQ tell that no BSDM jokes should be posted ;-)

Read the following:

http://www.lysator.liu.se/c/bwk-on-pascal.html

Janis Papanagnou

unread,
Mar 17, 2007, 8:34:42 PM3/17/07
to
Topi Linkala wrote:

> Richard Bos wrote:
>>
>> At least proper Pascal teaches you discipline.
>
> Doesn't r.g.r.n FAQ tell that no BSDM jokes should be posted ;-)
>
> Read the following:
>
> http://www.lysator.liu.se/c/bwk-on-pascal.html

He's biased. :-}

("He" = B.W.K.)

Janis

Doug Freyburger

unread,
Mar 18, 2007, 10:12:49 AM3/18/07
to
"Janis" <janis_papanag...@hotmail.com> wrote:
>
> PS: Back to on-topicness, at least in the post scriptum...
> Why would anyone suggest to use a language different from the existing
> huge code base if all he wants is just to extend that code base?

You have to learn to walk before you can run. It is a matter of
knowing what the prerequesites are and aren't. Patching
Nethack is a matter of exercising your programming skills.
To be able to do that you need to have those skills in the first
place.

Starting with a learning language is definitely the fastest way
to acquire programming skills. It's been demonstrated again
and again between colleges following that path and colleges
that let the student start with the most commercially popular
languages first.

Janis Papanagnou

unread,
Mar 18, 2007, 11:17:39 AM3/18/07
to

I think I understand what you mean; but I have a different opinion
in this case; patching existing code as apposed to designing and
writing code from scratch.

I agree that getting the programming skill is best done with other
languages than C. But you finally have to tackle C if you want to
change the Nethack code. And much what you've learned will be not
applicable in the C context, and the Nethack code has also its own,
umm.., coding style. So if you want to just "hack" a patch I don't
think you would want take all the way of a professional software
engineer; you'd orient yourself by the existing code patterns. Not
that this all would be the preferred way to produce any high quality
(rather the opposite is the case), but you can reach the intended
goal effectively. To become a proficient programmer you'll need to
spend a lot of time learning. I also agree that starting with the
"most commercially popular languages" is not the preferred approach
for people who want to seriously learn programming from scratch.

Janis

Kent Paul Dolan

unread,
Mar 20, 2007, 6:55:31 AM3/20/07
to
Ed_the_ro...@yahoo.com wrote:

> Well, here it is: my first post to a Usenet group!

And like a visitor to Ft. Ludius, you stepped into a
minefield!

> I have a few questions on making a patch:

> Assuming I have no knowledge whatsoever on
> programming, how can I go about making a patch
> that adds, say, a new class?

You can't. "Patching" is just a term of art for
programming done into an existing set of source
code, it isn't something separate from programming.

> If that's too complex for a patching newbie, then
> how about several monsters and a couple of new
> rooms?

Same answer. Though the rooms (dungeon levels) have
a "level compiler", and most programmers would
cringe to call what it uses "a programming
language", it is one, and programming-type skills
are still needed.

Don't even think about adding even one new monster
until you are expert. The NetHack monster code is
internally "order of declaration" dependent, and
that order dependency is spread widely across the
code.

So, teach yourself programming skills first.

Now, in which language, C, the language of NetHack,
or some other language, should you do this?

C is a very difficult first programming language to
learn; it is ugly (the operators aren't the ones you
learned in algebra), it is ill behaved (pointers
will rot your brain), and the standard programming
layout style is hideous (closing delimiters aren't
stacked vertically with matching opening
delimiters).

C is even a very difficult second programming
language to learn, it has countless warts ("integer"
doesn't mean the same number of bytes or bits
between any two C compilers, much of what you want
to do has to be done with a preprocessor because the
language doesn't contain the functionality needed)
and lacks huge features expected in more modern
programming languages, like object oriented
programming support, like built in graphical
interface operators.

The good news is, C is a pretty trivial third
programming language to learn, once you realize that
"pretty much all programming languages must have a
way to do this and this and this", and it has a huge
support base of software libraries to do pretty much
anything you want to do.

So, don't learn C first.

While the rest of the participants argue about which
programming language can beat its chest the hardest,
may I instead recommend Logo, a very simple
programming language deliberately designed for grade
school children, as a good place for an absolute
beginner to learn "programming self taught"?

My (admittedly bright) daughter was able to use it
at age 4, and it stood her in good stead, last I
heard she was working on her PhD in computer
science, as a programming practitioner returning
from the workforce for more education.

There are some very nice free Logo implementations
available for download.

HTH

xanthian.


0 new messages