Difference between revisions of "User:Paxed/HowTo AddNewRoomType"

From NetHackWiki
Jump to navigation Jump to search
m (explain a bit, and add references)
m (fix references)
Line 1: Line 1:
 
This page documents how to add a new special room type, such as a beehive.
 
This page documents how to add a new special room type, such as a beehive.
  
*Edit include/mkroom.h<ref>[[mkroom.h#line120]]</ref> and add the room number, like
+
*Edit include/mkroom.h<ref>[[mkroom.h#line50]]</ref> and add the room number, like
 
  #define MYROOM 14
 
  #define MYROOM 14
 
before the SHOPBASE definition, and renumber the room definitions that come after it.
 
before the SHOPBASE definition, and renumber the room definitions that come after it.
  
*Edit the levelflags struct in include/rm.h<ref>[[rm.h#line120]]</ref> and add
+
*Edit the levelflags struct in include/rm.h<ref>[[rm.h#line444]]</ref> and add
 
  Bitfield(has_myroom,1);
 
  Bitfield(has_myroom,1);
 
in it.
 
in it.
  
*Edit check_special_room() in src/hack.c<ref>[[hack.c#line120]]</ref> and add something like this in there in the proper place:
+
*Edit check_special_room() in src/hack.c<ref>[[hack.c#line1717]]</ref> and add something like this in there in the proper place:
 
  case MYROOM:
 
  case MYROOM:
 
   You("enter a strange room!");
 
   You("enter a strange room!");
Line 19: Line 19:
 
The message <tt>You enter a strange room!</tt> is shown to player when he enters the room, and clearing the has_myroom flag ensures the message is only shown once per room.
 
The message <tt>You enter a strange room!</tt> is shown to player when he enters the room, and clearing the has_myroom flag ensures the message is only shown once per room.
  
*Edit clear_level_structures() in src/mklev.c<ref>[[mklev.c#line120]]</ref> adding
+
*Edit clear_level_structures() in src/mklev.c<ref>[[mklev.c#line537]]</ref> adding
 
  level.flags.has_myroom = 0;
 
  level.flags.has_myroom = 0;
 
somewhere near where the other lines like it are.
 
somewhere near where the other lines like it are.
  
*Also in src/mklev.c, near the end of makelevel()<ref>[[mklev.c#lin120]]</ref>, add something like this:
+
*Also in src/mklev.c, near the end of makelevel()<ref>[[mklev.c#line727]]</ref>, add something like this:
 
  else if (u_depth > 11 && !rn2(6)) mkroom(MYROOM);
 
  else if (u_depth > 11 && !rn2(6)) mkroom(MYROOM);
 
in the block where other lines like that are. <tt>u_depth > 11</tt> means that the dungeon level must be deeper than 11 levels from top of dungeon and <tt>rn2(6)</tt> must be zero before your level is created in the dungeon level. rn2(6) returns a random value between 0 to 5, inclusive.
 
in the block where other lines like that are. <tt>u_depth > 11</tt> means that the dungeon level must be deeper than 11 levels from top of dungeon and <tt>rn2(6)</tt> must be zero before your level is created in the dungeon level. rn2(6) returns a random value between 0 to 5, inclusive.
  
*Edit mkroom() in src/mkroom.c, by adding a line like this:
+
*Edit mkroom() in src/mkroom.c<ref>[[mkroom.c#line46]]</ref>, by adding a line like this:
 
  case MYROOM:    mkzoo(MYROOM); break;
 
  case MYROOM:    mkzoo(MYROOM); break;
 
near where there are lines like it.
 
near where there are lines like it.
  
*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
+
*Also in src/mkroom.c, edit fill_zoo()<ref>[[mkroom.c#line226]]</ref> 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:
 
  case MYROOM:
 
   level.flags.has_myroom = 0;
 
   level.flags.has_myroom = 0;
Line 38: Line 38:
 
This is the part that requires most coding.
 
This is the part that requires most coding.
  
*Edit fill_room() in src/sp_lev.c and add something like this:
+
*Edit fill_room() in src/sp_lev.c<ref>[[sp_lev.c#line1457]]</ref> and add something like this:
 
     case MYROOM:
 
     case MYROOM:
 
         level.flags.has_myroom = TRUE;
 
         level.flags.has_myroom = TRUE;
 
         break;
 
         break;
  
*Edit dosounds() in src/sounds.c and add the ambient sounds when a your room is on a level, for example:
+
*Edit dosounds() in src/sounds.c<ref>[[sounds.c#line35]]</ref> and add the ambient sounds when a your room is on a level, for example:
 
  if (level.flags.has_myroom && !rn2(400)) {
 
  if (level.flags.has_myroom && !rn2(400)) {
 
       static const char * const myroom_msg[4] = {
 
       static const char * const myroom_msg[4] = {
Line 55: Line 55:
 
This will show one of the messages at random for the player when there is a room of the new type on the level.
 
This will show one of the messages at random for the player when there is a room of the new type on the level.
 
The chance of player hearing one of the messages for your room is 1 in 400 each turn.
 
The chance of player hearing one of the messages for your room is 1 in 400 each turn.
 
*Edit fill_room() in src/sp_lev.c and add something like this:
 
    case MYROOM:
 
        level.flags.has_myroom = TRUE;
 
        break;
 
  
 
*Edit util/lev_main.c and add your room to the room_types array for example adding a line like this in it:
 
*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 },
 
     { "myroom",      MYROOM },
 
This allows the room to be used in the [[Des-file format|special levels]].
 
This allows the room to be used in the [[Des-file format|special levels]].
 
  
 
<references/>
 
<references/>

Revision as of 18:22, 20 March 2007

This page documents how to add a new special room type, such as a beehive.

  • Edit include/mkroom.h[1] and add the room number, like
#define MYROOM 14

before the SHOPBASE definition, and renumber the room definitions that come after it.

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

in it.

  • Edit check_special_room() in src/hack.c[3] 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;

The message You enter a strange room! is shown to player when he enters the room, and clearing the has_myroom flag ensures the message is only shown once per room.

  • Edit clear_level_structures() in src/mklev.c[4] adding
level.flags.has_myroom = 0;

somewhere near where the other lines like it are.

  • Also in src/mklev.c, near the end of makelevel()[5], 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.

  • Edit mkroom() in src/mkroom.c[6], by adding a line like this:
case MYROOM:    mkzoo(MYROOM); break;

near where there are lines like it.

  • Also in src/mkroom.c, edit fill_zoo()[7] 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. This is the part that requires most coding.

  • Edit fill_room() in src/sp_lev.c[8] and add something like this:
   case MYROOM:
       level.flags.has_myroom = TRUE;
       break;
  • Edit dosounds() in src/sounds.c[9] 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]);

}

This will show one of the messages at random for the player when there is a room of the new type on the level. The chance of player hearing one of the messages for your room is 1 in 400 each turn.

  • 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 },

This allows the room to be used in the special levels.