1 /* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Timothy C. Stoehr. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)ring.c 8.1 (Berkeley) 05/31/93"; 13 #endif /* not lint */ 14 15 /* 16 * ring.c 17 * 18 * This source herein may be modified and/or distributed by anybody who 19 * so desires, with the following restrictions: 20 * 1.) No portion of this notice shall be removed. 21 * 2.) Credit shall not be taken for the creation of this source. 22 * 3.) This code is not to be traded, sold, or used for personal 23 * gain or profit. 24 * 25 */ 26 27 #include "rogue.h" 28 29 char *left_or_right = "left or right hand?"; 30 char *no_ring = "there's no ring on that hand"; 31 short stealthy; 32 short r_rings; 33 short add_strength; 34 short e_rings; 35 short regeneration; 36 short ring_exp; 37 short auto_search; 38 boolean r_teleport; 39 boolean r_see_invisible; 40 boolean sustain_strength; 41 boolean maintain_armor; 42 43 extern char *curse_message; 44 extern boolean wizard; 45 46 put_on_ring() 47 { 48 short ch; 49 char desc[DCOLS]; 50 object *ring; 51 52 if (r_rings == 2) { 53 message("wearing two rings already", 0); 54 return; 55 } 56 if ((ch = pack_letter("put on what?", RING)) == CANCEL) { 57 return; 58 } 59 if (!(ring = get_letter_object(ch))) { 60 message("no such item.", 0); 61 return; 62 } 63 if (!(ring->what_is & RING)) { 64 message("that's not a ring", 0); 65 return; 66 } 67 if (ring->in_use_flags & (ON_LEFT_HAND | ON_RIGHT_HAND)) { 68 message("that ring is already being worn", 0); 69 return; 70 } 71 if (r_rings == 1) { 72 ch = (rogue.left_ring ? 'r' : 'l'); 73 } else { 74 message(left_or_right, 0); 75 do { 76 ch = rgetchar(); 77 } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') && (ch != '\n') && 78 (ch != '\r')); 79 } 80 if ((ch != 'l') && (ch != 'r')) { 81 check_message(); 82 return; 83 } 84 if (((ch == 'l') && rogue.left_ring)||((ch == 'r') && rogue.right_ring)) { 85 check_message(); 86 message("there's already a ring on that hand", 0); 87 return; 88 } 89 if (ch == 'l') { 90 do_put_on(ring, 1); 91 } else { 92 do_put_on(ring, 0); 93 } 94 ring_stats(1); 95 check_message(); 96 get_desc(ring, desc); 97 message(desc, 0); 98 (void) reg_move(); 99 } 100 101 /* 102 * Do not call ring_stats() from within do_put_on(). It will cause 103 * serious problems when do_put_on() is called from read_pack() in restore(). 104 */ 105 106 do_put_on(ring, on_left) 107 object *ring; 108 boolean on_left; 109 { 110 if (on_left) { 111 ring->in_use_flags |= ON_LEFT_HAND; 112 rogue.left_ring = ring; 113 } else { 114 ring->in_use_flags |= ON_RIGHT_HAND; 115 rogue.right_ring = ring; 116 } 117 } 118 119 remove_ring() 120 { 121 boolean left = 0, right = 0; 122 short ch; 123 char buf[DCOLS]; 124 object *ring; 125 126 if (r_rings == 0) { 127 inv_rings(); 128 } else if (rogue.left_ring && !rogue.right_ring) { 129 left = 1; 130 } else if (!rogue.left_ring && rogue.right_ring) { 131 right = 1; 132 } else { 133 message(left_or_right, 0); 134 do { 135 ch = rgetchar(); 136 } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') && 137 (ch != '\n') && (ch != '\r')); 138 left = (ch == 'l'); 139 right = (ch == 'r'); 140 check_message(); 141 } 142 if (left || right) { 143 if (left) { 144 if (rogue.left_ring) { 145 ring = rogue.left_ring; 146 } else { 147 message(no_ring, 0); 148 } 149 } else { 150 if (rogue.right_ring) { 151 ring = rogue.right_ring; 152 } else { 153 message(no_ring, 0); 154 } 155 } 156 if (ring->is_cursed) { 157 message(curse_message, 0); 158 } else { 159 un_put_on(ring); 160 (void) strcpy(buf, "removed "); 161 get_desc(ring, buf + 8); 162 message(buf, 0); 163 (void) reg_move(); 164 } 165 } 166 } 167 168 un_put_on(ring) 169 object *ring; 170 { 171 if (ring && (ring->in_use_flags & ON_LEFT_HAND)) { 172 ring->in_use_flags &= (~ON_LEFT_HAND); 173 rogue.left_ring = 0; 174 } else if (ring && (ring->in_use_flags & ON_RIGHT_HAND)) { 175 ring->in_use_flags &= (~ON_RIGHT_HAND); 176 rogue.right_ring = 0; 177 } 178 ring_stats(1); 179 } 180 181 gr_ring(ring, assign_wk) 182 object *ring; 183 boolean assign_wk; 184 { 185 ring->what_is = RING; 186 if (assign_wk) { 187 ring->which_kind = get_rand(0, (RINGS - 1)); 188 } 189 ring->class = 0; 190 191 switch(ring->which_kind) { 192 /* 193 case STEALTH: 194 break; 195 case SLOW_DIGEST: 196 break; 197 case REGENERATION: 198 break; 199 case R_SEE_INVISIBLE: 200 break; 201 case SUSTAIN_STRENGTH: 202 break; 203 case R_MAINTAIN_ARMOR: 204 break; 205 case SEARCHING: 206 break; 207 */ 208 case R_TELEPORT: 209 ring->is_cursed = 1; 210 break; 211 case ADD_STRENGTH: 212 case DEXTERITY: 213 while ((ring->class = (get_rand(0, 4) - 2)) == 0) ; 214 ring->is_cursed = (ring->class < 0); 215 break; 216 case ADORNMENT: 217 ring->is_cursed = coin_toss(); 218 break; 219 } 220 } 221 222 inv_rings() 223 { 224 char buf[DCOLS]; 225 226 if (r_rings == 0) { 227 message("not wearing any rings", 0); 228 } else { 229 if (rogue.left_ring) { 230 get_desc(rogue.left_ring, buf); 231 message(buf, 0); 232 } 233 if (rogue.right_ring) { 234 get_desc(rogue.right_ring, buf); 235 message(buf, 0); 236 } 237 } 238 if (wizard) { 239 sprintf(buf, "ste %d, r_r %d, e_r %d, r_t %d, s_s %d, a_s %d, reg %d, r_e %d, s_i %d, m_a %d, aus %d", 240 stealthy, r_rings, e_rings, r_teleport, sustain_strength, 241 add_strength, regeneration, ring_exp, r_see_invisible, 242 maintain_armor, auto_search); 243 message(buf, 0); 244 } 245 } 246 247 ring_stats(pr) 248 boolean pr; 249 { 250 short i; 251 object *ring; 252 253 stealthy = 0; 254 r_rings = 0; 255 e_rings = 0; 256 r_teleport = 0; 257 sustain_strength = 0; 258 add_strength = 0; 259 regeneration = 0; 260 ring_exp = 0; 261 r_see_invisible = 0; 262 maintain_armor = 0; 263 auto_search = 0; 264 265 for (i = 0; i < 2; i++) { 266 if (!(ring = ((i == 0) ? rogue.left_ring : rogue.right_ring))) { 267 continue; 268 } 269 r_rings++; 270 e_rings++; 271 switch(ring->which_kind) { 272 case STEALTH: 273 stealthy++; 274 break; 275 case R_TELEPORT: 276 r_teleport = 1; 277 break; 278 case REGENERATION: 279 regeneration++; 280 break; 281 case SLOW_DIGEST: 282 e_rings -= 2; 283 break; 284 case ADD_STRENGTH: 285 add_strength += ring->class; 286 break; 287 case SUSTAIN_STRENGTH: 288 sustain_strength = 1; 289 break; 290 case DEXTERITY: 291 ring_exp += ring->class; 292 break; 293 case ADORNMENT: 294 break; 295 case R_SEE_INVISIBLE: 296 r_see_invisible = 1; 297 break; 298 case MAINTAIN_ARMOR: 299 maintain_armor = 1; 300 break; 301 case SEARCHING: 302 auto_search += 2; 303 break; 304 } 305 } 306 if (pr) { 307 print_stats(STAT_STRENGTH); 308 relight(); 309 } 310 } 311