games@tekred.TEK.COM (07/27/88)
Submitted by: "James E. Wilson" <wilson@ji.berkeley.edu> Comp.sources.games: Volume 5, Issue 36 Archive-name: umoria2/Part05 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 5 (of 18)." # Contents: moria1.c signals.c # Wrapped by billr@saab on Wed Jul 13 11:16:22 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'moria1.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'moria1.c'\" else echo shar: Extracting \"'moria1.c'\" \(47241 characters\) sed "s/^X//" >'moria1.c' <<'END_OF_FILE' X#include <stdio.h> X X#include "constants.h" X#include "config.h" X#include "types.h" X#include "externs.h" X X#ifdef USG X#include <string.h> X#else X#include <strings.h> X#endif X X#ifdef sun /* correct SUN stupidity in the stdio.h file */ Xchar *sprintf(); X#endif X Xbyteint de_statt(); Xbyteint in_statt(); X X/* global flags */ Xextern int moria_flag; /* Next level when true */ Xextern int search_flag; /* Player is searching */ Xextern int teleport_flag; /* Handle teleport traps */ Xextern int player_light; /* Player carrying light */ Xextern int cave_flag; /* used in get_panel */ Xextern int light_flag; /* used in move_light */ X X X/* Changes stats up or down for magic items -RAK- */ Xchange_stat_factor(stat, amount, factor) Xregister byteint *stat; Xint amount, factor; X{ X register int i, j, k; X X j = amount * factor; X if (amount < 0) X k = -amount; X else X k = amount; X for (i = 0; i < k; i++) X if (j < 0) X *stat = de_statt(*stat); X else X *stat = in_statt(*stat); X} X X X/* Changes speed of monsters relative to player -RAK- */ X/* Note: When the player is sped up or slowed down, I simply */ X/* change the speed of all the monsters. This greatly */ X/* simplified the logic... */ Xchange_speed(num) Xregister int num; X{ X register int i; X X py.flags.speed += num; X i = muptr; X while (i > 0) X { X m_list[i].cspeed += num; X i = m_list[i].nptr; X } X} X X X/* Player bonuses -RAK- */ X/* When an item is worn or taken off, this re-adjusts the player */ X/* bonuses. Factor==1 : wear; Factor==-1 : removed */ Xpy_bonuses(tobj, factor) Xtreasure_type tobj; Xint factor; X{ X register unsigned int item_flags; X int old_dis_ac; X register struct flags *p_ptr; X register struct misc *m_ptr; X register treasure_type *i_ptr; X register int i; X X p_ptr = &py.flags; X m_ptr = &py.misc; X if (p_ptr->slow_digest) X p_ptr->food_digested++; X if (p_ptr->regenerate) X p_ptr->food_digested -= 3; X p_ptr->see_inv = FALSE; X p_ptr->teleport = FALSE; X p_ptr->free_act = FALSE; X p_ptr->slow_digest = FALSE; X p_ptr->aggravate = FALSE; X p_ptr->sustain_str = FALSE; X p_ptr->sustain_int = FALSE; X p_ptr->sustain_wis = FALSE; X p_ptr->sustain_con = FALSE; X p_ptr->sustain_dex = FALSE; X p_ptr->sustain_chr = FALSE; X p_ptr->fire_resist = FALSE; X p_ptr->acid_resist = FALSE; X p_ptr->cold_resist = FALSE; X p_ptr->regenerate = FALSE; X p_ptr->lght_resist = FALSE; X p_ptr->ffall = FALSE; X X if (0x00000001 & tobj.flags) X { X change_stat_factor(&py.stats.cstr, tobj.p1, factor); X change_stat_factor(&py.stats.str, tobj.p1, factor); X print_stat = (0x0001 | print_stat); X } X if (0x00000002 & tobj.flags) X { X change_stat_factor(&py.stats.cdex, tobj.p1, factor); X change_stat_factor(&py.stats.dex, tobj.p1, factor); X print_stat = (0x0002 | print_stat); X } X if (0x00000004 & tobj.flags) X { X change_stat_factor(&py.stats.ccon, tobj.p1, factor); X change_stat_factor(&py.stats.con, tobj.p1, factor); X print_stat = (0x0004 | print_stat); X } X if (0x00000008 & tobj.flags) X { X change_stat_factor(&py.stats.cint, tobj.p1, factor); X change_stat_factor(&py.stats.intel, tobj.p1, factor); X print_stat = (0x0008 | print_stat); X } X if (0x00000010 & tobj.flags) X { X change_stat_factor(&py.stats.cwis, tobj.p1, factor); X change_stat_factor(&py.stats.wis, tobj.p1, factor); X print_stat = (0x0010 | print_stat); X } X if (0x00000020 & tobj.flags) X { X change_stat_factor(&py.stats.cchr, tobj.p1, factor); X change_stat_factor(&py.stats.chr, tobj.p1, factor); X print_stat = (0x0020 | print_stat); X } X if (0x00000040 & tobj.flags) X { X m_ptr->srh += (tobj.p1 * factor); X m_ptr->fos -= (tobj.p1 * factor); X } X if (0x00000100 & tobj.flags) X m_ptr->stl += 2*factor; X if (0x00001000 & tobj.flags) X { X i = tobj.p1*factor; X change_speed(-i); X } X if (0x08000000 & tobj.flags) X if (factor > 0) X p_ptr->blind += 1000; X if (0x10000000 & tobj.flags) X if (factor > 0) X p_ptr->afraid += 50; X if (0x40000000 & tobj.flags) X p_ptr->see_infra += (tobj.p1 * factor); X X old_dis_ac = m_ptr->dis_ac; X m_ptr->ptohit = tohit_adj(); /* Real To Hit */ X m_ptr->ptodam = todam_adj(); /* Real To Dam */ X m_ptr->ptoac = toac_adj(); /* Real To AC */ X m_ptr->pac = 0; /* Real AC */ X m_ptr->dis_th = m_ptr->ptohit; /* Display To Hit */ X m_ptr->dis_td = m_ptr->ptodam; /* Display To Dam */ X m_ptr->dis_ac = 0; /* Display To AC */ X m_ptr->dis_tac = m_ptr->ptoac; /* Display AC */ X for (i = 22; i < INVEN_MAX-2; i++) X { X i_ptr = &inventory[i]; X if (i_ptr->tval != 0) X { X if ((0x80000000 & i_ptr->flags) == 0) X { X m_ptr->pac += i_ptr->ac; X m_ptr->dis_ac += i_ptr->ac; X } X m_ptr->ptohit += i_ptr->tohit; X m_ptr->ptodam += i_ptr->todam; X m_ptr->ptoac += i_ptr->toac; X if (index(i_ptr->name, '^') == 0) X { X m_ptr->dis_th += i_ptr->tohit; X m_ptr->dis_td += i_ptr->todam; X m_ptr->dis_tac += i_ptr->toac; X } X } X } X m_ptr->dis_ac += m_ptr->dis_tac; X X /* Add in temporary spell increases */ X if (p_ptr->invuln > 0) X { X m_ptr->pac += 100; X m_ptr->dis_ac += 100; X } X if (p_ptr->blessed > 0) X { X m_ptr->pac += 2; X m_ptr->dis_ac += 2; X } X if (p_ptr->detect_inv > 0) X p_ptr->see_inv = TRUE; X X if (old_dis_ac != m_ptr->dis_ac) X print_stat = (0x0040 | print_stat); X X item_flags = 0; X for (i = 22; i < INVEN_MAX-2; i++) X { X i_ptr = &inventory[i]; X item_flags |= i_ptr->flags; X } X if (0x00000080 & item_flags) X p_ptr->slow_digest = TRUE; X if (0x00000200 & item_flags) X p_ptr->aggravate = TRUE; X if (0x00000400 & item_flags) X p_ptr->teleport = TRUE; X if (0x00000800 & item_flags) X p_ptr->regenerate = TRUE; X if (0x00080000 & item_flags) X p_ptr->fire_resist = TRUE; X if (0x00100000 & item_flags) X p_ptr->acid_resist = TRUE; X if (0x00200000 & item_flags) X p_ptr->cold_resist = TRUE; X if (0x00800000 & item_flags) X p_ptr->free_act = TRUE; X if (0x01000000 & item_flags) X p_ptr->see_inv = TRUE; X if (0x02000000 & item_flags) X p_ptr->lght_resist = TRUE; X if (0x04000000 & item_flags) X p_ptr->ffall = TRUE; X X for (i = 22; i < INVEN_MAX-2; i++) X { X i_ptr = &inventory[i]; X if (0x00400000 & i_ptr->flags) X switch(i_ptr->p1) X { X case 1: p_ptr->sustain_str = TRUE; break; X case 2: p_ptr->sustain_int = TRUE; break; X case 3: p_ptr->sustain_wis = TRUE; break; X case 4: p_ptr->sustain_con = TRUE; break; X case 5: p_ptr->sustain_dex = TRUE; break; X case 6: p_ptr->sustain_chr = TRUE; break; X default: break; X } X } X X if (p_ptr->slow_digest) X p_ptr->food_digested--; X if (p_ptr->regenerate) X p_ptr->food_digested += 3; X} X X X/* Returns a "*" for cursed items, a ")" for normal ones -RAK- */ X/* NOTE: "*" returned only if item has been identified... */ Xchar cur_char1(item_val) Xint item_val; X{ X register treasure_type *i_ptr; X X i_ptr = &inventory[item_val]; X if ((0x80000000 & i_ptr->flags) == 0) X return(')'); /* Not cursed... */ X else if (index(i_ptr->name, '^') != 0) X return(')'); /* Cursed, but not identified */ X else X return('*'); /* Cursed and identified... */ X} X X X/* Returns a "*" for cursed items, a ")" for normal ones -RAK- */ Xchar cur_char2(item_val) Xint item_val; X{ X register treasure_type *i_ptr; X X i_ptr = &inventory[item_val]; X if ((0x80000000 & i_ptr->flags) == 0) X return(')'); /* Not cursed... */ X else X return('*'); /* Cursed... */ X} X X X/* inventory functions, define some global variables here */ X/* scr_state == 0 : normal screen (i.e. map of dungeon) X or partial inventory list, (calling function sets redraw) X scr_state == 1 : inventory is displayed on the screen X scr_state == 2 : equipment list is displayed on the screen */ Xint scr_state; X X/* Displays inventory items from r1 to r2 -RAK- */ Xshow_inven(r1, r2) Xregister int r1, r2; X{ X register int i; X vtype tmp_val, out_val; X X if (r1 >= 0) /* R1 == 0 dummy call */ X { X for (i = r1; i <= r2; i++) /* Print the items */ X { X objdes(tmp_val, i, TRUE); X (void) sprintf(out_val, "%c%c %s", i+97, cur_char1(i), tmp_val); X prt(out_val, i+1, 0); X } X if (r2 < 22) X prt("", r2+2, 0); /* Clear line after */ X scr_state = 1; /* Set state to 1 */ X } X} X X/* Displays equipment items from r1 to end -RAK- */ Xshow_equip(r1) Xregister int r1; X{ X register int i, j; X vtype prt1, prt2, out_val; X register treasure_type *i_ptr; X X if (r1 >= equip_ctr) /* Last item gone */ X prt("", equip_ctr+2, 0); /* clear the line */ X else if (r1 >= 0) /* R1 == 0 dummy call */ X { X j = 0; X for (i = 22; i < INVEN_MAX; i++) /* Range of equipment */ X { X i_ptr = &inventory[i]; X if (i_ptr->tval != 0) X { X if (j >= r1) /* Display only given range */ X { X switch(i) /* Get position */ X { X case 22: X (void) strcpy(prt1, " You are wielding : "); break; X case 23: X (void) strcpy(prt1, " Worn on head : "); break; X case 24: X (void) strcpy(prt1, " Worn around neck : "); break; X case 25: X (void) strcpy(prt1, " Worn on body : "); break; X case 26: X (void) strcpy(prt1, " Worn on arm : "); break; X case 27: X (void) strcpy(prt1, " Worn on hands : "); break; X case 28: X (void) strcpy(prt1, " Worn on right hand : "); break; X case 29: X (void) strcpy(prt1, " Worn on left hand : "); break; X case 30: X (void) strcpy(prt1, " Worn on feet : "); break; X case 31: X (void) strcpy(prt1, " Worn about body : "); break; X case 32: X (void) strcpy(prt1, " Light source : "); break; X case 33: X (void) strcpy(prt1, " Secondary weapon : "); break; X default: X (void) strcpy(prt1, " Unknown value : "); break; X } X objdes(prt2, i, TRUE); X (void) sprintf(out_val, X "%c%c%s%s", j+97, cur_char2(i), prt1, prt2); X prt(out_val, j+2, 0); X } X j++; X } X } X prt("", j+2, 0); /* Clear last line */ X scr_state = 2; /* Set state of screen */ X } X} X X/* Remove item from equipment list -RAK- */ Xint remove(item_val) Xint item_val; X{ X register int i, j, typ; X vtype out_val, prt1, prt2; X int flag; X register treasure_type *i_ptr; X X i = 0; X flag = FALSE; X typ = inventory[item_val].tval; X do X { X i_ptr = &inventory[i]; X if (typ > i_ptr->tval) X { X for (j = inven_ctr-1; j >= i; j--) X inventory[j+1] = inventory[j]; X inventory[i] = inventory[item_val]; X inven_ctr++; X equip_ctr--; X flag = TRUE; X } X i++; X } X while (!flag); X i--; X switch(typ) X { X case 10: case 11: case 12: case 20: case 21: case 22: case 23: case 25 : X (void) strcpy(prt1, "Was wielding "); X break; X case 15: X (void) strcpy(prt1, "Light source was "); X break; X default: X (void) strcpy(prt1, "Was wearing "); X break; X } X objdes(prt2, i, TRUE); X (void) sprintf(out_val, "%s%s (%c)", prt1, prt2, i+97); X msg_print(out_val); X inventory[item_val] = blank_treasure; X if (item_val != INVEN_AUX) /* For secondary weapon */ X py_bonuses(inventory[i], -1); X return(i); X} X X X/* Unwear routine, remove a piece of equipment -RAK- */ Xunwear() X{ X register int i, j; X int exit_flag, test_flag, com_val; X char command; X vtype out_val; X X if (scr_state == 1) X { X clear_screen(0, 0); X show_equip(0); X } X exit_flag = FALSE; X do X { X (void) sprintf(out_val, X "(a-%c, * for equipment list, ESC to exit) Take off which one ?", X equip_ctr+96); X test_flag = FALSE; X msg_print(out_val); X do X { X inkey(&command); X com_val = (command); X switch(com_val) X { X case 0: case 27: X test_flag = TRUE; X exit_flag = TRUE; X break; X case 42: X clear_screen(1, 0); X show_equip(0); X break; X default: X com_val -= 97; X if ((com_val >= 0) && X (com_val < equip_ctr)) X test_flag = TRUE; X break; X } X } X while (!test_flag); X if (!exit_flag) X { X reset_flag = FALSE; /* Player turn */ X i = -1; X j = 21; X do X { X j++; X if (inventory[j].tval != 0) X i++; X } X while (i != com_val); X if (0x80000000 & inventory[j].flags) X { X msg_print("Hmmm, it seems to be cursed..."); X com_val = 0; X } X else X (void) remove(j); X } X if (scr_state == 0) X exit_flag = TRUE; X else if (equip_ctr == 0) X exit_flag = TRUE; X else if (inven_ctr > 21) X { X exit_flag = TRUE; X show_equip(0); X } X else if (!exit_flag) X show_equip(0); X } X while (!exit_flag); X if (scr_state != 0) X if (equip_ctr == 0) X clear_screen(0, 0); X else X prt("You are currently using -", 0, 0); X} X X X/* Wear routine, wear or wield an item -RAK- */ Xwear() X{ X register int i, j, k; X int com_val, tmp; X vtype out_val, prt1, prt2; X treasure_type unwear_obj; X int exit_flag, test_flag; X char command; X register treasure_type *i_ptr; X X if (scr_state == 2) X { X clear_screen(0, 0); X show_inven(0, inven_ctr-1); X } X exit_flag = FALSE; X do X { X (void) sprintf(out_val, X "(a-%c, * for equipment list, ESC to exit) Wear/Wield which one?", X inven_ctr+96); X test_flag = FALSE; X msg_print(out_val); X do X { X inkey(&command); X com_val = (command); X switch(com_val) X { X case 0: case 27: X test_flag = TRUE; X exit_flag = TRUE; X break; X case 42: X clear_screen(1, 0); X show_inven(0, inven_ctr-1); X break; X default: X com_val -= 97; X if ((com_val >= 0) && X (com_val < inven_ctr)) X test_flag = TRUE; X break; X } X } X while (!test_flag); X if (!exit_flag) /* Main logic for wearing */ X { X reset_flag = FALSE; /* Player turn */ X test_flag = TRUE; X switch(inventory[com_val].tval) /* Slot for equipment */ X { X case 10: i = 22; break; X case 11: i = 22; break; X case 12: i = 22; break; X case 15: i = 32; break; X case 20: i = 22; break; X case 21: i = 22; break; X case 22: i = 22; break; X case 23: i = 22; break; X case 25: i = 22; break; X case 30: i = 30; break; X case 31: i = 27; break; X case 32: i = 31; break; X case 33: i = 23; break; X case 34: i = 26; break; X case 35: i = 25; break; X case 36: i = 25; break; X case 40: i = 24; break; X case 45: X if (inventory[INVEN_RIGHT].tval == 0) /* Rings */ X i = INVEN_RIGHT; X else X i = INVEN_LEFT; X break; X default: X msg_print("I don't see how you can use that."); X test_flag = FALSE; X com_val = 0; X break; X } X if (test_flag) X if (inventory[i].tval != 0) X { X if (0x80000000 & inventory[i].flags) X { X objdes(prt1, i, FALSE); X (void) sprintf(out_val, "The %s you are ", prt1); X switch(i) X { X case 23: (void) strcat(out_val, "wielding "); break; X default: (void) strcat(out_val, "wearing "); break; X } X msg_print(strcat(out_val, "appears to be cursed.")); X test_flag = FALSE; X com_val = 0; X } X else if (inven_ctr > 21) X if (inventory[com_val].number > 1) X if (inventory[com_val].subval < 512) X { X msg_print("You will have to drop something first."); X test_flag = FALSE; X com_val = 0; X } X } X if (test_flag) X { X /* save old item */ X unwear_obj = inventory[i]; X /* now wear/wield new object */ X inventory[i] = inventory[com_val]; X i_ptr = &inventory[i]; X /* Fix for torches */ X if ((i_ptr->subval > 255) && (i_ptr->subval < 512)) X { X i_ptr->number = 1; X i_ptr->subval -= 255; X } X /* Fix for weight */ X inven_weight += i_ptr->weight*i_ptr->number; X inven_destroy(com_val); /* Subtracts weight */ X equip_ctr++; X /* subtract bonuses for old item before add bonuses for new */ X /* must do this after inven_destroy, otherwise inventory X may increase to 23 items thus destroying INVEN_WIELD */ X if (unwear_obj.tval != 0) X { X inventory[INVEN_MAX] = unwear_obj; X /* decrements equip_ctr, and calls py_bonuses with -1 */ X tmp = remove(INVEN_MAX); X if (tmp < com_val) X com_val = tmp; X } X py_bonuses(inventory[i], 1); X switch(i) X { X case 22: (void) strcpy(prt1, "You are wielding "); break; X case 32: (void) strcpy(prt1, "Your light source is "); break; X default: (void) strcpy(prt1, "You are wearing "); break; X } X objdes(prt2, i, TRUE); X j = -1; X k = 21; X do /* Get the right letter of equipment */ X { X k++; X if (inventory[k].tval != 0) X j++; X } X while (k != i); X (void) sprintf(out_val, "%s%s (%c%c", X prt1, prt2, j+97, cur_char2(i)); X msg_print(out_val); X if ((i == 22) && (py.stats.cstr*15 < i_ptr->weight)) X msg_print("You have trouble wielding such a heavy weapon."); X } X } X if (scr_state == 0) X exit_flag = TRUE; X else if (inven_ctr == 0) X exit_flag = TRUE; X else if (!exit_flag) X show_inven(com_val, inven_ctr-1); X } X while (!exit_flag); X if (scr_state != 0) prt("You are currently carrying -", 0, 0); X} X X/* Switch primary and secondary weapons -RAK- */ Xswitch_weapon() X{ X vtype prt1, prt2; X treasure_type tmp_obj; X X if (0x80000000 & inventory[INVEN_WIELD].flags) X { X objdes(prt1, INVEN_WIELD, FALSE); X (void) sprintf(prt2, X "The %s you are wielding appears to be cursed.", prt1); X msg_print(prt2); X } X else X { X /* Switch weapons */ X reset_flag = FALSE; X tmp_obj = inventory[INVEN_AUX]; X inventory[INVEN_AUX] = inventory[INVEN_WIELD]; X inventory[INVEN_WIELD] = tmp_obj; X py_bonuses(inventory[INVEN_AUX], -1); /* Subtract bonuses */ X py_bonuses(inventory[INVEN_WIELD], 1); /* Add bonuses */ X if (inventory[INVEN_WIELD].tval != 0) X { X (void) strcpy(prt1, "Primary weapon : "); X objdes(prt2, INVEN_WIELD, TRUE); X msg_print(strcat(prt1, prt2)); X if (py.stats.cstr * 15 < inventory[INVEN_WIELD].weight) X msg_print("You have trouble wielding such a heavy weapon."); X } X if (inventory[INVEN_AUX].tval != 0) X { X (void) strcpy(prt1, "Secondary weapon : "); X objdes(prt2, INVEN_AUX, TRUE); X msg_print(strcat(prt1, prt2)); X } X } X if (scr_state != 0) X { X /* make sure player sees last message */ X msg_print(" "); X clear_screen(0, 0); X prt("You are currently using -", 0, 0); X show_equip(0); X } X} X X X/* Comprehensive function block to handle all inventory -RAK- */ X/* and equipment routines. Five kinds of calls can take place. */ X/* Note that "?" is a special call for other routines to display */ X/* only a portion of the inventory, and take no other action. */ Xint inven_command(command, r1, r2) Xchar command; Xint r1, r2; X{ X register int com_val, inven; X register int exit_flag, test_flag; X X /* Main logic for INVEN_COMMAND -RAK- */ X inven = FALSE; X exit_flag = FALSE; X scr_state = 0; X do X { X switch(command) X { X case 'i': /* Inventory */ X if (inven_ctr == 0) X msg_print("You are not carrying anything."); X else if (scr_state != 1) X { /* Sets scr_state to 1 */ X clear_screen(0, 0); X prt("You are currently carrying -", 0, 0); X show_inven(0, inven_ctr-1); X } X break; X case 'e': /* Equipment */ X if (equip_ctr == 0) X msg_print("You are not using any equipment."); X else if (scr_state != 2) X { /* Sets scr_state to 2 */ X clear_screen(0, 0); X prt("You are currently using -", 0, 0); X show_equip(0); X } X break; X case 't': /* Take off */ X if (equip_ctr == 0) X msg_print("You are not using any equipment."); X else if (inven_ctr > 21) X msg_print("You will have to drop something first."); X else X unwear(); /* May set scr_state to 2 */ X break; X case 'w': /* Wear/wield */ X if (inven_ctr == 0) X msg_print("You are not carrying anything."); X else X wear(); /* May set scr_state to 1 */ X break; X case 'x': X if (inventory[INVEN_WIELD].tval != 0) X switch_weapon(); X else if (inventory[INVEN_AUX].tval != 0) X switch_weapon(); X else X msg_print("But you are wielding no weapons."); X break; X /* Special function for other routines */ X case '?': /* Displays part inven, returns */ X show_inven(r1, r2); X scr_state = 0; /* Clear screen state */ X break; X /* Nonsense command */ X default: X break; X } X if (scr_state > 0) X { X prt( X "<e>quip, <i>inven, <t>ake-off, <w>ear/wield, e<x>change, or ESC to exit.", X 23, 1); X test_flag = FALSE; X do X { X inkey(&command); X com_val = (command); X switch(com_val) X { X case 0: case 27: case 32: X /* Exit from module */ X exit_flag = TRUE; X test_flag = TRUE; X break; X default: X switch(command) /* Module commands */ X { X case 'e': test_flag = TRUE; break; X case 'i': test_flag = TRUE; break; X case 't': test_flag = TRUE; break; X case 'w': test_flag = TRUE; break; X case 'x': test_flag = TRUE; break; X case '?': break; /* Trap special feature */ X default: break; /* Nonsense command */ X } X } X } X while (!test_flag); X prt("", 23, 0); /* clear the line containing command list */ X } X else X exit_flag = TRUE; X } X while (!exit_flag); X if (scr_state > 0) /* If true, must redraw screen */ X inven = TRUE; X return(inven); X} X X X/* Get the ID of an item and return the CTR value of it -RAK- */ Xint get_item(com_val, pmt, redraw, i, j) Xint *com_val; Xchar *pmt; Xint *redraw; Xint i, j; X{ X char command; X vtype out_val; X register int test_flag, item; X X item = FALSE; X *com_val = 0; X if (inven_ctr > 0) X { X (void) sprintf(out_val, X "(Items %c-%c, * for inventory list, ESC to exit) %s", X i+97, j+97, pmt); X test_flag = FALSE; X prt(out_val, 0, 0); X do X { X inkey(&command); X *com_val = (command); X switch(*com_val) X { X case 0: case 27: X test_flag = TRUE; X reset_flag = TRUE; X break; X case 42: X clear_screen(1, 0); X (void) inven_command('?', i, j); X *redraw = TRUE; X break; X default: X *com_val -= 97; X if ((*com_val >= i) && X (*com_val <= j)) X { X test_flag = TRUE; X item = TRUE; X } X break; X } X } X while (!test_flag); X erase_line(MSG_LINE, 0); X } X else X msg_print("You are not carrying anything."); X return(item); X} X X/* I may have written the town level code, but I'm not exactly */ X/* proud of it. Adding the stores required some real slucky */ X/* hooks which I have not had time to re-think. -RAK- */ X X X/* Calculates current boundaries -RAK- */ Xpanel_bounds() X{ X panel_row_min = panel_row*(SCREEN_HEIGHT/2); X panel_row_max = panel_row_min + SCREEN_HEIGHT - 1; X panel_row_prt = panel_row_min - 1; X panel_col_min = panel_col*(SCREEN_WIDTH/2); X panel_col_max = panel_col_min + SCREEN_WIDTH - 1; X/* the value 13 puts one blank space between the stats and the map, leaving X the last column empty X the value 14 puts two blank spaces between the stats and the map, and X ends up printing in the last column X I think 14 gives a better display, but some curses wreak havoc when try to X print characters in the last column, hence the BUGGY_CURSES ifdef */ X#ifdef BUGGY_CURSES X panel_col_prt = panel_col_min - 13; X#else X panel_col_prt = panel_col_min - 14; X#endif X} X X X/* Given an row (y) and col (x), this routine detects -RAK- */ X/* when a move off the screen has occurred and figures new borders*/ Xint get_panel(y, x) Xint y, x; X{ X register int prow, pcol; X register int panel; X X prow = panel_row; X pcol = panel_col; X if ((y < panel_row_min + 2) || (y > panel_row_max - 2)) X { X prow = ((y - 2)/(SCREEN_HEIGHT/2)); X if (prow > max_panel_rows) X prow = max_panel_rows; X } X if ((x < panel_col_min + 3) || (x > panel_col_max - 3)) X { X pcol = ((x - 3)/(SCREEN_WIDTH/2)); X if (pcol > max_panel_cols) X pcol = max_panel_cols; X } X if ((prow != panel_row) || (pcol != panel_col) || (!cave_flag)) X { X panel_row = prow; X panel_col = pcol; X panel_bounds(); X panel = TRUE; X cave_flag = TRUE; X /* stop movement if any */ X if (find_flag) X find_flag = FALSE; /* no need to call move_light () */ X } X else X panel = FALSE; X return(panel); X} X X X/* Tests a given point to see if it is within the screen -RAK- */ X/* boundaries. */ Xint panel_contains(y, x) Xint y, x; X{ X register int panel; X X if ((y >= panel_row_min) && (y <= panel_row_max)) X if ((x >= panel_col_min) && (x <= panel_col_max)) X panel = TRUE; X else X panel = FALSE; X else X panel = FALSE; X return(panel); X} X X X/* Returns true if player has no light -RAK- */ Xint no_light() X{ X register int light; X register cave_type *c_ptr; X X light = FALSE; X c_ptr = &cave[char_row][char_col]; X if (!c_ptr->tl) X if (!c_ptr->pl) X light = TRUE; X return(light); X} X X X/* map rogue_like direction commands into numbers */ Xint map_roguedir(comval) Xregister int *comval; X{ X switch(*comval) X { X case 'h': X *comval = '4'; X return(4); X case 'y': X *comval = '7'; X return(7); X case 'k': X *comval = '8'; X return(8); X case 'u': X *comval = '9'; X return(9); X case 'l': X *comval = '6'; X return(6); X case 'n': X *comval = '3'; X return(3); X case 'j': X *comval = '2'; X return(2); X case 'b': X *comval = '1'; X return(1); X } X return(*comval - 48); X} X X X X/* Prompts for a direction -RAK- */ Xint get_dir(prompt, dir, com_val, y, x) Xchar *prompt; Xint *dir, *com_val, *y, *x; X{ X int flag; X char command; X int res; X X flag = FALSE; X do X { X if (get_com(prompt, &command)) X { X *com_val = (command); X if (key_bindings == ORIGINAL) X *dir = *com_val - 48; X else /* rogue_like bindings */ X *dir = map_roguedir(com_val); X /* Note that "5" is not a valid direction */ X if ((*dir >= 1) && (*dir <= 9) && (*dir != 5)) X { X (void) move(*dir, y, x); X flag = TRUE; X res = TRUE; X } X } X else X { X reset_flag = TRUE; X res = FALSE; X flag = TRUE; X } X } X while (!flag); X return(res); X} X X X/* Moves creature record from one space to another -RAK- */ Xmove_rec(y1, x1, y2, x2) Xregister int y1, x1, y2, x2; X{ X if ((y1 != y2) || (x1 != x2)) X { X cave[y2][x2].cptr = cave[y1][x1].cptr; X cave[y1][x1].cptr = 0; X } X} X X Xfind_light(y1, x1, y2, x2) Xint y1, x1, y2, x2; X{ X register int i, j, k, l; X X for (i = y1; i <= y2; i++) X for (j = x1; j <= x2; j++) X if ((cave[i][j].fval == 1) || (cave[i][j].fval == 2)) X { X for (k = i-1; k <= i+1; k++) X for (l = j-1; l <= j+1; l++) X cave[k][l].pl = TRUE; X cave[i][j].fval = 2; X } X} X X X/* Room is lit, make it appear -RAK- */ Xlight_room(y, x) Xint y, x; X{ X register cave_type *c_ptr; X register int i, j; X int tmp1, tmp2; X int start_row, end_row; X register int start_col, end_col; X int ypos, xpos; X vtype floor_str, tmp_str; X X tmp1 = (SCREEN_HEIGHT/2); X tmp2 = (SCREEN_WIDTH /2); X start_row = (y/tmp1)*tmp1; X start_col = (x/tmp2)*tmp2; X end_row = start_row + tmp1 - 1; X end_col = start_col + tmp2 - 1; X find_light(start_row, start_col, end_row, end_col); X for (i = start_row; i <= end_row; i++) X { X floor_str[0] = '\0'; X ypos = i; X for (j = start_col; j <= end_col; j++) X { X c_ptr = &cave[i][j]; X if ((c_ptr->pl) || (c_ptr->fm)) X { X if (strlen(floor_str) == 0) X xpos = j; X loc_symbol(i, j, tmp_str); X tmp_str[1] = '\0'; X (void) strcat(floor_str, tmp_str); X } X else X if (strlen(floor_str) > 0) X { X print(floor_str, ypos, xpos); X floor_str[0] = '\0'; X } X } X if (strlen(floor_str) > 0) X print(floor_str, ypos, xpos); X } X} X X X/* Lights up given location -RAK- */ Xlite_spot(y, x) Xregister int y, x; X{ X char temp[2]; X X temp[1] = '\0'; X if (panel_contains(y, x)) X { X loc_symbol(y, x, temp); X print(temp, y, x); X } X} X X X/* Blanks out given location -RAK- */ Xunlite_spot(y, x) Xregister int y, x; X{ X if (panel_contains(y, x)) X print(" ", y, x); X} X X X/* Minimum of a maximum -RAK- */ Xint minmax(x, y, z) Xregister int x, y, z; X{ X register int max; X X max = ( y > x ? y : x) + 1; X return((max > z ? z : max)); X} X X/* Maximum of a minimum -RAK- */ Xint maxmin(x, y, z) Xregister int x, y, z; X{ X register int min; X X min = (x > y ? y : x) - 1; X return((min > z ? min : z)); X} X X X/* Given two sets of points, draw the block */ Xdraw_block(y1, x1, y2, x2) Xint y1, x1, y2, x2; X{ X register cave_type *c_ptr; X register int i, j; X int xpos; X int topp, bott, left, righ; X int new_topp, new_bott, new_left, new_righ; X vtype floor_str, save_str; X char tmp_char[2]; X int flag; X X tmp_char[1] = '\0'; /* This is supposed to be a one */ X /* From uppermost to bottom most lines player was on... */ X /* Points are guaranteed to be on the screen (I hope...) */ X topp = maxmin(y1, y2, panel_row_min); X bott = minmax(y1, y2, panel_row_max); X left = maxmin(x1, x2, panel_col_min); X righ = minmax(x1, x2, panel_col_max); X new_topp = y2 - 1; /* Margins for new things to appear*/ X new_bott = y2 + 1; X new_left = x2 - 1; X new_righ = x2 + 1; X for (i = topp; i <= bott; i++) X { X floor_str[0] = '\0'; /* Null out print string */ X xpos = -1; X save_str[0] = '\0'; X for (j = left; j <= righ; j++) /* Leftmost to rightmost do*/ X { X c_ptr = &cave[i][j]; X if ((c_ptr->pl) || (c_ptr->fm)) X if (((i==y1) && (j==x1)) || ((i==y2) && (j==x2))) X flag = TRUE; X else X flag = FALSE; X else X { X flag = TRUE; X if (((i >= new_topp) && (i <= new_bott)) && X ((j >= new_left) && (j <= new_righ))) X { X if (c_ptr->tl) X if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) || X (c_ptr->fval == 15)) X c_ptr->pl = TRUE; X else if (c_ptr->tptr != 0) X if ((t_list[c_ptr->tptr].tval >= 102) && X (t_list[c_ptr->tptr].tval <= 110) && X (t_list[c_ptr->tptr].tval != 106)) X if (!c_ptr->fm) X c_ptr->fm = TRUE; X } X } X if ((c_ptr->pl) || (c_ptr->tl) || (c_ptr->fm)) X loc_symbol(i, j, tmp_char); X else X tmp_char[0] = ' '; X if (py.flags.image > 0) X if (randint(12) == 1) X tmp_char[0] = (randint(95) + 31); X if (flag) X { X if (xpos < 0) xpos = j; X if (strlen(save_str) > 0) X { X (void) strcat(floor_str, save_str); X save_str[0] = '\0'; X } X (void) strcat(floor_str, tmp_char); X } X else if (xpos >= 0) X (void) strcat(save_str, tmp_char); X } X if (xpos >= 0) X { X print(floor_str, i, xpos); X } X } X} X X X/* Normal movement */ Xsub1_move_light(y1, x1, y2, x2) Xregister int x1, x2; Xint y1, y2; X{ X register int i, j; X X light_flag = TRUE; X for (i = y1-1; i <= y1+1; i++) /* Turn off lamp light */ X for (j = x1-1; j <= x1+1; j++) X cave[i][j].tl = FALSE; X for (i = y2-1; i <= y2+1; i++) X for (j = x2-1; j <= x2+1; j++) X cave[i][j].tl = TRUE; X draw_block(y1, x1, y2, x2); /* Redraw area */ X} X X/* When FIND_FLAG, light only permanent features */ Xsub2_move_light(y1, x1, y2, x2) Xint y1, x1, y2, x2; X{ X register int i, j; X int xpos; X vtype floor_str, save_str; X char tmp_char[2]; X int flag; X register cave_type *c_ptr; X X tmp_char[1] = '\0'; X if (light_flag) X { X for (i = y1-1; i <= y1+1; i++) X for (j = x1-1; j <= x1+1; j++) X cave[i][j].tl = FALSE; X draw_block(y1, x1, y1, x1); X light_flag = FALSE; X } X for (i = y2-1; i <= y2+1; i++) X { X floor_str[0] = '\0'; X save_str[0] = '\0'; X xpos = 0; X for (j = x2-1; j <= x2+1; j++) X { X c_ptr = &cave[i][j]; X flag = FALSE; X if ((!c_ptr->fm) && (!c_ptr->pl)) X { X tmp_char[0] = ' '; X if (player_light) X if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) || X (c_ptr->fval == 15)) X { X c_ptr->pl = TRUE; /* Turn on perm light */ X loc_symbol(i, j, tmp_char); X flag = TRUE; X } X else X if (c_ptr->tptr != 0) X if ((t_list[c_ptr->tptr].tval >= 102) && X (t_list[c_ptr->tptr].tval <= 110) && X (t_list[c_ptr->tptr].tval != 106)) X { X c_ptr->fm = TRUE; /* Turn on field marker */ X loc_symbol(i, j, tmp_char); X flag = TRUE; X } X } X else X loc_symbol(i, j, tmp_char); X if (flag) X { X if (xpos == 0) xpos = j; X if (strlen(save_str) > 0) X { X (void) strcat(floor_str, save_str); X save_str[0] = '\0'; X } X (void) strcat(floor_str, tmp_char); X } X else if (xpos > 0) X (void) strcat(save_str, tmp_char); X } X if (xpos > 0) X { X j = i; X print(floor_str, j, xpos); X } X } X} X X/* When blinded, move only the player symbol... */ Xsub3_move_light(y1, x1, y2, x2) Xregister int x1, y1; Xint x2, y2; X{ X register int i, j; X X if (light_flag) X { X for (i = y1-1; i <= y1+1; i++) X for (j = x1-1; j <= x1+1; j++) X cave[i][j].tl = FALSE; X light_flag = FALSE; X } X print(" ", y1, x1); X print("@", y2, x2); X} X X/* With no light, movement becomes involved... */ Xsub4_move_light(y1, x1, y2, x2) Xregister y1, x1; Xint y2, x2; X{ X register int i, j; X X light_flag = TRUE; X if (cave[y1][x1].tl) X { X for (i = y1-1; i <= y1+1; i++) X for (j = x1-1; j <= x1+1; j++) X { X cave[i][j].tl = FALSE; X if (test_light(i, j)) X lite_spot(i, j); X else X unlite_spot(i, j); X } X } X else if (test_light(y1, x1)) X lite_spot(y1, x1); X else X unlite_spot(y1, x1); X print("@", y2, x2); X} X X/* Package for moving the character's light about the screen */ X/* Three cases : Normal, Finding, and Blind -RAK- */ Xmove_light(y1, x1, y2, x2) Xint y1, x1, y2, x2; X{ X if (py.flags.blind > 0) X sub3_move_light(y1, x1, y2, x2); X else if (find_flag) X sub2_move_light(y1, x1, y2, x2); X else if (!player_light) X sub4_move_light(y1, x1, y2, x2); X else X sub1_move_light(y1, x1, y2, x2); X} X X X/* Returns random co-ordinates -RAK- */ Xnew_spot(y, x) Xregister int *y, *x; X{ X do X { X *y = randint(cur_height) - 1; X *x = randint(cur_width) - 1; X } X while ((!cave[*y][*x].fopen) || (cave[*y][*x].cptr != 0) || X (cave[*y][*x].tptr != 0)); X} X X X/* Search Mode enhancement -RAK- */ Xsearch_on() X{ X search_flag = TRUE; X change_speed(1); X py.flags.status |= 0x00000100; X prt_search(); X py.flags.food_digested++; X} X Xsearch_off() X{ X search_flag = FALSE; X find_flag = FALSE; X move_light (char_row, char_col, char_row, char_col); X change_speed(-1); X py.flags.status &= 0xFFFFFEFF; X prt_search(); X py.flags.food_digested--; X} X X X/* Resting allows a player to safely restore his hp -RAK- */ Xrest() X{ X int rest_num; X vtype rest_str; X X prt("Rest for how long? ", 0, 0); X rest_num = 0; X if (get_string(rest_str, 0, 19, 10)) X (void) sscanf(rest_str, "%d", &rest_num); X if (rest_num > 0) X { X if (search_flag) X search_off(); X py.flags.rest = rest_num; X py.flags.status |= 0x00000200; X prt_rest(); X py.flags.food_digested--; X msg_print("Press ^C to wake up..."); X put_qio(); X } X else X { X erase_line(MSG_LINE, 0); X reset_flag = TRUE; X } X} X Xrest_off() X{ X py.flags.rest = 0; X py.flags.status &= 0xFFFFFDFF; X erase_line(0, 0); X prt_rest(); X py.flags.food_digested++; X} X X X/* Attacker's level and plusses, defender's AC -RAK- */ Xint test_hit(bth, level, pth, ac) Xint bth, level, pth, ac; X{ X register int i; X int test; X X if (search_flag) X search_off(); X if (py.flags.rest > 0) X rest_off(); X i = bth + level*BTH_LEV_ADJ + pth*BTH_PLUS_ADJ; X /* pth could be less than 0 if player wielding weapon too heavy for him */ X if ((i > 0) && (randint(i) > ac)) /* Normal hit */ X test = TRUE; X else if (randint(20) == 1) /* Always hit 1/20 */ X test = TRUE; X else /* Missed */ X { X if (i <= 0) X msg_print("You have trouble swinging such a heavy weapon."); X test = FALSE; X } X return(test); X} X X X/* Decreases players hit points and sets death flag if necessary*/ X/* -RAK- */ Xtake_hit(damage, hit_from) Xint damage; Xchar *hit_from; X{ X if (py.flags.invuln > 0) damage = 0; X py.misc.chp -= (double)damage; X if (search_flag) search_off(); X if (py.flags.rest > 0) rest_off(); X if (find_flag) X { X find_flag = FALSE; X move_light (char_row, char_col, char_row, char_col); X } X flush(); X if (py.misc.chp <= -1) X { X if (!death) X { /* Hee, hee... Ain't I mean? */ X death = TRUE; X (void) strcpy(died_from, hit_from); X total_winner = FALSE; X } X moria_flag = TRUE; X } X else X prt_chp(); X} X X X/* Given speed, returns number of moves this turn. -RAK- */ X/* NOTE: Player must always move at least once per iteration, */ X/* a slowed player is handled by moving monsters faster */ Xint movement_rate(speed) Xint speed; X{ X if (speed > 0) X { X if (py.flags.rest > 0) X return 1; X else X return speed; X } X else X { X /* speed must be negative here */ X return ((turn % (2 - speed)) == 0); X/* if ((turn % (2 - speed)) == 0) X return 1; X else X return 0; */ X } X} X X X/* Regenerate hit points -RAK- */ Xregenhp(percent) Xdouble percent; X{ X register struct misc *p_ptr; X X p_ptr = &py.misc; X p_ptr->chp += p_ptr->mhp*percent + PLAYER_REGEN_HPBASE; X} X X X/* Regenerate mana points -RAK- */ Xregenmana(percent) Xdouble percent; X{ X register struct misc *p_ptr; X X p_ptr = &py.misc; X p_ptr->cmana += p_ptr->mana*percent + PLAYER_REGEN_MNBASE; X} X X X/* Change a trap from invisible to visible -RAK- */ X/* Note: Secret doors are handled here */ Xchange_trap(y, x) Xregister int y, x; X{ X register int k; X register cave_type *c_ptr; X X c_ptr = &cave[y][x]; X if ((t_list[c_ptr->tptr].tval == 101) || (t_list[c_ptr->tptr].tval == 109)) X { X k = c_ptr->tptr; X /* subtract one, since zeroth item has subval of one */ X place_trap(y, x, 2, t_list[k].subval-1); X pusht(k); X lite_spot(y, x); X } X} X X X/* Searches for hidden things... -RAK- */ Xsearch(y, x, chance) Xint y, x, chance; X{ X register int i, j; X register cave_type *c_ptr; X register treasure_type *t_ptr; X register struct flags *p_ptr; X vtype tmp_str; X X p_ptr = &py.flags; X if (p_ptr->confused+p_ptr->blind > 0) X chance = chance / 10.0; X else if (no_light()) X chance = chance / 5.0; X for (i = (y - 1); i <= (y + 1); i++) X for (j = (x - 1); j <= (x + 1); j++) X if (in_bounds(i, j)) X if ((i != y) || (j != x)) X if (randint(100) < chance) X { X c_ptr = &cave[i][j]; X /* Search for hidden objects */ X if (c_ptr->tptr != 0) X { X t_ptr = &t_list[c_ptr->tptr]; X /* Trap on floor? */ X if (t_ptr->tval == 101) X { X (void) sprintf(tmp_str,"You have found %s.",t_ptr->name); X msg_print(tmp_str); X change_trap(i, j); X if (find_flag) X { X find_flag = FALSE; X move_light (char_row, char_col, char_row, char_col); X } X } X /* Secret door? */ X else if (t_ptr->tval == 109) X { X msg_print("You have found a secret door."); X c_ptr->fval = corr_floor2.ftval; X change_trap(i, j); X if (find_flag) X { X find_flag = FALSE; X move_light (char_row, char_col, char_row, char_col); X } X } X /* Chest is trapped? */ X else if (t_ptr->tval == 2) X { X /* mask out the treasure bits */ X if ((t_ptr->flags & 0x00FFFFFF) > 1) X if (index(t_ptr->name, '^') != 0) X { X known2(t_ptr->name); X msg_print("You have discovered a trap on the chest!"); X } X else X { X msg_print("The chest is trapped!"); X } X } X } X } X} X X X/* Turns off Find_flag if something interesting appears -RAK- */ X/* BUG: Does not handle corridor/room corners, but I didn't want */ X/* to add a lot of checking for such a minor detail */ Xarea_affect(dir, y, x) Xint dir, y, x; X{ X int z[3]; X register int i; X int row, col; X register cave_type *c_ptr; X monster_type *m_ptr; X X if (cave[y][x].fval == 4) X { X i = 0; X if (next_to4(y, x, 4, 5, 6) > 2) X { X find_flag = FALSE; /* no need to call move_light () */ X return; X } X } X if ((find_flag) && (py.flags.blind < 1)) X { X switch(dir) X { X case 1: X z[0] = 4; X z[1] = 1; X z[2] = 3; X break; X case 2: X z[0] = 4; X z[1] = 2; X z[2] = 6; X break; X case 3: X z[0] = 2; X z[1] = 3; X z[2] = 6; X break; X case 4: X z[0] = 8; X z[1] = 4; X z[2] = 2; X break; X case 6: X z[0] = 2; X z[1] = 6; X z[2] = 8; X break; X case 7: X z[0] = 8; X z[1] = 7; X z[2] = 4; X break; X case 8: X z[0] = 4; X z[1] = 8; X z[2] = 6; X break; X case 9: X z[0] = 8; X z[1] = 9; X z[2] = 6; X break; X } X for (i = 0; i < 3; i++) X { X row = y; X col = x; X if (move(z[i], &row, &col)) X { X c_ptr = &cave[row][col]; X /* Empty doorways */ X if (c_ptr->fval == 5) X { X find_flag = FALSE; /* no need to call move_light () */ X return; X } X /* Objects player can see*/ X /* Including doors */ X if (find_flag) X if (player_light) X { X if (c_ptr->tptr != 0) X if ((t_list[c_ptr->tptr].tval != 101) && X (t_list[c_ptr->tptr].tval != 109)) X { X find_flag = FALSE; /* no need to call move_light */ X return; X } X } X else if ((c_ptr->tl) || (c_ptr->pl) || (c_ptr->fm)) X if (c_ptr->tptr != 0) X if ((t_list[c_ptr->tptr].tval != 101) && X (t_list[c_ptr->tptr].tval != 109)) X { X find_flag = FALSE; /* no need to call move_light */ X return; X } X /* Creatures */ X if (find_flag) X if ((c_ptr->tl) || (c_ptr->pl) || (player_light)) X if (c_ptr->cptr > 1) X { X m_ptr = &m_list[c_ptr->cptr]; X if (m_ptr->ml) X { X find_flag = FALSE; /* no need to call move_light */ X return; X } X } X } X } X } X return; X} X X X/* Picks new direction when in find mode -RAK- */ Xint pick_dir(dir) Xint dir; X{ X int z[2]; X register int i, pick; X int y, x; X X if ((find_flag) && (next_to4(char_row, char_col, 4, 5, -1) == 2)) X { X switch(dir) X { X case 1: X z[0] = 2; X z[1] = 4; X break; X case 2: X z[0] = 4; X z[1] = 6; X break; X case 3: X z[0] = 2; X z[1] = 6; X break; X case 4: X z[0] = 2; X z[1] = 8; X break; X case 6: X z[0] = 2; X z[1] = 8; X break; X case 7: X z[0] = 4; X z[1] = 8; X break; X case 8: X z[0] = 4; X z[1] = 6; X break; X case 9: X z[0] = 6; X z[1] = 8; X break; X } X pick = FALSE; X for (i = 0; i < 2; i++) X { X y = char_row; X x = char_col; X if (move(z[i], &y, &x)) X if (cave[y][x].fopen) X { X pick = TRUE; X global_com_val = z[i] + 48; X } X } X } X else X { X pick = FALSE; X } X return(pick); X} X X X/* AC gets worse -RAK- */ X/* Note: This routine affects magical AC bonuses so that stores */ X/* can detect the damage. */ Xint minus_ac(typ_dam) Xint typ_dam; X{ X register int i, j; X int tmp[6]; X int minus; X register treasure_type *i_ptr; X vtype out_val, tmp_str; X X i = 0; X if (inventory[INVEN_BODY].tval != 0) X { X tmp[i] = INVEN_BODY; X i++; X } X if (inventory[INVEN_ARM].tval != 0) X { X tmp[i] = INVEN_ARM; X i++; X } X if (inventory[INVEN_OUTER].tval != 0) X { X tmp[i] = INVEN_OUTER; X i++; X } X if (inventory[INVEN_HANDS].tval != 0) X { X tmp[i] = INVEN_HANDS; X i++; X } X if (inventory[INVEN_HEAD].tval != 0) X { X tmp[i] = INVEN_HEAD; X i++; X } X /* also affect boots */ X if (inventory[INVEN_FEET].tval != 0) X { X tmp[i] = INVEN_FEET; X i++; X } X minus = FALSE; X if (i > 0) X { X j = tmp[randint(i) - 1]; X i_ptr = &inventory[j]; X if (i_ptr->flags & typ_dam) X { X objdes(tmp_str, j, FALSE); X (void) sprintf(out_val, "Your %s resists damage!", tmp_str); X msg_print(out_val); X minus = TRUE; X } X else if ((i_ptr->ac+i_ptr->toac) > 0) X { X objdes(tmp_str, j, FALSE); X (void) sprintf(out_val, "Your %s is damaged!", tmp_str); X msg_print(out_val); X i_ptr->toac--; X py_bonuses(blank_treasure, 0); X minus = TRUE; X } X } X return(minus); X} X X X/* Corrode the unsuspecting person's armor -RAK- */ Xcorrode_gas(kb_str) Xchar *kb_str; X{ X int set_corrodes(); X X if (!minus_ac((int)0x00100000)) X take_hit(randint(8), kb_str); X print_stat |= 0x0040; X if (inven_damage(set_corrodes, 5) > 0) X msg_print("There is an acrid smell coming from your pack."); X} X X X/* Poison gas the idiot... -RAK- */ Xpoison_gas(dam, kb_str) Xint dam; Xchar *kb_str; X{ X take_hit(dam, kb_str); X print_stat |= 0x0040; X py.flags.poisoned += 12 + randint(dam); X} X X X/* Burn the fool up... -RAK- */ Xfire_dam(dam, kb_str) Xint dam; Xchar *kb_str; X{ X int set_flammable(); X X if (py.flags.fire_resist) X dam = dam / 3; X if (py.flags.resist_heat > 0) X dam = dam / 3; X take_hit(dam, kb_str); X print_stat |= 0x0080; X if (inven_damage(set_flammable, 3) > 0) X msg_print("There is smoke coming from your pack!"); X} X X X/* Freeze him to death... -RAK- */ Xcold_dam(dam, kb_str) Xint dam; Xchar *kb_str; X{ X int set_frost_destroy(); X X if (py.flags.cold_resist) X dam = dam / 3; X if (py.flags.resist_cold > 0) X dam = dam / 3; X take_hit(dam, kb_str); X print_stat |= 0x0080; X if (inven_damage(set_frost_destroy, 5) > 0) X msg_print("Something shatters inside your pack!"); X} X X X/* Lightning bolt the sucker away... -RAK- */ Xlight_dam(dam, kb_str) Xint dam; Xchar *kb_str; X{ X if (py.flags.lght_resist) X take_hit((dam / 3), kb_str); X else X take_hit(dam, kb_str); X print_stat |= 0x0080; X} X X X/* Throw acid on the hapless victim -RAK- */ Xacid_dam(dam, kb_str) Xint dam; Xchar *kb_str; X{ X int flag; X int set_acid_affect(); X X flag = 0; X if (minus_ac((int)0x00100000)) X flag = 1; X if (py.flags.acid_resist) X flag += 2; X switch(flag) X { X case 0: take_hit(dam, kb_str); break; X case 1: take_hit((dam / 2), kb_str); break; X case 2: take_hit((dam / 3), kb_str); break; X case 3: take_hit((dam / 4), kb_str); break; X } X print_stat |= 0x00C0; X if (inven_damage(set_acid_affect, 3) > 0) X msg_print("There is an acrid smell coming from your pack!"); X} END_OF_FILE if test 47241 -ne `wc -c <'moria1.c'`; then echo shar: \"'moria1.c'\" unpacked with wrong size! fi # end of 'moria1.c' fi if test -f 'signals.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'signals.c'\" else echo shar: Extracting \"'signals.c'\" \(5400 characters\) sed "s/^X//" >'signals.c' <<'END_OF_FILE' X#include <curses.h> X#include <signal.h> X X#include "constants.h" X#include "config.h" X#include "types.h" X#include "externs.h" X X#ifdef USG X#include <string.h> X#else X#include <strings.h> X#endif X Xextern int total_winner; Xextern int moria_flag; Xextern int search_flag; X X#ifdef USG X/* no local special characters */ X#else Xextern struct ltchars save_special_chars; X#endif X Xint error_sig, error_code; X X/* This signal package was brought to you by -JEW- */ X X/* on some systems, signal and suspend_handler must be declared as 'void' X instead of 'int', this varies even among different OS releases, so there X is no good way to solve the problem with ifdefs */ Xint (*signal())(); Xint signal_save_core(); Xint signal_save_no_core(); Xint signal_ask_quit(); X X#ifdef USG X/* no suspend signal */ X#else Xint (*suspend_handler)(); X#endif X X/* only allow one signal handler to execute, otherwise can get multiple save X files by sending multiple signals */ Xstatic int caught_signal = 0; X Xinit_signals() X{ X (void) signal(SIGHUP, signal_save_no_core); X (void) signal(SIGINT, signal_ask_quit); X (void) signal(SIGQUIT, signal_save_core); X (void) signal(SIGILL, signal_save_core); X (void) signal(SIGTRAP, signal_save_core); X (void) signal(SIGIOT, signal_save_core); X (void) signal(SIGEMT, signal_save_core); X (void) signal(SIGFPE, signal_save_core); X (void) signal(SIGKILL, signal_save_core); X (void) signal(SIGBUS, signal_save_core); X (void) signal(SIGSEGV, signal_save_core); X (void) signal(SIGSYS, signal_save_core); X (void) signal(SIGTERM, signal_save_core); X} X X/*ARGSUSED*/ X#ifdef USG Xsignal_save_core(sig) Xint sig; X{ X if (caught_signal) X return; X caught_signal = 1; X panic_save = 1; X X error_sig = sig; X error_code = 0; X if (!character_saved) X { X prt("OH NO!!!!!!!!!! Attempting panic save.", 23, 0); X save_char(FALSE, FALSE); X } X (void) signal(SIGQUIT, SIG_DFL); X /* restore terminal settings */ X#ifndef BUGGY_CURSES X nl(); X#endif X#if defined(ultrix) X nocrmode(); X#else X nocbreak(); X#endif X echo(); X resetterm(); X /* restore the saved values of the local special chars */ X /* no local special characters */ X /* allow QUIT signal */ X /* nothing needs to be done here */ X (void) kill(getpid(), 3); X exit_game(); X} X#else Xsignal_save_core(sig, code, scp) Xint sig, code; Xstruct sigcontext *scp; X{ X if (caught_signal) X return; X caught_signal = 1; X panic_save = 1; X X error_sig = sig; X error_code = code; X if (!character_saved) X { X prt("OH NO!!!!!!!!!! Attempting panic save.", 23, 0); X save_char(FALSE, FALSE); X } X (void) signal(SIGQUIT, SIG_DFL); X /* restore terminal settings */ X#ifndef BUGGY_CURSES X nl(); X#endif X#if defined(ultrix) X nocrmode(); X#else X nocbreak(); X#endif X echo(); X /* restore the saved values of the local special chars */ X (void) ioctl(0, TIOCSLTC, (char *)&save_special_chars); X /* allow QUIT signal */ X (void) sigsetmask(0); X (void) kill(getpid(), 3); X exit_game(); X} X#endif X X/*ARGSUSED*/ X#ifdef USG Xsignal_save_no_core(sig) Xint sig; X{ X if (caught_signal) X return; X caught_signal = 1; X panic_save = 1; X X error_sig = sig; X error_code = 0; X if (!character_saved) X save_char(FALSE, TRUE); X exit_game(); X} X#else Xsignal_save_no_core(sig, code, scp) Xint sig, code; Xstruct sigcontext *scp; X{ X if (caught_signal) X return; X caught_signal = 1; X panic_save = 1; X X error_sig = sig; X error_code = code; X if (!character_saved) X save_char(FALSE, TRUE); X exit_game(); X} X#endif X X/*ARGSUSED*/ X#ifdef USG Xsignal_ask_quit(sig) Xint sig; X{ X char command; X X /* reset signal handler */ X (void) signal(sig, signal_ask_quit); X find_flag = FALSE; X if (search_flag) X search_off(); X if (py.flags.rest > 0) X { X rest_off(); X return; X } X if (get_com("Do you really want to quit?", &command)) X switch(command) X { X case 'y': case 'Y': X if (character_generated) X { X (void) strcpy(died_from, "Quitting."); X upon_death(); X } X else X exit_game(); X break; X } X erase_line(MSG_LINE, 0); X /* in case control-c typed during msg_print */ X if (wait_for_more) X { X put_buffer(" -more-", MSG_LINE, 0); X put_qio(); X } X} X#else Xsignal_ask_quit(sig, code, scp) Xint sig, code; Xstruct sigcontext *scp; X{ X char command; X X /* no need to reset signal handler */ X find_flag = FALSE; X if (search_flag) X search_off(); X if (py.flags.rest > 0) X { X rest_off(); X return; X } X if (get_com("Do you really want to quit?", &command)) X switch(command) X { X case 'y': case 'Y': X if (character_generated) X { X (void) strcpy(died_from, "Quitting."); X upon_death(); X } X else X exit_game(); X break; X } X erase_line(MSG_LINE, 0); X /* in case control-c typed during msg_print */ X if (wait_for_more) X { X put_buffer(" -more-", MSG_LINE, 0); X put_qio(); X } X} X#endif X Xno_controlz() X{ X#ifdef USG X /* no suspend signal */ X#else X suspend_handler = signal(SIGTSTP, SIG_IGN); X#endif X} X Xcontrolz() X{ X#ifdef USG X /* no suspend signal */ X#else X (void) signal(SIGTSTP, suspend_handler); X#endif X} X Xignore_signals() X{ X (void) signal(SIGINT, SIG_IGN); X (void) signal(SIGQUIT, SIG_IGN); X} X Xdefault_signals() X{ X (void) signal(SIGINT, SIG_DFL); X (void) signal(SIGQUIT, SIG_DFL); X} X Xrestore_signals() X{ X (void) signal(SIGINT, signal_ask_quit); X (void) signal(SIGQUIT, signal_save_core); X} END_OF_FILE if test 5400 -ne `wc -c <'signals.c'`; then echo shar: \"'signals.c'\" unpacked with wrong size! fi # end of 'signals.c' fi echo shar: End of archive 5 \(of 18\). cp /dev/null ark5isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 18 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0