Mercurial > hg > early-roguelike
comparison urogue/rings.c @ 256:c495a4f288c6
Import UltraRogue from the Roguelike Restoration Project (r1490)
author | John "Elwin" Edwards |
---|---|
date | Tue, 31 Jan 2017 19:56:04 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
253:d9badb9c0179 | 256:c495a4f288c6 |
---|---|
1 /* | |
2 rings.c - Routines dealing specificaly with rings | |
3 | |
4 UltraRogue: The Ultimate Adventure in the Dungeons of Doom | |
5 Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong | |
6 All rights reserved. | |
7 | |
8 Based on "Advanced Rogue" | |
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka | |
10 All rights reserved. | |
11 | |
12 Based on "Rogue: Exploring the Dungeons of Doom" | |
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
14 All rights reserved. | |
15 | |
16 See the file LICENSE.TXT for full copyright and licensing information. | |
17 */ | |
18 | |
19 #include <string.h> | |
20 #include <stdlib.h> | |
21 #include "rogue.h" | |
22 | |
23 void | |
24 ring_on(void) | |
25 { | |
26 struct object *obj; | |
27 struct linked_list *item; | |
28 int ring; | |
29 char buf[2 * LINELEN]; | |
30 | |
31 if ((item = get_item("put on", RING)) == NULL) | |
32 return; | |
33 | |
34 obj = OBJPTR(item); | |
35 | |
36 if (obj->o_type != RING) | |
37 { | |
38 msg("You can't put that on!"); | |
39 return; | |
40 } | |
41 | |
42 /* find out which hand to put it on */ | |
43 | |
44 if (is_current(obj)) | |
45 { | |
46 msg("Already wearing that!"); | |
47 return; | |
48 } | |
49 | |
50 if (cur_ring[LEFT_1] == NULL) | |
51 ring = LEFT_1; | |
52 else if (cur_ring[LEFT_2] == NULL) | |
53 ring = LEFT_2; | |
54 else if (cur_ring[LEFT_3] == NULL) | |
55 ring = LEFT_3; | |
56 else if (cur_ring[LEFT_4] == NULL) | |
57 ring = LEFT_4; | |
58 else if (cur_ring[LEFT_5] == NULL) | |
59 ring = LEFT_5; | |
60 else if (cur_ring[RIGHT_1] == NULL) | |
61 ring = RIGHT_1; | |
62 else if (cur_ring[RIGHT_2] == NULL) | |
63 ring = RIGHT_2; | |
64 else if (cur_ring[RIGHT_3] == NULL) | |
65 ring = RIGHT_3; | |
66 else if (cur_ring[RIGHT_4] == NULL) | |
67 ring = RIGHT_4; | |
68 else if (cur_ring[RIGHT_5] == NULL) | |
69 ring = RIGHT_5; | |
70 else | |
71 { | |
72 msg("You already have on ten rings."); | |
73 return; | |
74 } | |
75 | |
76 cur_ring[ring] = obj; | |
77 | |
78 /* Calculate the effect it has on the poor guy. */ | |
79 | |
80 switch (obj->o_which) | |
81 { | |
82 case R_ADDSTR: | |
83 pstats.s_str += obj->o_ac; | |
84 break; | |
85 case R_ADDHIT: | |
86 pstats.s_dext += obj->o_ac; | |
87 break; | |
88 case R_ADDINTEL: | |
89 pstats.s_intel += obj->o_ac; | |
90 break; | |
91 case R_ADDWISDOM: | |
92 pstats.s_wisdom += obj->o_ac; | |
93 break; | |
94 case R_FREEDOM: | |
95 turn_off(player, ISHELD); | |
96 hold_count = 0; | |
97 break; | |
98 case R_TRUESEE: | |
99 if (off(player, PERMBLIND)) | |
100 { | |
101 turn_on(player, CANTRUESEE); | |
102 msg("You become more aware of your surroundings."); | |
103 sight(NULL); | |
104 light(&hero); | |
105 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
106 } | |
107 break; | |
108 | |
109 case R_SEEINVIS: | |
110 if (off(player, PERMBLIND)) | |
111 { | |
112 turn_on(player, CANTRUESEE); | |
113 msg("Your eyes begin to tingle."); | |
114 sight(NULL); | |
115 light(&hero); | |
116 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
117 } | |
118 break; | |
119 | |
120 case R_AGGR: | |
121 aggravate(); | |
122 break; | |
123 | |
124 case R_CARRYING: | |
125 updpack(); | |
126 break; | |
127 | |
128 case R_LEVITATION: | |
129 msg("You begin to float in the air!"); | |
130 break; | |
131 | |
132 case R_LIGHT: | |
133 if (roomin(hero) != NULL) | |
134 { | |
135 light(&hero); | |
136 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
137 } | |
138 } | |
139 | |
140 status(FALSE); | |
141 | |
142 if (know_items[TYP_RING][obj->o_which] && | |
143 guess_items[TYP_RING][obj->o_which]) | |
144 { | |
145 mem_free(guess_items[TYP_RING][obj->o_which]); | |
146 guess_items[TYP_RING][obj->o_which] = NULL; | |
147 } | |
148 else if (!know_items[TYP_RING][obj->o_which] && | |
149 askme && | |
150 (obj->o_flags & ISKNOW) == 0 && | |
151 guess_items[TYP_RING][obj->o_which] == NULL) | |
152 { | |
153 mpos = 0; | |
154 msg("What do you want to call it? "); | |
155 | |
156 if (get_string(buf, cw) == NORM) | |
157 { | |
158 guess_items[TYP_RING][obj->o_which] = | |
159 new_alloc(strlen(buf) + 1); | |
160 strcpy(guess_items[TYP_RING][obj->o_which], buf); | |
161 } | |
162 msg(""); | |
163 } | |
164 } | |
165 | |
166 void | |
167 ring_off(void) | |
168 { | |
169 struct object *obj; | |
170 struct linked_list *item; | |
171 | |
172 if (cur_ring[LEFT_1] == NULL && cur_ring[LEFT_2] == NULL && | |
173 cur_ring[LEFT_3] == NULL && cur_ring[LEFT_4] == NULL && | |
174 cur_ring[LEFT_5] == NULL && | |
175 cur_ring[RIGHT_1] == NULL && cur_ring[RIGHT_2] == NULL && | |
176 cur_ring[RIGHT_3] == NULL && cur_ring[RIGHT_4] == NULL && | |
177 cur_ring[RIGHT_5] == NULL) | |
178 { | |
179 msg("You aren't wearing any rings."); | |
180 return; | |
181 } | |
182 else if ((item = get_item("remove", RING)) == NULL) | |
183 return; | |
184 | |
185 mpos = 0; | |
186 obj = OBJPTR(item); | |
187 | |
188 if ((obj = OBJPTR(item)) == NULL) | |
189 msg("You are not wearing that!"); | |
190 | |
191 if (dropcheck(obj)) | |
192 { | |
193 switch (obj->o_which) | |
194 { | |
195 case R_SEEINVIS: | |
196 msg("Your eyes stop tingling."); | |
197 break; | |
198 | |
199 case R_CARRYING: | |
200 updpack(); | |
201 break; | |
202 | |
203 case R_LEVITATION: | |
204 msg("You float gently to the ground."); | |
205 break; | |
206 | |
207 case R_LIGHT: | |
208 if (roomin(hero) != NULL) | |
209 { | |
210 light(&hero); | |
211 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
212 } | |
213 break; | |
214 | |
215 case R_TRUESEE: | |
216 msg("Your sensory perceptions return to normal."); | |
217 break; | |
218 } | |
219 | |
220 msg("Was wearing %s.", inv_name(obj, LOWERCASE)); | |
221 } | |
222 } | |
223 | |
224 /* | |
225 ring_eat() | |
226 how much food does this ring use up? | |
227 */ | |
228 | |
229 int | |
230 ring_eat(int hand) | |
231 { | |
232 int ret_val = 0; | |
233 int ac; | |
234 | |
235 if (cur_ring[hand] != NULL) | |
236 { | |
237 switch (cur_ring[hand]->o_which) | |
238 { | |
239 case R_REGEN: | |
240 case R_VREGEN: | |
241 ret_val = rnd(pstats.s_lvl > 10 ? 10 : pstats.s_lvl); | |
242 | |
243 case R_DIGEST: | |
244 | |
245 ac = cur_ring[hand]->o_ac; | |
246 | |
247 if (ac < 0 && rnd(1 - (ac / 3)) == 0) | |
248 ret_val = -ac + 1; | |
249 else if (rnd((ac / 2) + 2) == 0) | |
250 ret_val = -1 - ac; | |
251 break; | |
252 | |
253 case R_SEARCH: | |
254 ret_val = rnd(100) < 33; | |
255 break; | |
256 | |
257 default: | |
258 ret_val = 1; | |
259 } | |
260 } | |
261 | |
262 ret_val += rnd(luck); | |
263 | |
264 return(ret_val); | |
265 } | |
266 | |
267 /* | |
268 ring_num() | |
269 print ring bonuses | |
270 */ | |
271 | |
272 char * | |
273 ring_num(struct object *obj, char *buf) | |
274 { | |
275 char buffer[1024]; | |
276 | |
277 if (buf == NULL) | |
278 return("A bug in UltraRogue #101"); | |
279 | |
280 buf[0] = 0; | |
281 | |
282 if (obj->o_flags & ISKNOW) | |
283 { | |
284 switch (obj->o_which) | |
285 { | |
286 case R_SEARCH: | |
287 case R_PROTECT: | |
288 case R_ADDSTR: | |
289 case R_ADDDAM: | |
290 case R_ADDHIT: | |
291 case R_ADDINTEL: | |
292 case R_ADDWISDOM: | |
293 case R_CARRYING: | |
294 case R_VREGEN: | |
295 case R_RESURRECT: | |
296 case R_TELCONTROL: | |
297 case R_REGEN: | |
298 case R_PIETY: | |
299 case R_WIZARD: | |
300 buf[0] = ' '; | |
301 strcpy(&buf[1], num(obj->o_ac, 0,buffer)); | |
302 break; | |
303 | |
304 case R_DIGEST: | |
305 buf[0] = ' '; | |
306 strcpy(&buf[1], num(obj->o_ac < 0 ? | |
307 obj->o_ac : obj->o_ac - 1, 0, buffer)); | |
308 break; | |
309 | |
310 default: | |
311 if (obj->o_flags & ISCURSED) | |
312 strcpy(buf, " cursed"); | |
313 break; | |
314 } | |
315 } | |
316 | |
317 return(buf); | |
318 } | |
319 | |
320 /* | |
321 ring_value() | |
322 Return the effect of the specified ring | |
323 */ | |
324 | |
325 #define ISRING(h, r) (cur_ring[h] != NULL && cur_ring[h]->o_which == r) | |
326 | |
327 int | |
328 ring_value(int type) | |
329 { | |
330 int result = 0; | |
331 | |
332 if (ISRING(LEFT_1, type)) | |
333 result += cur_ring[LEFT_1]->o_ac; | |
334 if (ISRING(LEFT_2, type)) | |
335 result += cur_ring[LEFT_2]->o_ac; | |
336 if (ISRING(LEFT_3, type)) | |
337 result += cur_ring[LEFT_3]->o_ac; | |
338 if (ISRING(LEFT_4, type)) | |
339 result += cur_ring[LEFT_4]->o_ac; | |
340 if (ISRING(LEFT_5, type)) | |
341 result += cur_ring[LEFT_5]->o_ac; | |
342 if (ISRING(RIGHT_1, type)) | |
343 result += cur_ring[RIGHT_1]->o_ac; | |
344 if (ISRING(RIGHT_2, type)) | |
345 result += cur_ring[RIGHT_2]->o_ac; | |
346 if (ISRING(RIGHT_3, type)) | |
347 result += cur_ring[RIGHT_3]->o_ac; | |
348 if (ISRING(RIGHT_4, type)) | |
349 result += cur_ring[RIGHT_4]->o_ac; | |
350 if (ISRING(RIGHT_5, type)) | |
351 result += cur_ring[RIGHT_5]->o_ac; | |
352 | |
353 return(result); | |
354 } |