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

WIZARD.C are debug/developer/dungeonmaster/god commands that are used in
several places.

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

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



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

IDENTIFY OBJECT

16    Define whatis with no arguments
17    BLOCK START - whatis, identifies an object
18    Declare pointer to the object
19    BLANK
20    If the player has no inventory...
21    Print failure message
22    Return failure
23    End check for inventory
24    BLANK
25    Loop forever while the player chooses something
26    If the player doesn't choose anything...
27    Print instructions
28    Print a blank space
29    Reset message buffer
30    Otherwise, the player chose something
31    Break from loop
32    BLANK
33    BLOCK START - Switch on chosen object type
34    CASE scroll
35    Set scroll type to known
36    Remove any guesses
37    CASE potion
38    Set potion type to known
39    Remove any guesses
40    CASE wand/staff
41    Set wand/staff type to known
42    Set the known flag
43    Remove any guesses
44    CASE weapon (fallthrough)
45    CASE armor
46    Set the known flag
47    CASE ring
48    Set the ring magic to known
49    Set the ring to known
50    Remove any guesses
51    BLOCK END - Switch on chosen object type
52    COMMENT
53    COMMENT
54    COMMENT
55    COMMENT
56    If the object has a vorpal enchantment...
57    Reveal the enchantment
58    Print out all information about the object
59    BLOCK START - whatis
60    BLANK
61    Checks for wizard mode preprocessor definition
62    COMMENT
63    COMMENT
64    COMMENT
65    COMMENT

CREATE OBJECT

66    Defines create_object with no arguments
67    BLOCK START - create_obj, creates an object out of thin air
68    Declare a pointer to an object
69    Declare a user input character and a magic effect blessing character
70    BLANK
71    Create a new blank object, but if one couldn't be created (memory)
72    BLOCK START - Can't create any item
73    Print fail message
74    Return fail
75    BLOCK END - Can't create any item
76    Query user for type of item to create
77    BLOCK START - Switch on user input to create item
78    CASE !: new object is a potion
79    CASE ?: new object is a scroll
80    CASE /: new object is a wand/staff
81    CASE =: new object is a ring
82    CASE ): new object is a weapon
83    CASE ]: new object is armor
84    CASE ,: new object is the amulet of Yendor
85    Otherwise...
86    New object is food
87    BLOCK END - Switch on user input to create item
88    Reset message buffer position to 0
89    Ask player for the object's magical effect
90    Read in user input and set the effect
91    New object is in item group 0
92    There is only 1 new object
93    Set all damage to 0d0 for now
94    Reset message buffer to position 0
95    If the object is a weapon or armor
96    BLOCK START - Set damage or protection values
97    Ask for a blessing type on the gear (good, bad, or not)
98    Get user input
99    Reset message buffer
100   If the blessing is negative...
101   Set the item cursed flag
102   If the new object is a weapon...
103   BLOCK START - Bless new weapon
104   Initialize the object as a weapon
105   If the blessing is negative...
106   Reduce the item's hit bonus between 1 and 3 points
107   If the blessing is positive
108   Boost the item's hit bonus between 1 and 3 points
109   BLOCK END - Bless new weapon
110   Otherwise, this item is armor...
111   BLOCK START - Bless new armor
112   Set the base armor class based on the armor table
113   If the blessing is negative
114   Increase (worsen) armor class between 1 and 3 points
115   If the blessing is positive
116   Decrease (improve) armor class between 1 and 3 points
117   BLOCK END - Bless new armor
118   BLOCK END - Set damage or protection values
119   If we're creating a ring...
120   Switch on ring effects
121   BLOCK START - Switch on ring effects for blessing
122   CASE protection ring (fallthrough)
123   CASE strength ring (fallthrough)
124   CASE hit bonus ring (fallthrough)
125   CASE damage bonus ring (fallthrough)
126   Ask the player for a blessing
127   Read player input
128   Reset message buffer
129   If the blessing is negative...
130   Ring is now cursed
131   Ring ac (power) is reduced by -1 if negative, boosted 1-2 if positive
132   CASE monster aggression ring (fallthrough)
133   CASE teleport ring
134   These rings are always cursed
135   BLOCK END - Switch on ring effects for blessing
136   If this is a wand/staff
137   Initialize the wand/staff
138   Otherwise, if this is a gold pile
139   BLOCK START - Make a gold pile
140   Ask the player how big the gold pile is
141   Read and set the gold value
142   BLOCK END - Make a gold pile
143   Add the new item to the player's inventory
144   BLOCK START - create_obj
145   End check for wizard mode
146   BLANK
147   COMMENT
148   COMMENT
149   COMMENT
150   COMMENT

