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

SCROLLS.C implements scroll usage and the associated effects

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

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



1     COMMENT
2     COMMENT
3     COMMENT
4     COMMENT
5     COMMENT
6     BLANK
7     Include game header
8     Include console management header
9     BLANK
10    Declare a string used when reading a scare monster scroll
11    Declare an extra string for scare monster scrolls (non-terse extension)
12    COMMENT
13    COMMENT
14    COMMENT
15    COMMENT

READ A SCROLL
The largest procedure in the game!

16    Defines read_scroll with no arguments
17    BLOCK START - read_scroll, invokes scroll magic
18    Declare a pointer to the scroll
19    Declare position iterators
20    Declare a character to hold map values
21    Declare a pointer to a monster
22    Declare an array index
23    Declare a flag for destroying a scroll
24    BLANK
25    Query the player for a scroll to read
26    If the player didn't choose anything
27    Do nothing
28    If the player didn't choose a scroll
29    Print failure message
30    Return failure
31    End check for non-scroll reading
32    Print out a message that the scroll has been used
33    COMMENT
34    COMMENT
35    COMMENT
36    If the player read his weapon...?
37    Remove the weapon (still in inventory)
38    BLOCK START - Switch on scroll type

CONFUSION SCROLL

39    CASE confusion scroll
40    COMMENT
41    COMMENT
42    COMMENT
43    The player can now confuse monsters
44    Print a message for the player

ARMOR SCROLL

45    CASE armor scroll
46    If the player is wearing armor
47    Reduce (improve) the armor class
48    Remove the cursed flag
49    Print a message for the player
50    End check for wearing armor

HOLD MONSTER SCROLL

51    CASE hold monster scroll
52    COMMENT
53    COMMENT
54    COMMENT
55    COMMENT
56    BLANK
57    Loop across the nearest 7 columns around the player
58    ..as long as it's not off the map..
59    And loop through the 7 rows around the player..
60    If this position is on the map and there is a monster...
61    Remove the monster's run flag
62    Add the monster held flag
63    End check for monster

SLEEP SCROLL

64    CASE sleep scroll
65    COMMENT
66    COMMENT
67    COMMENT
68    Player now knows about the sleep scroll
69    Put the player to sleep for 9 or 10 turns
70    Player is no longer runner
71    Print a message for the player

CREATE MONSTER SCROLL

72    CASE create monster scroll
73    BLOCK START - create monster
74    Declare a coordinate for a new monster
75    BLANK
76    If we successfully create a new monster near the player...
77    Initialize the monster in the new location
78    Otherwise...
79    Print a terse message for the player
80    Print an extended message for the player
81    BLOCK END - create monster

IDENTIFY SCROLL

82    CASE identify scroll
83    COMMENT
84    COMMENT
85    COMMENT
86    The player now knows the identify scroll
87    Print a message for the player
88    IF the player selects an item...
89    Wait for more input
90    Reveal the identify of the target

MAP SCROLL

91    CASE show map scroll
92    COMMENT
93    COMMENT
94    COMMENT
95    The player now knows the map scroll
96    Print a message for the player
97    COMMENT
98    COMMENT
99    COMMENT
100   Loop through all map rows
101   And loop through all map columns
102   Get the data array position
103   Switch on the map position character
104   BLOCK START - Switch on map location type
105   CASE vertical wall (fallthrough)
106   CASE horizontal wall (fallthrough)
107   CASE upper-left corner wall (fallthrough)
108   CASE upper-right corner wall (fallthrough)
109   CASE lower-left corner wall (fallthrough)
110   CASE lower-right corner wall
111   If the wall position is fake
112   Reveal the door in that position
113   Remove the fake flag
114   End check for fake walls
115   CASE door (fallthrough)
116   CASE passage (fallthrough)
117   CASE stairs
118   If there is a monster at this position
119   And the monster hasn't buffered the proper floor character
120   Buffer it now
121   Break on floor type
122   CASE any other floor type
123   Character is blank
124   BLOCK END - Switch on map location type
125   If the character is a door
126   Move cursor to the door
127   If the actual charater there isn't a door
128   Emphasize the output (invert)
129   End check for door
130   If the character isn't a blank
131   Draw the actual character
132   End extended output formatting
133   End loop through the whole map

DETECT FOOD SCROLL

