Decoded: Rogue (1980) by Toy, Arnold, Wichman
DOS version (1983) by Mel Sibony and Jon Lane
Source file: DAEMONS.C
Beginner friendly, line-by-line code walkthrough by MaiZure

DAEMONS.C defines specific daemon functions used throughout Rogue

Original code:
https://britzl.github.io/roguearchive/

Original code with line numbers
http://www.maizure.org/projects/decoded-rogue/DAEMONS_linenum.txt



1     COMMENT
2     COMMENT
3     COMMENT
4     COMMENT
5     COMMENT
6     BLANK
7     Include the game header
8     Include the console management header
9     BLANK
10    COMMENT
11    COMMENT
12    COMMENT
13    COMMENT

HEALING DAEMON

14    Defines doctor with no arguments
15    BLOCK START - doctor, healing over time daemon
16    Declare integers for player level and hitpoints
17    BLANK
18    Get the player's level
19    Get the player's hitpoints
20    Increment counter for quiet/inactive turns
21    If the player is less than level 8...
22    BLOCK START - Low level regen bonus
23    If the quiet counter plus double the player level is greater than 20
24    Add an extra regen hitpoint
25    BLOCK END - Low level regen bonus
26    Otherwise...
27    If the player has had 3 or more quiet turns...
28    Regenerate at least 1 health point, possibly more
29    If the player has a regen ring on the left hand...
30    Regen a hitpoint
31    If the player has a regen ring on the right hand...
32    Regen a hitpoint
33    If some regeneration occurred...
34    BLOCK START - Regen boundary check
35    If the player's health is higher than max..
36    Reset health to max
37    Reset the quiet counter...sorry, can't chain regen
38    BLOCK END - Regen boundary check
39    BLOCK END - doctor
40    BLANK
41    COMMENT
42    COMMENT
43    COMMENT
44    COMMENT

WANDER DAEMON

45    Defines swander with no arguments
46    BLOCK START - swander, triggers monster wander
47    Creates a monster wandering daemon
48    BLOCK END - swander
49    BLANK
50    COMMENT
51    COMMENT
52    COMMENT
53    COMMENT

WANDERING MONSTER CREATION DAEMON

54    Defines rollwand with no argument
55    BLOCK START - rollwand, rolls for random chance to wake up a monster
56    Declares a static variable for wandering (retains value every call)
57    BLANK
58    If the incremented between is between 3 and 6....
59    BLOCK START - wander roll
60    There is a 17% chance that...
61    BLOCK START - Create wandering monster
62    Create a wandering monster
63    Destroy this daemon
64    Create a new wander daemon triggered between 0 and 70 ticks
65    BLOCK END - Create wandering monster
66    Reset the between counter
67    BLOCK END - wander roll
68    BLOCK END - rollwand
69    BLANK
70    COMMENT
71    COMMENT
72    COMMENT
73    COMMENT

REMOVE PLAYER CONFUSION

74    Defines unconfuse with no arguments
75    BLOCK START - unconfuse player
76    Reset the player's confused flag
77    Send message that player is no longer confused
78    BLOCK END - unconfuse player
79    BLANK
80    COMMENT
81    COMMENT
82    COMMENT
83    COMMENT

REMOVE PLAYER SEE INVIS

84    Defines unsee with no arguments
85    BLOCK START - unsee, remove see invisible
86    Declare a pointer to an object
87    BLANK
88    Loop through the monster list
89    If the monster is invisible, but the player can see the monster
90    Add the monster's buffered character (floor tile) to the position
91    Remove the player's see-inivisble flag
92    BLOCK END - unsee
93    BLANK
94    COMMENT
95    COMMENT
96    COMMENT
97    COMMENT

REMOVE PLAYER BLINDNESS

98    Defines sight with no arguments
99    BLOCK START - sight, remove player blindness
100   If the player is blind...
101   BLOCK START - remove blindness
102   Remove this daemon from processing
103   Remove the player blindness flag
104   If the player is in an actual room
105   Run the room visibility procedure
106   Send a message that the player can now see
107   BLOCK END - remove blindness
108   BLOCK END - sight
109   BLANK
110   COMMENT
111   COMMENT
112   COMMENT
113   COMMENT

REMOVE HASTE

114   Defines nohaste with no arguments
115   BLOCK START - nohaste, player loses haste effect
116   Remove the haste flag
117   Send a message about slowing down
118   BLOCK END - nohaste
119   BLANK
120   COMMENT
121   COMMENT
122   COMMENT
123   COMMENT

HUNGER DAEMON

124   Defines stomach with no arguments
125   BLOCK START - stomach, makes the player more hungry. Adds hunger effects
126   Declares temporary variables to track old values and changes
127   BLANK
128   If the player has an empty stomach
129   BLOCK START - Starvation effects
130   If the player's starvation time is lower than the limit...
131   Player dies
132   COMMENT
133   COMMENT
134   COMMENT
135   If the player is already sleeping, or a random 20% chance roll...
136   Return without effects
137   Player loses between 4 and 12 turns
138   Player is no longer running
139   Remove global running flag
140   Reset event counter
141   Set the player's hunger state to bad
142   Send message that the player is starving
143   BLOCK END - Starvation effects
144   Otherwise, the player isn't completely starving..
145   BLOCK START - food level change
146   Get the current food level
147   COMMENT
148   COMMENT
149   COMMENT
150   COMMENT
151   Player rings use up food faster
152   Terse mode...
153   Uses up more food!! Smaller levels means more time passes to balance
154   Remove the player's food level
155   BLANK
156   If the player's food level passes the 2nd level threshold...
157   BLOCK START - getting weak from no food
158   Set hungry state to 2nd highest
159   Send message about getting weak
160   BLOCK END - getting weak from no food
161   Otherwise, check if player is passing the first threshold
162   BLOCK START - getting hungry from no food
163   Set hunger state to 3rd highest
164   Send message about getting hungry
165   BLOCK END - getting hungry from no food
166   BLOCK END - food level change
167   BLOCK END - stomach
168   EOF