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