134   CASE detect food scroll
135   COMMENT
136   COMMENT
137   COMMENT
138   Clear the character variable
139   Loop through all objects on the level
140   If there is an object of type food
141   Set the character variable to true
142   Emphasize output
143   Draw the food in it's real position
144   End printing emphasis 
145   Otherwise this isn't food but...
146   If the object is the amulet
147   Set character flag to true
148   Emphasize printing output
149   Draw the amulet
150   End printing emphasis
151   End check for amulet
152   Retry loop through level
153   If any food or the amulet was detected on the level...
154   The player now knows about detect food scrolls
155   Print a successful message for the player
156   Otherwise
157   Print an unsuccessful message for the player

TELEPORT SCROLL

158   CASE teleport scroll
159   COMMENT
160   COMMENT
161   COMMENT
162   COMMENT
163   BLOCK START - Teleport player
164   Declare a pointer to a room
165   BLANK
166   Get the current room
167   Teleport!
168   If the room changed
169   Player now knows about the teleport scroll
170   BLOCK END - Teleport player

ENCHANTMENT SCROLL

171   CASE enchantment scroll
172   If the player has no weapon or isn't using a weapon
173   Print a failure message for the unwise player
174   Otherwise
175   BLOCK START - Enchant wepaon
176   Remove curse flag
177   Roll a 50% chance...
178   To improve hit bonus
179   Otherwise
180   Boost damage bonus
181   Print a message for the player
182   BLOCK END - Enchant weapon

SCARE MONSTER SCROLL

183   CASE scare monster scroll
184   COMMENT
185   COMMENT
186   COMMENT
187   COMMENT
188   Laugh mercilessly at the player

REMOVE CURSE SCROLL

189   CASE remove curse scroll
190   If the player is wearing armor
191   Remove armor curse
192   If the player is wearing a weapon
193   Remove weapon curse
194   If the player is wearing a left ring
195   Remove left ring curse
196   If the player is wearing a right ring
197   Remove right ring curse
198   Print a message for the player

AGGRAVATE MONSTER SCROLL

199   CASE aggravate monster scroll
200   COMMENT
201   COMMENT
202   COMMENT
203   COMMENT
204   Activate all monsters!
205   Print a message for the player
206   Print a message for the player

USELESS SCROLL

207   CASE useless scroll
208   Print an equally useless message

VORPAL SCROLL

209   CASE vorpal enchantment scroll
210   COMMENT
211   COMMENT
212   COMMENT
213   COMMENT
214   COMMENT
215   COMMENT
216   COMMENT
217   COMMENT
218   COMMENT
219   COMMENT
220   COMMENT
221   COMMENT
222   COMMENT
223   COMMENT
224   If the player is not wearing a weapon...
225   Laugh mercilessly at the poor guy
226   Otherwise....
227   COMMENT
228   COMMENT
229   COMMENT
230   If the weapon already has a vorpal enchantment
231   Print a bad message for the player
232   Include the name of the weapon
233   Steal the weapon from the player
234   Destroy it forever
235   Leave the player with empty hands
236   Otherwise...
237   Choose a random monster to vorpalize
238   Add a hit bonus to the weapon
239   Add a damage bonus to the weapon
240   Add charges to the weapon
241   Print a message about a blinding flash
242   A very blinding flash!
243   BLANK
244   COMMENT
245   COMMENT
246   COMMENT
247   COMMENT
248   COMMENT
249   COMMENT
250   COMMENT
251   COMMENT
252   COMMENT
253   COMMENT
254   COMMENT
255   COMMENT
256   End vorpal enchantment
257   End check for current weapon

UNKNOWN SCROLL

258   CASE unknown scroll type
259   Print message about the unknown scroll type
260   Return without anything happening
261   BLOCK END - Switch on scroll type
262   Full update of the screen
263   Update status bar
264   COMMENT
265   COMMENT
266   COMMENT
267   Decrement inventory counter
268   If there is more than one scroll on the stack
269   Decrement th stack counter
270   Otherwise there was only one scroll of this type
271   BLOCK START - Remove inventory stack
272   Remove from inventory
273   Set discard flag to true
274   BLOCK END - Remove inventory stack
275   Update player's knowledge about the scroll
276   BLANK
277   If we're discarding the object
278   Free the memory
279   BLOCK END - read_scroll
280   EOF