Decoded: Rogue (1980) by Toy, Arnold, Wichman DOS version (1983) by Mel Sibony and Jon Lane Source file: POTIONS.C Beginner friendly, line-by-line code walkthrough by MaiZure POTIONS.C provides potion usage and effects Original code: https://britzl.github.io/roguearchive/ Original code with line numbers http://www.maizure.org/projects/decoded-rogue/POTIONS_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 COMMENT 11 COMMENT 12 COMMENT 13 COMMENT DRINK A POTION 14 Defines quaff with no arguments 15 BLOCK START - quaff, drinks a potion and applies effects 16 Declare a pointer to the potion and a monster 17 Declare a flag to remove inventory potion stack if it's empty 18 BLANK 19 Ask the player to choose a potion from inventory and if they don't... 20 Return - nothing to drink 21 COMMENT 22 COMMENT 23 COMMENT 24 If the chosen object is not a potion.. 25 BLOCK START - Drinking non-potion 26 Print a message to the player 27 Return failure 28 BLOCK END - Drinking non-potion 29 If the player chose to drink their weapon (shouldn't actually execute) 30 Take off the weapon 31 BLANK 32 COMMENT 33 COMMENT 34 COMMENT 35 Switch on potion effect 36 BLOCK START - Switch on potion effect 37 CASE confusion potion 38 Player now knows about confusion 39 If the player isn't already confused 40 BLOCK START - add confusion effect 41 If the player is a already confused... 42 Add up to 27 ticks of confusion to the player 43 Otherwise player isn't confused 44 Confuse player for up to 27 turns 45 Set the player confusion flag 46 Print a message to the player 47 BLOCK END - add confusion effect 48 CASE poison potion 49 BLOCK START - add poison effect 50 Initialize a sickness message string 51 BLANK 52 The player now knows about poison potions 53 If the player isn't wearing a strength sustainment ring.. 54 BLOCK START - poison strength reduction 55 Remove between 1 and 3 points of strength 56 Print a message to the player 57 BLOCK END - poison strength reduction 58 Otherwise the player doesn't lose strength 59 Print a message to the player 60 BLOCK END - add poison effect 61 CASE healing potion 62 The player now knows about healing potions 63 Add a random amount of health (level d4). If it's greater than max hp 64 Add 1 to player max health and clamp current health 65 Remove player blindness 66 Print a message to the player 67 CASE strength potion 68 The player now knows about strength potions 69 Add 1 to strength 70 Print a message to the player 71 CASE monster magic potion 72 If this is NOT the demo version... 73 Add a timer to player confusion 74 If there are no monster... 75 Print a message to the player 76 Print an extended message to the player 77 Otherwise.. 78 BLOCK START - reveal monsters 79 If player sees a new monster they now know about detect monster potions 80 Clear message buffer 81 BLOCK START - reveal monsters 82 Poor demo players get to read an advertisement 83 Print an annoying demo message to the player 84 Print an annoying demo message to the player 85 Print an annoying demo message to the player 86 Print an annoying demo message to the player 87 Print an annoying demo message to the player 88 Print an annoying demo message to the player 89 Players now know about detect monster potions 90 End check for demo version 91 CASE magic detection potion 92 COMMENT 93 COMMENT 94 COMMENT 95 COMMENT 96 COMMENT 97 If the level has items...(BUG: No loose items - cant see monster items?) 98 BLOCK START - Reveal magical things 99 Declare a poointer to an item 100 Declare a flag to reveal items 101 BLANK 102 Assume we can't see items to start 103 Loop through all loose items on the level 104 BLOCK START - Reveal magical items 105 If the item is magic 106 BLOCK START - Verify magical items 107 Reveal item 108 Add the object's character to the map 109 If they player sees a new magic item they now know about detect potions 110 BLOCK END - Verify magical items 111 BLOCK END - Reveal magical items 112 Loop through all monsters 113 BLOCK START - Check all monster for magical items 114 Loop through all inventories 115 BLOCK START - Check monster inventories for magical items 116 If the item is magical... 117 BLOCK START - Verify magical items in inventories 118 Reveal the item 119 Add the item to the map 120 If the player sees a new magic monster now knows about detect potions 121 BLOCK END - Verify magical items in inventories 122 BLOCK END - Check monster inventories for magical items 123 BLOCK END - Check all monsters for magical items 124 If at least one item was revealed... 125 BLOCK START - Item reveal message 126 Print a message to the player 127 BLOCK END - Item reveal message 128 End loop 129 BLOCK END - Reveal magical things 130 Print a message to the player 131 Print an extended message to the player 132 CASE paralyze potion 133 The player now knows about paralyze potions 134 Cancel up to 2 player turns 135 Remove player running flag 136 Print a paralyze message to the player 137 CASE detect invisible potion 138 If the player can't already see invisible.. 139 Set the timer to remove effect in up to between 270-330 turns 140 Partially update the screen 141 Turn on see invisible 142 End check for see invisible 143 Remove blindness 144 Print a see invis message to the player 145 CASE raise level potion 146 The player now knows about raise level potions 147 Print a message to the player 148 Increase player level 149 CASE extra healing potion 150 The player now knows about extra healing potions 151 Boost player health (level)d8 points and if we're higher than max health 152 BLOCK START - Permanent health boost 153 If health is far above max 154 Add a first bonus to max health 155 In all cases, add at least 1 health to permanent 156 BLOCK END - Permanent health boost 157 Remove blindness 158 Print a message to the player 159 CASE haste potion 160 The player now knows about haste potions 161 Add haste to the player 162 Print a haste message to the player 163 CASE restore strength potion 164 If the player is wear a strength ring on the left hand... 165 Remove the ring's bonus for now to calculate base strength 166 If the player is wear a strength ring on the right hand... 167 Remove the ring's bonus for now to calculate base strength 168 If the player's current strength is less than maximum... 169 Set current strength back to maximum 170 If the player is wear a strength ring on the left hand... 171 Re-apply the ring's strength bonus 172 If the player is wear a strength ring on the right hand... 173 Re-apply the ring's strength bonus 174 Print a message to the player 175 Print an extended message to the player 176 CASE blindness potion 177 The player now knows about blindness potions 178 If the player isn't blind... 179 BLOCK START - Blind player 180 Set the player's blindness flag 181 Add a timer for blindness, 270-330 turns 182 Partially update view 183 BLOCK END - Blind player 184 Print a blindness message to the player 185 CASE placebo potion 186 Print a useless potion message to the player 187 CASE unknown potion 188 Print an unknown potion message to the player 189 Potion is finished - return 190 BLOCK END - Switch on potion effect 191 Update status bar with new effect 192 COMMENT 193 COMMENT 194 COMMENT 195 Decrement the inventory counter 196 If the potion stack has more than one of these potions.. 197 Decrement the stack 198 Otherwise the stack is empty 199 BLOCK START - Remove potion stack from inventory 200 Remove potion from inventory 201 Set flag to destroy potion (still need the reference on line 204) 202 BLOCK END - Remove potion stack from inventory 203 BLANK 204 Update player knowledge about this potion type 205 BLANK 206 If this was the last potion in the stack 207 Free the object from memory 208 BLOCK END - quaff 209 BLANK 210 COMMENT 211 COMMENT 212 COMMENT 213 COMMENT SEE INIVISIBLE EFFECT 214 Define invis_on with no arguments 215 BLOCK START - invis_on, turn on see invisible effect 216 Declare a pointer to a monster 217 BLANK 218 Set the player's see invisible flag 219 Loop through the monster list 220 If the monster is inivisble and the player can see the monster.. 221 BLOCK START - See invisible monster 222 Add the monster's visible character to the screen 223 BLOCK END - See invisible monster 224 BLOCK END - invis_on 225 BLANK 226 COMMENT 227 COMMENT 228 COMMENT 229 COMMENT DETECT MONSTERS EFFECT 230 Defines turn_see with one argument 231 Argument 1 is a flag to turn off detect monster 232 BLOCK START - turn_see, toggle detect monsters effect 233 Declare a pointer to a monster 234 Declare flags for seeing monsters 235 Declare a char for the old value 236 BLANK 237 Assume there is nothing to add 238 Loop through all monsters on the level 239 Move the cursor to the current monster 240 Player can see the monster if he is visible or he previously saw it 241 If we are turning off detect monsters... 242 If we can no longer see the monster and we previous saw the monster 243 Draw the old character in place 244 Otherwise we're turning on detect monsters 245 If player can't see the monster... 246 Turn on emphasis 247 Save the monster's previous character 248 End check for can't see 249 Add the character real character to display 250 If the player can't actually see the monster 251 Remove extended emphasis formatting 252 Increment the add monster counter 253 End check for can't see 254 End check for turning on detect mosnter 255 Repeat loop for all monsters 256 Set the player's detect monster flag 257 If we're turning off detect monsters 258 Reset the detect monster flag 259 Return the number of new monsters added 260 BLOCK END - turn_see 261 BLANK 262 COMMENT 263 COMMENT 264 COMMENT 265 COMMENT 266 BLANK MONSTER EFFECT POTIONS 267 Defines th_effect with two arguments 268 Arguments 1 and 2 are object pointers to a potion and a monster 269 BLOCK START - th_effect, apply thrown potion effect to monsters 270 Switch on the potion magic type 271 BLOCK START - Switch on potion type 272 CASE confuse effect 273 CASE blind effect 274 Set the confusion flag on the monster 275 Print a message to the player 276 CASE paralyze effect 277 Remove the running flag on the monster 278 Set the held flag on the monster 279 CASE healing effect 280 CASE extra healing effect 281 Add up to 7 health points and if health is higher than max... 282 Add to max health and max out current health 283 CASE raise level effect 284 Add 8 hitpoints to monster 285 Add 8 maximum hitpoints to monster 286 Increase monster level 287 CASE haste effect 288 Set haste flag on monster 289 BLOCK END - Switch on potion type 290 Print a message to the player 291 BLOCK END - th_effect 292 EOF˙