Mercurial > hg > early-roguelike
comparison arogue5/monsters.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 | 56e748983fa8 |
comparison
equal
deleted
inserted
replaced
62:0ef99244acb8 | 63:0ed67132cf10 |
---|---|
1 /* | |
2 * File with various monster functions in it | |
3 * | |
4 * Advanced Rogue | |
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
6 * All rights reserved. | |
7 * | |
8 * Based on "Rogue: Exploring the Dungeons of Doom" | |
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
10 * All rights reserved. | |
11 * | |
12 * See the file LICENSE.TXT for full copyright and licensing information. | |
13 */ | |
14 | |
15 #include "curses.h" | |
16 #include "rogue.h" | |
17 #include <ctype.h> | |
18 #include <string.h> | |
19 | |
20 | |
21 /* | |
22 * Check_residue takes care of any effect of the monster | |
23 */ | |
24 check_residue(tp) | |
25 register struct thing *tp; | |
26 { | |
27 /* | |
28 * Take care of special abilities | |
29 */ | |
30 if (on(*tp, DIDHOLD) && (--hold_count == 0)) turn_off(player, ISHELD); | |
31 | |
32 /* If it has lowered player, give him back a level */ | |
33 if (on(*tp, DIDDRAIN)) raise_level(FALSE); | |
34 | |
35 /* If frightened of this monster, stop */ | |
36 if (on(player, ISFLEE) && | |
37 player.t_dest == &tp->t_pos) turn_off(player, ISFLEE); | |
38 | |
39 /* If monster was suffocating player, stop it */ | |
40 if (on(*tp, DIDSUFFOCATE)) extinguish(suffocate); | |
41 | |
42 /* If something with fire, may darken */ | |
43 if (on(*tp, HASFIRE)) { | |
44 register struct room *rp=roomin(&tp->t_pos); | |
45 register struct linked_list *fire_item; | |
46 | |
47 if (rp) { | |
48 for (fire_item = rp->r_fires; fire_item != NULL; | |
49 fire_item = next(fire_item)) { | |
50 if (THINGPTR(fire_item) == tp) { | |
51 detach(rp->r_fires, fire_item); | |
52 destroy_item(fire_item); | |
53 if (rp->r_fires == NULL) { | |
54 rp->r_flags &= ~HASFIRE; | |
55 if (cansee(tp->t_pos.y, tp->t_pos.x)) light(&hero); | |
56 } | |
57 break; | |
58 } | |
59 } | |
60 } | |
61 } | |
62 } | |
63 | |
64 /* | |
65 * Creat_mons creates the specified monster -- any if 0 | |
66 */ | |
67 | |
68 bool | |
69 creat_mons(person, monster, report) | |
70 struct thing *person; /* Where to create next to */ | |
71 short monster; | |
72 bool report; | |
73 { | |
74 struct linked_list *nitem; | |
75 register struct thing *tp; | |
76 struct room *rp; | |
77 coord *mp; | |
78 | |
79 if (levtype == POSTLEV) | |
80 return(FALSE); | |
81 if ((mp = fallpos(&(person->t_pos), FALSE, 2)) != NULL) { | |
82 nitem = new_item(sizeof (struct thing)); | |
83 new_monster(nitem, | |
84 monster == 0 ? randmonster(FALSE, FALSE) | |
85 : monster, | |
86 mp, | |
87 TRUE); | |
88 tp = THINGPTR(nitem); | |
89 runto(tp, &hero); | |
90 tp->t_no_move = 1; /* since it just got here, it is disoriented */ | |
91 carry_obj(tp, monsters[tp->t_index].m_carry/2); /* only half chance */ | |
92 if (on(*tp, HASFIRE)) { | |
93 rp = roomin(&tp->t_pos); | |
94 if (rp) { | |
95 register struct linked_list *fire_item; | |
96 | |
97 /* Put the new fellow in the room list */ | |
98 fire_item = creat_item(); | |
99 ldata(fire_item) = (char *) tp; | |
100 attach(rp->r_fires, fire_item); | |
101 | |
102 rp->r_flags |= HASFIRE; | |
103 } | |
104 } | |
105 | |
106 /* | |
107 * If we can see this monster, set oldch to ' ' to make light() | |
108 * think the creature used to be invisible (ie. not seen here) | |
109 */ | |
110 if (cansee(tp->t_pos.y, tp->t_pos.x)) tp->t_oldch = ' '; | |
111 return(TRUE); | |
112 } | |
113 if (report) msg("You hear a faint cry of anguish in the distance."); | |
114 return(FALSE); | |
115 } | |
116 | |
117 /* | |
118 * Genmonsters: | |
119 * Generate at least 'least' monsters for this single room level. | |
120 * 'Treas' indicates whether this is a "treasure" level. | |
121 */ | |
122 | |
123 void | |
124 genmonsters(least, treas) | |
125 register int least; | |
126 bool treas; | |
127 { | |
128 reg int i; | |
129 reg struct room *rp = &rooms[0]; | |
130 reg struct linked_list *item; | |
131 reg struct thing *mp; | |
132 coord tp; | |
133 | |
134 for (i = 0; i < level + least; i++) { | |
135 if (!treas && rnd(100) < 50) /* put in some little buggers */ | |
136 continue; | |
137 /* | |
138 * Put the monster in | |
139 */ | |
140 item = new_item(sizeof *mp); | |
141 mp = THINGPTR(item); | |
142 do { | |
143 rnd_pos(rp, &tp); | |
144 } until(mvwinch(stdscr, tp.y, tp.x) == FLOOR); | |
145 | |
146 new_monster(item, randmonster(FALSE, FALSE), &tp, FALSE); | |
147 /* | |
148 * See if we want to give it a treasure to carry around. | |
149 */ | |
150 carry_obj(mp, monsters[mp->t_index].m_carry); | |
151 | |
152 /* Is it going to give us some light? */ | |
153 if (on(*mp, HASFIRE)) { | |
154 register struct linked_list *fire_item; | |
155 | |
156 fire_item = creat_item(); | |
157 ldata(fire_item) = (char *) mp; | |
158 attach(rp->r_fires, fire_item); | |
159 rp->r_flags |= HASFIRE; | |
160 } | |
161 } | |
162 } | |
163 | |
164 /* | |
165 * id_monst returns the index of the monster given its letter | |
166 */ | |
167 | |
168 short | |
169 id_monst(monster) | |
170 register char monster; | |
171 { | |
172 register short result; | |
173 | |
174 result = NLEVMONS*vlevel; | |
175 if (result > NUMMONST) result = NUMMONST; | |
176 | |
177 for(; result>0; result--) | |
178 if (monsters[result].m_appear == monster) return(result); | |
179 for (result=(NLEVMONS*vlevel)+1; result <= NUMMONST; result++) | |
180 if (monsters[result].m_appear == monster) return(result); | |
181 return(0); | |
182 } | |
183 | |
184 | |
185 /* | |
186 * new_monster: | |
187 * Pick a new monster and add it to the list | |
188 */ | |
189 | |
190 new_monster(item, type, cp, max_monster) | |
191 struct linked_list *item; | |
192 short type; | |
193 register coord *cp; | |
194 bool max_monster; | |
195 { | |
196 register struct thing *tp; | |
197 register struct monster *mp; | |
198 register char *ip, *hitp; | |
199 register int i, min_intel, max_intel; | |
200 register int num_dice, num_sides=8, num_extra=0; | |
201 | |
202 attach(mlist, item); | |
203 tp = THINGPTR(item); | |
204 tp->t_turn = TRUE; | |
205 tp->t_pack = NULL; | |
206 tp->t_index = type; | |
207 tp->t_wasshot = FALSE; | |
208 tp->t_type = monsters[type].m_appear; | |
209 tp->t_ctype = C_MONSTER; | |
210 tp->t_no_move = 0; | |
211 tp->t_doorgoal = 0; | |
212 tp->t_quiet = 0; | |
213 tp->t_pos = tp->t_oldpos = *cp; | |
214 tp->t_oldch = CCHAR( mvwinch(cw, cp->y, cp->x) ); | |
215 mvwaddch(mw, cp->y, cp->x, tp->t_type); | |
216 mp = &monsters[tp->t_index]; | |
217 | |
218 /* Figure out monster's hit points */ | |
219 hitp = mp->m_stats.s_hpt; | |
220 num_dice = atoi(hitp); | |
221 if ((hitp = strchr(hitp, 'd')) != NULL) { | |
222 num_sides = atoi(++hitp); | |
223 if ((hitp = strchr(hitp, '+')) != NULL) | |
224 num_extra = atoi(++hitp); | |
225 } | |
226 | |
227 tp->t_stats.s_lvl = mp->m_stats.s_lvl; | |
228 tp->t_stats.s_arm = mp->m_stats.s_arm; | |
229 strncpy(tp->t_stats.s_dmg,mp->m_stats.s_dmg,sizeof(tp->t_stats.s_dmg)); | |
230 tp->t_stats.s_str = mp->m_stats.s_str; | |
231 if (vlevel > HARDER) { /* the deeper, the meaner we get */ | |
232 tp->t_stats.s_lvl += (vlevel - HARDER); | |
233 num_dice += (vlevel - HARDER)/2; | |
234 } | |
235 if (max_monster) | |
236 tp->t_stats.s_hpt = num_dice * num_sides + num_extra; | |
237 else | |
238 tp->t_stats.s_hpt = roll(num_dice, num_sides) + num_extra; | |
239 tp->t_stats.s_exp = mp->m_stats.s_exp + mp->m_add_exp*tp->t_stats.s_hpt; | |
240 | |
241 /* | |
242 * just initailize others values to something reasonable for now | |
243 * maybe someday will *really* put these in monster table | |
244 */ | |
245 tp->t_stats.s_wisdom = 8 + rnd(4); | |
246 tp->t_stats.s_dext = 8 + rnd(4); | |
247 tp->t_stats.s_const = 8 + rnd(4); | |
248 tp->t_stats.s_charisma = 8 + rnd(4); | |
249 | |
250 /* Set the initial flags */ | |
251 for (i=0; i<16; i++) tp->t_flags[i] = 0; | |
252 for (i=0; i<MAXFLAGS; i++) | |
253 turn_on(*tp, mp->m_flags[i]); | |
254 | |
255 /* suprising monsters don't always surprise you */ | |
256 if (!max_monster && on(*tp, CANSURPRISE) && | |
257 off(*tp, ISUNIQUE) && rnd(100) < 20) | |
258 turn_off(*tp, CANSURPRISE); | |
259 | |
260 /* If this monster is unique, gen it */ | |
261 if (on(*tp, ISUNIQUE)) mp->m_normal = FALSE; | |
262 | |
263 /* | |
264 * if is it the quartermaster, then compute his level and exp pts | |
265 * based on the level. This will make it fair when thieves try to | |
266 * steal and give them reasonable experience if they succeed. | |
267 */ | |
268 if (on(*tp, CANSELL)) { | |
269 tp->t_stats.s_exp = vlevel * 100; | |
270 tp->t_stats.s_lvl = vlevel/2 + 1; | |
271 attach(tp->t_pack, new_thing(ALL)); | |
272 } | |
273 | |
274 /* Normally scared monsters have a chance to not be scared */ | |
275 if (on(*tp, ISFLEE) && (rnd(4) == 0)) turn_off(*tp, ISFLEE); | |
276 | |
277 /* Figure intelligence */ | |
278 min_intel = atoi(mp->m_intel); | |
279 if ((ip = (char *) strchr(mp->m_intel, '-')) == NULL) | |
280 tp->t_stats.s_intel = min_intel; | |
281 else { | |
282 max_intel = atoi(++ip); | |
283 if (max_monster) | |
284 tp->t_stats.s_intel = max_intel; | |
285 else | |
286 tp->t_stats.s_intel = min_intel + rnd(max_intel - min_intel); | |
287 } | |
288 if (vlevel > HARDER) | |
289 tp->t_stats.s_intel += ((vlevel - HARDER)/2); | |
290 tp->maxstats = tp->t_stats; | |
291 | |
292 /* If the monster can shoot, it may have a weapon */ | |
293 if (on(*tp, CANSHOOT) && ((rnd(100) < (22 + vlevel)) || max_monster)) { | |
294 struct linked_list *item1; | |
295 register struct object *cur, *cur1; | |
296 | |
297 item = new_item(sizeof *cur); | |
298 item1 = new_item(sizeof *cur1); | |
299 cur = OBJPTR(item); | |
300 cur1 = OBJPTR(item1); | |
301 cur->o_hplus = (rnd(4) < 3) ? 0 | |
302 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
303 cur->o_dplus = (rnd(4) < 3) ? 0 | |
304 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
305 cur1->o_hplus = (rnd(4) < 3) ? 0 | |
306 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
307 cur1->o_dplus = (rnd(4) < 3) ? 0 | |
308 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
309 strcpy(cur->o_damage,"0d0"); | |
310 strcpy(cur->o_hurldmg,"0d0"); | |
311 strcpy(cur1->o_damage,"0d0"); | |
312 strcpy(cur1->o_hurldmg,"0d0"); | |
313 cur->o_ac = cur1->o_ac = 11; | |
314 cur->o_count = cur1->o_count = 1; | |
315 cur->o_group = cur1->o_group = 0; | |
316 cur->contents = cur1->contents = NULL; | |
317 if ((cur->o_hplus <= 0) && (cur->o_dplus <= 0)) cur->o_flags = ISCURSED; | |
318 if ((cur1->o_hplus <= 0) && (cur1->o_dplus <= 0)) | |
319 cur1->o_flags = ISCURSED; | |
320 cur->o_flags = cur1->o_flags = 0; | |
321 cur->o_type = cur1->o_type = WEAPON; | |
322 cur->o_mark[0] = cur1->o_mark[0] = '\0'; | |
323 | |
324 /* The monster may use a crossbow, sling, or an arrow */ | |
325 i = rnd(100); | |
326 if (i < 10) { | |
327 cur->o_which = CROSSBOW; | |
328 cur1->o_which = BOLT; | |
329 init_weapon(cur, CROSSBOW); | |
330 init_weapon(cur1, BOLT); | |
331 } | |
332 else if (i < 70) { | |
333 cur->o_which = BOW; | |
334 cur1->o_which = ARROW; | |
335 init_weapon(cur, BOW); | |
336 init_weapon(cur1, ARROW); | |
337 } | |
338 else { | |
339 cur->o_which = SLING; | |
340 cur1->o_which = ROCK; | |
341 init_weapon(cur, SLING); | |
342 init_weapon(cur1, ROCK); | |
343 } | |
344 | |
345 attach(tp->t_pack, item); | |
346 attach(tp->t_pack, item1); | |
347 } | |
348 | |
349 | |
350 if (ISWEARING(R_AGGR)) | |
351 runto(tp, &hero); | |
352 if (on(*tp, ISDISGUISE)) | |
353 { | |
354 char mch = 0; | |
355 | |
356 if (tp->t_pack != NULL) | |
357 mch = (OBJPTR(tp->t_pack))->o_type; | |
358 else | |
359 switch (rnd(10)) { | |
360 case 0: mch = GOLD; | |
361 when 1: mch = POTION; | |
362 when 2: mch = SCROLL; | |
363 when 3: mch = FOOD; | |
364 when 4: mch = WEAPON; | |
365 when 5: mch = ARMOR; | |
366 when 6: mch = RING; | |
367 when 7: mch = STICK; | |
368 when 8: mch = monsters[randmonster(FALSE, FALSE)].m_appear; | |
369 when 9: mch = MM; | |
370 } | |
371 tp->t_disguise = mch; | |
372 } | |
373 } | |
374 | |
375 /* | |
376 * randmonster: | |
377 * Pick a monster to show up. The lower the level, | |
378 * the meaner the monster. | |
379 */ | |
380 | |
381 short | |
382 randmonster(wander, no_unique) | |
383 register bool wander, no_unique; | |
384 { | |
385 register int d, cur_level, range, i; | |
386 | |
387 /* | |
388 * Do we want a merchant? Merchant is always in place 'NUMMONST' | |
389 */ | |
390 if (wander && monsters[NUMMONST].m_wander && rnd(100) < 3) return NUMMONST; | |
391 | |
392 cur_level = vlevel; | |
393 range = 4*NLEVMONS; | |
394 i = 0; | |
395 do | |
396 { | |
397 if (i++ > range*10) { /* just in case all have be genocided */ | |
398 i = 0; | |
399 if (--cur_level <= 0) | |
400 fatal("Rogue could not find a monster to make"); | |
401 } | |
402 d = NLEVMONS*(cur_level - 1) + (rnd(range) - (range - 1 - NLEVMONS)); | |
403 if (d < 1) | |
404 d = rnd(NLEVMONS) + 1; | |
405 if (d > NUMMONST - NUMUNIQUE - 1) { | |
406 if (no_unique) | |
407 d = rnd(range) + (NUMMONST - NUMUNIQUE - 1) - (range - 1); | |
408 else if (d > NUMMONST - 1) | |
409 d = rnd(range+NUMUNIQUE) + (NUMMONST-1) - (range+NUMUNIQUE-1); | |
410 } | |
411 } | |
412 while (wander ? !monsters[d].m_wander || !monsters[d].m_normal | |
413 : !monsters[d].m_normal); | |
414 return d; | |
415 } | |
416 | |
417 /* Sell displays a menu of goods from which the player may choose | |
418 * to purchase something. | |
419 */ | |
420 | |
421 sell(tp) | |
422 register struct thing *tp; | |
423 { | |
424 register struct linked_list *item; | |
425 register struct object *obj; | |
426 register int i, j, min_worth, nitems, goods = 0, chance, which_item; | |
427 char buffer[LINELEN]; | |
428 struct { | |
429 int which; | |
430 int plus1, plus2; | |
431 int count; | |
432 int worth; | |
433 char *name; | |
434 } selection[10]; | |
435 | |
436 min_worth = 100000; | |
437 item = find_mons(tp->t_pos.y, tp->t_pos.x); /* Get pointer to monster */ | |
438 | |
439 /* Select the items */ | |
440 nitems = rnd(6) + 5; | |
441 | |
442 for (i=0; i<nitems; i++) { | |
443 selection[i].worth = selection[i].plus1 | |
444 = selection[i].plus2 | |
445 = selection[i].which | |
446 = selection[i].count | |
447 = 0; | |
448 } | |
449 switch (rnd(9)) { | |
450 /* Armor */ | |
451 case 0: | |
452 case 1: | |
453 goods = ARMOR; | |
454 for (i=0; i<nitems; i++) { | |
455 chance = rnd(100); | |
456 for (j = 0; j < MAXARMORS; j++) | |
457 if (chance < armors[j].a_prob) | |
458 break; | |
459 if (j == MAXARMORS) { | |
460 debug("Picked a bad armor %d", chance); | |
461 j = 0; | |
462 } | |
463 selection[i].which = j; | |
464 selection[i].count = 1; | |
465 if (rnd(100) < 40) selection[i].plus1 = rnd(5) + 1; | |
466 else selection[i].plus1 = 0; | |
467 selection[i].name = armors[j].a_name; | |
468 | |
469 /* Calculate price */ | |
470 selection[i].worth = armors[j].a_worth; | |
471 selection[i].worth += | |
472 2 * s_magic[S_ALLENCH].mi_worth * selection[i].plus1; | |
473 if (min_worth > selection[i].worth) | |
474 min_worth = selection[i].worth; | |
475 } | |
476 break; | |
477 | |
478 /* Weapon */ | |
479 case 2: | |
480 case 3: | |
481 goods = WEAPON; | |
482 for (i=0; i<nitems; i++) { | |
483 selection[i].which = rnd(MAXWEAPONS); | |
484 selection[i].count = 1; | |
485 if (rnd(100) < 35) { | |
486 selection[i].plus1 = rnd(3); | |
487 selection[i].plus2 = rnd(3); | |
488 } | |
489 else { | |
490 selection[i].plus1 = 0; | |
491 selection[i].plus2 = 0; | |
492 } | |
493 if (weaps[selection[i].which].w_flags & ISMANY) | |
494 selection[i].count = rnd(15) + 5; | |
495 selection[i].name = weaps[selection[i].which].w_name; | |
496 /* | |
497 * note: use "count" before adding in the enchantment cost | |
498 * of an item. This will keep the price of arrows | |
499 * and such to a reasonable price. | |
500 */ | |
501 j = selection[i].plus1 + selection[i].plus2; | |
502 selection[i].worth = weaps[selection[i].which].w_worth; | |
503 selection[i].worth *= selection[i].count; | |
504 selection[i].worth += 2 * s_magic[S_ALLENCH].mi_worth * j; | |
505 if (min_worth > selection[i].worth) | |
506 min_worth = selection[i].worth; | |
507 } | |
508 break; | |
509 | |
510 /* Staff or wand */ | |
511 case 4: | |
512 goods = STICK; | |
513 for (i=0; i<nitems; i++) { | |
514 selection[i].which = pick_one(ws_magic, MAXSTICKS); | |
515 selection[i].plus1 = rnd(11) + 5; /* Charges */ | |
516 selection[i].count = 1; | |
517 selection[i].name = ws_magic[selection[i].which].mi_name; | |
518 selection[i].worth = ws_magic[selection[i].which].mi_worth; | |
519 selection[i].worth += 20 * selection[i].plus1; | |
520 if (min_worth > selection[i].worth) | |
521 min_worth = selection[i].worth; | |
522 } | |
523 break; | |
524 | |
525 /* Ring */ | |
526 case 5: | |
527 goods = RING; | |
528 for (i=0; i<nitems; i++) { | |
529 selection[i].which = pick_one(r_magic, MAXRINGS); | |
530 selection[i].plus1 = rnd(2) + 1; /* Armor class */ | |
531 selection[i].count = 1; | |
532 if (rnd(100) < r_magic[selection[i].which].mi_bless + 10) | |
533 selection[i].plus1 += rnd(2) + 1; | |
534 selection[i].name = r_magic[selection[i].which].mi_name; | |
535 selection[i].worth = r_magic[selection[i].which].mi_worth; | |
536 | |
537 switch (selection[i].which) { | |
538 case R_DIGEST: | |
539 if (selection[i].plus1 > 2) selection[i].plus1 = 2; | |
540 else if (selection[i].plus1 < 1) selection[i].plus1 = 1; | |
541 /* fall thru here to other cases */ | |
542 case R_ADDSTR: | |
543 case R_ADDDAM: | |
544 case R_PROTECT: | |
545 case R_ADDHIT: | |
546 case R_ADDINTEL: | |
547 case R_ADDWISDOM: | |
548 if (selection[i].plus1 > 0) | |
549 selection[i].worth += selection[i].plus1 * 50; | |
550 } | |
551 if(min_worth > selection[i].worth) | |
552 min_worth = selection[i].worth; | |
553 } | |
554 break; | |
555 | |
556 /* scroll */ | |
557 case 6: | |
558 goods = SCROLL; | |
559 for (i=0; i<nitems; i++) { | |
560 selection[i].which = pick_one(s_magic, MAXSCROLLS); | |
561 selection[i].count = 1; | |
562 selection[i].name = s_magic[selection[i].which].mi_name; | |
563 selection[i].worth = s_magic[selection[i].which].mi_worth; | |
564 if (min_worth > selection[i].worth) | |
565 min_worth = selection[i].worth; | |
566 } | |
567 break; | |
568 | |
569 /* potions */ | |
570 case 7: | |
571 goods = POTION; | |
572 for (i=0; i<nitems; i++) { | |
573 selection[i].which = pick_one(p_magic, MAXPOTIONS); | |
574 selection[i].count = 1; | |
575 selection[i].name = p_magic[selection[i].which].mi_name; | |
576 selection[i].worth = p_magic[selection[i].which].mi_worth; | |
577 if (min_worth > selection[i].worth) | |
578 min_worth = selection[i].worth; | |
579 } | |
580 break; | |
581 | |
582 /* Miscellaneous magic */ | |
583 case 8: | |
584 goods = MM; | |
585 for (i=0; i<nitems; i++) { /* don't sell as many mm as others */ | |
586 selection[i].which = pick_one(m_magic, MAXMM); | |
587 selection[i].count = 1; | |
588 selection[i].name = m_magic[selection[i].which].mi_name; | |
589 selection[i].worth = m_magic[selection[i].which].mi_worth; | |
590 | |
591 switch (selection[i].which) { | |
592 case MM_JUG: | |
593 switch(rnd(9)) { | |
594 case 0: selection[i].plus1 = P_PHASE; | |
595 when 1: selection[i].plus1 = P_CLEAR; | |
596 when 2: selection[i].plus1 = P_SEEINVIS; | |
597 when 3: selection[i].plus1 = P_HEALING; | |
598 when 4: selection[i].plus1 = P_MFIND; | |
599 when 5: selection[i].plus1 = P_TFIND; | |
600 when 6: selection[i].plus1 = P_HASTE; | |
601 when 7: selection[i].plus1 = P_RESTORE; | |
602 when 8: selection[i].plus1 = P_FLY; | |
603 } | |
604 when MM_OPEN: | |
605 case MM_HUNGER: | |
606 case MM_DRUMS: | |
607 case MM_DISAPPEAR: | |
608 case MM_CHOKE: | |
609 case MM_KEOGHTOM: | |
610 selection[i].plus1 = 3 + (rnd(3)+1) * 3; | |
611 selection[i].worth += selection[i].plus1 * 50; | |
612 when MM_BRACERS: | |
613 selection[i].plus1 = rnd(10)+1; | |
614 selection[i].worth += selection[i].plus1 * 75; | |
615 when MM_DISP: | |
616 selection[i].plus1 = 2; | |
617 when MM_PROTECT: | |
618 selection[i].plus1 = rnd(5)+1; | |
619 selection[i].worth += selection[i].plus1 * 100; | |
620 when MM_SKILLS: | |
621 selection[i].plus1 = player.t_ctype; | |
622 otherwise: | |
623 break; | |
624 } | |
625 if(min_worth > selection[i].worth) | |
626 min_worth = selection[i].worth; | |
627 } | |
628 break; | |
629 } | |
630 | |
631 /* See if player can afford an item */ | |
632 if (min_worth > purse) { | |
633 msg("The %s eyes your small purse and departs.", | |
634 monsters[NUMMONST].m_name); | |
635 /* Get rid of the monster */ | |
636 killed(item, FALSE, FALSE); | |
637 return; | |
638 } | |
639 | |
640 /* Display the goods */ | |
641 msg("The %s shows you his wares.--More--", monsters[NUMMONST].m_name); | |
642 wait_for(cw,' '); | |
643 msg(""); | |
644 clearok(cw, TRUE); | |
645 touchwin(cw); | |
646 | |
647 wclear(hw); | |
648 touchwin(hw); | |
649 for (i=0; i < nitems; i++) { | |
650 mvwaddch(hw, i+2, 0, '['); | |
651 waddch(hw, (char) ((int) 'a' + i)); | |
652 waddstr(hw, "] "); | |
653 switch (goods) { | |
654 case ARMOR: | |
655 waddstr(hw, "Some "); | |
656 when WEAPON: | |
657 if (selection[i].count == 1) | |
658 waddstr(hw, " A "); | |
659 else { | |
660 sprintf(buffer, "%2d ", selection[i].count); | |
661 waddstr(hw, buffer); | |
662 } | |
663 when STICK: | |
664 wprintw(hw, "A %-5s of ", ws_type[selection[i].which]); | |
665 when RING: | |
666 waddstr(hw, "A ring of "); | |
667 when SCROLL: | |
668 waddstr(hw, "A scroll of "); | |
669 when POTION: | |
670 waddstr(hw, "A potion of "); | |
671 } | |
672 if (selection[i].count > 1) | |
673 sprintf(buffer, "%s%s ", selection[i].name, "s"); | |
674 else | |
675 sprintf(buffer, "%s ", selection[i].name); | |
676 wprintw(hw, "%-24s", buffer); | |
677 wprintw(hw, " Price:%5d", selection[i].worth); | |
678 } | |
679 sprintf(buffer, "Purse: %d", purse); | |
680 mvwaddstr(hw, nitems+3, 0, buffer); | |
681 mvwaddstr(hw, 0, 0, "How about one of the following goods? "); | |
682 draw(hw); | |
683 /* Get rid of the monster */ | |
684 killed(item, FALSE, FALSE); | |
685 | |
686 which_item = (int) (wgetch(hw) - 'a'); | |
687 while (which_item < 0 || which_item >= nitems) { | |
688 if (which_item == (int) ESCAPE - (int) 'a') { | |
689 return; | |
690 } | |
691 mvwaddstr(hw, 0, 0, "Please enter one of the listed items. "); | |
692 draw(hw); | |
693 which_item = (int) (wgetch(hw) - 'a'); | |
694 } | |
695 | |
696 if (selection[which_item].worth > purse) { | |
697 msg("You cannot afford it."); | |
698 return; | |
699 } | |
700 | |
701 purse -= selection[which_item].worth; | |
702 | |
703 item = spec_item(goods, selection[which_item].which, | |
704 selection[which_item].plus1, selection[which_item].plus2); | |
705 | |
706 obj = OBJPTR(item); | |
707 if (selection[which_item].count > 1) { | |
708 obj->o_count = selection[which_item].count; | |
709 obj->o_group = newgrp(); | |
710 } | |
711 /* If a stick or ring, let player know the type */ | |
712 switch (goods) { | |
713 case RING: r_know[selection[which_item].which] = TRUE; | |
714 when POTION:p_know[selection[which_item].which] = TRUE; | |
715 when SCROLL:s_know[selection[which_item].which] = TRUE; | |
716 when STICK: ws_know[selection[which_item].which] = TRUE; | |
717 when MM: m_know[selection[which_item].which] = TRUE; | |
718 | |
719 } | |
720 | |
721 if (add_pack(item, FALSE, NULL) == FALSE) { | |
722 | |
723 obj->o_pos = hero; | |
724 fall(item, TRUE); | |
725 } | |
726 } | |
727 | |
728 | |
729 | |
730 /* | |
731 * what to do when the hero steps next to a monster | |
732 */ | |
733 struct linked_list * | |
734 wake_monster(y, x) | |
735 int y, x; | |
736 { | |
737 register struct thing *tp; | |
738 register struct linked_list *it; | |
739 register struct room *trp; | |
740 register const char *mname; | |
741 bool nasty; /* Will the monster "attack"? */ | |
742 char ch; | |
743 | |
744 if ((it = find_mons(y, x)) == NULL) { | |
745 msg("Can't find monster in show"); | |
746 return (NULL); | |
747 } | |
748 tp = THINGPTR(it); | |
749 ch = tp->t_type; | |
750 | |
751 trp = roomin(&tp->t_pos); /* Current room for monster */ | |
752 mname = monsters[tp->t_index].m_name; | |
753 | |
754 /* | |
755 * Let greedy ones in a room guard gold | |
756 * (except in a maze where lots of creatures would all go for the | |
757 * same piece of gold) | |
758 */ | |
759 if (on(*tp, ISGREED) && off(*tp, ISRUN) && | |
760 levtype != MAZELEV && trp != NULL && | |
761 lvl_obj != NULL) { | |
762 register struct linked_list *item; | |
763 register struct object *cur; | |
764 | |
765 for (item = lvl_obj; item != NULL; item = next(item)) { | |
766 cur = OBJPTR(item); | |
767 if ((cur->o_type == GOLD) && | |
768 (roomin(&cur->o_pos) == trp)) { | |
769 /* Run to the gold */ | |
770 tp->t_dest = &cur->o_pos; | |
771 turn_on(*tp, ISRUN); | |
772 turn_off(*tp, ISDISGUISE); | |
773 | |
774 /* Make it worth protecting */ | |
775 cur->o_count += GOLDCALC + GOLDCALC; | |
776 break; | |
777 } | |
778 } | |
779 } | |
780 | |
781 /* | |
782 * Every time he sees mean monster, it might start chasing him | |
783 */ | |
784 if (on(*tp, ISMEAN) && | |
785 off(*tp, ISHELD) && | |
786 off(*tp, ISRUN) && | |
787 rnd(100) > 33 && | |
788 (!is_stealth(&player) || (on(*tp, ISUNIQUE) && rnd(100) > 95)) && | |
789 (off(player, ISINVIS) || on(*tp, CANSEE)) || | |
790 (trp != NULL && (trp->r_flags & ISTREAS))) { | |
791 tp->t_dest = &hero; | |
792 turn_on(*tp, ISRUN); | |
793 turn_off(*tp, ISDISGUISE); | |
794 } | |
795 | |
796 /* See if the monster will bother the player */ | |
797 nasty = (on(*tp, ISRUN) && cansee(tp->t_pos.y, tp->t_pos.x)); | |
798 | |
799 /* | |
800 * Let the creature summon if it can. | |
801 * Also check to see if there is room around the player, | |
802 * if not then the creature will wait | |
803 */ | |
804 if (on(*tp, CANSUMMON) && nasty && | |
805 rnd(40) < tp->t_stats.s_lvl && | |
806 fallpos(&hero, FALSE, 2) != NULL) { | |
807 const char *helpname; | |
808 int fail; | |
809 register int which, i; | |
810 | |
811 turn_off(*tp, CANSUMMON); | |
812 helpname = monsters[tp->t_index].m_typesum; | |
813 for (which=1; which<NUMMONST; which++) { | |
814 if (strcmp(helpname, monsters[which].m_name) == 0) | |
815 break; | |
816 } | |
817 if (which >= NUMMONST) | |
818 debug("couldn't find summoned one"); | |
819 if ((off(*tp, ISINVIS) || on(player, CANSEE)) && | |
820 (off(*tp, ISSHADOW) || on(player, CANSEE)) && | |
821 (off(*tp, CANSURPRISE) || ISWEARING(R_ALERT))) { | |
822 if (monsters[which].m_normal == FALSE) { /* genocided? */ | |
823 msg("The %s appears dismayed", mname); | |
824 monsters[tp->t_index].m_numsum = 0; | |
825 } | |
826 else { | |
827 sprintf(outstring,"The %s summons %ss for help", mname, helpname); | |
828 msg(outstring); | |
829 } | |
830 } | |
831 else { | |
832 if (monsters[which].m_normal == FALSE) /* genocided? */ | |
833 monsters[tp->t_index].m_numsum = 0; | |
834 else | |
835 msg("%ss seem to appear from nowhere!", helpname); | |
836 } | |
837 /* | |
838 * try to make all the creatures around player but remember | |
839 * if unsuccessful | |
840 */ | |
841 for (i=0, fail=0; i<monsters[tp->t_index].m_numsum; i++) { | |
842 if (!creat_mons(&player, which, FALSE)) | |
843 fail++; /* remember the failures */ | |
844 } | |
845 /* | |
846 * try once again to make the buggers | |
847 */ | |
848 for (i=0; i<fail; i++) | |
849 creat_mons(tp, which, FALSE); | |
850 | |
851 /* Now let the poor fellow see all the trouble */ | |
852 light(&hero); | |
853 } | |
854 | |
855 /* | |
856 * Handle monsters that can gaze and do things while running | |
857 * Player must be able to see the monster and the monster must | |
858 * not be asleep | |
859 */ | |
860 if (nasty && !invisible(tp)) { | |
861 /* | |
862 * Confusion | |
863 */ | |
864 if (on(*tp, CANHUH) && | |
865 (off(*tp, ISINVIS) || on(player, CANSEE)) && | |
866 (off(*tp, CANSURPRISE) || ISWEARING(R_ALERT))) { | |
867 if (!save(VS_MAGIC, &player, 0)) { | |
868 if (off(player, ISCLEAR)) { | |
869 if (find_slot(unconfuse)) | |
870 lengthen(unconfuse, rnd(20)+HUHDURATION); | |
871 else { | |
872 fuse(unconfuse, 0, rnd(20)+HUHDURATION, AFTER); | |
873 msg("The %s's gaze has confused you.",mname); | |
874 turn_on(player, ISHUH); | |
875 } | |
876 } | |
877 else msg("You feel dizzy for a moment, but it quickly passes."); | |
878 } | |
879 else if (rnd(100) < 67) | |
880 turn_off(*tp, CANHUH); /* Once you save, maybe that's it */ | |
881 } | |
882 | |
883 /* Sleep */ | |
884 if(on(*tp, CANSNORE) && | |
885 no_command == 0 && | |
886 !save(VS_PARALYZATION, &player, 0)) { | |
887 if (ISWEARING(R_ALERT)) | |
888 msg("You feel slightly drowsy for a moment."); | |
889 else { | |
890 msg("The %s's gaze puts you to sleep.", mname); | |
891 no_command += SLEEPTIME; | |
892 if (rnd(100) < 50) turn_off(*tp, CANSNORE); | |
893 } | |
894 } | |
895 | |
896 /* Fear */ | |
897 if (on(*tp, CANFRIGHTEN)) { | |
898 turn_off(*tp, CANFRIGHTEN); | |
899 if (!ISWEARING(R_HEROISM) && | |
900 !save(VS_WAND, &player, 0) && | |
901 !(on(player, ISFLEE) && (player.t_dest == &tp->t_pos))) { | |
902 turn_on(player, ISFLEE); | |
903 player.t_dest = &tp->t_pos; | |
904 msg("The sight of the %s terrifies you.", mname); | |
905 } | |
906 } | |
907 | |
908 /* blinding creatures */ | |
909 if(on(*tp, CANBLIND) && | |
910 !find_slot(sight) && | |
911 !save(VS_WAND,&player, 0)){ | |
912 msg("The gaze of the %s blinds you", mname); | |
913 turn_on(player, ISBLIND); | |
914 fuse(sight, 0, rnd(30)+20, AFTER); | |
915 light(&hero); | |
916 } | |
917 | |
918 /* the sight of the ghost can age you! */ | |
919 if (on(*tp, CANAGE)) { | |
920 turn_off (*tp, CANAGE); | |
921 if (!save(VS_MAGIC, &player, 0)) { | |
922 msg ("The sight of the %s ages you!", mname); | |
923 pstats.s_const--; | |
924 max_stats.s_const--; | |
925 if (pstats.s_const < 0) | |
926 death (D_CONSTITUTION); | |
927 } | |
928 } | |
929 | |
930 | |
931 /* Turning to stone */ | |
932 if (on(*tp, LOOKSTONE)) { | |
933 turn_off(*tp, LOOKSTONE); | |
934 | |
935 if (on(player, CANINWALL)) | |
936 msg("The gaze of the %s has no effect.", mname); | |
937 else { | |
938 if (!save(VS_PETRIFICATION, &player, 0) && rnd(100) < 15) { | |
939 pstats.s_hpt = -1; | |
940 msg("The gaze of the %s petrifies you.", mname); | |
941 msg("You are turned to stone !!! --More--"); | |
942 wait_for(cw,' '); | |
943 death(D_PETRIFY); | |
944 } | |
945 else { | |
946 msg("The gaze of the %s stiffens your limbs.", mname); | |
947 no_command += STONETIME; | |
948 } | |
949 } | |
950 } | |
951 } | |
952 | |
953 return it; | |
954 } | |
955 /* | |
956 * wanderer: | |
957 * A wandering monster has awakened and is headed for the player | |
958 */ | |
959 | |
960 wanderer() | |
961 { | |
962 register int i; | |
963 register struct room *hr = roomin(&hero); | |
964 register struct linked_list *item; | |
965 register struct thing *tp; | |
966 register const long *attr; /* Points to monsters' attributes */ | |
967 int carry; /* Chance of wanderer carrying anything */ | |
968 short rmonst; /* Our random wanderer */ | |
969 bool canteleport = FALSE, /* Can the monster teleport? */ | |
970 seehim; /* Is monster within sight? */ | |
971 coord cp; | |
972 | |
973 rmonst = randmonster(TRUE, FALSE); /* Choose a random wanderer */ | |
974 attr = &monsters[rmonst].m_flags[0]; /* Start of attributes */ | |
975 for (i=0; i<MAXFLAGS; i++) | |
976 if (*attr++ == CANTELEPORT) { | |
977 canteleport = TRUE; | |
978 break; | |
979 } | |
980 | |
981 /* Find a place for it -- avoid the player's room if can't teleport */ | |
982 do { | |
983 do { | |
984 i = rnd_room(); | |
985 } until (canteleport || hr != &rooms[i] || levtype == MAZELEV || | |
986 levtype == OUTSIDE || levtype == POSTLEV); | |
987 | |
988 /* Make sure the monster does not teleport on top of the player */ | |
989 do { | |
990 rnd_pos(&rooms[i], &cp); | |
991 } while (hr == &rooms[i] && ce(cp, hero)); | |
992 } until (step_ok(cp.y, cp.x, NOMONST, NULL)); | |
993 | |
994 /* Create a new wandering monster */ | |
995 item = new_item(sizeof *tp); | |
996 new_monster(item, rmonst, &cp, FALSE); | |
997 tp = THINGPTR(item); | |
998 turn_on(*tp, ISRUN); | |
999 turn_off(*tp, ISDISGUISE); | |
1000 tp->t_dest = &hero; | |
1001 tp->t_pos = cp; /* Assign the position to the monster */ | |
1002 seehim = cansee(tp->t_pos.y, tp->t_pos.x); | |
1003 if (on(*tp, HASFIRE)) { | |
1004 register struct room *rp; | |
1005 | |
1006 rp = roomin(&tp->t_pos); | |
1007 if (rp) { | |
1008 register struct linked_list *fire_item; | |
1009 | |
1010 fire_item = creat_item(); | |
1011 ldata(fire_item) = (char *) tp; | |
1012 attach(rp->r_fires, fire_item); | |
1013 | |
1014 rp->r_flags |= HASFIRE; | |
1015 if (seehim && next(rp->r_fires) == NULL) | |
1016 light(&hero); | |
1017 } | |
1018 } | |
1019 | |
1020 /* See if we give the monster anything */ | |
1021 carry = monsters[tp->t_index].m_carry; | |
1022 if (off(*tp, ISUNIQUE)) carry /= 2; /* Non-unique has only a half chance */ | |
1023 carry_obj(tp, carry); | |
1024 | |
1025 /* Alert the player if a monster just teleported in */ | |
1026 if (hr == &rooms[i] && canteleport && seehim && !invisible(tp)) { | |
1027 msg("A %s just teleported in", monsters[rmonst].m_name); | |
1028 light(&hero); | |
1029 running = FALSE; | |
1030 } | |
1031 | |
1032 if (wizard) | |
1033 msg("Started a wandering %s", monsters[tp->t_index].m_name); | |
1034 } |