Decoded: Rogue (1980) by Toy, Arnold, Wichman DOS version (1983) by Mel Sibony and Jon Lane Source file: RINGS.C Beginner friendly, line-by-line code walkthrough by MaiZure RINGS.C contains all the procedures for wearing rings and applying effects Original code: https://britzl.github.io/roguearchive/ Original code with line numbers http://www.maizure.org/projects/decoded-rogue/RINGS_linenum.txt 1 COMMENT 2 COMMENT 3 COMMENT 4 COMMENT 5 COMMENT 6 BLANK 7 Include the game header 8 Included the console management header 9 BLANK 10 BLANK 11 COMMENT 12 COMMENT 13 COMMENT 14 COMMENT WEAR RING 15 Define ring_on with no arguments 16 BLOCK START - ring_on, wears a ring and applies effects 17 Declares a pointer to an object, hopefully a ring 18 Initializes a counter for ring wear slots 19 BLANK 20 If the player doesn't have a ring inventory... 21 Jump to failure handler on line 67 22 COMMENT 23 COMMENT 24 COMMENT 25 If the selected item from inventory is not a ring... 26 Send a failure message 27 Jump to failure exit handler on line 67 28 End check for non-ring type 29 BLANK 30 COMMENT 31 COMMENT 32 COMMENT 33 If the chosen ring is already worn... 34 Nothing to do - jump to failure case on line 67 35 BLANK 36 If there is no ring on the left hand... 37 Tag the ring to wear on the left hand 38 If there is no ring on the right hnd... 39 Tag the ring to wear on the right hand 40 If there are no rings on either hand... 41 Ask the player for a hand and if the player doesn't choose one... 42 Jump to failure on line 67 43 If there is no free ring slot... 44 Send a message that all ring slots are in use 45 Jump to failure case on line 67 46 End check for all rings worn 47 Wear. That. Ring. Finally! 48 BLANK 49 COMMENT 50 COMMENT 51 COMMENT 52 BLOCK START - SWITCH on ring magical effect 53 CASE strength ring 54 Change strength based on the ring's power level 55 Break from check for magic effect 56 CASE see inivisible ring 57 Activate see invisible for the player 58 Break from check for magic effect 59 CASE aggro ring 60 Set off the monsters on the level 61 Break from check for magic effect 62 BLOCK END - SWITCH on ring magical effect 63 BLANK 64 Print message that ring is now worn 65 Return success 66 BLANK 67 Ring wear failure exit handler 68 Do not waste a turn on this failure 69 Return to 70 BLOCK END - ring_on 71 BLANK 72 COMMENT 73 COMMENT 74 COMMENT 75 COMMENT TAKE OFF A RING 76 Defines ring_off with no arguments 77 BLOCK START - ring_off, removes a ring and its effects 78 Declare an index for a ring slot 79 Declare a pointer to a item, hopefully a ring 80 Declare a character for an inventory letter tag 81 BLANK 82 If there are no rings worn... 83 Print failure message 84 Don't pass time 85 Return failure 86 Otherwise, if there is no ring on the left hand... 87 Player must want to take off a ring from the right hand 88 Conversely, if there is no ring on the right.... 89 Player must want to remove ring from the left hand 90 Finally... 91 Allow the player to choose a hand, but if they don't 92 Return failure 93 Reset position in the message buffer 94 Point to the chosen ring 95 If the object doesn't exist... 96 Print a failure message 97 Don't pass a turn 98 Return failure 99 End check for no ring 100 Get the inventory letter of the ring 101 If the ring can be removed...remove it 102 Send a message that the ring was removed 103 BLOCK END - ring_off 104 BLANK 105 COMMENT 106 COMMENT 107 COMMENT 108 COMMENT GET HAND CHOICE FROM PLAYER 109 Define gethand with no arguments 110 BLOCK START - gethand, requests the interested hand from the player 111 Declare a character to hold player's selection 112 BLANK 113 Loop forever... 114 Print a query for the player to choose a hand 115 If the player pressed escape 116 Don't pass a turn 117 Return failure to choose 118 End check for escape 119 Reset message buffer position 120 If the player chose [lL] 121 Return index for the left hand 122 If the player chose [rR] 123 Return the index for the right hand 124 Otherwise, the player chose something odd - print instructions 125 Retry loop until good input is received 126 BLOCK END - gethand 127 BLANK 128 COMMENT 129 COMMENT 130 COMMENT 131 COMMENT EXTRA FOOD CONSUMPTION FOR RINGS 132 Define ring eat_with one argument 133 Argument 1 is the hand index (left or right) 134 BLOCK START - ring_eat, ring magic alters player food consumption 135 If the chose hand has no ring... 136 Return failure 137 BLOCK START - SWITCH on ring type 138 CASE regeneration ring 139 Set extra food consumption to 2 140 CASE sustain strength (fallthrough) 141 CASE sustain armor (fallthrough) 142 CASE protection (fallthrough) 143 CASE add strength (fallthrough) 144 CASE stealth 145 Set extra food consumption to 1 146 CASE searching 147 20% chance of 1 consumption, otherwise 0 148 CASE hit chance bonus (fallthrough) 149 CASE damage bonus 150 33% chance of 1 consumption, otherwise 0 151 CASE slow digestion 152 Reduced food usage, -2 or -1 153 CASE see invisible 154 20% chance of 1, otherwise 0 155 All other ring types.. 156 No extra food consumption 157 BLOCK END - SWITCH on ring type 158 BLOCK END - ring_eat 159 BLANK 160 COMMENT 161 COMMENT 162 COMMENT 163 COMMENT PRINT RING INFORMATION 164 ring_num returns a string pointer 165 Defines ring_num with one argument 166 Argument 1 is a pointer to an object, hopefull ring 167 BLOCK START - ring_num, prints information about the ring 168 Declare a temporary string buffer 169 BLANK 170 If the player doesn't know about the ring 171 Return no information 172 BLOCK START - SWITCH on ring type 173 CASE protection ring (fallthrough) 174 CASE add strength (fallthrough) 175 CASE add damage (fallthrough) 176 CASE add hit chance 177 First character of the ring buffer is blank (a space) 178 Get the ring's bonuses and power 179 CASE other ring types 180 Return nothing 181 BLOCK END - SWITCH on ring type 182 Return the ring text 183 BLOCK END - ring_num 184 EOF˙