Mercurial > hg > early-roguelike
comparison arogue5/misc.c @ 63:0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author | elwin |
---|---|
date | Thu, 09 Aug 2012 22:58:48 +0000 |
parents | |
children | c49f7927b0fa |
comparison
equal
deleted
inserted
replaced
62:0ef99244acb8 | 63:0ed67132cf10 |
---|---|
1 /* | |
2 * routines dealing specifically with miscellaneous magic | |
3 * | |
4 * Advanced Rogue | |
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
6 * All rights reserved. | |
7 * | |
8 * See the file LICENSE.TXT for full copyright and licensing information. | |
9 */ | |
10 | |
11 #include "curses.h" | |
12 #include <ctype.h> | |
13 #include "rogue.h" | |
14 | |
15 /* | |
16 * See if a monster has some magic it can use. Use it and return TRUE if so. | |
17 */ | |
18 bool | |
19 m_use_item(monster, monst_pos, defend_pos) | |
20 register struct thing *monster; | |
21 register coord *monst_pos, *defend_pos; | |
22 { | |
23 register struct linked_list *pitem; | |
24 register struct object *obj; | |
25 register coord *shoot_dir = can_shoot(monst_pos, defend_pos); | |
26 int dist=DISTANCE(monst_pos->y, monst_pos->x, defend_pos->y, defend_pos->x); | |
27 | |
28 for (pitem=monster->t_pack; pitem; pitem=next(pitem)) { | |
29 obj = OBJPTR(pitem); | |
30 if (obj->o_type != RELIC) continue; /* Only care about relics now */ | |
31 switch (obj->o_which) { | |
32 case MING_STAFF: { | |
33 static struct object missile = { | |
34 MISSILE, {0,0}, "", 0, "", "0d4 " , NULL, 0, WS_MISSILE, 100, 1 | |
35 }; | |
36 | |
37 if (shoot_dir != NULL) { | |
38 sprintf(missile.o_hurldmg, "%dd4", monster->t_stats.s_lvl); | |
39 do_motion(&missile, shoot_dir->y, shoot_dir->x, monster); | |
40 hit_monster(unc(missile.o_pos), &missile, monster); | |
41 return(TRUE); | |
42 } | |
43 } | |
44 when ASMO_ROD: | |
45 /* The bolt must be able to reach the defendant */ | |
46 if (shoot_dir != NULL && dist < BOLT_LENGTH * BOLT_LENGTH) { | |
47 char *name; | |
48 | |
49 switch (rnd(3)) { /* Select a function */ | |
50 case 0: name = "lightning bolt"; | |
51 when 1: name = "flame"; | |
52 otherwise: name = "ice"; | |
53 } | |
54 shoot_bolt( monster, | |
55 *monst_pos, | |
56 *shoot_dir, | |
57 FALSE, | |
58 monster->t_index, | |
59 name, | |
60 roll(monster->t_stats.s_lvl,6)); | |
61 return(TRUE); | |
62 } | |
63 when BRIAN_MANDOLIN: | |
64 /* The defendant must be the player and within 2 spaces */ | |
65 if (ce(*defend_pos, hero) && dist < 9 && no_command == 0 && | |
66 rnd(100) < 33) { | |
67 if (!save(VS_MAGIC, &player, -4) && | |
68 !ISWEARING(R_ALERT)) { | |
69 msg("Some beautiful music enthralls you."); | |
70 no_command += FREEZETIME; | |
71 } | |
72 else msg("You wince at a sour note."); | |
73 return(TRUE); | |
74 } | |
75 when GERYON_HORN: | |
76 /* The defendant must be the player and within 2 spaces */ | |
77 if (ce(*defend_pos, hero) && dist < 9 && | |
78 (off(player, ISFLEE) || player.t_dest != &monster->t_pos) | |
79 && rnd(100) < 33) { | |
80 if (!ISWEARING(R_HEROISM) && | |
81 !save(VS_MAGIC, &player, -4)) { | |
82 turn_on(player, ISFLEE); | |
83 player.t_dest = &monster->t_pos; | |
84 msg("A shrill blast terrifies you."); | |
85 } | |
86 else msg("A shrill blast sends chills up your spine."); | |
87 return(TRUE); | |
88 } | |
89 } | |
90 } | |
91 return(FALSE); | |
92 } | |
93 | |
94 /* | |
95 * add something to the contents of something else | |
96 */ | |
97 put_contents(bag, item) | |
98 register struct object *bag; /* the holder of the items */ | |
99 register struct linked_list *item; /* the item to put inside */ | |
100 { | |
101 register struct linked_list *titem; | |
102 register struct object *tobj; | |
103 | |
104 bag->o_ac++; | |
105 tobj = OBJPTR(item); | |
106 for (titem = bag->contents; titem != NULL; titem = next(titem)) { | |
107 if ((OBJPTR(titem))->o_which == tobj->o_which) | |
108 break; | |
109 } | |
110 if (titem == NULL) { /* if not a duplicate put at beginning */ | |
111 attach(bag->contents, item); | |
112 } | |
113 else { | |
114 item->l_prev = titem; | |
115 item->l_next = titem->l_next; | |
116 if (next(titem) != NULL) | |
117 (titem->l_next)->l_prev = item; | |
118 titem->l_next = item; | |
119 } | |
120 } | |
121 | |
122 /* | |
123 * remove something from something else | |
124 */ | |
125 take_contents(bag, item) | |
126 register struct object *bag; /* the holder of the items */ | |
127 register struct linked_list *item; | |
128 { | |
129 | |
130 if (bag->o_ac <= 0) { | |
131 msg("Nothing to take out"); | |
132 return; | |
133 } | |
134 bag->o_ac--; | |
135 detach(bag->contents, item); | |
136 if (!add_pack(item, FALSE, NULL)) | |
137 put_contents(bag, item); | |
138 } | |
139 | |
140 | |
141 do_bag(item) | |
142 register struct linked_list *item; | |
143 { | |
144 | |
145 register struct linked_list *titem = NULL; | |
146 register struct object *obj; | |
147 bool doit = TRUE; | |
148 | |
149 obj = OBJPTR(item); | |
150 while (doit) { | |
151 msg("What do you want to do? (* for a list): "); | |
152 mpos = 0; | |
153 switch (readchar()) { | |
154 case EOF: | |
155 case ESCAPE: | |
156 msg (""); | |
157 doit = FALSE; | |
158 when '1': | |
159 inventory(obj->contents, ALL); | |
160 | |
161 when '2': | |
162 if (obj->o_ac >= MAXCONTENTS) { | |
163 msg("the %s is full", m_magic[obj->o_which].mi_name); | |
164 break; | |
165 } | |
166 switch (obj->o_which) { | |
167 case MM_BEAKER: titem = get_item(pack, "put in", POTION); | |
168 when MM_BOOK: titem = get_item(pack, "put in", SCROLL); | |
169 } | |
170 if (titem == NULL) | |
171 break; | |
172 detach(pack, titem); | |
173 inpack--; | |
174 put_contents(obj, titem); | |
175 | |
176 when '3': | |
177 titem = get_item(obj->contents,"take out",ALL); | |
178 if (titem == NULL) | |
179 break; | |
180 take_contents(obj, titem); | |
181 | |
182 when '4': | |
183 switch (obj->o_which) { | |
184 case MM_BEAKER: | |
185 titem = get_item(obj->contents,"quaff",ALL); | |
186 if (titem == NULL) | |
187 break; | |
188 obj->o_ac--; | |
189 detach(obj->contents, titem); | |
190 quaff((OBJPTR(titem))->o_which, | |
191 (OBJPTR(titem))->o_flags & (ISCURSED | ISBLESSED), | |
192 TRUE); | |
193 o_discard(titem); | |
194 when MM_BOOK: | |
195 if (on(player, ISBLIND)) { | |
196 msg("You can't see to read anything"); | |
197 break; | |
198 } | |
199 titem = get_item(obj->contents,"read",ALL); | |
200 if (titem == NULL) | |
201 break; | |
202 obj->o_ac--; | |
203 detach(obj->contents, titem); | |
204 read_scroll((OBJPTR(titem))->o_which, | |
205 (OBJPTR(titem))->o_flags & (ISCURSED|ISBLESSED), | |
206 TRUE); | |
207 o_discard(titem); | |
208 } | |
209 doit = FALSE; | |
210 | |
211 otherwise: | |
212 wclear(hw); | |
213 touchwin(hw); | |
214 mvwaddstr(hw,0,0,"The following operations are available:"); | |
215 mvwaddstr(hw,2,0,"[1]\tInventory\n"); | |
216 wprintw(hw,"[2]\tPut something in the %s\n", | |
217 m_magic[obj->o_which].mi_name); | |
218 wprintw(hw,"[3]\tTake something out of the %s\n", | |
219 m_magic[obj->o_which].mi_name); | |
220 switch(obj->o_which) { | |
221 case MM_BEAKER: waddstr(hw,"[4]\tQuaff a potion\n"); | |
222 when MM_BOOK: waddstr(hw,"[4]\tRead a scroll\n"); | |
223 } | |
224 waddstr(hw,"[ESC]\tLeave this menu\n"); | |
225 mvwaddstr(hw, LINES-1, 0, spacemsg); | |
226 draw(hw); | |
227 wait_for (hw,' '); | |
228 clearok(cw, TRUE); | |
229 touchwin(cw); | |
230 } | |
231 } | |
232 } | |
233 | |
234 do_panic() | |
235 { | |
236 register int x,y; | |
237 register struct linked_list *mon; | |
238 register struct thing *th; | |
239 | |
240 for (x = hero.x-2; x <= hero.x+2; x++) { | |
241 for (y = hero.y-2; y <= hero.y+2; y++) { | |
242 if (y < 1 || x < 0 || y > LINES - 3 || x > COLS - 1) | |
243 continue; | |
244 if (isalpha(mvwinch(mw, y, x))) { | |
245 if ((mon = find_mons(y, x)) != NULL) { | |
246 th = THINGPTR(mon); | |
247 if (!on(*th, ISUNDEAD) && !save(VS_MAGIC, th, 0)) { | |
248 turn_on(*th, ISFLEE); | |
249 turn_on(*th, WASTURNED); | |
250 | |
251 /* If monster was suffocating, stop it */ | |
252 if (on(*th, DIDSUFFOCATE)) { | |
253 turn_off(*th, DIDSUFFOCATE); | |
254 extinguish(suffocate); | |
255 } | |
256 | |
257 /* If monster held us, stop it */ | |
258 if (on(*th, DIDHOLD) && (--hold_count == 0)) | |
259 turn_off(player, ISHELD); | |
260 turn_off(*th, DIDHOLD); | |
261 } | |
262 runto(th, &hero); | |
263 } | |
264 } | |
265 } | |
266 } | |
267 } | |
268 | |
269 /* | |
270 * print miscellaneous magic bonuses | |
271 */ | |
272 char * | |
273 misc_name(obj) | |
274 register struct object *obj; | |
275 { | |
276 static char buf[LINELEN]; | |
277 char buf1[LINELEN]; | |
278 | |
279 buf[0] = '\0'; | |
280 buf1[0] = '\0'; | |
281 if (!(obj->o_flags & ISKNOW)) | |
282 return (m_magic[obj->o_which].mi_name); | |
283 switch (obj->o_which) { | |
284 case MM_BRACERS: | |
285 case MM_PROTECT: | |
286 strcat(buf, num(obj->o_ac, 0)); | |
287 strcat(buf, " "); | |
288 } | |
289 switch (obj->o_which) { | |
290 case MM_G_OGRE: | |
291 case MM_G_DEXTERITY: | |
292 case MM_JEWEL: | |
293 case MM_STRANGLE: | |
294 case MM_R_POWERLESS: | |
295 case MM_DANCE: | |
296 if (obj->o_flags & ISCURSED) | |
297 strcat(buf, "cursed "); | |
298 } | |
299 strcat(buf, m_magic[obj->o_which].mi_name); | |
300 switch (obj->o_which) { | |
301 case MM_JUG: | |
302 if (obj->o_ac == JUG_EMPTY) | |
303 strcat(buf1, " [empty]"); | |
304 else if (p_know[obj->o_ac]) | |
305 sprintf(buf1, " [containing a potion of %s (%s)]", | |
306 p_magic[obj->o_ac].mi_name, | |
307 p_colors[obj->o_ac]); | |
308 else sprintf(buf1, " [containing a%s %s liquid]", | |
309 vowelstr(p_colors[obj->o_ac]), | |
310 p_colors[obj->o_ac]); | |
311 when MM_BEAKER: | |
312 case MM_BOOK: { | |
313 sprintf(buf1, " [containing %d]", obj->o_ac); | |
314 } | |
315 when MM_OPEN: | |
316 case MM_HUNGER: | |
317 sprintf(buf1, " [%d ring%s]", obj->o_charges, | |
318 obj->o_charges == 1 ? "" : "s"); | |
319 when MM_DRUMS: | |
320 sprintf(buf1, " [%d beat%s]", obj->o_charges, | |
321 obj->o_charges == 1 ? "" : "s"); | |
322 when MM_DISAPPEAR: | |
323 case MM_CHOKE: | |
324 sprintf(buf1, " [%d pinch%s]", obj->o_charges, | |
325 obj->o_charges == 1 ? "" : "es"); | |
326 when MM_KEOGHTOM: | |
327 sprintf(buf1, " [%d application%s]", obj->o_charges, | |
328 obj->o_charges == 1 ? "" : "s"); | |
329 when MM_SKILLS: | |
330 switch (obj->o_ac) { | |
331 case C_MAGICIAN: strcpy(buf1, " [magic user]"); | |
332 when C_FIGHTER: strcpy(buf1, " [fighter]"); | |
333 when C_CLERIC: strcpy(buf1, " [cleric]"); | |
334 when C_THIEF: strcpy(buf1, " [thief]"); | |
335 } | |
336 } | |
337 strcat (buf, buf1); | |
338 return buf; | |
339 } | |
340 | |
341 use_emori() | |
342 { | |
343 char selection; /* Cloak function */ | |
344 int state = 0; /* Menu state */ | |
345 | |
346 msg("What do you want to do? (* for a list): "); | |
347 do { | |
348 selection = tolower(readchar()); | |
349 switch (selection) { | |
350 case '*': | |
351 if (state != 1) { | |
352 wclear(hw); | |
353 touchwin(hw); | |
354 mvwaddstr(hw, 2, 0, "[1] Fly\n[2] Stop flying\n"); | |
355 waddstr(hw, "[3] Turn invisible\n[4] Turn Visible\n"); | |
356 mvwaddstr(hw, 0, 0, "What do you want to do? "); | |
357 draw(hw); | |
358 state = 1; /* Now in prompt window */ | |
359 } | |
360 break; | |
361 | |
362 case ESCAPE: | |
363 if (state == 1) { | |
364 clearok(cw, TRUE); /* Set up for redraw */ | |
365 touchwin(cw); | |
366 } | |
367 msg(""); | |
368 | |
369 after = FALSE; | |
370 return; | |
371 | |