Monster creation
A user has suggested improving this page or section as follows:
"Could use more details on the placement of generated monsters - the timing seems to be mostly covered. Could also stand to flesh out what levels employ special rules and link to the dedicated pages, as well as what governs other forms of monster creation."
Monster creation is the process by which NetHack determines when, where and how a particular monster is generated - whether it is randomly placing an unspecified creature somewhere on the floor, or else populating a freshly created level as soon as the player enters.
Normal monster generation takes place during level creation and at the end of each turn. Monster creation code is also invoked when the player or another monster makes use of an item that generates a monster, such as a scroll of create monster or a bag of tricks.
Contents
Normal monster selection
When a monster is generated, NetHack first determines which of the monsters in its database is eligible. Unique monsters and any monster marked with the flag G_NOGEN
cannot be randomly generated; genocided and extinct monsters are excluded as well.[1]
From there, a monster is generally eligible if:[2]
- Its monster difficulty is less than or equal to the average of the level's difficulty and the hero's experience level.
- Its difficulty is at least one-sixth of the current level's difficulty.
- If the hero is on the Rogue level, then monsters represented by glyphs with lower-case letters (e.g., a, b, c) are excluded from eligibility.
- If the hero is in Gehennom, lawful monsters and those marked with the flag
G_NOHELL
(e.g., winter wolf) are excluded, while monsters with the flagG_HELL
) (e.g., hell hounds) are only eligible to be randomly generated in Gehennom and are ineligible elsewhere.[3][4] - On the Elemental Planes:[5]
- If the hero is on the Plane of Water, only swimmers are eligible for random generation.
- If the hero is on the Plane of Fire, only monsters with fire resistance are eligible.
- If the hero is on the Plane of Air, only monsters that are capable of flying or floating, and are whirly, amorphous, or unsolid are eligible. The trapper or lurker above monster class is explicitly excluded, as both monsters rely on matching the surroundings of the dungeon walls, floor and ceiling in order to hide.
Each monster remaining on this list that meets the above conditions is eligible, and has a probability of being generated equal to its effective monster frequency (adjusted based on its monster alignment versus the branch's alignment) divided by the sum of the monster frequencies of every eligible monster. This can be visualized as a hat full of labeled slips of paper, with each one bearing the name of a monster - each creature's monster frequency determines how many slips of paper in the hat have its name, and the game then selects a name out of the hat at random.
The following information pertains to an upcoming version (NetHack 3.7.0). If this version is now released, please verify that the information below is still accurate, then update the page to incorporate it.
After adjusting monster frequency for alignment, a monster species may get another +3 bonus if they have a resistance matching the current level temperature: cold resistance on cold levels, and fire resistance on hot levels.Where this mechanism is used
At the end of each turn, or if an item that generates a monster is used, the possibility of creating a monster depends on the following:[6]
- If the demigod flag is set by either killing the Wizard of Yendor at least once or performing the Invocation, there is a 1⁄25 chance of at least one monster being generated.
- If the demigod flag is not set, but the hero is in Gehennom, monster generation will occur with a 1⁄50 chance each turn.
- Otherwise, normal monster generation takes place with a 1⁄70 chance each turn.
The following items or spells that create monsters are subject to this rule:
Selection by monster class
Where a class of monster is specified, such as during the creation of certain levels (including the Gnomish Mines) or random generation in the Quest, a different monster generation algorithm is used, and monsters may be generated with probabilities different from the normal mechanism.[7]
Monster selection follows this procedure:
- Monsters of the same class are assumed to be contiguously defined in the mons[] array, and in the order of their difficulty.
- Quest guardians and player monsters are not eligible because they are defined separately from the rest of the @.
- If an alignment is specified, only monsters of that alignment are eligible.
- Unique monsters, monsters with the G_NOGEN flag, extinct, and genocided monsters are not eligible.
- Imagine a bag that is initially empty. For each eligible monster starting with the first defined monster of the class, monsters are added to the bag:
- If the difficulty level of the current monster is more than twice the level difficulty, there is a 1⁄2 chance that we stop adding any more monsters to the bag; the current monster is not added and we go directly to the final step of selecting a monster from the bag. However, if the current monster's difficulty is the same as the previous monster's, or if there is no monster in the bag yet, we instead continue the process (thus, monsters of the same difficulty are always added to the bag together, and the bag is never empty if there are any eligible monsters).
- Let k be the monster's monster frequency. If k is greater than 0, k+1 copies of that monster are added to the bag, except that only k copies are added if the adjusted monster level is greater than twice the player's experience level.
- Finally, a random monster is selected from the bag.
Note that this process ignores some restrictions that are normally in place, such as monsters that normally would not generate outside of Gehennom. In addition, monsters that are too difficult to be generated via the normal mechanism may be generated by this process - in particular, this is how minesflayers generate.
The following information pertains to an upcoming version (NetHack 3.7.0). If this version is now released, please verify that the information below is still accurate, then update the page to incorporate it.
Per commit c29ffe1d, this mechanism no longer generates master liches and arch-liches outside of Gehennom. For other monsters that normally generate only inside or outside of Gehennom, this mechanism respects the restriction 8⁄9 of the time.Where this mechanism is used
Condition | Monster classes | Notes |
---|---|---|
Ringing a cursed bell | n[8] | 1⁄4 chance; not generated with inventory; if any nymph is genocided or extinct, none of them are generated. |
Digging a grave | ZM[9] | 1⁄5 chance each of Z or M. |
Demon gating; summon nasties in Gehennom (1⁄10 chance); chaotic or unaligned minion generation | &[10][11] | Same alignment as summoner, or any alignment if summoner is unaligned. |
Summoning a lawful minion | A[12] | |
Summon insects | aS[13] | Snakes are generated only if all insects are gone. |
1⁄5 of the time when attempting to generate a trapped secret door when level difficulty is at least 9 | m[14] | The mimic is generated instead of a secret door. |
Inaccessible closet corpse | @[15] | It's a corpse, not a living monster. |
Graveyard room creation; cursed charged Bell of Opening or cursed Book of the Dead | &VZ[16] | Other monsters may also be selected by a non-mkclass() mechanism. |
Swamp creation | F[17] | Some ; are also generated in swamps, but mkclass() is explicitly not used for them here to avoid generating kraken. |
Throne room creation | DHTCoGk[18] | Bugbear and hobgoblin may also be selected. |
Shop creation | m[19] | |
Random monster generation in the Quest | specified Quest monster classes[20] | See Quest#Quest leaders and nemeses for monster classes. |
Special level creation | specified monster classes[21] |
Notable monster class selection in special levels
- Normal Gnomish Mines levels and the first two Mines' End variants contain one random h, which may be a mind flayer.[22]
- The Castle places 27 random monsters from the list LNEHMORTXZ (2–3 of each class) in the central room. The L may include master liches or arch-liches.
- The Astral Plane also contains 3 L, which may include master liches or arch-liches.
Level creation
The following steps are used to place monsters around the level upon its initial creation.
- In normal room-and-corridor levels, there is a 33% chance of generating a monster (or group) per room.
- In mazes, there is a 33% chance of generating 7-11 monsters + 0-2 minotaurs.
Other levels and branches follow various special rules for initial monster placement that are generally unique to each area and detailed on their respective articles.
Monster placement
Monsters may be placed differently depending on how the monster is created. Monsters are placed randomly when they are created as part of the normal end-of-turn random monster creation.[23] Shrieker-summoned monsters and some regenerated Keystone Kops are also placed randomly.[24][25] When monsters are placed randomly, the placement algorithm prefers to place monsters where you can't see them.[26] Most player actions that result in monster creation result in the monsters being created around you.
See also
References
- ↑ src/makemon.c in NetHack 3.6.7, line 1468
- ↑ src/makemon.c in NetHack 3.6.7, line 1546
- ↑ src/makemon.c in NetHack 3.6.7, line 1473
- ↑ src/makemon.c in NetHack 3.6.7, line 1568
- ↑ src/makemon.c in NetHack 3.6.7, line 51
- ↑ src/allmain.c in NetHack 3.6.7, line 121
- ↑ src/makemon.c in NetHack 3.6.7, line 1639
- ↑ src/apply.c in NetHack 3.6.7, line 1042
- ↑ src/dig.c in NetHack 3.6.7, line 939
- ↑ src/minion.c in NetHack 3.6.7, line 406
- ↑ src/minion.c in NetHack 3.6.7, line 51
- ↑ src/minion.c in NetHack 3.6.7, line 396
- ↑ src/mcastu.c in NetHack 3.6.7, line 584
- ↑ src/mklev.c in NetHack 3.6.7, line 431
- ↑ src/mklev.c in NetHack 3.6.7, line 533
- ↑ src/mkroom.c in NetHack 3.6.7, line 459
- ↑ src/mkroom.c in NetHack 3.6.7, line 542
- ↑ src/mkroom.c in NetHack 3.6.7, line 735
- ↑ src/shknam.c in NetHack 3.6.7, line 471
- ↑ src/questpgr.c in NetHack 3.6.7, line 655
- ↑ src/sp_lev.c in NetHack 3.6.7, line 1621
- ↑ dat/mines.des in NetHack 3.6.7, line 37
- ↑ src/allmain.c in NetHack 3.6.7, line 127:
makemon()
is called with coordinates <0,0>, indicating random placement - ↑ src/mon.c in NetHack 3.6.7, line 2867: Shrieker
- ↑ src/mon.c in NetHack 3.6.7, line 2056: Kops
- ↑ src/makemon.c in NetHack 3.6.7, line 1034:
makemon_rnd_goodpos()
picks the location whenmakemon()
was called with random placement