games-request@tekred.TEK.COM (11/05/87)
Submitted by: "James E. Wilson" <wilson@ji.berkeley.edu>
Comp.sources.games: Volume 2, Issue 70
Archive-name: umoria/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 16)."
# Contents: desc.c moria1.c
# Wrapped by billr@tekred on Wed Nov 4 09:59:45 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f desc.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"desc.c\"
else
echo shar: Extracting \"desc.c\" \(7825 characters\)
sed "s/^X//" >desc.c <<'END_OF_desc.c'
X#include <stdio.h>
X#ifdef USG
X#include <string.h>
X#else
X#include <strings.h>
X#endif
X
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
X
X#ifdef sun /* correct SUN stupidity in the stdio.h file */
Xchar *sprintf();
X#endif
X
X/* Object descriptor routines */
X
Xint is_a_vowel(ch)
Xchar ch;
X{
X switch(ch)
X {
X case 'a': case 'e': case 'i': case 'o': case 'u':
X case 'A': case 'E': case 'I': case 'O': case 'U':
X return(TRUE);
X break;
X default:
X return(FALSE);
X break;
X }
X return(FALSE);
X}
X
X
X/* Randomize colors, woods, and metals */
Xrandes()
X{
X int i, j;
X vtype tmp;
X
X for (i = 0; i < MAX_COLORS; i++)
X {
X j = randint(MAX_COLORS) - 1;
X (void) strcpy(tmp, colors[i]);
X (void) strcpy(colors[i], colors[j]);
X (void) strcpy(colors[j], tmp);
X }
X for (i = 0; i < MAX_WOODS; i++)
X {
X j = randint(MAX_WOODS) - 1;
X (void) strcpy(tmp, woods[i]);
X (void) strcpy(woods[i], woods[j]);
X (void) strcpy(woods[j], tmp);
X }
X for (i = 0; i < MAX_METALS; i++)
X {
X j = randint(MAX_METALS) - 1;
X (void) strcpy(tmp, metals[i]);
X (void) strcpy(metals[i], metals[j]);
X (void) strcpy(metals[j], tmp);
X }
X for (i = 0; i < MAX_ROCKS; i++)
X {
X j = randint(MAX_ROCKS) - 1;
X (void) strcpy(tmp, rocks[i]);
X (void) strcpy(rocks[i], rocks[j]);
X (void) strcpy(rocks[j], tmp);
X }
X for (i = 0; i < MAX_AMULETS; i++)
X {
X j = randint(MAX_AMULETS) - 1;
X (void) strcpy(tmp, amulets[i]);
X (void) strcpy(amulets[i], amulets[j]);
X (void) strcpy(amulets[j], tmp);
X }
X for (i = 0; i < MAX_MUSH; i++)
X {
X j = randint(MAX_MUSH) - 1;
X (void) strcpy(tmp, mushrooms[i]);
X (void) strcpy(mushrooms[i], mushrooms[j]);
X (void) strcpy(mushrooms[j], tmp);
X }
X}
X
X
X/* Return random title */
Xrantitle(title)
Xchar *title;
X{
X int i, j, k;
X
X k = randint(2) + 1;
X (void) strcpy(title, "Titled \"");
X for (i = 0; i < k; i++)
X {
X for (j = 0; j < randint(2); j++)
X (void) strcat(title, syllables[randint(MAX_SYLLABLES) - 1]);
X if (i < k-1)
X (void) strcat(title, " ");
X }
X (void) strcat(title, "\"");
X}
X
X
X/* Initialize all Potions, wands, staves, scrolls, ect... */
Xmagic_init()
X{
X int i, tmpv;
X vtype tmps;
X
X set_seed(randes_state, randes_seed);
X randes();
X for (i = 0; i < MAX_OBJECTS; i++)
X {
X tmpv = (0xFF & object_list[i].subval);
X switch(object_list[i].tval)
X {
X case 75: case 76:
X if (tmpv < MAX_COLORS)
X insert_str(object_list[i].name, "%C", colors[tmpv]);
X break;
X case 70: case 71:
X rantitle(tmps);
X insert_str(object_list[i].name, "%T", tmps);
X break;
X case 45:
X if (tmpv < MAX_ROCKS)
X insert_str(object_list[i].name, "%R", rocks[tmpv]);
X break;
X case 40: if (tmpv < MAX_AMULETS)
X insert_str(object_list[i].name, "%A", amulets[tmpv]);
X break;
X case 65:
X if (tmpv < MAX_METALS)
X insert_str(object_list[i].name, "%M", metals[tmpv]);
X break;
X case 55:
X if (tmpv < MAX_WOODS)
X insert_str(object_list[i].name, "%W", woods[tmpv]);
X break;
X case 80:
X if (tmpv < MAX_MUSH)
X insert_str(object_list[i].name, "%M", mushrooms[tmpv]);
X break;
X case 60:
X /*if (tmpv < MAX_RODS)
X insert_str(object_list[i].name, "%D", rods[tmpv])*/;
X break;
X default:
X break;
X }
X }
X reset_seed();
X}
X
X
X/* Remove "Secret" symbol for identity of object */
Xknown1(object_str)
Xchar *object_str;
X{
X int pos;
X vtype str1, str2;
X char *string;
X
X string = index(object_str, '|');
X if (string)
X pos = strlen(object_str) - strlen(string);
X else
X pos = -1;
X if (pos >= 0)
X {
X (void) strncpy(str1, object_str, pos);
X str1[pos] = '\0';
X (void) strcpy(str2, &object_str[pos+1]);
X (void) strcpy(object_str, strcat(str1, str2));
X }
X}
X
X
X/* Remove "Secret" symbol for identity of plusses */
Xknown2(object_str)
Xchar *object_str;
X{
X int pos;
X vtype str1, str2;
X char *string;
X
X string = index(object_str, '^');
X if (string)
X pos = strlen(object_str) - strlen(string);
X else
X pos = -1;
X if (pos >= 0)
X {
X (void) strncpy(str1, object_str, pos);
X str1[pos] = '\0';
X (void) strcpy(str2, &object_str[pos+1]);
X (void) strcpy(object_str, strcat(str1, str2));
X }
X}
X
X
X/* Return string without quoted portion */
Xunquote(object_str)
Xchar *object_str;
X{
X int pos0, pos1, pos2;
X vtype str1, str2;
X char *string;
X
X string = index(object_str, '\"');
X if (string)
X pos0 = strlen(string) - strlen(object_str);
X else
X pos0 = -1;
X if (pos0 >= 0)
X {
X string = index(object_str, '~');
X if (string)
X pos1 = strlen(string) - strlen(object_str);
X else
X pos1 = 0;
X string = index(object_str, '|');
X if (string)
X pos2 = strlen(string) - strlen(object_str);
X else
X pos2 = 0;
X (void) strncpy(str1, object_str, pos1);
X str1[pos1] = '\0';
X (void) strcpy(str2, &object_str[pos2+1]);
X (void) strcpy(object_str, strcat(str1, str2));
X }
X}
X
X
X/* Somethings been identified */
Xidentify(item)
Xtreasure_type item;
X{
X int i, x1, x2;
X treasure_type *t_ptr;
X char *string;
X
X x1 = item.tval;
X x2 = item.subval;
X if (index(item.name, '|') != 0)
X {
X for (i = 0; i < MAX_TALLOC; i++)
X {
X t_ptr = &t_list[i];
X if ((t_ptr->tval == x1) && (t_ptr->subval == x2))
X {
X unquote(t_ptr->name);
X known1(t_ptr->name);
X }
X }
X for (i = 0; i <= INVEN_MAX; i++)
X {
X t_ptr = &inventory[i];
X if ((t_ptr->tval == x1) && (t_ptr->subval == x2))
X {
X unquote(t_ptr->name);
X known1(t_ptr->name);
X }
X }
X i = 0;
X do
X {
X t_ptr = &object_list[i];
X if ((t_ptr->tval == x1) && (t_ptr->subval == x2))
X if ((string = index(t_ptr->name, '%')) && (string[0] == 'T'))
X {
X insert_str(t_ptr->name, " %T|", "");
X object_ident[i] = TRUE;
X }
X else
X {
X unquote(t_ptr->name);
X known1(t_ptr->name);
X object_ident[i] = TRUE;
X }
X i++;
X }
X while (i != MAX_OBJECTS);
X }
X}
X
X
X/* Returns a description of item for inventory */
Xobjdes(out_val, ptr, pref)
Xchar *out_val;
Xint ptr;
Xint pref;
X{
X int pos;
X vtype tmp_val;
X treasure_type *i_ptr;
X char *string;
X
X i_ptr = &inventory[ptr];
X (void) strcpy(tmp_val, i_ptr->name);
X string = index(tmp_val, '|');
X if (string)
X pos = strlen(tmp_val) - strlen(string);
X else
X pos = -1;
X if (pos >= 0)
X {
X tmp_val[pos] = '\0';
X }
X string = index(tmp_val, '^');
X if (string)
X pos = strlen(tmp_val) - strlen(string);
X else
X pos = -1;
X if (pos >= 0)
X {
X tmp_val[pos] = '\0';
X }
X if (!pref)
X {
X string = index(tmp_val, '(');
X if (string)
X pos = strlen(tmp_val) - strlen(string);
X else
X pos = -1;
X if (pos >= 0)
X {
X tmp_val[pos] = '\0';
X }
X }
X insert_num(tmp_val, "%P1", i_ptr->p1, TRUE);
X insert_num(tmp_val, "%P2", i_ptr->tohit, TRUE);
X insert_num(tmp_val, "%P3", i_ptr->todam, TRUE);
X insert_num(tmp_val, "%P4", i_ptr->toac, TRUE);
X insert_num(tmp_val, "%P5", i_ptr->p1, FALSE);
X insert_num(tmp_val, "%P6", i_ptr->ac, FALSE);
X if (i_ptr->number != 1)
X {
X insert_str(tmp_val, "ch~", "ches");
X insert_str(tmp_val, "~", "s");
X }
X else
X insert_str(tmp_val, "~", "");
X if (pref)
X {
X if (index(tmp_val, '&') != 0)
X {
X insert_str(tmp_val, "&", "");
X if (i_ptr->number > 1)
X (void) sprintf(out_val, "%d%s", (int)i_ptr->number, tmp_val);
X else if (i_ptr->number < 1)
X (void) sprintf(out_val, "%s%s", "no more", tmp_val);
X else if (is_a_vowel(tmp_val[1]))
X (void) sprintf(out_val, "an%s", tmp_val);
X else
X (void) sprintf(out_val, "a%s", tmp_val);
X }
X else
X (void) strcpy(out_val, tmp_val);
X (void) strcat(out_val, ".");
X }
X else
X {
X insert_str(tmp_val, "& ", "");
X (void) strcpy(out_val, tmp_val);
X }
X}
END_OF_desc.c
if test 7825 -ne `wc -c <desc.c`; then
echo shar: \"desc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f moria1.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"moria1.c\"
else
echo shar: Extracting \"moria1.c\" \(44858 characters\)
sed "s/^X//" >moria1.c <<'END_OF_moria1.c'
X#include <stdio.h>
X#ifdef USG
X#include <string.h>
X#else
X#include <strings.h>
X#endif
X
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
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)
Xbyteint *stat;
Xint amount, factor;
X{
X int i, j, k;
X
X j = amount * factor;
X k = abs(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)
Xint num;
X{
X 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 unsigned int item_flags;
X int i, old_dis_ac;
X struct flags *p_ptr;
X struct misc *m_ptr;
X treasure_type *i_ptr;
X
X p_ptr = &py.flags;
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 py.misc.srh += (tobj.p1 * factor);
X py.misc.fos -= (tobj.p1 * factor);
X }
X if (0x00000100 & tobj.flags)
X py.misc.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 py.flags.blind += 1000;
X if (0x10000000 & tobj.flags)
X if (factor > 0)
X py.flags.afraid += 50;
X if (0x40000000 & tobj.flags)
X py.flags.see_infra += (tobj.p1 * factor);
X m_ptr = &py.misc;
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 p_ptr = &py.flags;
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 py.flags.slow_digest = TRUE;
X if (0x00000200 & item_flags)
X py.flags.aggravate = TRUE;
X if (0x00000400 & item_flags)
X py.flags.teleport = TRUE;
X if (0x00000800 & item_flags)
X py.flags.regenerate = TRUE;
X if (0x00080000 & item_flags)
X py.flags.fire_resist = TRUE;
X if (0x00100000 & item_flags)
X py.flags.acid_resist = TRUE;
X if (0x00200000 & item_flags)
X py.flags.cold_resist = TRUE;
X if (0x00800000 & item_flags)
X py.flags.free_act = TRUE;
X if (0x01000000 & item_flags)
X py.flags.see_inv = TRUE;
X if (0x02000000 & item_flags)
X py.flags.lght_resist = TRUE;
X if (0x04000000 & item_flags)
X py.flags.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: py.flags.sustain_str = TRUE; break;
X case 2: py.flags.sustain_int = TRUE; break;
X case 3: py.flags.sustain_wis = TRUE; break;
X case 4: py.flags.sustain_con = TRUE; break;
X case 5: py.flags.sustain_dex = TRUE; break;
X case 6: py.flags.sustain_chr = TRUE; break;
X default: break;
X }
X }
X
X p_ptr = &py.flags;
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 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 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 */
Xint scr_state;
X
X/* Displays inventory items from r1 to r2 -RAK- */
Xshow_inven(r1, r2)
Xint r1, r2;
X{
X 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)
Xint r1;
X{
X int i, j;
X vtype prt1, prt2, out_val;
X treasure_type *i_ptr;
X
X if (r1 >= equip_ctr) /* Last item gone */
X prt("", equip_ctr+2, 0);
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 int i, j, typ;
X vtype out_val, prt1, prt2;
X int flag;
X 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 int i, j, com_val;
X int exit_flag, test_flag;
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 exit_flag = TRUE;
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 int com_val, i, j, k, tmp;
X vtype out_val, prt1, prt2;
X treasure_type unwear_obj;
X int exit_flag, test_flag;
X char command;
X 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[28].tval == 0) /* Rings */
X i = 28;
X else
X i = 29;
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 unwear_obj = inventory[i];
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 py_bonuses(inventory[i], 1);
X if (unwear_obj.tval != 0)
X {
X inventory[INVEN_MAX] = unwear_obj;
X tmp = remove(INVEN_MAX);
X if (tmp < com_val)
X com_val = tmp;
X }
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[22].flags)
X {
X objdes(prt1, 22, 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[33];
X inventory[33] = inventory[22];
X inventory[22] = tmp_obj;
X py_bonuses(inventory[33], -1); /* Subtract bonuses */
X py_bonuses(inventory[22], 1); /* Add bonuses */
X if (inventory[22].tval != 0)
X {
X (void) strcpy(prt1, "Primary weapon : ");
X objdes(prt2, 22, TRUE);
X msg_print(strcat(prt1, prt2));
X }
X if (inventory[33].tval != 0)
X {
X (void) strcpy(prt1, "Secondary weapon : ");
X objdes(prt2, 33, TRUE);
X msg_print(strcat(prt1, prt2));
X }
X }
X if (scr_state != 0)
X {
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 int com_val;
X int exit_flag, test_flag;
X int inven;
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[22].tval != 0)
X switch_weapon();
X else if (inventory[33].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);
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 int test_flag;
X int 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, msg_line);
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 int prow, pcol;
X 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 }
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 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 int light;
X 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)
Xint *comval;
X{
X switch(*comval)
X {
X case 'h':
X *comval = '4';
X return(4);
X break;
X case 'y':
X *comval = '7';
X return(7);
X break;
X case 'k':
X *comval = '8';
X return(8);
X break;
X case 'u':
X *comval = '9';
X return(9);
X break;
X case 'l':
X *comval = '6';
X return(6);
X break;
X case 'n':
X *comval = '3';
X return(3);
X break;
X case 'j':
X *comval = '2';
X return(2);
X break;
X case 'b':
X *comval = '1';
X return(1);
X break;
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
X/* Moves creature record from one space to another -RAK- */
Xmove_rec(y1, x1, y2, x2)
Xint 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 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 int tmp1, tmp2;
X int start_row, start_col;
X int end_row, end_col;
X int i, j;
X int ypos, xpos;
X vtype floor_str, tmp_str;
X cave_type *c_ptr;
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)
Xint y, x;
X{
X vtype spot_char;
X char temp[2];
X
X temp[1] = '\0';
X if (panel_contains(y, x))
X {
X loc_symbol(y, x, temp);
X (void) strcpy(spot_char, temp);
X print(spot_char, y, x);
X }
X}
X
X
X/* Blanks out given location -RAK- */
Xunlite_spot(y, x)
Xint 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)
Xint x, y, z;
X{
X 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)
Xint x, y, z;
X{
X 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 int i, j, 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 cave_type *c_ptr;
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)
Xint y1, x1, y2, x2;
X{
X 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 int i, j, xpos;
X vtype floor_str, save_str;
X char tmp_char[2];
X int flag;
X 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)
Xint y1, x1, y2, x2;
X{
X 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)
Xint y1, x1, y2, x2;
X{
X 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)
Xint *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_char(5);
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 erase_line(msg_line, msg_line);
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 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 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 int rate;
X
X if (speed > 0)
X if (py.flags.rest > 0)
X rate = 1;
X else
X rate = speed;
X else
X {
X if ((turn % (abs(speed) + 2)) == 0)
X rate = 1;
X else
X rate = 0;
X }
X return(rate);
X}
X
X
X/* Regenerate hit points -RAK- */
Xregenhp(percent)
Xdouble percent;
X{
X 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 struct misc *p_ptr;
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)
Xint y, x;
X{
X int k;
X 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 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 int i, j;
X struct flags *p_ptr;
X cave_type *c_ptr;
X treasure_type *t_ptr;
X vtype tmp_str;
X
X p_ptr = &py.flags;
X if (p_ptr->confused+p_ptr->blind > 0)
X chance /= 10.0;
X else if (no_light())
X 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 find_flag = FALSE;
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 find_flag = FALSE;
X }
X /* Chest is trapped? */
X else if (t_ptr->tval == 2)
X {
X if (t_ptr->flags > 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 empty.");
X known2(t_ptr->name);
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 int i, row, col;
X 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 find_flag = FALSE;
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 find_flag = FALSE;
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 find_flag = FALSE;
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 find_flag = FALSE;
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 find_flag = FALSE;
X }
X }
X }
X }
X}
X
X
X/* Picks new direction when in find mode -RAK- */
Xint pick_dir(dir)
Xint dir;
X{
X int z[2];
X int i, y, x;
X int pick;
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 int i, j;
X int tmp[5];
X int minus;
X treasure_type *i_ptr;
X vtype out_val, tmp_str;
X
X i = 0;
X if (inventory[25].tval != 0)
X {
X tmp[i] = 25;
X i++;
X }
X if (inventory[26].tval != 0)
X {
X tmp[i] = 26;
X i++;
X }
X if (inventory[31].tval != 0)
X {
X tmp[i] = 31;
X i++;
X }
X if (inventory[27].tval != 0)
X {
X tmp[i] = 27;
X i++;
X }
X if (inventory[23].tval != 0)
X {
X tmp[i] = 23;
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 /= 3;
X if (py.flags.resist_heat > 0)
X 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 /= 3;
X if (py.flags.resist_cold > 0)
X 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_moria1.c
if test 44858 -ne `wc -c <moria1.c`; then
echo shar: \"moria1.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 5 \(of 16\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 16 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