home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!zephyr.ens.tek.com!tekred!saab!billr
- From: billr@saab.CNA.TEK.COM (Bill Randle)
- Newsgroups: comp.sources.games
- Subject: v09i080: umoria3 - single player dungeon simulation (ver. 5.2), Part25/31
- Message-ID: <5615@tekred.CNA.TEK.COM>
- Date: 17 May 90 16:28:20 GMT
- Sender: news@tekred.CNA.TEK.COM
- Lines: 2466
- Approved: billr@saab.CNA.TEK.COM
-
- Submitted-by: wilson@ernie.Berkeley.EDU (Jim Wilson)
- Posting-number: Volume 9, Issue 80
- Archive-name: umoria3/Part25
- Supersedes: umoria2: Volume 5, Issue 32-37,41-52,87
-
-
-
- #! /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 25 (of 31)."
- # Contents: mac/macio.c source/create.c source/help.c source/store1.c
- # util/mc/symtab.c
- # Wrapped by billr@saab on Wed May 16 11:54:42 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'mac/macio.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'mac/macio.c'\"
- else
- echo shar: Extracting \"'mac/macio.c'\" \(12472 characters\)
- sed "s/^X//" >'mac/macio.c' <<'END_OF_FILE'
- X/* macio.c: terminal I/O code for the macintosh
- X
- X Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
- X
- X This software may be copied and distributed for educational, research, and
- X not for profit purposes provided that this copyright and statement are
- X included in all such copies. */
- X
- X#include <scrnmgr.h>
- X
- X#include <ctype.h>
- X
- X#include "constant.h"
- X#include "config.h"
- X#include "types.h"
- X#include "externs.h"
- X
- X#include <string.h>
- X
- Xvoid exit();
- Xunsigned sleep();
- X
- X/* Attributes of normal and hilighted characters */
- X#define ATTR_NORMAL attrNormal
- X#define ATTR_HILITED attrReversed
- X
- X/* initializes curses routines */
- Xvoid init_curses()
- X{
- X /* Primary initialization is done in mac.c since game is restartable */
- X /* Only need to clear the screen here */
- X Rect scrn;
- X
- X scrn.left = scrn.top = 0;
- X scrn.right = SCRN_COLS;
- X scrn.bottom = SCRN_ROWS;
- X EraseScreen(&scrn);
- X UpdateScreen();
- X}
- X
- X/* Set up the terminal into a suitable state for moria. -CJS- */
- Xvoid moriaterm()
- X/* Nothing to do on Mac */
- X{
- X}
- X
- X/* Dump IO to buffer -RAK- */
- Xvoid put_buffer(out_str, row, col)
- Xchar *out_str;
- Xint row, col;
- X{
- X /* The screen manager handles writes past the edge ok */
- X DSetScreenCursor(col, row);
- X DWriteScreenStringAttr(out_str, ATTR_NORMAL);
- X}
- X
- X/* Dump the IO buffer to terminal -RAK- */
- Xvoid put_qio()
- X{
- X screen_change = TRUE; /* Let inven_command know something has changed. */
- X UpdateScreen();
- X}
- X
- X/* Put the terminal in the original mode. -CJS- */
- Xvoid restore_term()
- X/* Nothing to do on Mac */
- X{
- X}
- X
- Xvoid shell_out()
- X{
- X alert_error("This command is not implemented on the Macintosh.");
- X}
- X
- X/* Returns a single character input from the terminal. This silently -CJS-
- X consumes ^R to redraw the screen and reset the terminal, so that this
- X operation can always be performed at any input prompt. inkey() never
- X returns ^R. */
- Xchar inkey()
- X/* The Mac does not need ^R, so it just consumes it */
- X/* This routine does nothing special with direction keys */
- X/* Just returns their keypad ascii value (e.g. '0'-'9') */
- X/* Compare with inkeydir() below */
- X{
- X char ch;
- X int dir;
- X int shift_flag, ctrl_flag;
- X
- X put_qio();
- X command_count = 0;
- X
- X do {
- X macgetkey(&ch, FALSE);
- X } while (ch == CTRL('R'));
- X
- X dir = extractdir(ch, &shift_flag, &ctrl_flag);
- X if (dir != -1)
- X ch = '0' + dir;
- X
- X return(ch);
- X}
- X
- Xchar inkeydir()
- X/* The Mac does not need ^R, so it just consumes it */
- X/* This routine translates the direction keys in rogue-like mode */
- X{
- X char ch;
- X int dir;
- X int shift_flag, ctrl_flag;
- X static char tab[9] = {
- X 'b', 'j', 'n',
- X 'h', '.', 'l',
- X 'y', 'k', 'u'
- X };
- X static char shifttab[9] = {
- X 'B', 'J', 'N',
- X 'H', '.', 'L',
- X 'Y', 'K', 'U'
- X };
- X static char ctrltab[9] = {
- X CTRL('B'), CTRL('J'), CTRL('N'),
- X CTRL('H'), '.', CTRL('L'),
- X CTRL('Y'), CTRL('K'), CTRL('U')
- X };
- X
- X put_qio();
- X command_count = 0;
- X
- X do {
- X macgetkey(&ch, FALSE);
- X } while (ch == CTRL('R'));
- X
- X dir = extractdir(ch, &shift_flag, &ctrl_flag);
- X
- X if (dir != -1) {
- X if (!rogue_like_commands) {
- X ch = '0' + dir;
- X }
- X else {
- X if (ctrl_flag)
- X ch = ctrltab[dir - 1];
- X else if (shift_flag)
- X ch = shifttab[dir - 1];
- X else
- X ch = tab[dir - 1];
- X }
- X }
- X
- X return(ch);
- X}
- X
- X/* Flush the buffer -RAK- */
- Xvoid flush()
- X{
- X/* Removed put_qio() call. Reduces flashing. Doesn't seem to hurt. */
- X FlushScreenKeys();
- X}
- X
- X/* Clears given line of text -RAK- */
- Xvoid erase_line(row, col)
- Xint row;
- Xint col;
- X{
- X Rect line;
- X
- X if (row == MSG_LINE && msg_flag)
- X msg_print(NULL);
- X
- X line.left = col;
- X line.top = row;
- X line.right = SCRN_COLS;
- X line.bottom = row + 1;
- X DEraseScreen(&line);
- X}
- X
- X/* Clears screen */
- Xvoid clear_screen()
- X{
- X Rect area;
- X
- X if (msg_flag)
- X msg_print(NULL);
- X
- X area.left = area.top = 0;
- X area.right = SCRN_COLS;
- X area.bottom = SCRN_ROWS;
- X DEraseScreen(&area);
- X}
- X
- Xvoid clear_from (row)
- Xint row;
- X{
- X Rect area;
- X
- X area.left = 0;
- X area.top = row;
- X area.right = SCRN_COLS;
- X area.bottom = SCRN_ROWS;
- X DEraseScreen(&area);
- X}
- X
- X/* Outputs a char to a given interpolated y, x position -RAK- */
- X/* sign bit of a character used to indicate standout mode. -CJS */
- Xvoid print(ch, row, col)
- Xchar ch;
- Xint row;
- Xint col;
- X{
- X char cnow, anow, cnew, anew;
- X
- X row -= panel_row_prt;/* Real co-ords convert to screen positions */
- X col -= panel_col_prt;
- X
- X if (ch & 0x80) {
- X cnew = ch & ~0x80;
- X anew = ATTR_HILITED;
- X }
- X else {
- X cnew = ch;
- X anew = ATTR_NORMAL;
- X }
- X
- X GetScreenCharAttr(&cnow, &anow, col, row); /* Check current */
- X
- X if ((cnow != ch) || (anow != anew)) /* If char is already set, ignore op */
- X DSetScreenCharAttr(cnew, anew, col, row);
- X}
- X
- X/* Moves the cursor to a given interpolated y, x position -RAK- */
- Xvoid move_cursor_relative(row, col)
- Xint row;
- Xint col;
- X{
- X row -= panel_row_prt;/* Real co-ords convert to screen positions */
- X col -= panel_col_prt;
- X
- X DSetScreenCursor(col, row);
- X}
- X
- X/* Print a message so as not to interrupt a counted command. -CJS- */
- Xvoid count_msg_print(p)
- Xchar *p;
- X{
- X int i;
- X
- X i = command_count;
- X msg_print(p);
- X command_count = i;
- X}
- X
- X/* Outputs a line to a given y, x position -RAK- */
- Xvoid prt(str_buff, row, col)
- Xchar *str_buff;
- Xint row;
- Xint col;
- X{
- X Rect line;
- X
- X if (row == MSG_LINE && msg_flag)
- X msg_print(NULL);
- X
- X line.left = col;
- X line.top = row;
- X line.right = SCRN_COLS;
- X line.bottom = row + 1;
- X DEraseScreen(&line);
- X
- X put_buffer(str_buff, row, col);
- X}
- X
- X/* move cursor to a given y, x position */
- Xvoid move_cursor(row, col)
- Xint row, col;
- X{
- X DSetScreenCursor(col, row);
- X}
- X
- X/* Outputs message to top line of screen */
- X/* These messages are kept for later reference. */
- Xvoid msg_print(str_buff)
- Xchar *str_buff;
- X{
- X register int old_len;
- X char in_char;
- X Rect line;
- X
- X if (msg_flag)
- X {
- X old_len = strlen(old_msg[last_msg]) + 1;
- X /* ensure that the complete -more- message is visible. */
- X if (old_len > 73)
- X old_len = 73;
- X put_buffer(" -more-", MSG_LINE, old_len);
- X /* let sigint handler know that we are waiting for a space */
- X wait_for_more = 1;
- X do
- X {
- X in_char = inkey();
- X }
- X while ((in_char != ' ') && (in_char != ESCAPE) && (in_char != '\n') &&
- X (in_char != '\r'));
- X wait_for_more = 0;
- X }
- X line.left = 0;
- X line.top = MSG_LINE;
- X line.right = SCRN_COLS;
- X line.bottom = MSG_LINE+1;
- X DEraseScreen(&line);
- X
- X /* Make the null string a special case. -CJS- */
- X if (str_buff)
- X {
- X put_buffer(str_buff, MSG_LINE, 0);
- X command_count = 0;
- X last_msg++;
- X if (last_msg >= MAX_SAVE_MSG)
- X last_msg = 0;
- X (void) strncpy(old_msg[last_msg], str_buff, VTYPESIZ);
- X old_msg[last_msg][VTYPESIZ - 1] = '\0';
- X msg_flag = TRUE;
- X }
- X else
- X msg_flag = FALSE;
- X}
- X
- X/* Used to verify a choice - user gets the chance to abort choice. -CJS- */
- Xint get_check(prompt)
- Xchar *prompt;
- X{
- X int res;
- X int x, y;
- X
- X prt(prompt, 0, 0);
- X GetScreenCursor(&x, &y);
- X if (x > 73)
- X DSetScreenCursor(73, y);
- X DWriteScreenStringAttr(" [y/n]", ATTR_NORMAL);
- X do
- X {
- X res = inkey();
- X }
- X while(res == ' ');
- X erase_line(0, 0);
- X if (res == 'Y' || res == 'y')
- X return TRUE;
- X else
- X return FALSE;
- X}
- X
- X/* Prompts (optional) and returns ord value of input char */
- X/* Function returns false if <ESCAPE> is input */
- Xint get_com(prompt, command)
- Xchar *prompt;
- Xchar *command;
- X{
- X int res;
- X
- X if (prompt)
- X prt(prompt, 0, 0);
- X *command = inkey();
- X if (*command == 0 || *command == ESCAPE)
- X res = FALSE;
- X else
- X res = TRUE;
- X erase_line(MSG_LINE, 0);
- X return(res);
- X}
- X
- X/* Same as get_com(), but translates direction keys from keypad */
- Xint get_comdir(prompt, command)
- Xchar *prompt;
- Xchar *command;
- X{
- X int res;
- X
- X if (prompt)
- X prt(prompt, 0, 0);
- X *command = inkeydir();
- X if (*command == 0 || *command == ESCAPE)
- X res = FALSE;
- X else
- X res = TRUE;
- X erase_line(MSG_LINE, 0);
- X return(res);
- X}
- X
- X/* Gets a string terminated by <RETURN> */
- X/* Function returns false if <ESCAPE> is input */
- Xint get_string(in_str, row, column, slen)
- Xchar *in_str;
- Xint row, column, slen;
- X{
- X register int start_col, end_col, i;
- X char *p;
- X int flag, abort;
- X Rect area;
- X
- X abort = FALSE;
- X flag = FALSE;
- X area.left = column;
- X area.top = row;
- X area.right = column + slen;
- X area.bottom = row + 1;
- X DEraseScreen(&area);
- X DSetScreenCursor(column, row);
- X start_col = column;
- X end_col = column + slen - 1;
- X if (end_col > 79)
- X {
- X slen = 80 - column;
- X end_col = 79;
- X }
- X p = in_str;
- X do
- X {
- X i = inkey();
- X switch(i)
- X {
- X case ESCAPE:
- X abort = TRUE;
- X break;
- X case CTRL('J'): case CTRL('M'):
- X flag = TRUE;
- X break;
- X case DELETE: case CTRL('H'):
- X if (column > start_col)
- X {
- X column--;
- X put_buffer(" ", row, column);
- X move_cursor(row, column);
- X *--p = '\0';
- X }
- X break;
- X default:
- X if (!isprint(i) || column > end_col)
- X bell();
- X else
- X {
- X DSetScreenCursor(column, row);
- X DWriteScreenCharAttr((char) i, ATTR_NORMAL);
- X *p++ = i;
- X column++;
- X }
- X break;
- X }
- X }
- X while ((!flag) && (!abort));
- X if (abort)
- X return(FALSE);
- X /* Remove trailing blanks */
- X while (p > in_str && p[-1] == ' ')
- X p--;
- X *p = '\0';
- X return(TRUE);
- X}
- X
- X/* Pauses for user response before returning -RAK- */
- Xvoid pause_line(prt_line)
- Xint prt_line;
- X{
- X prt("[Press any key to continue.]", prt_line, 23);
- X (void) inkey();
- X erase_line(prt_line, 0);
- X}
- X
- X/* Pauses for user response before returning -RAK- */
- X/* NOTE: Delay is for players trying to roll up "perfect" */
- X/* characters. Make them wait a bit. */
- Xvoid pause_exit(prt_line, delay)
- Xint prt_line;
- Xint delay;
- X{
- X char dummy;
- X
- X prt("[Press any key to continue, or Q to exit.]", prt_line, 10);
- X dummy = inkey();
- X if (dummy == 'Q')
- X {
- X erase_line(prt_line, 0);
- X if (delay > 0) (void) sleep((unsigned)delay);
- X exit_game();
- X }
- X erase_line(prt_line, 0);
- X}
- X
- Xvoid save_screen()
- X{
- X mac_save_screen();
- X}
- X
- Xvoid restore_screen()
- X{
- X mac_restore_screen();
- X}
- X
- Xvoid bell()
- X{
- X put_qio();
- X mac_beep();
- X}
- X
- X/* definitions used by screen_map() */
- X/* index into border character array */
- X#define TL 0 /* top left */
- X#define TR 1
- X#define BL 2
- X#define BR 3
- X#define HE 4 /* horizontal edge */
- X#define VE 5
- X
- X/* Display highest priority object in the RATIO by RATIO area */
- X#define RATIO 3
- X
- Xvoid screen_map()
- X{
- X register int i, j;
- X static int8u border[6] = {
- X '+', '+', '+', '+', '-', '|' /* normal chars */
- X };
- X int8u map[MAX_WIDTH / RATIO + 1];
- X int8u tmp;
- X int priority[256];
- X int row, orow, col, myrow, mycol = 0;
- X
- X for (i = 0; i < 256; i++)
- X priority[i] = 0;
- X priority['<'] = 5;
- X priority['>'] = 5;
- X priority['@'] = 10;
- X priority['#'] = -5;
- X priority['.'] = -10;
- X priority['\''] = -3;
- X priority[' '] = -15;
- X
- X save_screen();
- X clear_screen();
- X DSetScreenCursor(0, 0);
- X DWriteScreenCharAttr(border[TL], ATTR_NORMAL);
- X for (i = 0; i < MAX_WIDTH / RATIO; i++)
- X DWriteScreenCharAttr(border[HE], ATTR_NORMAL);
- X DWriteScreenCharAttr(border[TR], ATTR_NORMAL);
- X orow = -1;
- X map[MAX_WIDTH / RATIO] = '\0';
- X for (i = 0; i < MAX_HEIGHT; i++)
- X {
- X row = i / RATIO;
- X if (row != orow)
- X {
- X if (orow >= 0)
- X {
- X DSetScreenCursor(0, orow+1);
- X DWriteScreenCharAttr(border[VE], ATTR_NORMAL);
- X DWriteScreenString(map);
- X DWriteScreenCharAttr(border[VE], ATTR_NORMAL);
- X }
- X for (j = 0; j < MAX_WIDTH / RATIO; j++)
- X map[j] = ' ';
- X orow = row;
- X }
- X for (j = 0; j < MAX_WIDTH; j++)
- X {
- X col = j / RATIO;
- X tmp = loc_symbol(i, j);
- X /* Attributes are not handled correctly by DWriteScreenString */
- X /* Also, no special priority for the vein character */
- X if (tmp & 0x80)
- X tmp &= ~0x80;
- X if (priority[map[col]] < priority[tmp])
- X map[col] = tmp;
- X if (map[col] == '@')
- X {
- X mycol = col + 1; /* account for border */
- X myrow = row + 1;
- X }
- X }
- X }
- X if (orow >= 0)
- X {
- X DSetScreenCursor(0, orow+1);
- X DWriteScreenCharAttr(border[VE], ATTR_NORMAL);
- X DWriteScreenString(map);
- X DWriteScreenCharAttr(border[VE], ATTR_NORMAL);
- X }
- X DSetScreenCursor(0, orow + 2);
- X DWriteScreenCharAttr(border[BL], ATTR_NORMAL);
- X for (i = 0; i < MAX_WIDTH / RATIO; i++)
- X DWriteScreenCharAttr(border[HE], ATTR_NORMAL);
- X DWriteScreenCharAttr(border[BR], ATTR_NORMAL);
- X DSetScreenCursor(23, 23);
- X DWriteScreenStringAttr("Hit any key to continue", ATTR_NORMAL);
- X if (mycol > 0)
- X DSetScreenCursor(mycol, myrow);
- X (void) inkey();
- X restore_screen();
- X}
- END_OF_FILE
- if test 12472 -ne `wc -c <'mac/macio.c'`; then
- echo shar: \"'mac/macio.c'\" unpacked with wrong size!
- fi
- # end of 'mac/macio.c'
- fi
- if test -f 'source/create.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'source/create.c'\"
- else
- echo shar: Extracting \"'source/create.c'\" \(12587 characters\)
- sed "s/^X//" >'source/create.c' <<'END_OF_FILE'
- X/* create.c: create a player character
- X
- X Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
- X
- X This software may be copied and distributed for educational, research, and
- X not for profit purposes provided that this copyright and statement are
- X included in all such copies. */
- X
- X#include "constant.h"
- X#include "config.h"
- X#include "types.h"
- X#include "externs.h"
- X
- X#ifdef USG
- X#ifndef ATARIST_MWC
- X#include <string.h>
- X#endif
- X#else
- X#include <strings.h>
- X#endif
- X
- X#if defined(LINT_ARGS)
- Xstatic void get_stats(void);
- Xstatic void change_stat(int, int8);
- Xstatic void get_all_stats(void);
- Xstatic void choose_race(void);
- Xstatic void print_history(void);
- Xstatic void get_history(void);
- Xstatic void get_sex(void);
- Xstatic void get_ahw(void);
- Xstatic void get_class(void);
- Xstatic int monval(int8u);
- Xstatic void get_money(void);
- X#endif
- X
- X
- X/* Generates character's stats -JWT- */
- Xstatic void get_stats()
- X{
- X register int i, tot;
- X int dice[18];
- X
- X do
- X {
- X tot = 0;
- X for (i = 0; i < 18; i++)
- X {
- X dice[i] = randint (3 + i % 3); /* Roll 3,4,5 sided dice once each */
- X tot += dice[i];
- X }
- X }
- X while (tot <= 42 || tot >= 54);
- X
- X for (i = 0; i < 6; i++)
- X py.stats.max_stat[i] = 5 + dice[3*i] + dice[3*i+1] + dice[3*i+2];
- X}
- X
- X
- X/* Changes stats by given amount -JWT- */
- Xstatic void change_stat(stat, amount)
- Xint stat;
- Xint16 amount;
- X{
- X register int i;
- X register int tmp_stat;
- X
- X tmp_stat = py.stats.max_stat[stat];
- X if (amount < 0)
- X for (i = 0; i > amount; i--)
- X {
- X if (tmp_stat > 108)
- X tmp_stat--;
- X else if (tmp_stat > 88)
- X tmp_stat += -randint(6) - 2;
- X else if (tmp_stat > 18)
- X {
- X tmp_stat += -randint(15) - 5;
- X if (tmp_stat < 18)
- X tmp_stat = 18;
- X }
- X else if (tmp_stat > 3)
- X tmp_stat--;
- X }
- X else
- X for (i = 0; i < amount; i++)
- X {
- X if (tmp_stat < 18)
- X tmp_stat++;
- X else if (tmp_stat < 88)
- X tmp_stat += randint(15) + 5;
- X else if (tmp_stat < 108)
- X tmp_stat += randint(6) + 2;
- X else if (tmp_stat < 118)
- X tmp_stat++;
- X }
- X py.stats.max_stat[stat] = tmp_stat;
- X}
- X
- X
- X/* generate all stats and modify for race. needed in a separate module so
- X looping of character selection would be allowed -RGM- */
- Xstatic void get_all_stats ()
- X{
- X register player_type *p_ptr;
- X register race_type *r_ptr;
- X register int j;
- X
- X p_ptr = &py;
- X r_ptr = &race[p_ptr->misc.prace];
- X get_stats ();
- X change_stat (A_STR, r_ptr->str_adj);
- X change_stat (A_INT, r_ptr->int_adj);
- X change_stat (A_WIS, r_ptr->wis_adj);
- X change_stat (A_DEX, r_ptr->dex_adj);
- X change_stat (A_CON, r_ptr->con_adj);
- X change_stat (A_CHR, r_ptr->chr_adj);
- X for (j = 0; j < 6; j++)
- X {
- X py.stats.cur_stat[j] = py.stats.max_stat[j];
- X set_use_stat (j);
- X }
- X
- X p_ptr->misc.srh = r_ptr->srh;
- X p_ptr->misc.bth = r_ptr->bth;
- X p_ptr->misc.bthb = r_ptr->bthb;
- X p_ptr->misc.fos = r_ptr->fos;
- X p_ptr->misc.stl = r_ptr->stl;
- X p_ptr->misc.save = r_ptr->bsav;
- X p_ptr->misc.hitdie = r_ptr->bhitdie;
- X p_ptr->misc.lev = 1;
- X p_ptr->misc.ptodam = todam_adj();
- X p_ptr->misc.ptohit = tohit_adj();
- X p_ptr->misc.ptoac = 0;
- X p_ptr->misc.pac = toac_adj();
- X p_ptr->misc.expfact = r_ptr->b_exp;
- X p_ptr->flags.see_infra = r_ptr->infra;
- X}
- X
- X
- X/* Allows player to select a race -JWT- */
- Xstatic void choose_race()
- X{
- X register int j, k;
- X int l, m, exit_flag;
- X char s;
- X char tmp_str[80];
- X register player_type *p_ptr;
- X register race_type *r_ptr;
- X
- X j = 0;
- X k = 0;
- X l = 2;
- X m = 21;
- X clear_from (20);
- X put_buffer("Choose a race (? for Help):", 20, 2);
- X do
- X {
- X (void) sprintf(tmp_str, "%c) %s", k+'a', race[j].trace);
- X put_buffer(tmp_str, m, l);
- X k++;
- X l += 15;
- X if (l > 70)
- X {
- X l = 2;
- X m++;
- X }
- X j++;
- X }
- X while (j < MAX_RACES);
- X exit_flag = FALSE;
- X do
- X {
- X move_cursor (20, 30);
- X s = inkey();
- X j = s - 'a';
- X if ((j < MAX_RACES) && (j >= 0))
- X exit_flag = TRUE;
- X else if (s == '?')
- X helpfile (MORIA_WELCOME);
- X else
- X bell ();
- X }
- X while (!exit_flag);
- X
- X p_ptr = &py;
- X r_ptr = &race[j];
- X p_ptr->misc.prace = j;
- X put_buffer(r_ptr->trace, 3, 15);
- X}
- X
- X
- X/* Will print the history of a character -JWT- */
- Xstatic void print_history()
- X{
- X register int i;
- X
- X put_buffer("Character Background", 14, 27);
- X for (i = 0; i < 4; i++)
- X prt(py.misc.history[i], i+15, 10);
- X}
- X
- X
- X/* Get the racial history, determines social class -RAK- */
- X/* Assumptions: Each race has init history beginning at */
- X/* (race-1)*3+1 */
- X/* All history parts are in ascending order */
- Xstatic void get_history()
- X{
- X int hist_ptr, cur_ptr, test_roll, flag;
- X register int start_pos, end_pos, cur_len;
- X int line_ctr, new_start, social_class;
- X char history_block[240];
- X register background_type *b_ptr;
- X
- X /* Get a block of history text */
- X hist_ptr = py.misc.prace*3 + 1;
- X history_block[0] = '\0';
- X social_class = randint(4);
- X cur_ptr = 0;
- X do
- X {
- X flag = FALSE;
- X do
- X {
- X if (background[cur_ptr].chart == hist_ptr)
- X {
- X test_roll = randint(100);
- X while (test_roll > background[cur_ptr].roll)
- X cur_ptr++;
- X b_ptr = &background[cur_ptr];
- X (void) strcat(history_block, b_ptr->info);
- X social_class += b_ptr->bonus - 50;
- X if (hist_ptr > b_ptr->next)
- X cur_ptr = 0;
- X hist_ptr = b_ptr->next;
- X flag = TRUE;
- X }
- X else
- X cur_ptr++;
- X }
- X while (!flag);
- X }
- X while (hist_ptr >= 1);
- X
- X /* clear the previous history strings */
- X for (hist_ptr = 0; hist_ptr < 4; hist_ptr++)
- X py.misc.history[hist_ptr][0] = '\0';
- X
- X /* Process block of history text for pretty output */
- X start_pos = 0;
- X end_pos = strlen(history_block) - 1;
- X line_ctr = 0;
- X flag = FALSE;
- X while (history_block[end_pos] == ' ')
- X end_pos--;
- X do
- X {
- X while (history_block[start_pos] == ' ')
- X start_pos++;
- X cur_len = end_pos - start_pos + 1;
- X if (cur_len > 60)
- X {
- X cur_len = 60;
- X while (history_block[start_pos+cur_len-1] != ' ')
- X cur_len--;
- X new_start = start_pos + cur_len;
- X while (history_block[start_pos+cur_len-1] == ' ')
- X cur_len--;
- X }
- X else
- X flag = TRUE;
- X (void) strncpy(py.misc.history[line_ctr], &history_block[start_pos],
- X cur_len);
- X py.misc.history[line_ctr][cur_len] = '\0';
- X line_ctr++;
- X start_pos = new_start;
- X }
- X while (!flag);
- X
- X /* Compute social class for player */
- X if (social_class > 100)
- X social_class = 100;
- X else if (social_class < 1)
- X social_class = 1;
- X py.misc.sc = social_class;
- X}
- X
- X
- X/* Gets the character's sex -JWT- */
- Xstatic void get_sex()
- X{
- X register int exit_flag;
- X char c;
- X
- X exit_flag = FALSE;
- X clear_from (20);
- X put_buffer("Choose a sex (? for Help):", 20, 2);
- X put_buffer("m) Male f) Female", 21, 2);
- X do
- X {
- X move_cursor (20, 29);
- X /* speed not important here */
- X c = inkey();
- X if (c == 'f' || c == 'F')
- X {
- X py.misc.male = FALSE;
- X put_buffer("Female", 4, 15);
- X exit_flag = TRUE;
- X }
- X else if (c == 'm' || c == 'M')
- X {
- X py.misc.male = TRUE;
- X put_buffer("Male", 4, 15);
- X exit_flag = TRUE;
- X }
- X else if (c == '?')
- X helpfile (MORIA_WELCOME);
- X else
- X bell ();
- X }
- X while (!exit_flag);
- X}
- X
- X
- X/* Computes character's age, height, and weight -JWT- */
- Xstatic void get_ahw()
- X{
- X register int i;
- X
- X i = py.misc.prace;
- X py.misc.age = race[i].b_age + randint((int)race[i].m_age);
- X if (py.misc.male)
- X {
- X py.misc.ht = randnor((int)race[i].m_b_ht, (int)race[i].m_m_ht);
- X py.misc.wt = randnor((int)race[i].m_b_wt, (int)race[i].m_m_wt);
- X }
- X else
- X {
- X py.misc.ht = randnor((int)race[i].f_b_ht, (int)race[i].f_m_ht);
- X py.misc.wt = randnor((int)race[i].f_b_wt, (int)race[i].f_m_wt);
- X }
- X py.misc.disarm = race[i].b_dis + todis_adj();
- X}
- X
- X
- X/* Gets a character class -JWT- */
- Xstatic void get_class()
- X{
- X register int i, j;
- X int k, l, m, min_value, max_value;
- X int cl[MAX_CLASS], exit_flag;
- X register struct misc *m_ptr;
- X register player_type *p_ptr;
- X class_type *c_ptr;
- X char tmp_str[80], s;
- X int32u mask;
- X
- X for (j = 0; j < MAX_CLASS; j++)
- X cl[j] = 0;
- X i = py.misc.prace;
- X j = 0;
- X k = 0;
- X l = 2;
- X m = 21;
- X mask = 0x1;
- X clear_from (20);
- X put_buffer("Choose a class (? for Help):", 20, 2);
- X do
- X {
- X if (race[i].rtclass & mask)
- X {
- X (void) sprintf(tmp_str, "%c) %s", k+'a', class[j].title);
- X put_buffer(tmp_str, m, l);
- X cl[k] = j;
- X l += 15;
- X if (l > 70)
- X {
- X l = 2;
- X m++;
- X }
- X k++;
- X }
- X j++;
- X mask <<= 1;
- X }
- X while (j < MAX_CLASS);
- X py.misc.pclass = 0;
- X exit_flag = FALSE;
- X do
- X {
- X move_cursor (20, 31);
- X s = inkey();
- X j = s - 'a';
- X if ((j < k) && (j >= 0))
- X {
- X py.misc.pclass = cl[j];
- X c_ptr = &class[py.misc.pclass];
- X exit_flag = TRUE;
- X clear_from (20);
- X put_buffer(c_ptr->title, 5, 15);
- X
- X /* Adjust the stats for the class adjustment -RAK- */
- X p_ptr = &py;
- X change_stat (A_STR, c_ptr->madj_str);
- X change_stat (A_INT, c_ptr->madj_int);
- X change_stat (A_WIS, c_ptr->madj_wis);
- X change_stat (A_DEX, c_ptr->madj_dex);
- X change_stat (A_CON, c_ptr->madj_con);
- X change_stat (A_CHR, c_ptr->madj_chr);
- X for(i = 0; i < 6; i++)
- X {
- X p_ptr->stats.cur_stat[i] = p_ptr->stats.max_stat[i];
- X set_use_stat(i);
- X }
- X
- X p_ptr->misc.ptodam = todam_adj(); /* Real values */
- X p_ptr->misc.ptohit = tohit_adj();
- X p_ptr->misc.ptoac = toac_adj();
- X p_ptr->misc.pac = 0;
- X p_ptr->misc.dis_td = p_ptr->misc.ptodam; /* Displayed values */
- X p_ptr->misc.dis_th = p_ptr->misc.ptohit;
- X p_ptr->misc.dis_tac= p_ptr->misc.ptoac;
- X p_ptr->misc.dis_ac = p_ptr->misc.pac + p_ptr->misc.dis_tac;
- X
- X /* now set misc stats, do this after setting stats because
- X of con_adj() for hitpoints */
- X m_ptr = &py.misc;
- X m_ptr->hitdie += c_ptr->adj_hd;
- X m_ptr->mhp = con_adj() + m_ptr->hitdie;
- X m_ptr->chp = m_ptr->mhp;
- X m_ptr->chp_frac = 0;
- X
- X /* initialize hit_points array */
- X /* put bounds on total possible hp, only succeed if it is within
- X 1/8 of average value */
- X min_value = (MAX_PLAYER_LEVEL*3/8 * (m_ptr->hitdie-1)) +
- X MAX_PLAYER_LEVEL;
- X max_value = (MAX_PLAYER_LEVEL*5/8 * (m_ptr->hitdie-1)) +
- X MAX_PLAYER_LEVEL;
- X player_hp[0] = m_ptr->hitdie;
- X do
- X {
- X for (i = 1; i < MAX_PLAYER_LEVEL; i++)
- X {
- X player_hp[i] = randint((int)m_ptr->hitdie);
- X player_hp[i] += player_hp[i-1];
- X }
- X }
- X while ((player_hp[MAX_PLAYER_LEVEL-1] < min_value) ||
- X (player_hp[MAX_PLAYER_LEVEL-1] > max_value));
- X
- X m_ptr->bth += c_ptr->mbth;
- X m_ptr->bthb += c_ptr->mbthb; /*RAK*/
- X m_ptr->srh += c_ptr->msrh;
- X m_ptr->disarm += c_ptr->mdis;
- X m_ptr->fos += c_ptr->mfos;
- X m_ptr->stl += c_ptr->mstl;
- X m_ptr->save += c_ptr->msav;
- X m_ptr->expfact += c_ptr->m_exp;
- X }
- X else if (s == '?')
- X helpfile (MORIA_WELCOME);
- X else
- X bell ();
- X }
- X while (!exit_flag);
- X}
- X
- X
- X/* Given a stat value, return a monetary value, which affects the amount
- X of gold a player has. */
- Xstatic int monval (i)
- Xint8u i;
- X{
- X return 5 * (i - 10);
- X}
- X
- X
- Xstatic void get_money()
- X{
- X register int tmp, gold;
- X register int8u *a_ptr;
- X
- X a_ptr = py.stats.max_stat;
- X tmp = monval (a_ptr[A_STR]) + monval (a_ptr[A_INT])
- X + monval (a_ptr[A_WIS]) + monval (a_ptr[A_CON])
- X + monval (a_ptr[A_DEX]);
- X
- X gold = py.misc.sc*6 + randint (25) + 325; /* Social Class adj */
- X gold -= tmp; /* Stat adj */
- X gold += monval (a_ptr[A_CHR]); /* Charisma adj */
- X if (!py.misc.male)
- X gold += 50; /* She charmed the banker into it! -CJS- */
- X if (gold < 80)
- X gold = 80; /* Minimum */
- X py.misc.au = gold;
- X}
- X
- X
- X/* ---------- M A I N for Character Creation Routine ---------- */
- X/* -JWT- */
- Xvoid create_character()
- X{
- X register int exit_flag = 1;
- X register char c;
- X
- X put_character();
- X choose_race();
- X get_sex();
- X
- X /* here we start a loop giving a player a choice of characters -RGM- */
- X get_all_stats ();
- X get_history();
- X get_ahw();
- X print_history();
- X put_misc1();
- X put_stats();
- X
- X clear_from (20);
- X put_buffer("Hit space to reroll or ESC to accept characteristics: ", 20, 2);
- X do
- X {
- X move_cursor (20, 56);
- X c = inkey();
- X if (c == ESCAPE)
- X exit_flag = 0;
- X else if (c == ' ')
- X {
- X get_all_stats ();
- X get_history();
- X get_ahw();
- X print_history();
- X put_misc1();
- X put_stats();
- X }
- X else
- X bell ();
- X } /* done with stats generation */
- X while (exit_flag == 1);
- X
- X get_class();
- X get_money();
- X put_stats();
- X put_misc2();
- X put_misc3();
- X get_name();
- X
- X /* This delay may be reduced, but is recommended to keep players */
- X /* from continuously rolling up characters, which can be VERY */
- X /* expensive CPU wise. */
- X pause_exit(23, PLAYER_EXIT_PAUSE);
- X}
- END_OF_FILE
- if test 12587 -ne `wc -c <'source/create.c'`; then
- echo shar: \"'source/create.c'\" unpacked with wrong size!
- fi
- # end of 'source/create.c'
- fi
- if test -f 'source/help.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'source/help.c'\"
- else
- echo shar: Extracting \"'source/help.c'\" \(6390 characters\)
- sed "s/^X//" >'source/help.c' <<'END_OF_FILE'
- X/* help.c: identify a symbol
- X
- X Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
- X
- X This software may be copied and distributed for educational, research, and
- X not for profit purposes provided that this copyright and statement are
- X included in all such copies. */
- X
- X#include "constant.h"
- X#include "config.h"
- X#include "types.h"
- X#include "externs.h"
- X
- X
- Xvoid ident_char()
- X{
- X char command, query;
- X register int i, n;
- X
- X if (get_com("Enter character to be identified :", &command))
- X switch(command)
- X {
- X /* every printing ASCII character is listed here, in the order in which
- X they appear in the ASCII character set */
- X case ' ': prt(" - An open pit.", 0, 0); break;
- X case '!': prt("! - A potion.", 0, 0); break;
- X case '"': prt("\" - An amulet, periapt, or necklace.", 0, 0); break;
- X case '#': prt("# - A stone wall.", 0, 0); break;
- X case '$': prt("$ - Treasure.", 0, 0); break;
- X case '%':
- X if (highlight_seams == TRUE)
- X prt("% - A magma or quartz vein.", 0, 0);
- X else
- X prt("% - Not used.", 0, 0);
- X break;
- X case '&': prt("& - Treasure chest.", 0, 0); break;
- X case '\'': prt("' - An open door.", 0, 0); break;
- X case '(': prt("( - Soft armor.", 0, 0); break;
- X case ')': prt(") - A shield.", 0, 0); break;
- X case '*': prt("* - Gems.", 0, 0); break;
- X case '+': prt("+ - A closed door.", 0, 0); break;
- X case ',': prt(", - Food or mushroom patch.", 0, 0); break;
- X case '-': prt("- - A wand", 0, 0); break;
- X case '.': prt(". - Floor.", 0, 0); break;
- X case '/': prt("/ - A pole weapon.", 0, 0); break;
- X /* case '0': prt("0 - Not used.", 0, 0); break; */
- X case '1': prt("1 - Entrance to General Store.", 0, 0); break;
- X case '2': prt("2 - Entrance to Armory.", 0, 0); break;
- X case '3': prt("3 - Entrance to Weaponsmith.", 0, 0); break;
- X case '4': prt("4 - Entrance to Temple.", 0, 0); break;
- X case '5': prt("5 - Entrance to Alchemy shop.", 0, 0); break;
- X case '6': prt("6 - Entrance to Magic-Users store.", 0, 0); break;
- X /* case '7': prt("7 - Not used.", 0, 0); break; */
- X /* case '8': prt("8 - Not used.", 0, 0); break; */
- X /* case '9': prt("9 - Not used.", 0, 0); break;*/
- X case ':': prt(": - Rubble.", 0, 0); break;
- X case ';': prt("; - A loose rock.", 0, 0); break;
- X case '<': prt("< - An up staircase.", 0, 0); break;
- X case '=': prt("= - A ring.", 0, 0); break;
- X case '>': prt("> - A down staircase.", 0, 0); break;
- X case '?': prt("? - A scroll.", 0, 0); break;
- X case '@': prt(py.misc.name, 0, 0); break;
- X case 'A': prt("A - Giant Ant Lion.", 0, 0); break;
- X case 'B': prt("B - The Balrog.", 0, 0); break;
- X case 'C': prt("C - Gelatinous Cube.", 0, 0); break;
- X case 'D': prt("D - An Ancient Dragon (Beware).", 0, 0); break;
- X case 'E': prt("E - Elemental.", 0, 0); break;
- X case 'F': prt("F - Giant Fly.", 0, 0); break;
- X case 'G': prt("G - Ghost.", 0, 0); break;
- X case 'H': prt("H - Hobgoblin.", 0, 0); break;
- X /* case 'I': prt("I - Invisible Stalker.", 0, 0); break; */
- X case 'J': prt("J - Jelly.", 0, 0); break;
- X case 'K': prt("K - Killer Beetle.", 0, 0); break;
- X case 'L': prt("L - Lich.", 0, 0); break;
- X case 'M': prt("M - Mummy.", 0, 0); break;
- X /* case 'N': prt("N - Not used.", 0, 0); break; */
- X case 'O': prt("O - Ooze.", 0, 0); break;
- X case 'P': prt("P - Giant humanoid.", 0, 0); break;
- X case 'Q': prt("Q - Quylthulg (Pulsing Flesh Mound).", 0, 0); break;
- X case 'R': prt("R - Reptile.", 0, 0); break;
- X case 'S': prt("S - Giant Scorpion.", 0, 0); break;
- X case 'T': prt("T - Troll.", 0, 0); break;
- X case 'U': prt("U - Umber Hulk.", 0, 0); break;
- X case 'V': prt("V - Vampire.", 0, 0); break;
- X case 'W': prt("W - Wight or Wraith.", 0, 0); break;
- X case 'X': prt("X - Xorn.", 0, 0); break;
- X case 'Y': prt("Y - Yeti.", 0, 0); break;
- X /* case 'Z': prt("Z - Not used.", 0, 0); break; */
- X case '[': prt("[ - Hard armor.", 0, 0); break;
- X case '\\': prt("\\ - A hafted weapon.", 0, 0); break;
- X case ']': prt("] - Misc. armor.", 0, 0); break;
- X case '^': prt("^ - A trap.", 0, 0); break;
- X case '_': prt("_ - A staff.", 0, 0); break;
- X /* case '`': prt("` - Not used.", 0, 0); break; */
- X case 'a': prt("a - Giant Ant.", 0, 0); break;
- X case 'b': prt("b - Giant Bat.", 0, 0); break;
- X case 'c': prt("c - Giant Centipede.", 0, 0); break;
- X case 'd': prt("d - Dragon.", 0, 0); break;
- X case 'e': prt("e - Floating Eye.", 0, 0); break;
- X case 'f': prt("f - Giant Frog", 0, 0); break;
- X case 'g': prt("g - Golem.", 0, 0); break;
- X case 'h': prt("h - Harpy.", 0, 0); break;
- X case 'i': prt("i - Icky Thing.", 0, 0); break;
- X case 'j': prt("j - Jackal.", 0, 0); break;
- X case 'k': prt("k - Kobold.", 0, 0); break;
- X case 'l': prt("l - Giant Louse.", 0, 0); break;
- X case 'm': prt("m - Mold.", 0, 0); break;
- X case 'n': prt("n - Naga.", 0, 0); break;
- X case 'o': prt("o - Orc or Ogre.", 0, 0); break;
- X case 'p': prt("p - Person (Humanoid).", 0, 0); break;
- X case 'q': prt("q - Quasit.", 0, 0); break;
- X case 'r': prt("r - Rodent.", 0, 0); break;
- X case 's': prt("s - Skeleton.", 0, 0); break;
- X case 't': prt("t - Giant Tick.", 0, 0); break;
- X /* case 'u': prt("u - Not used.", 0, 0); break; */
- X /* case 'v': prt("v - Not used.", 0, 0); break; */
- X case 'w': prt("w - Worm or Worm Mass.", 0, 0); break;
- X /* case 'x': prt("x - Not used.", 0, 0); break; */
- X case 'y': prt("y - Yeek.", 0, 0); break;
- X case 'z': prt("z - Zombie.", 0, 0); break;
- X case '{': prt("{ - Arrow, bolt, or bullet.", 0, 0); break;
- X case '|': prt("| - A sword or dagger.", 0, 0); break;
- X case '}': prt("} - Bow, crossbow, or sling.", 0, 0); break;
- X case '~': prt("~ - Miscellaneous item.", 0, 0); break;
- X default: prt("Not Used.", 0, 0); break;
- X }
- X
- X /* Allow access to monster memory. -CJS- */
- X n = 0;
- X for (i = MAX_CREATURES-1; i >= 0; i--)
- X if ((c_list[i].cchar == command) && bool_roff_recall (i))
- X {
- X if (n == 0)
- X {
- X put_buffer ("You recall those details? [y/n]", 0, 40);
- X query = inkey();
- X if (query != 'y' && query != 'Y')
- X break;
- X erase_line (0, 40);
- X save_screen ();
- X }
- X n++;
- X query = roff_recall (i);
- X restore_screen ();
- X if (query == ESCAPE)
- X break;
- X }
- X}
- END_OF_FILE
- if test 6390 -ne `wc -c <'source/help.c'`; then
- echo shar: \"'source/help.c'\" unpacked with wrong size!
- fi
- # end of 'source/help.c'
- fi
- if test -f 'source/store1.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'source/store1.c'\"
- else
- echo shar: Extracting \"'source/store1.c'\" \(11806 characters\)
- sed "s/^X//" >'source/store1.c' <<'END_OF_FILE'
- X/* store1.c: store code, updating store inventory, pricing objects
- X
- X Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
- X
- X This software may be copied and distributed for educational, research, and
- X not for profit purposes provided that this copyright and statement are
- X included in all such copies. */
- X
- X#include "constant.h"
- X#include "config.h"
- X#include "types.h"
- X#include "externs.h"
- X
- X#ifdef USG
- X#ifndef ATARIST_MWC
- X#include <string.h>
- X#endif
- X#else
- X#include <strings.h>
- X#endif
- X
- X#if defined(LINT_ARGS)
- Xstatic void insert_store(int, int, int32, struct inven_type *);
- Xstatic void store_create(int);
- X#else
- Xstatic void insert_store();
- Xstatic void store_create();
- X#endif
- X
- X
- X/* Returns the value for any given object -RAK- */
- Xint32 item_value(i_ptr)
- Xregister inven_type *i_ptr;
- X{
- X register int32 value;
- X
- X value = i_ptr->cost;
- X /* don't purchase known cursed items */
- X if (i_ptr->ident & ID_DAMD)
- X value = 0;
- X else if (((i_ptr->tval >= TV_BOW) && (i_ptr->tval <= TV_SWORD)) ||
- X ((i_ptr->tval >= TV_BOOTS) && (i_ptr->tval <= TV_SOFT_ARMOR)))
- X { /* Weapons and armor */
- X if (!known2_p(i_ptr))
- X value = object_list[i_ptr->index].cost;
- X else if ((i_ptr->tval >= TV_BOW) && (i_ptr->tval <= TV_SWORD))
- X {
- X if (i_ptr->tohit < 0)
- X value = 0;
- X else if (i_ptr->todam < 0)
- X value = 0;
- X else if (i_ptr->toac < 0)
- X value = 0;
- X else
- X value = i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*100;
- X }
- X else
- X {
- X if (i_ptr->toac < 0)
- X value = 0;
- X else
- X value = i_ptr->cost+i_ptr->toac*100;
- X }
- X }
- X else if ((i_ptr->tval >= TV_SLING_AMMO) && (i_ptr->tval <= TV_SPIKE))
- X { /* Ammo */
- X if (!known2_p(i_ptr))
- X value = object_list[i_ptr->index].cost;
- X else
- X {
- X if (i_ptr->tohit < 0)
- X value = 0;
- X else if (i_ptr->todam < 0)
- X value = 0;
- X else if (i_ptr->toac < 0)
- X value = 0;
- X else
- X /* use 5, because missiles generally appear in groups of 20,
- X so 20 * 5 == 100, which is comparable to weapon bonus above */
- X value = i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*5;
- X }
- X }
- X else if ((i_ptr->tval == TV_SCROLL1) || (i_ptr->tval == TV_SCROLL2) ||
- X (i_ptr->tval == TV_POTION1) || (i_ptr->tval == TV_POTION2))
- X { /* Potions, Scrolls, and Food */
- X if (!known1_p(i_ptr))
- X value = 20;
- X }
- X else if (i_ptr->tval == TV_FOOD)
- X {
- X if ((i_ptr->subval < (ITEM_SINGLE_STACK_MIN + MAX_MUSH))
- X && !known1_p(i_ptr))
- X value = 1;
- X }
- X else if ((i_ptr->tval == TV_AMULET) || (i_ptr->tval == TV_RING))
- X { /* Rings and amulets */
- X if (!known1_p(i_ptr))
- X /* player does not know what type of ring/amulet this is */
- X value = 45;
- X else if (!known2_p(i_ptr))
- X /* player knows what type of ring, but does not know whether it is
- X cursed or not, if refuse to buy cursed objects here, then
- X player can use this to 'identify' cursed objects */
- X value = object_list[i_ptr->index].cost;
- X }
- X else if ((i_ptr->tval == TV_STAFF) || (i_ptr->tval == TV_WAND))
- X { /* Wands and staffs*/
- X if (!known1_p(i_ptr))
- X {
- X if (i_ptr->tval == TV_WAND)
- X value = 50;
- X else
- X value = 70;
- X }
- X else if (known2_p(i_ptr))
- X value = i_ptr->cost + (i_ptr->cost / 20) * i_ptr->p1;
- X }
- X /* picks and shovels */
- X else if (i_ptr->tval == TV_DIGGING)
- X {
- X if (!known2_p(i_ptr))
- X value = object_list[i_ptr->index].cost;
- X else
- X {
- X if (i_ptr->p1 < 0)
- X value = 0;
- X else
- X {
- X /* some digging tools start with non-zero p1 values, so only
- X multiply the plusses by 100, make sure result is positive */
- X value = i_ptr->cost
- X + (i_ptr->p1 - object_list[i_ptr->index].p1) * 100;
- X if (value < 0)
- X value = 0;
- X }
- X }
- X }
- X /* multiply value by number of items if it is a group stack item */
- X if (i_ptr->subval > ITEM_GROUP_MIN) /* do not include torches here */
- X value = value * i_ptr->number;
- X return(value);
- X}
- X
- X
- X/* Asking price for an item -RAK- */
- Xint32 sell_price(snum, max_sell, min_sell, item)
- Xint snum;
- Xint32 *max_sell, *min_sell;
- Xinven_type *item;
- X{
- X register int32 i;
- X register store_type *s_ptr;
- X
- X s_ptr = &store[snum];
- X i = item_value(item);
- X /* check item->cost in case it is cursed, check i in case it is damaged */
- X if ((item->cost > 0) && (i > 0))
- X {
- X i = i * rgold_adj[owners[s_ptr->owner].owner_race][py.misc.prace] / 100;
- X if (i < 1) i = 1;
- X *max_sell = i * owners[s_ptr->owner].max_inflate / 100;
- X *min_sell = i * owners[s_ptr->owner].min_inflate / 100;
- X if (min_sell > max_sell) min_sell = max_sell;
- X return(i);
- X }
- X else
- X /* don't let the item get into the store inventory */
- X return(0);
- X}
- X
- X
- X/* Check to see if he will be carrying too many objects -RAK- */
- Xint store_check_num(t_ptr, store_num)
- Xinven_type *t_ptr;
- Xint store_num;
- X{
- X register int store_check, i;
- X register store_type *s_ptr;
- X register inven_type *i_ptr;
- X
- X store_check = FALSE;
- X s_ptr = &store[store_num];
- X if (s_ptr->store_ctr < STORE_INVEN_MAX)
- X store_check = TRUE;
- X else if (t_ptr->subval >= ITEM_SINGLE_STACK_MIN)
- X for (i = 0; i < s_ptr->store_ctr; i++)
- X {
- X i_ptr = &s_ptr->store_inven[i].sitem;
- X /* note: items with subval of gte ITEM_SINGLE_STACK_MAX only stack
- X if their subvals match */
- X if (i_ptr->tval == t_ptr->tval && i_ptr->subval == t_ptr->subval
- X && ((int)i_ptr->number + (int)t_ptr->number < 256)
- X && (t_ptr->subval < ITEM_GROUP_MIN
- X || (i_ptr->p1 == t_ptr->p1)))
- X store_check = TRUE;
- X }
- X return(store_check);
- X}
- X
- X
- X/* Insert INVEN_MAX at given location */
- Xstatic void insert_store(store_num, pos, icost, i_ptr)
- Xregister int pos;
- Xint store_num;
- Xint32 icost;
- Xinven_type *i_ptr;
- X{
- X register int i;
- X register store_type *s_ptr;
- X
- X s_ptr = &store[store_num];
- X for (i = s_ptr->store_ctr-1; i >= pos; i--)
- X s_ptr->store_inven[i+1] = s_ptr->store_inven[i];
- X s_ptr->store_inven[pos].sitem = *i_ptr;
- X s_ptr->store_inven[pos].scost = -icost;
- X s_ptr->store_ctr++;
- X}
- X
- X
- X/* Add the item in INVEN_MAX to stores inventory. -RAK- */
- Xvoid store_carry(store_num, ipos, t_ptr)
- Xint store_num;
- Xint *ipos;
- Xinven_type *t_ptr;
- X{
- X int item_num, item_val, flag;
- X register int typ, subt;
- X int32 icost, dummy;
- X register inven_type *i_ptr;
- X register store_type *s_ptr;
- X
- X *ipos = -1;
- X if (sell_price(store_num, &icost, &dummy, t_ptr) > 0)
- X {
- X s_ptr = &store[store_num];
- X item_val = 0;
- X item_num = t_ptr->number;
- X flag = FALSE;
- X typ = t_ptr->tval;
- X subt = t_ptr->subval;
- X do
- X {
- X i_ptr = &s_ptr->store_inven[item_val].sitem;
- X if (typ == i_ptr->tval)
- X {
- X if (subt == i_ptr->subval && /* Adds to other item */
- X subt >= ITEM_SINGLE_STACK_MIN
- X && (subt < ITEM_GROUP_MIN || i_ptr->p1 == t_ptr->p1))
- X {
- X *ipos = item_val;
- X i_ptr->number += item_num;
- X /* must set new scost for group items, do this only for items
- X strictly greater than group_min, not for torches, this
- X must be recalculated for entire group */
- X if (subt > ITEM_GROUP_MIN)
- X {
- X (void) sell_price (store_num, &icost, &dummy, i_ptr);
- X s_ptr->store_inven[item_val].scost = -icost;
- X }
- X /* must let group objects (except torches) stack over 24
- X since there may be more than 24 in the group */
- X else if (i_ptr->number > 24)
- X i_ptr->number = 24;
- X flag = TRUE;
- X }
- X }
- X else if (typ > i_ptr->tval)
- X { /* Insert into list */
- X insert_store(store_num, item_val, icost, t_ptr);
- X flag = TRUE;
- X *ipos = item_val;
- X }
- X item_val++;
- X }
- X while ((item_val < s_ptr->store_ctr) && (!flag));
- X if (!flag) /* Becomes last item in list */
- X {
- X insert_store(store_num, (int)s_ptr->store_ctr, icost, t_ptr);
- X *ipos = s_ptr->store_ctr - 1;
- X }
- X }
- X}
- X
- X/* Destroy an item in the stores inventory. Note that if */
- X/* "one_of" is false, an entire slot is destroyed -RAK- */
- Xvoid store_destroy(store_num, item_val, one_of)
- Xint store_num, item_val;
- Xint one_of;
- X{
- X register int j, number;
- X register store_type *s_ptr;
- X register inven_type *i_ptr;
- X
- X s_ptr = &store[store_num];
- X i_ptr = &s_ptr->store_inven[item_val].sitem;
- X
- X /* for single stackable objects, only destroy one half on average,
- X this will help ensure that general store and alchemist have
- X reasonable selection of objects */
- X if ((i_ptr->subval >= ITEM_SINGLE_STACK_MIN) &&
- X (i_ptr->subval <= ITEM_SINGLE_STACK_MAX))
- X {
- X if (one_of)
- X number = 1;
- X else
- X number = randint((int)i_ptr->number);
- X }
- X else
- X number = i_ptr->number;
- X
- X if (number != i_ptr->number)
- X i_ptr->number -= number;
- X else
- X {
- X for (j = item_val; j < s_ptr->store_ctr-1; j++)
- X s_ptr->store_inven[j] = s_ptr->store_inven[j+1];
- X invcopy(&s_ptr->store_inven[s_ptr->store_ctr-1].sitem, OBJ_NOTHING);
- X s_ptr->store_inven[s_ptr->store_ctr-1].scost = 0;
- X s_ptr->store_ctr--;
- X }
- X}
- X
- X
- X/* Initializes the stores with owners -RAK- */
- Xvoid store_init()
- X{
- X register int i, j, k;
- X register store_type *s_ptr;
- X
- X i = MAX_OWNERS / MAX_STORES;
- X for (j = 0; j < MAX_STORES; j++)
- X {
- X s_ptr = &store[j];
- X s_ptr->owner = MAX_STORES*(randint(i)-1) + j;
- X s_ptr->insult_cur = 0;
- X s_ptr->store_open = 0;
- X s_ptr->store_ctr = 0;
- X s_ptr->good_buy = 0;
- X s_ptr->bad_buy = 0;
- X for (k = 0; k < STORE_INVEN_MAX; k++)
- X {
- X invcopy(&s_ptr->store_inven[k].sitem, OBJ_NOTHING);
- X s_ptr->store_inven[k].scost = 0;
- X }
- X }
- X}
- X
- X
- X/* Creates an item and inserts it into store's inven -RAK- */
- Xstatic void store_create(store_num)
- Xint store_num;
- X{
- X register int i, tries;
- X int cur_pos, dummy;
- X register store_type *s_ptr;
- X register inven_type *t_ptr;
- X
- X tries = 0;
- X cur_pos = popt();
- X s_ptr = &store[store_num];
- X do
- X {
- X i = store_choice[store_num][randint(STORE_CHOICES)-1];
- X invcopy(&t_list[cur_pos], i);
- X magic_treasure(cur_pos, OBJ_TOWN_LEVEL);
- X t_ptr = &t_list[cur_pos];
- X if (store_check_num(t_ptr, store_num))
- X {
- X if ((t_ptr->cost > 0) && /* Item must be good */
- X (t_ptr->cost < owners[s_ptr->owner].max_cost))
- X {
- X /* equivalent to calling ident_spell(), except will not
- X change the object_ident array */
- X store_bought(t_ptr);
- X store_carry(store_num, &dummy, t_ptr);
- X tries = 10;
- X }
- X }
- X tries++;
- X }
- X while (tries <= 3);
- X pusht((int8u)cur_pos);
- X}
- X
- X
- X/* Initialize and up-keep the store's inventory. -RAK- */
- Xvoid store_maint()
- X{
- X register int i, j;
- X register store_type *s_ptr;
- X
- X for (i = 0; i < MAX_STORES; i++)
- X {
- X s_ptr = &store[i];
- X s_ptr->insult_cur = 0;
- X if (s_ptr->store_ctr >= STORE_MIN_INVEN)
- X {
- X j = randint(STORE_TURN_AROUND);
- X if (s_ptr->store_ctr >= STORE_MAX_INVEN)
- X j += 1 + s_ptr->store_ctr - STORE_MAX_INVEN;
- X while (--j >= 0)
- X store_destroy(i, randint((int)s_ptr->store_ctr)-1, FALSE);
- X }
- X
- X if (s_ptr->store_ctr <= STORE_MAX_INVEN)
- X {
- X j = randint(STORE_TURN_AROUND);
- X if (s_ptr->store_ctr < STORE_MIN_INVEN)
- X j += STORE_MIN_INVEN - s_ptr->store_ctr;
- X while (--j >= 0)
- X store_create(i);
- X }
- X }
- X}
- X
- X/* eliminate need to bargain if player has haggled well in the past -DJB- */
- Xint noneedtobargain(store_num, minprice)
- Xint store_num;
- Xint32 minprice;
- X{
- X register int flagnoneed;
- X register store_type *s_ptr;
- X
- X s_ptr = &store[store_num];
- X flagnoneed = ((s_ptr->good_buy == MAX_SHORT)
- X || ((s_ptr->good_buy > 3 * s_ptr->bad_buy + 20) &&
- X (minprice < 1000)));
- X
- X return (flagnoneed);
- X}
- X
- X
- X/* update the bargin info -DJB- */
- Xvoid updatebargain(store_num, price, minprice)
- Xint store_num;
- Xint32 price, minprice;
- X{
- X register store_type *s_ptr;
- X
- X s_ptr = &store[store_num];
- X if ((minprice > 9) && (minprice < 1000))
- X if (price == minprice)
- X {
- X if (s_ptr->good_buy < MAX_SHORT)
- X s_ptr->good_buy++;
- X }
- X else
- X {
- X if (s_ptr->bad_buy < MAX_SHORT)
- X s_ptr->bad_buy++;
- X }
- X}
- END_OF_FILE
- if test 11806 -ne `wc -c <'source/store1.c'`; then
- echo shar: \"'source/store1.c'\" unpacked with wrong size!
- fi
- # end of 'source/store1.c'
- fi
- if test -f 'util/mc/symtab.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'util/mc/symtab.c'\"
- else
- echo shar: Extracting \"'util/mc/symtab.c'\" \(12502 characters\)
- sed "s/^X//" >'util/mc/symtab.c' <<'END_OF_FILE'
- X/*
- X * st_symtab.c
- X *
- X * routines for managing symbol tables -- reasonably fast and reasonably
- X * efficient, but not very much of either
- X *
- X * Copyright 1989 by Joseph Hall.
- X * All rights reserved except as stated below.
- X *
- X * Jim Wilson and any other holders of copyright on substantial portions
- X * of Moria are granted rights to use, modify, and distribute this program
- X * as they see fit, so long as the terms of its use, modification and/or
- X * distribution are no less restrictive than those applying to Moria,
- X * version 5.0 or later, itself, and so long as this use is related to
- X * the further development of Moria.
- X *
- X * Anyone having any other use in mind for this code should contact the
- X * author at 4116 Brewster Dr., Raleigh NC 27606 (jnh@ecemwl.ncsu.edu).
- X */
- X
- X
- X#include <stdio.h>
- X#include <string.h>
- X#include <ctype.h>
- X
- X#ifdef ANSI_LIBS
- X#include <stdlib.h>
- X#else
- Xextern char *malloc();
- Xextern char *calloc();
- Xextern void free();
- Xextern void cfree();
- X#endif
- X
- X#include "st.h"
- X
- X/* #define _TESTING_ */
- X
- X/*
- X * There's a symbol table containing all the names of the symbol tables,
- X * and of course it contains its own name ...
- X *
- X * "tnt" stands for "Table Name Table" ...
- X */
- Xstatic st_Table_Pt tnt_P = NULL;
- X
- X/*
- X * If there are a lot of symbol tables around you might want to increase
- X * TNT_SIZE. For best results use a prime number.
- X */
- X
- X#define TNT_SIZE 11
- X
- X/*
- X * Names of basic generic types.
- X */
- X
- X#define NAMES 7
- X
- X/*
- X * Hash--
- X * Simple, stupid hash function. Why be great, you know, when you can
- X * be adequate so easily?
- X */
- Xstatic int Hash(s, mod)
- Xregister char *s;
- Xint mod;
- X{
- X register int h = 0;
- X
- X while (*s)
- X h += (unsigned) *s++;
- X
- X return h % mod;
- X}
- X
- X
- X/*
- X * LookupSym--
- X * Search for a name in a table. Returns NULL if not found.
- X */
- Xstatic st_Entry_Pt LookupSym(st_P, name)
- Xst_Table_Pt st_P;
- Xchar *name;
- X{
- X st_Entry_Pt entry_P;
- X int h;
- X
- X h = Hash(name, st_P->size);
- X
- X for (entry_P = st_P->tab_A[h]; entry_P; entry_P = entry_P->next_P)
- X if (!strncmp(entry_P->name, name, ST_MAX_SYM_LEN))
- X break;
- X
- X return entry_P;
- X}
- X
- X
- X
- X/*
- X * AddSym--
- X * Add a name to a table and return a pointer to the new entry.
- X * ASSUMES THAT NAME DOESN'T EXIST ALREADY IN TABLE (check with LookupSym
- X * above before calling here).
- X */
- Xstatic st_Entry_Pt AddSym(st_P, name)
- Xst_Table_Pt st_P;
- Xchar *name;
- X
- X{
- X int h;
- X st_Entry_Pt new_P;
- X
- X h = Hash(name, st_P->size);
- X
- X new_P = (st_Entry_Pt) malloc(sizeof(st_Entry_t));
- X strncpy(new_P->name, name, ST_MAX_SYM_LEN - 1);
- X new_P->name[ST_MAX_SYM_LEN - 1] = 0;
- X new_P->next_P = st_P->tab_A[h];
- X st_P->tab_A[h] = new_P;
- X
- X st_P->entryCt++;
- X
- X return new_P;
- X
- X}
- X
- X
- X/*
- X * St_NewTable--
- X * Create a new symbol table header. Returns NULL if name isn't
- X * unique with respect to the symbol tables currently in existence.
- X */
- Xst_Table_Pt St_NewTable(name, size)
- Xchar *name;
- Xint size;
- X{
- X st_Table_Pt st_P;
- X generic_t gval;
- X
- X /*
- X * Create the name table if doesn't already exist. Obviously we
- X * can't use St_NewTable for this ...
- X */
- X
- X if (!tnt_P) {
- X tnt_P = (st_Table_Pt) malloc(sizeof(st_Table_t));
- X
- X strncpy(tnt_P->name, "_TNT_", ST_MAX_SYM_LEN - 1);
- X tnt_P->name[ST_MAX_SYM_LEN - 1] = 0;
- X tnt_P->size = TNT_SIZE;
- X tnt_P->tab_A = (st_Entry_Pt *) calloc(TNT_SIZE, sizeof(st_Entry_Pt));
- X tnt_P->entryCt = 0;
- X
- X gval.v = (char *) tnt_P;
- X St_DefSym(tnt_P, "_TNT_", GEN_TYPE_VOID_PTR, gval);
- X
- X }
- X
- X /*
- X * See if the new table name is unique.
- X */
- X
- X if (LookupSym(tnt_P, name))
- X return NULL;
- X
- X /*
- X * Create the new table.
- X */
- X
- X st_P = (st_Table_Pt) malloc(sizeof(st_Table_t));
- X
- X strncpy(st_P->name, name, ST_MAX_SYM_LEN - 1);
- X st_P->name[ST_MAX_SYM_LEN - 1] = 0;
- X st_P->size = size;
- X st_P->tab_A = (st_Entry_Pt *) calloc((unsigned) size, sizeof(st_Entry_Pt));
- X st_P->entryCt = 0;
- X
- X /*
- X * Add the name of the new table to the "table name table" now.
- X * gval.v is a pointer to the new table.
- X */
- X
- X gval.v = (char *) st_P;
- X St_DefSym(tnt_P, name, GEN_TYPE_VOID_PTR, gval);
- X
- X return st_P;
- X}
- X
- X
- X
- X
- X/*
- X * St_DelTable--
- X * Delete a symbol table and associated storage. If entries in the
- X * table point to dynamically allocated objects, the user must free these
- X * objects before calling this routine, else the pointers to those objects
- X * will be lost. (** NOTE: this feature has been removed from the version
- X * accompanying the monster compiler, since it isn't needed --jnh **)
- X */
- Xvoid St_DelTable(st_P)
- Xst_Table_Pt st_P;
- X{
- X st_Entry_Pt entry_P;
- X int i;
- X
- X if (!st_P)
- X return;
- X
- X for (i = 0; i < st_P->size; i++)
- X for (entry_P = st_P->tab_A[i]; entry_P; entry_P = entry_P->next_P) {
- X free((char *) entry_P);
- X }
- X
- X if (strncmp(st_P->name, "_TNT_", ST_MAX_SYM_LEN))
- X St_DelSym(tnt_P, st_P->name);
- X
- X cfree((char *) st_P->tab_A);
- X cfree((char *) st_P);
- X
- X return;
- X
- X}
- X
- X
- X
- X
- X/*
- X * St_ListTable--
- X * Returns an unsorted list of symbols in the table. The list will be
- X * terminated with a NULL pointer. This routine frees the storage used by
- X * the last call to St_ListTable or St_SListTable; a call with a NULL
- X * argument is a convenient way to free storage allocated by a previous call.
- X */
- Xchar **St_ListTable(st_P)
- Xst_Table_Pt st_P;
- X{
- X
- X st_Entry_Pt entry_P;
- X int i, j;
- X static char **list_A = NULL,
- X *chars_P = NULL;
- X
- X if (list_A) {
- X free((char *) list_A);
- X free((char *) chars_P);
- X list_A = NULL;
- X chars_P = NULL;
- X }
- X
- X if (!st_P)
- X return NULL;
- X
- X list_A = (char **) malloc(sizeof(char *) * (st_P->entryCt + 1));
- X chars_P = (char *) malloc(sizeof(char) * ST_MAX_SYM_LEN * st_P->entryCt);
- X
- X for (i = 0; i < st_P->entryCt; i++)
- X list_A[i] = chars_P + ST_MAX_SYM_LEN * i;
- X list_A[st_P->entryCt] = NULL;
- X
- X j = 0;
- X for (i = 0; i < st_P->size; i++)
- X for (entry_P = st_P->tab_A[i]; entry_P; entry_P = entry_P->next_P)
- X strcpy(list_A[j++], entry_P->name);
- X
- X list_A[st_P->entryCt] = NULL;
- X
- X return list_A;
- X
- X}
- X
- X
- X/*
- X * St_SListTable--
- X * Returns a sorted list of symbols in a table. Otherwise is exactly
- X * like St_ListTable, above.
- X */
- Xchar **St_SListTable(st_P)
- Xst_Table_Pt st_P;
- X{
- X char **list_A;
- X
- X if (!(list_A = St_ListTable(st_P)))
- X return NULL;
- X
- X qsort(*list_A, st_P->entryCt, sizeof(char) * ST_MAX_SYM_LEN, strcmp);
- X
- X return list_A;
- X}
- X
- X
- X
- X/*
- X * St_GetSym--
- X * Look for a symbol in a table. Return type and ptr to val if found.
- X */
- Xint St_GetSym(st_P, name, type_P, gval_P)
- Xst_Table_Pt st_P;
- Xchar *name;
- Xint *type_P;
- Xgeneric_Pt gval_P;
- X{
- X st_Entry_Pt entry_P;
- X
- X if (!st_P)
- X return ST_NULL_TABLE;
- X
- X if (!(entry_P = LookupSym(st_P, name)))
- X return ST_SYM_NOT_FOUND;
- X
- X *type_P = entry_P->type;
- X *gval_P = entry_P->gval;
- X
- X return ST_SYM_FOUND;
- X}
- X
- X
- X
- X/*
- X * St_DefSym--
- X * Add a symbol to a table. Returns ST_SYM_FOUND and does nothing if
- X * name is already in table.
- X */
- Xint St_DefSym(st_P, name, type, gval)
- Xst_Table_Pt st_P;
- Xchar *name;
- Xint type;
- Xgeneric_t gval;
- X{
- X st_Entry_Pt entry_P;
- X
- X if (!st_P)
- X return ST_NULL_TABLE;
- X
- X if (LookupSym(st_P, name))
- X return ST_SYM_FOUND;
- X
- X entry_P = AddSym(st_P, name);
- X
- X /*
- X * Assign data.
- X */
- X
- X entry_P->type = type;
- X entry_P->gval = gval;
- X
- X return ST_SYM_NOT_FOUND;
- X
- X}
- X
- X
- X/*
- X * St_ReplSym--
- X * Add or supersede a symbol in a table.
- X */
- Xint St_ReplSym(st_P, name, type, gval)
- Xst_Table_Pt st_P;
- Xchar *name;
- Xint type;
- Xgeneric_t gval;
- X{
- X st_Entry_Pt entry_P;
- X int status;
- X
- X if (!st_P)
- X return ST_NULL_TABLE;
- X
- X if (!(entry_P = LookupSym(st_P, name))) {
- X entry_P = AddSym(st_P, name);
- X status = ST_SYM_NOT_FOUND;
- X } else {
- X status = ST_SYM_FOUND;
- X }
- X
- X /*
- X * Assign data.
- X */
- X
- X entry_P->type = type;
- X entry_P->gval = gval;
- X
- X return status;
- X}
- X
- X
- X
- X
- X/*
- X * St_DelSym--
- X * Delete a symbol from the table.
- X */
- Xint St_DelSym(st_P, name)
- Xst_Table_Pt st_P;
- Xchar *name;
- X{
- X st_Entry_Pt entry_P, last_P;
- X int h;
- X
- X if (!st_P)
- X return ST_NULL_TABLE;
- X
- X h = Hash(name, st_P->size);
- X
- X for (last_P = NULL, entry_P = st_P->tab_A[h]; entry_P;
- X last_P = entry_P, entry_P = entry_P->next_P)
- X if (!strncmp(entry_P->name, name, ST_MAX_SYM_LEN))
- X break;
- X
- X if (!entry_P)
- X return ST_SYM_NOT_FOUND;
- X
- X if (last_P)
- X last_P->next_P = entry_P->next_P;
- X else
- X st_P->tab_A[h] = NULL;
- X
- X cfree((char *) entry_P);
- X st_P->entryCt--;
- X
- X return ST_SYM_FOUND;
- X}
- X
- X
- X
- X/*
- X * St_GetTable--
- X * Get a table by name
- X */
- Xst_Table_Pt St_GetTable(name)
- Xchar *name;
- X{
- X int type;
- X generic_t gval;
- X
- X if (!tnt_P)
- X return NULL;
- X
- X if (St_GetSym(tnt_P, name, &type, &gval) != ST_SYM_FOUND)
- X return NULL;
- X
- X return (st_Table_Pt) gval.v;
- X}
- X
- X
- X/* -Jim Wilson-
- X * St_TableSize--
- X * Returns the number of entries in the table.
- X */
- Xint St_TableSize(st_P)
- Xst_Table_Pt st_P;
- X{
- X return st_P->entryCt;
- X}
- X
- X
- X/*
- X * St_DumpTable--
- X * Dump a table (for debugging or utility purposes)
- X */
- Xvoid St_DumpTable(output_F, st_P)
- XFILE *output_F;
- Xst_Table_Pt st_P;
- X{
- X st_Entry_Pt entry_P;
- X int bucket;
- X
- X if (!st_P) {
- X fprintf(output_F, "Table ptr is NULL.\n");
- X return;
- X }
- X
- X fprintf(output_F, "Dumping table '%s', size = %d, count = %d\n",
- X st_P->name, st_P->size, st_P->entryCt);
- X
- X for (bucket = 0; bucket < st_P->size; bucket++) {
- X
- X fprintf(output_F, " Bucket %d:\n", bucket);
- X
- X entry_P = st_P->tab_A[bucket];
- X
- X if (!entry_P) {
- X fprintf(output_F, " empty\n");
- X continue;
- X }
- X
- X while (entry_P) {
- X
- X switch(entry_P->type) {
- X
- X case GEN_TYPE_INT:
- X fprintf(output_F, " '%s' = %d (int)\n", entry_P->name,
- X entry_P->gval.i);
- X break;
- X
- X case GEN_TYPE_LONG:
- X fprintf(output_F, " '%s' = %ld (long)\n", entry_P->name,
- X entry_P->gval.l);
- X break;
- X
- X case GEN_TYPE_FLOAT:
- X fprintf(output_F, " '%s' = %e (float)\n", entry_P->name,
- X entry_P->gval.f);
- X break;
- X
- X case GEN_TYPE_DOUBLE:
- X fprintf(output_F, " '%s' = %e (double)\n",
- X entry_P->name, entry_P->gval.d);
- X break;
- X
- X case GEN_TYPE_CHAR:
- X fprintf(output_F, " '%s' = '%c'/%d (char)\n",
- X entry_P->name,
- X entry_P->gval.c, entry_P->gval.c);
- X break;
- X
- X case GEN_TYPE_STRING:
- X if (entry_P->gval.s)
- X fprintf(output_F, " '%s' = '%s' (string)\n",
- X entry_P->name, entry_P->gval.s);
- X else
- X fprintf(output_F, " '%s' = NULL (string)\n",
- X entry_P->name);
- X break;
- X
- X case GEN_TYPE_STRING_A:
- X
- X if (!entry_P->gval.s_A) {
- X fprintf(output_F, " '%s' = NULL (string array)\n",
- X entry_P->name);
- X } else {
- X char **s_A;
- X fprintf(output_F, " '%s' is string array:\n",
- X entry_P->name);
- X for (s_A = entry_P->gval.s_A; *s_A; s_A++)
- X fprintf(output_F, " '%s'\n", *s_A);
- X }
- X break;
- X
- X case GEN_TYPE_VOID_PTR:
- X if (entry_P->gval.v)
- X fprintf(output_F, " '%s' is user type (void ptr)\n",
- X entry_P->name);
- X else
- X fprintf(output_F, " '%s' is NULL user type (void ptr)\n",
- X entry_P->name);
- X break;
- X
- X default:
- X fprintf(output_F, " '%s' is unknown type\n", entry_P->name);
- X break;
- X
- X }
- X
- X entry_P = entry_P->next_P;
- X
- X }
- X
- X }
- X
- X return;
- X}
- X
- X
- X
- X#ifdef _TESTING_
- X
- Xmain()
- X{
- X st_Table_Pt st_P;
- X generic_t gval;
- X int type;
- X static char *s_A[] = {"Joe", "Bloe", NULL};
- X char **list_A;
- X
- X st_P = St_NewTable("Test", 3);
- X
- X gval.i = 10;
- X St_DefSym(st_P, "A", GEN_TYPE_INT, gval);
- X
- X gval.d = 3.14;
- X St_DefSym(st_P, "PI", GEN_TYPE_DOUBLE, gval);
- X
- X gval.i = 1;
- X St_DefSym(st_P, "ONE", GEN_TYPE_INT, gval);
- X
- X gval.s = "Testing!";
- X St_DefSym(st_P, "TESTING", GEN_TYPE_STRING, gval);
- X
- X gval.c = 7;
- X St_DefSym(st_P, "BELL", GEN_TYPE_CHAR, gval);
- X
- X gval.s_A = s_A;
- X St_DefSym(st_P, "JOE BLOE", GEN_TYPE_STRING_A, gval);
- X
- X St_GetSym(st_P, "A", &type, &gval);
- X printf("A = %d, type = %d\n", gval.i, type);
- X
- X St_GetSym(st_P, "PI", &type, &gval);
- X printf("PI = %f, type = %d\n", gval.d, type);
- X
- X St_DumpTable(stdout, St_GetTable("Test"));
- X
- X St_DelSym(st_P, "TESTING");
- X
- X St_DumpTable(stdout, St_GetTable("Test"));
- X
- X St_DelSym(st_P, "PI");
- X
- X gval.s = "Joe Bloe";
- X St_ReplSym(st_P, "JOE BLOE", GEN_TYPE_STRING, gval);
- X gval.s = "Jane Bloe";
- X St_ReplSym(st_P, "JANE BLOE", GEN_TYPE_STRING, gval);
- X
- X St_DumpTable(stdout, St_GetTable("Test"));
- X
- X list_A = St_ListTable(St_GetTable("Test"));
- X
- X while (*list_A)
- X printf("'%s'\n", *list_A++);
- X
- X list_A = St_SListTable(St_GetTable("Test"));
- X
- X while (*list_A)
- X printf("'%s'\n", *list_A++);
- X
- X return 0;
- X}
- X
- X#endif
- END_OF_FILE
- if test 12502 -ne `wc -c <'util/mc/symtab.c'`; then
- echo shar: \"'util/mc/symtab.c'\" unpacked with wrong size!
- fi
- # end of 'util/mc/symtab.c'
- fi
- echo shar: End of archive 25 \(of 31\).
- cp /dev/null ark25isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 31 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
-