TELEPORT PLAYER

151   Define teleport with no arguments
152   BLOCK START - teleport, moves player to another location
153   Declare an index to a room number
154   Declare a coordinate for moving the player
155   BLANK
156   Remove player - draw the actual floor tile at the player's location
157   Loop through all rooms
158   BLOCK START - Choose random position in a random room
159   Choose the room
160   Choose a poisition in the room and redo loop if invalid
161   BLOCK END - Choose a random position in a random room
162   If the new room isn't the same room the player is in
163   BLOCK START - Change rooms
164   Exit the current room
165   Move the player to the new position
166   End the new room
167   BLOCK END - Change rooms
168   Otherwise the hero is still in the same room
169   BLOCK START - Teleport within the same room
170   Move the player to the new coordinates
171   Update screen
172   BLOCK END - Teleport within the same room
173   Draw the player in the new position
174   COMMENT
175   COMMENT
176   COMMENT
177   COMMENT
178   If the player is held by fungi
179   Teleport removes the held flag
180   Exit the flighting
181   End check for held player
182   Reset player no movement counter
183   Reset the general counter
184   Remove running mode
185   Clear user input buffer
186   COMMENT
187   COMMENT
188   COMMENT
189   COMMENT
190   Checks for wizard mode preprocessor definition
191   If wizard mode is not active (this was a basic magical teleport)
192   BLOCK START - Regular teleport
193   End check for wizard mode
194   If the player is confused...
195   Extend player's confusion time period
196   Otherwise player wasn't confused so...
197   Make them confused for a while
198   Set player confusion flag
199   End check for wizard mode
200   End check for wizard mode
201   End check for wizard mode
202   Return the current room index
203   BLOCK START - teleport
204   BLANK
205   Checks for UNIX mode preprocessor definition
206   Checks for wizard mode preprocessor definition
207   COMMENT
208   COMMENT
209   COMMENT
210   COMMENT

WIZARD PASSWORD

211   Define passwd with no arguments
212   BLOCK START - passwd, pings the player for the secret code
213   Declare a buffer pointers and a string pointer
214   Declare a buffer and a pointer to a hash function
215   BLANK
216   Prompt user for wizard password
217   Reset buffer position
218   Point to the temporary input buffer
219   Read the user input until newline character or an escape character
220   If the user is trying to exit this program (sig_kill)
221   Reset the buffer position to retry
222   If the user is trying to backspace or typing beyond the buffer
223   Backspace
224   Otherwise this is a normal character
225   Add it to the buffer
226   If the buffer is completely empty
227   Return fail
228   Nullterm the buffer so we can compare...
229   If the password hashes match the real password hash ('mT')..return true
230   BLOCK START - passwd
231   BLANK
232   End check for wizard definition
233   End check for UNIX definition
234   BLANK
235   Checks for wizard mode preprocessor definition
236   COMMENT
237   COMMENT
238   COMMENT
239   COMMENT

SHOW MAP

240   Defines show map with no arguments
241   BLOCK START - show_map, prints out the complete map
242   Declare integer iterators and a map value
243   BLANK
244   Save the current screen
245   Clear the screen
246   Loop through each row...
247   and loop through each column...
248   BLOCK START - Loop through map
249   If the value at the shown position is differen from actual  
250   Format for emphasis (inverted colors)
251   Add the actual map character
252   If the map character is different from actual
253   End the extended formatting
254   BLOCK END - Loop through map
255   Show a prompt and wait
256   Bring back the current game map
257   BLOCK START - show_map
258   BLANK

GET NUMBER FROM PLAYER

259   Define get_num with one argumen
260   Input is a pointer to an integer
261   BLOCK START - get_num, gets a number from the player
262   Declare a character buffer
263   BLANK
264   Get the number from the player
265   Convert the input string to a number
266   Return the number
267   BLOCK START - get_num
268   End check for wizard mode
269   BLANK
270   EOF