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