Annotation of early-roguelike/arogue7/player.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: * player.c - This file contains functions for dealing with special player
! 3: * abilities
! 4: *
! 5: * Advanced Rogue
! 6: * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T
! 7: * All rights reserved.
! 8: *
! 9: * Based on "Rogue: Exploring the Dungeons of Doom"
! 10: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
! 11: * All rights reserved.
! 12: *
! 13: * See the file LICENSE.TXT for full copyright and licensing information.
! 14: */
! 15:
! 16: /*
! 17: * This file contains functions for dealing with special player abilities
! 18: */
! 19:
! 20: #include <ctype.h>
! 21: #include <string.h>
! 22: #include "curses.h"
! 23: #include "rogue.h"
! 24: #ifdef PC7300
! 25: #include "menu.h"
! 26: #endif
! 27:
! 28: bool pick_spell(struct spells spells[], int ability, int num_spells, int power,
! 29: char *prompt, char *type);
! 30:
! 31: /*
! 32: * affect:
! 33: * cleric affecting undead
! 34: */
! 35:
! 36: void
! 37: affect(void)
! 38: {
! 39: register struct linked_list *item;
! 40: register struct thing *tp;
! 41: register char *mname;
! 42: bool see;
! 43: coord new_pos;
! 44: int lvl;
! 45:
! 46: if (!(player.t_ctype == C_CLERIC ||
! 47: (player.t_ctype == C_PALADIN && pstats.s_lvl > 4) ||
! 48: cur_relic[HEIL_ANKH] != 0)) {
! 49: msg("You cannot affect undead.");
! 50: return;
! 51: }
! 52:
! 53: new_pos.y = hero.y + player.t_newpos.y;
! 54: new_pos.x = hero.x + player.t_newpos.x;
! 55:
! 56: if (cansee(new_pos.y, new_pos.x)) see = TRUE;
! 57: else see = FALSE;
! 58:
! 59: /* Anything there? */
! 60: if (new_pos.y < 0 || new_pos.y > lines-3 ||
! 61: new_pos.x < 0 || new_pos.x > cols-1 ||
! 62: mvwinch(mw, new_pos.y, new_pos.x) == ' ') {
! 63: msg("Nothing to affect.");
! 64: return;
! 65: }
! 66:
! 67: if ((item = find_mons(new_pos.y, new_pos.x)) == NULL) {
! 68: debug("Affect what @ %d,%d?", new_pos.y, new_pos.x);
! 69: return;
! 70: }
! 71: tp = THINGPTR(item);
! 72: mname = monster_name(tp);
! 73:
! 74: if (on(player, ISINVIS) && off(*tp, CANSEE)) {
! 75: msg("%s%s cannot see you", see ? "The " : "It",
! 76: see ? mname : "");
! 77: return;
! 78: }
! 79:
! 80: if (off(*tp, TURNABLE) || on(*tp, WASTURNED))
! 81: goto annoy;
! 82: turn_off(*tp, TURNABLE);
! 83:
! 84: lvl = pstats.s_lvl;
! 85: if (player.t_ctype == C_PALADIN && cur_relic[HEIL_ANKH] == 0) {
! 86: lvl -= 4;
! 87: }
! 88: /* Can cleric kill it? */
! 89: if (lvl >= 3 * tp->t_stats.s_lvl) {
! 90: unsigned long test; /* For overflow check */
! 91:
! 92: msg("You have destroyed %s%s.", see ? "the " : "it", see ? mname : "");
! 93: test = pstats.s_exp + tp->t_stats.s_exp;
! 94:
! 95: /* Be sure there is no overflow before increasing experience */
! 96: if (test > pstats.s_exp) pstats.s_exp = test;
! 97: killed(item, FALSE, TRUE, TRUE);
! 98: check_level();
! 99: return;
! 100: }
! 101:
! 102: /* Can cleric turn it? */
! 103: if (rnd(100) + 1 >
! 104: (100 * ((2 * tp->t_stats.s_lvl) - lvl)) / lvl) {
! 105: unsigned long test; /* Overflow test */
! 106:
! 107: /* Make the monster flee */
! 108: turn_on(*tp, WASTURNED); /* No more fleeing after this */
! 109: turn_on(*tp, ISFLEE);
! 110: runto(tp, &hero);
! 111:
! 112: /* Disrupt it */
! 113: dsrpt_monster(tp, TRUE, TRUE);
! 114:
! 115: /* Let player know */
! 116: msg("You have turned %s%s.", see ? "the " : "it", see ? mname : "");
! 117:
! 118: /* get points for turning monster -- but check overflow first */
! 119: test = pstats.s_exp + tp->t_stats.s_exp/2;
! 120: if (test > pstats.s_exp) pstats.s_exp = test;
! 121: check_level();
! 122:
! 123: /* If monster was suffocating, stop it */
! 124: if (on(*tp, DIDSUFFOCATE)) {
! 125: turn_off(*tp, DIDSUFFOCATE);
! 126: extinguish(suffocate);
! 127: }
! 128:
! 129: /* If monster held us, stop it */
! 130: if (on(*tp, DIDHOLD) && (--hold_count == 0))
! 131: turn_off(player, ISHELD);
! 132: turn_off(*tp, DIDHOLD);
! 133:
! 134: /* It is okay to turn tail */
! 135: tp->t_oldpos = tp->t_pos;
! 136:
! 137: return;
! 138: }
! 139:
! 140: /* Otherwise -- no go */
! 141: annoy:
! 142: if (see && tp->t_stats.s_intel > 16)
! 143: msg("%s laughs at you...", prname(mname, TRUE));
! 144: else
! 145: msg("You do not affect %s%s.", see ? "the " : "it", see ? mname : "");
! 146:
! 147: /* Annoy monster */
! 148: if (off(*tp, ISFLEE)) runto(tp, &hero);
! 149: }
! 150:
! 151: /*
! 152: * the magic user is going to try and cast a spell
! 153: */
! 154: void
! 155: cast(void)
! 156: {
! 157: int spell_ability,
! 158: which_spell,
! 159: num_spells;
! 160:
! 161: if (player.t_ctype != C_MAGICIAN && player.t_ctype != C_RANGER) {
! 162: msg("You are not permitted to cast spells.");
! 163: return;
! 164: }
! 165: spell_ability = pstats.s_lvl * pstats.s_intel;
! 166: if (player.t_ctype != C_MAGICIAN)
! 167: spell_ability /= 3;
! 168:
! 169: if (player.t_action != C_CAST) {
! 170: /*
! 171: * Get the number of avilable spells
! 172: */
! 173: num_spells = 0;
! 174: if (pstats.s_intel >= 16)
! 175: num_spells += pstats.s_intel - 15;
! 176: num_spells += pstats.s_lvl;
! 177: if (player.t_ctype != C_MAGICIAN)
! 178: num_spells /= 3;
! 179: if (num_spells > MAXSPELLS)
! 180: num_spells = MAXSPELLS;
! 181: if (num_spells < 1) {
! 182: msg("You are not allowed to cast spells yet.");
! 183: return;
! 184: }
! 185: if (pick_spell( magic_spells,
! 186: spell_ability,
! 187: num_spells,
! 188: spell_power,
! 189: "cast",
! 190: "spell"))
! 191: player.t_action = C_CAST;
! 192: return;
! 193: }
! 194:
! 195: /* We've waited our required casting time. */
! 196: which_spell = player.t_selection;
! 197: player.t_selection = 0;
! 198: player.t_using = NULL;
! 199: player.t_action = A_NIL;
! 200:
! 201: if ((spell_power + magic_spells[which_spell].s_cost) > spell_ability) {
! 202: msg("Your attempt fails.");
! 203: return;
! 204: }
! 205:
! 206: msg("Your spell is successful.");
! 207:
! 208: if (magic_spells[which_spell].s_type == TYP_POTION)
! 209: quaff( magic_spells[which_spell].s_which,
! 210: 0,
! 211: magic_spells[which_spell].s_flag,
! 212: FALSE);
! 213: else if (magic_spells[which_spell].s_type == TYP_SCROLL)
! 214: read_scroll( magic_spells[which_spell].s_which,
! 215: magic_spells[which_spell].s_flag,
! 216: FALSE);
! 217: else if (magic_spells[which_spell].s_type == TYP_STICK) {
! 218: if (!player_zap(magic_spells[which_spell].s_which,
! 219: magic_spells[which_spell].s_flag)) {
! 220: after = FALSE;
! 221: return;
! 222: }
! 223: }
! 224: spell_power += magic_spells[which_spell].s_cost;
! 225: }
! 226:
! 227: /*
! 228: * the druid asks his deity for a spell
! 229: */
! 230: void
! 231: chant(void)
! 232: {
! 233: register int num_chants,
! 234: chant_ability,
! 235: which_chant;
! 236:
! 237: which_chant = num_chants = chant_ability = 0;
! 238:
! 239: if (player.t_ctype != C_DRUID && player.t_ctype != C_RANGER) {
! 240: msg("You are not permitted to chant.");
! 241: return;
! 242: }
! 243: if (cur_misc[WEAR_CLOAK] != NULL &&
! 244: cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) {
! 245: msg("You can't seem to chant!");
! 246: return;
! 247: }
! 248: chant_ability = pstats.s_lvl * pstats.s_wisdom;
! 249: if (player.t_ctype != C_DRUID)
! 250: chant_ability /= 3;
! 251:
! 252: if (player.t_action != C_CHANT) {
! 253: num_chants = 0;
! 254:
! 255: /* Get the number of avilable chants */
! 256: if (pstats.s_wisdom > 16)
! 257: num_chants = (pstats.s_wisdom - 15) / 2;
! 258:
! 259: num_chants += pstats.s_lvl;
! 260:
! 261: if (player.t_ctype != C_DRUID)
! 262: num_chants /= 3;
! 263:
! 264: if (num_chants > MAXCHANTS)
! 265: num_chants = MAXCHANTS;
! 266:
! 267: if (num_chants < 1) {
! 268: msg("You are not permitted to chant yet.");
! 269: return;
! 270: }
! 271:
! 272: /* Prompt for chant */
! 273: if (pick_spell( druid_spells,
! 274: chant_ability,
! 275: num_chants,
! 276: chant_time,
! 277: "sing",
! 278: "chant"))
! 279: player.t_action = C_CHANT;
! 280:
! 281: return;
! 282: }
! 283:
! 284: /* We've waited our required chanting time. */
! 285: which_chant = player.t_selection;
! 286: player.t_selection = 0;
! 287: player.t_using = NULL;
! 288: player.t_action = A_NIL;
! 289:
! 290: if (druid_spells[which_chant].s_cost + chant_time > chant_ability) {
! 291: msg("Your chant fails.");
! 292: return;
! 293: }
! 294:
! 295: msg("Your chant has been granted.");
! 296:
! 297: if (druid_spells[which_chant].s_type == TYP_POTION)
! 298: quaff( druid_spells[which_chant].s_which,
! 299: 0,
! 300: druid_spells[which_chant].s_flag,
! 301: FALSE);
! 302: else if (druid_spells[which_chant].s_type == TYP_SCROLL)
! 303: read_scroll( druid_spells[which_chant].s_which,
! 304: druid_spells[which_chant].s_flag,
! 305: FALSE);
! 306: else if (druid_spells[which_chant].s_type == TYP_STICK) {
! 307: if (!player_zap(druid_spells[which_chant].s_which,
! 308: druid_spells[which_chant].s_flag)) {
! 309: after = FALSE;
! 310: return;
! 311: }
! 312: }
! 313: chant_time += druid_spells[which_chant].s_cost;
! 314: }
! 315:
! 316: /* Constitution bonus */
! 317:
! 318: int
! 319: const_bonus(void) /* Hit point adjustment for changing levels */
! 320: {
! 321: register int bonus;
! 322: if (pstats.s_const > 6 && pstats.s_const <= 14)
! 323: bonus = 0;
! 324: else if (pstats.s_const > 14)
! 325: bonus = pstats.s_const-14;
! 326: else if (pstats.s_const > 3)
! 327: bonus = -1;
! 328: else
! 329: bonus = -2;
! 330: switch(player.t_ctype) {
! 331: case C_FIGHTER: bonus = min(bonus, 11);
! 332: when C_MAGICIAN: bonus = min(bonus, 4);
! 333: when C_CLERIC: bonus = min(bonus, 4);
! 334: when C_THIEF: bonus = min(bonus, 4);
! 335: when C_RANGER: bonus = min(bonus, 6);
! 336: when C_PALADIN: bonus = min(bonus, 8);
! 337: when C_ASSASIN: bonus = min(bonus, 4);
! 338: when C_MONK: bonus = min(bonus, 6);
! 339: when C_DRUID: bonus = min(bonus, 4);
! 340: otherwise: bonus = min(bonus, 4);
! 341: }
! 342: return(bonus);
! 343: }
! 344:
! 345:
! 346: /* Routines for thieves */
! 347:
! 348: /*
! 349: * gsense:
! 350: * Sense gold
! 351: */
! 352:
! 353: void
! 354: gsense(void)
! 355: {
! 356: /* Only thieves can do this */
! 357: if (player.t_ctype != C_THIEF && player.t_ctype != C_ASSASIN) {
! 358: msg("You seem to have no gold sense.");
! 359: return;
! 360: }
! 361:
! 362: read_scroll(S_GFIND, 0, FALSE);
! 363: }
! 364:
! 365: /*
! 366: * the cleric asks his deity for a spell
! 367: */
! 368: void
! 369: pray(void)
! 370: {
! 371: register int num_prayers,
! 372: prayer_ability,
! 373: which_prayer;
! 374:
! 375: which_prayer = num_prayers = prayer_ability = 0;
! 376:
! 377: if (player.t_ctype != C_CLERIC &&
! 378: player.t_ctype != C_PALADIN &&
! 379: cur_relic[HEIL_ANKH] == 0) {
! 380: msg("You are not permitted to pray.");
! 381: return;
! 382: }
! 383: if (cur_misc[WEAR_CLOAK] != NULL &&
! 384: cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) {
! 385: msg("You can't seem to pray!");
! 386: return;
! 387: }
! 388:
! 389: prayer_ability = pstats.s_lvl * pstats.s_wisdom;
! 390: if (player.t_ctype != C_CLERIC)
! 391: prayer_ability /= 3;
! 392:
! 393: if (cur_relic[HEIL_ANKH]) prayer_ability *= 2;
! 394:
! 395: if (player.t_action != C_PRAY) {
! 396: num_prayers = 0;
! 397:
! 398: /* Get the number of avilable prayers */
! 399: if (pstats.s_wisdom > 16)
! 400: num_prayers += (pstats.s_wisdom - 15) / 2;
! 401:
! 402: num_prayers += pstats.s_lvl;
! 403: if (cur_relic[HEIL_ANKH]) num_prayers += 3;
! 404:
! 405: if (player.t_ctype != C_CLERIC)
! 406: num_prayers /= 3;
! 407:
! 408: if (num_prayers > MAXPRAYERS)
! 409: num_prayers = MAXPRAYERS;
! 410: if (num_prayers < 1) {
! 411: msg("You are not permitted to pray yet.");
! 412: return;
! 413: }
! 414:
! 415: /* Prompt for prayer */
! 416: if (pick_spell( cleric_spells,
! 417: prayer_ability,
! 418: num_prayers,
! 419: pray_time,
! 420: "offer",
! 421: "prayer"))
! 422: player.t_action = C_PRAY;
! 423:
! 424: return;
! 425: }
! 426:
! 427: /* We've waited our required praying time. */
! 428: which_prayer = player.t_selection;
! 429: player.t_selection = 0;
! 430: player.t_using = NULL;
! 431: player.t_action = A_NIL;
! 432:
! 433: if (cleric_spells[which_prayer].s_cost + pray_time > prayer_ability) {
! 434: msg("Your prayer fails.");
! 435: return;
! 436: }
! 437:
! 438: msg("Your prayer has been granted.");
! 439:
! 440: if (cleric_spells[which_prayer].s_type == TYP_POTION)
! 441: quaff( cleric_spells[which_prayer].s_which,
! 442: 0,
! 443: cleric_spells[which_prayer].s_flag,
! 444: FALSE);
! 445: else if (cleric_spells[which_prayer].s_type == TYP_SCROLL)
! 446: read_scroll( cleric_spells[which_prayer].s_which,
! 447: cleric_spells[which_prayer].s_flag,
! 448: FALSE);
! 449: else if (cleric_spells[which_prayer].s_type == TYP_STICK) {
! 450: if (!player_zap(cleric_spells[which_prayer].s_which,
! 451: cleric_spells[which_prayer].s_flag)) {
! 452: after = FALSE;
! 453: return;
! 454: }
! 455: }
! 456: pray_time += cleric_spells[which_prayer].s_cost;
! 457: }
! 458:
! 459:
! 460:
! 461: /*
! 462: * steal:
! 463: * Steal in direction given in delta
! 464: */
! 465:
! 466: void
! 467: steal(void)
! 468: {
! 469: register struct linked_list *item;
! 470: register struct thing *tp;
! 471: register char *mname;
! 472: coord new_pos;
! 473: int thief_bonus = -50;
! 474: bool isinvisible = FALSE;
! 475:
! 476: if (player.t_ctype != C_THIEF && player.t_ctype != C_ASSASIN) {
! 477: msg("Only thieves and assassins can steal.");
! 478: return;
! 479: }
! 480: if (on(player, ISBLIND)) {
! 481: msg("You can't see anything.");
! 482: return;
! 483: }
! 484:
! 485: new_pos.y = hero.y + player.t_newpos.y;
! 486: new_pos.x = hero.x + player.t_newpos.x;
! 487:
! 488: /* Anything there? */
! 489: if (new_pos.y < 0 || new_pos.y > lines-3 ||
! 490: new_pos.x < 0 || new_pos.x > cols-1 ||
! 491: mvwinch(mw, new_pos.y, new_pos.x) == ' ') {
! 492: msg("Nothing to steal from.");
! 493: return;
! 494: }
! 495:
! 496: if ((item = find_mons(new_pos.y, new_pos.x)) == NULL)
! 497: debug("Steal from what @ %d,%d?", new_pos.y, new_pos.x);
! 498: tp = THINGPTR(item);
! 499: if (on(*tp, ISSTONE)) {
! 500: msg ("You can't steal from stone!");
! 501: return;
! 502: }
! 503: if (isinvisible = invisible(tp)) mname = "creature";
! 504: else mname = monster_name(tp);
! 505:
! 506: /* Can player steal something unnoticed? */
! 507: if (player.t_ctype == C_THIEF) thief_bonus = 10;
! 508: if (player.t_ctype == C_ASSASIN) thief_bonus = 0;
! 509: if (on(*tp, ISUNIQUE)) thief_bonus -= 15;
! 510: if (isinvisible) thief_bonus -= 20;
! 511: if (on(*tp, ISINWALL) && off(player, CANINWALL)) thief_bonus -= 50;
! 512:
! 513: if (on(*tp, ISHELD) || tp->t_action == A_FREEZE ||
! 514: rnd(100) <
! 515: (thief_bonus + 2*dex_compute() + 5*pstats.s_lvl -
! 516: 5*(tp->t_stats.s_lvl - 3))) {
! 517: register struct linked_list *s_item, *pack_ptr;
! 518: int count = 0;
! 519: unsigned long test; /* Overflow check */
! 520:
! 521: s_item = NULL; /* Start stolen goods out as nothing */
! 522:
! 523: /* Find a good item to take */
! 524: for (pack_ptr=tp->t_pack; pack_ptr != NULL; pack_ptr=next(pack_ptr))
! 525: if ((OBJPTR(pack_ptr))->o_type != RELIC &&
! 526: pack_ptr != tp->t_using && /* Monster can't be using it */
! 527: rnd(++count) == 0)
! 528: s_item = pack_ptr;
! 529:
! 530: /*
! 531: * Find anything?
! 532: */
! 533: if (s_item == NULL) {
! 534: msg("%s apparently has nothing to steal.", prname(mname, TRUE));
! 535: return;
! 536: }
! 537:
! 538: /* Take it from monster */
! 539: if (tp->t_pack) detach(tp->t_pack, s_item);
! 540:
! 541: /* Recalculate the monster's encumberance */
! 542: updpack(TRUE, tp);
! 543:
! 544: /* Give it to player */
! 545: if (add_pack(s_item, FALSE, NULL) == FALSE) {
! 546: (OBJPTR(s_item))->o_pos = hero;
! 547: fall(s_item, TRUE);
! 548: }
! 549:
! 550: /* Get points for stealing -- but first check for overflow */
! 551: test = pstats.s_exp + tp->t_stats.s_exp/2;
! 552: if (test > pstats.s_exp) pstats.s_exp = test;
! 553:
! 554: /*
! 555: * Do adjustments if player went up a level
! 556: */
! 557: check_level();
! 558: }
! 559:
! 560: else {
! 561: msg("Your attempt fails.");
! 562:
! 563: /* Annoy monster (maybe) */
! 564: if (rnd(35) >= dex_compute() + thief_bonus) {
! 565: /*
! 566: * If this is a charmed creature, there is a chance it
! 567: * will become uncharmed.
! 568: */
! 569: if (on(*tp, ISCHARMED) && save(VS_MAGIC, tp, 0)) {
! 570: msg("The eyes of %s turn clear.", prname(mname, FALSE));
! 571: turn_off(*tp, ISCHARMED);
! 572: }
! 573: if (on(*tp, CANSELL)) {
! 574: turn_off(*tp, CANSELL);
! 575: tp->t_action = A_NIL;
! 576: tp->t_movement = 0;
! 577: if (rnd(100) < 50) /* make him steal something */
! 578: turn_on(*tp, STEALMAGIC);
! 579: else
! 580: turn_on(*tp, STEALGOLD);
! 581: if (!isinvisible)
! 582: msg("%s looks insulted.", prname(mname, TRUE));
! 583: }
! 584: runto(tp, &hero);
! 585: }
! 586: }
! 587: }
! 588:
! 589: #ifdef PC7300
! 590: /* Use MAXSPELLS or whatever is the biggest number of spells/prayers/etc */
! 591: static menu_t Display; /* The menu structure */
! 592: static mitem_t Dispitems[MAXSPELLS+1]; /* Info for each line */
! 593: static char Displines[MAXSPELLS+1][LINELEN+1]; /* The lines themselves */
! 594: #endif
! 595:
! 596: /*
! 597: * this routine lets the player pick the spell that they
! 598: * want to cast regardless of character class
! 599: * spells: spell list
! 600: * ability: spell ability
! 601: * num_spells: number of spells that can be cast
! 602: * power: spell power
! 603: * prompt: prompt for spell list
! 604: * type: type of thing--> spell, prayer, chant
! 605: */
! 606: bool
! 607: pick_spell(struct spells spells[], int ability, int num_spells, int power,
! 608: char *prompt, char *type)
! 609: {
! 610: bool nohw = FALSE;
! 611: register int i;
! 612: int curlen,
! 613: maxlen,
! 614: dummy,
! 615: which_spell,
! 616: spell_left;
! 617: #ifdef PC7300
! 618: char label[LINELEN], /* For menu label */
! 619: title[LINELEN]; /* For menu title */
! 620: #endif
! 621:
! 622: if (cur_misc[WEAR_CLOAK] != NULL &&
! 623: cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) {
! 624: msg("You can't seem to start a %s!", type);
! 625: return(FALSE);
! 626: }
! 627:
! 628: /* Prompt for spells */
! 629: msg("Which %s are you %sing? (* for list): ", type, prompt);
! 630:
! 631: which_spell = (int) (readchar() - 'a');
! 632: msg(""); /* Get rid of the prompt */
! 633: if (which_spell == (int) ESCAPE - (int) 'a') {
! 634: after = FALSE;
! 635: return(FALSE);
! 636: }
! 637: if (which_spell >= 0 && which_spell < num_spells) nohw = TRUE;
! 638:
! 639: else if (slow_invent) {
! 640: register char c;
! 641:
! 642: nohw = TRUE;
! 643: do {
! 644: for (i=0; i<num_spells; i++) {
! 645: msg("");
! 646: mvwaddch(msgw, 0, 0, '[');
! 647: waddch(msgw, (char) ((int) 'a' + i));
! 648: wprintw(msgw, "] A %s of ", type);
! 649: if (spells[i].s_type == TYP_POTION)
! 650: waddstr(msgw, p_magic[spells[i].s_which].mi_name);
! 651: else if (spells[i].s_type == TYP_SCROLL)
! 652: waddstr(msgw, s_magic[spells[i].s_which].mi_name);
! 653: else if (spells[i].s_type == TYP_STICK)
! 654: waddstr(msgw, ws_magic[spells[i].s_which].mi_name);
! 655: waddstr(msgw, morestr);
! 656: wclrtobot(msgw);
! 657: clearok(msgw, FALSE);
! 658: draw(msgw);
! 659: do {
! 660: c = readchar();
! 661: } while (c != ' ' && c != ESCAPE);
! 662: if (c == ESCAPE)
! 663: break;
! 664: }
! 665: msg("");
! 666: wmove(msgw, 0, 0);
! 667: wprintw(msgw, "Which %s are you %sing? ", type, prompt);
! 668: clearok(msgw, FALSE);
! 669: draw(msgw);
! 670:
! 671: which_spell = (int) (readchar() - 'a');
! 672: } while (which_spell != (int) (ESCAPE - 'a') &&
! 673: (which_spell < 0 || which_spell >= num_spells));
! 674:
! 675: if (which_spell == (int) (ESCAPE - 'a')) {
! 676: mpos = 0;
! 677: msg("");
! 678: after = FALSE;
! 679: return(FALSE);
! 680: }
! 681: }
! 682: else {
! 683: /* Now display the possible spells */
! 684: wclear(hw);
! 685: touchwin(hw);
! 686: wmove(hw, 2, 0);
! 687: *type = toupper(*type);
! 688: wprintw(hw, " Cost %s", type);
! 689: *type = tolower(*type);
! 690: mvwaddstr(hw, 3, 0,
! 691: "-----------------------------------------------");
! 692: maxlen = 47; /* Maximum width of header */
! 693:
! 694: for (i=0; i<num_spells; i++) {
! 695: sprintf(prbuf, "[%c] %3d A %s of ",
! 696: (char) ((int) 'a' + i), spells[i].s_cost, type);
! 697: if (spells[i].s_type == TYP_POTION)
! 698: strcat(prbuf, p_magic[spells[i].s_which].mi_name);
! 699: else if (spells[i].s_type == TYP_SCROLL)
! 700: strcat(prbuf, s_magic[spells[i].s_which].mi_name);
! 701: else if (spells[i].s_type == TYP_STICK)
! 702: strcat(prbuf, ws_magic[spells[i].s_which].mi_name);
! 703: mvwaddstr(hw, i+4, 0, prbuf);
! 704:
! 705: /* Get the length of the line */
! 706: getyx(hw, dummy, curlen);
! 707: if (maxlen < curlen) maxlen = curlen;
! 708:
! 709: #ifdef PC7300
! 710: /* Put it into the PC menu display */
! 711: strcpy(Displines[i], prbuf);
! 712: Dispitems[i].mi_name = Displines[i];
! 713: Dispitems[i].mi_flags = 0;
! 714: Dispitems[i].mi_val = i;
! 715: #endif
! 716: }
! 717:
! 718: spell_left = ability - power;
! 719: if (spell_left < 0) {
! 720: spell_left = 0;
! 721: if (spell_left < -20) power = ability + 20;
! 722: }
! 723: sprintf(prbuf, "[Current %s power = %d]", type, spell_left);
! 724:
! 725: mvwaddstr(hw, 0, 0, prbuf);
! 726: wprintw(hw, " Which %s are you %sing? ", type, prompt);
! 727: getyx(hw, dummy, curlen);
! 728: if (maxlen < curlen) maxlen = curlen;
! 729:
! 730: #ifdef PC7300
! 731: /* Place an end marker for the items */
! 732: Dispitems[num_spells].mi_name = 0;
! 733:
! 734: /* Design prompts */
! 735: sprintf(label, "Current %s power is %d", type, spell_left);
! 736: *type = toupper(*type);
! 737: sprintf(title, " Cost %s", type);
! 738: *type = tolower(*type);
! 739: sprintf(prbuf, "Select a %s or press Cancl to continue.", type);
! 740:
! 741: /* Set up the main menu structure */
! 742: Display.m_label = label;
! 743: Display.m_title = title;
! 744: Display.m_prompt = prbuf;
! 745: Display.m_curptr = '\0';
! 746: Display.m_markptr = '\0';
! 747: Display.m_flags = M_ASISTITLE;
! 748: Display.m_selcnt = 1;
! 749: Display.m_items = Dispitems;
! 750: Display.m_curi = 0;
! 751:
! 752: /*
! 753: * Try to display the menu. If we don't have a local terminal,
! 754: * the call will fail and we will just continue with the
! 755: * normal mode.
! 756: */
! 757: if (menu(&Display) >= 0) {
! 758: if (Display.m_selcnt == 0) {
! 759: /* Menu was cancelled */
! 760: after = FALSE;
! 761: return FALSE; /* all done if abort */
! 762: }
! 763: else which_spell = (int) Display.m_curi->mi_val;
! 764: goto got_spell;
! 765: }
! 766: #endif
! 767: /* Should we overlay? */
! 768: if (menu_overlay && num_spells + 3 < lines / 2) {
! 769: over_win(cw, hw, num_spells + 5, maxlen + 3, 0, curlen, '\0');
! 770: }
! 771: else draw(hw);
! 772: }
! 773:
! 774: if (!nohw) {
! 775: which_spell = (int) (readchar() - 'a');
! 776: while (which_spell < 0 || which_spell >= num_spells) {
! 777: if (which_spell == (int) ESCAPE - (int) 'a') {
! 778: after = FALSE;
! 779:
! 780: /* Restore the screen */
! 781: touchwin(cw);
! 782: if (num_spells + 3 < lines / 2) clearok(cw, FALSE);
! 783: else clearok(cw, TRUE);
! 784: return(FALSE);
! 785: }
! 786: wmove(hw, 0, 0);
! 787: wclrtoeol(hw);
! 788: wprintw(hw, "Please enter one of the listed %ss. ", type);
! 789: getyx(hw, dummy, curlen);
! 790: if (maxlen < curlen) maxlen = curlen;
! 791:
! 792: /* Should we overlay? */
! 793: if (menu_overlay && num_spells + 3 < lines / 2) {
! 794: over_win(cw, hw, num_spells + 5, maxlen + 3,
! 795: 0, curlen, '\0');
! 796: }
! 797: else draw(hw);
! 798:
! 799: which_spell = (int) (readchar() - 'a');
! 800: }
! 801: }
! 802:
! 803: /* Now restore the screen if we have to */
! 804: if (!nohw) {
! 805: touchwin(cw);
! 806: if (num_spells + 3 < lines / 2) clearok(cw, FALSE);
! 807: else clearok(cw, TRUE);
! 808: }
! 809:
! 810: #ifdef PC7300
! 811: got_spell:
! 812: #endif
! 813: if (spells[which_spell].s_type == TYP_STICK &&
! 814: need_dir(STICK, spells[which_spell].s_which)) {
! 815: if (!get_dir(&player.t_newpos)) {
! 816: after = FALSE;
! 817: return(FALSE);
! 818: }
! 819: }
! 820: player.t_selection = which_spell;
! 821: player.t_using = NULL;
! 822: player.t_no_move = (which_spell/3 + 1) * movement(&player);
! 823: return(TRUE);
! 824: }
CVSweb