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 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)ring.c 8.1 (Berkeley) 5/31/93 33 * $FreeBSD: src/games/rogue/ring.c,v 1.3 1999/11/30 03:49:26 billf Exp $ 34 * $DragonFly: src/games/rogue/ring.c,v 1.3 2006/09/02 19:31:07 pavalos Exp $ 35 */ 36 37 /* 38 * ring.c 39 * 40 * This source herein may be modified and/or distributed by anybody who 41 * so desires, with the following restrictions: 42 * 1.) No portion of this notice shall be removed. 43 * 2.) Credit shall not be taken for the creation of this source. 44 * 3.) This code is not to be traded, sold, or used for personal 45 * gain or profit. 46 * 47 */ 48 49 #include "rogue.h" 50 51 const char *left_or_right = "left or right hand?"; 52 const char *no_ring = "there's no ring on that hand"; 53 short stealthy; 54 short r_rings; 55 short add_strength; 56 short e_rings; 57 short regeneration; 58 short ring_exp; 59 short auto_search; 60 boolean r_teleport; 61 boolean r_see_invisible; 62 boolean sustain_strength; 63 boolean maintain_armor; 64 65 extern char *curse_message; 66 extern boolean wizard; 67 68 void 69 put_on_ring(void) 70 { 71 short ch; 72 char desc[DCOLS]; 73 object *ring; 74 75 if (r_rings == 2) { 76 message("wearing two rings already", 0); 77 return; 78 } 79 if ((ch = pack_letter("put on what?", RING)) == CANCEL) { 80 return; 81 } 82 if (!(ring = get_letter_object(ch))) { 83 message("no such item.", 0); 84 return; 85 } 86 if (!(ring->what_is & RING)) { 87 message("that's not a ring", 0); 88 return; 89 } 90 if (ring->in_use_flags & (ON_LEFT_HAND | ON_RIGHT_HAND)) { 91 message("that ring is already being worn", 0); 92 return; 93 } 94 if (r_rings == 1) { 95 ch = (rogue.left_ring ? 'r' : 'l'); 96 } else { 97 message(left_or_right, 0); 98 do { 99 ch = rgetchar(); 100 } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') && (ch != '\n') && 101 (ch != '\r')); 102 } 103 if ((ch != 'l') && (ch != 'r')) { 104 check_message(); 105 return; 106 } 107 if (((ch == 'l') && rogue.left_ring)||((ch == 'r') && rogue.right_ring)) { 108 check_message(); 109 message("there's already a ring on that hand", 0); 110 return; 111 } 112 if (ch == 'l') { 113 do_put_on(ring, 1); 114 } else { 115 do_put_on(ring, 0); 116 } 117 ring_stats(1); 118 check_message(); 119 get_desc(ring, desc); 120 message(desc, 0); 121 reg_move(); 122 } 123 124 /* 125 * Do not call ring_stats() from within do_put_on(). It will cause 126 * serious problems when do_put_on() is called from read_pack() in restore(). 127 */ 128 129 void 130 do_put_on(object *ring, boolean on_left) 131 { 132 if (on_left) { 133 ring->in_use_flags |= ON_LEFT_HAND; 134 rogue.left_ring = ring; 135 } else { 136 ring->in_use_flags |= ON_RIGHT_HAND; 137 rogue.right_ring = ring; 138 } 139 } 140 141 void 142 remove_ring(void) 143 { 144 boolean left = 0, right = 0; 145 short ch; 146 char buf[DCOLS]; 147 object *ring; 148 149 ring = NULL; 150 if (r_rings == 0) { 151 inv_rings(); 152 } else if (rogue.left_ring && !rogue.right_ring) { 153 left = 1; 154 } else if (!rogue.left_ring && rogue.right_ring) { 155 right = 1; 156 } else { 157 message(left_or_right, 0); 158 do { 159 ch = rgetchar(); 160 } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') && 161 (ch != '\n') && (ch != '\r')); 162 left = (ch == 'l'); 163 right = (ch == 'r'); 164 check_message(); 165 } 166 if (left || right) { 167 if (left) { 168 if (rogue.left_ring) { 169 ring = rogue.left_ring; 170 } else { 171 message(no_ring, 0); 172 } 173 } else { 174 if (rogue.right_ring) { 175 ring = rogue.right_ring; 176 } else { 177 message(no_ring, 0); 178 } 179 } 180 if (ring->is_cursed) { 181 message(curse_message, 0); 182 } else { 183 un_put_on(ring); 184 strcpy(buf, "removed "); 185 get_desc(ring, buf + 8); 186 message(buf, 0); 187 reg_move(); 188 } 189 } 190 } 191 192 void 193 un_put_on(object *ring) 194 { 195 if (ring && (ring->in_use_flags & ON_LEFT_HAND)) { 196 ring->in_use_flags &= (~ON_LEFT_HAND); 197 rogue.left_ring = NULL; 198 } else if (ring && (ring->in_use_flags & ON_RIGHT_HAND)) { 199 ring->in_use_flags &= (~ON_RIGHT_HAND); 200 rogue.right_ring = NULL; 201 } 202 ring_stats(1); 203 } 204 205 void 206 gr_ring(object *ring, boolean assign_wk) 207 { 208 ring->what_is = RING; 209 if (assign_wk) { 210 ring->which_kind = get_rand(0, (RINGS - 1)); 211 } 212 ring->class = 0; 213 214 switch(ring->which_kind) { 215 case R_TELEPORT: 216 ring->is_cursed = 1; 217 break; 218 case ADD_STRENGTH: 219 case DEXTERITY: 220 while ((ring->class = (get_rand(0, 4) - 2)) == 0) 221 ; 222 ring->is_cursed = (ring->class < 0); 223 break; 224 case ADORNMENT: 225 ring->is_cursed = coin_toss(); 226 break; 227 } 228 } 229 230 void 231 inv_rings(void) 232 { 233 char buf[DCOLS]; 234 235 if (r_rings == 0) { 236 message("not wearing any rings", 0); 237 } else { 238 if (rogue.left_ring) { 239 get_desc(rogue.left_ring, buf); 240 message(buf, 0); 241 } 242 if (rogue.right_ring) { 243 get_desc(rogue.right_ring, buf); 244 message(buf, 0); 245 } 246 } 247 if (wizard) { 248 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", 249 stealthy, r_rings, e_rings, r_teleport, sustain_strength, 250 add_strength, regeneration, ring_exp, r_see_invisible, 251 maintain_armor, auto_search); 252 message(buf, 0); 253 } 254 } 255 256 void 257 ring_stats(boolean pr) 258 { 259 short i; 260 object *ring; 261 262 stealthy = 0; 263 r_rings = 0; 264 e_rings = 0; 265 r_teleport = 0; 266 sustain_strength = 0; 267 add_strength = 0; 268 regeneration = 0; 269 ring_exp = 0; 270 r_see_invisible = 0; 271 maintain_armor = 0; 272 auto_search = 0; 273 274 for (i = 0; i < 2; i++) { 275 if (!(ring = ((i == 0) ? rogue.left_ring : rogue.right_ring))) { 276 continue; 277 } 278 r_rings++; 279 e_rings++; 280 switch(ring->which_kind) { 281 case STEALTH: 282 stealthy++; 283 break; 284 case R_TELEPORT: 285 r_teleport = 1; 286 break; 287 case REGENERATION: 288 regeneration++; 289 break; 290 case SLOW_DIGEST: 291 e_rings -= 2; 292 break; 293 case ADD_STRENGTH: 294 add_strength += ring->class; 295 break; 296 case SUSTAIN_STRENGTH: 297 sustain_strength = 1; 298 break; 299 case DEXTERITY: 300 ring_exp += ring->class; 301 break; 302 case ADORNMENT: 303 break; 304 case R_SEE_INVISIBLE: 305 r_see_invisible = 1; 306 break; 307 case MAINTAIN_ARMOR: 308 maintain_armor = 1; 309 break; 310 case SEARCHING: 311 auto_search += 2; 312 break; 313 } 314 } 315 if (pr) { 316 print_stats(STAT_STRENGTH); 317 relight(); 318 } 319 } 320