games-request@tekred.TEK.COM (11/05/87)
Submitted by: "James E. Wilson" <wilson@ji.berkeley.edu>
Comp.sources.games: Volume 2, Issue 79
Archive-name: umoria/Part14
#! /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 14 (of 16)."
# Contents: files.c generate.c
# Wrapped by billr@tekred on Wed Nov 4 10:00:13 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f files.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"files.c\"
else
echo shar: Extracting \"files.c\" \(25891 characters\)
sed "s/^X//" >files.c <<'END_OF_files.c'
X#include <stdio.h>
X#ifdef USG
X#include <string.h>
X#include <fcntl.h>
X#else
X#include <strings.h>
X#include <sys/file.h>
X#endif
X
X#include "config.h"
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#if defined(ultrix) || defined(USG)
Xvoid exit();
X#endif
X
X/*
X * init_scorefile
X * Open the score file while we still have the setuid privileges. Later
X * when the score is being written out, you must be sure to flock the file
X * so we don't have multiple people trying to write to it at the same time.
X * Craig Norborg (doc) Mon Aug 10 16:41:59 EST 1987
X */
Xinit_scorefile()
X{
X if (1 > (highscore_fd = open(MORIA_TOP, O_RDWR | O_CREAT, 0644)))
X {
X (void) fprintf(stderr, "Can't open score file!\n");
X exit(1);
X }
X}
X
X/* Attempt to open the intro file -RAK- */
X/* This routine also checks the hours file vs. what time it is -Doc */
Xintro(finam)
Xchar *finam;
X{
X int xpos, i;
X vtype in_line;
X FILE *file1;
X char *string;
X
X /* Attempt to read hours.dat. If it does not exist, */
X /* inform the user so he can tell the wizard about it */
X if ((file1 = fopen(MORIA_HOU, "r")) != NULL)
X {
X while (fgets(in_line, 80, file1) != NULL)
X if (strlen(in_line) > 3)
X {
X if (!strncmp(in_line, "SUN:", 4))
X (void) strcpy(days[0], in_line);
X else if (!strncmp(in_line, "MON:", 4))
X (void) strcpy(days[1], in_line);
X else if (!strncmp(in_line, "TUE:", 4))
X (void) strcpy(days[2], in_line);
X else if (!strncmp(in_line, "WED:", 4))
X (void) strcpy(days[3], in_line);
X else if (!strncmp(in_line, "THU:", 4))
X (void) strcpy(days[4], in_line);
X else if (!strncmp(in_line, "FRI:", 4))
X (void) strcpy(days[5], in_line);
X else if (!strncmp(in_line, "SAT:", 4))
X (void) strcpy(days[6], in_line);
X }
X (void) fclose(file1);
X }
X else
X {
X (void) fprintf(stderr, "There is no hours file.\nPlease inform the wizard, %s, so he can correct this!\n", WIZARD);
X exit_game();
X }
X
X /* Check the hours, if closed require password */
X string = index(finam, '^');
X if (string)
X xpos = strlen(finam) - strlen(string);
X else
X xpos = -1;
X if (xpos >= 0)
X if (check_pswd())
X insert_str(finam, "^", "");
X if (!check_time())
X {
X if (!wizard1)
X {
X if ((file1 = fopen(MORIA_HOU, "r")) != NULL)
X {
X clear_screen(0, 0);
X for (i = 0; fgets(in_line, 80, file1) != NULL; i++)
X prt(in_line, i, 0);
X (void) fclose(file1);
X }
X exit_game();
X }
X }
X
X /* Print the introduction message, news, ect... */
X if ((file1 = fopen(MORIA_MOR, "r")) != NULL)
X {
X clear_screen(0, 0);
X for (i = 0; fgets(in_line, 80, file1) != NULL; i++)
X prt(in_line, i, 0);
X pause_line(23);
X (void) fclose(file1);
X }
X}
X
X
X/* Prints dungeon map to external file -RAK- */
Xprint_map()
X{
X int i, j, k, l, m, n, i7, i8;
X char dun_line[MAX_WIDTH];
X vtype filename1;
X char tmp;
X char tmp_str[80];
X FILE *file1;
X int page_width = OUTPAGE_WIDTH;
X int page_height = OUTPAGE_HEIGHT;
X
X prt("File name: ", 0, 0);
X if (get_string(filename1, 0, 11, 64))
X {
X if (strlen(filename1) == 0)
X (void) strcpy(filename1, "MORIAMAP.DAT");
X if ((file1 = fopen(filename1, "w")) == NULL)
X {
X (void) sprintf(dun_line, "Cannot open file %s", filename1);
X prt(dun_line, 0, 0);
X put_qio();
X return;
X }
X (void) sprintf(tmp_str, "section width (default = %d char):", page_width);
X prt(tmp_str, 0, 0);
X (void) get_string(tmp_str, 0, strlen(tmp_str), 10);
X (void) sscanf(tmp_str, "%d", &page_width);
X if (page_width < 10)
X page_width = 10;
X
X (void) sprintf(tmp_str, "section height (default = %d lines):", page_height);
X prt(tmp_str, 0, 0);
X (void) get_string(tmp_str, 0, strlen(tmp_str), 10);
X (void) sscanf(tmp_str, "%d", &page_height);
X if (page_height < 10)
X page_height = 10;
X
X prt("Writing Moria Dungeon Map...", 0, 0);
X put_qio();
X
X i = 0;
X i7 = 0;
X do
X {
X j = 0;
X k = i + page_height - 1;
X if (k >= cur_height)
X k = cur_height - 1;
X i7++;
X i8 = 0;
X do
X {
X l = j + page_width - 1;
X if (l >= cur_width)
X l = cur_width - 1;
X i8++;
X (void) fprintf(file1, "%c\n", 12);
X (void) fprintf(file1, "Section[%d,%d]; ", i7, i8);
X (void) fprintf(file1, "Depth : %d (feet)\n", (dun_level * 50));
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, " ");
X for (m = j; m <= l; m++)
X {
X n = (m / 100);
X (void) fprintf(file1, "%d", n);
X }
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, " ");
X for (m = j; m <= l; m++)
X {
X n = (m / 10) - (m / 100) * 10;
X (void) fprintf(file1, "%d", n);
X }
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, " ");
X for (m = j; m <= l; m++)
X {
X n = m - (m / 10) * 10;
X (void) fprintf(file1, "%d", n);
X }
X (void) fprintf(file1, "\n");
X for (m = i; m <= k; m++)
X {
X (void) sprintf(dun_line, "%2d ", m);
X for (n = j; n <= l; n++)
X {
X if (test_light(m, n))
X loc_symbol(m, n, &tmp);
X else
X tmp = ' ';
X (void) sprintf(dun_line, "%s%c", dun_line, tmp);
X }
X (void) fprintf(file1, "%s\n", dun_line);
X }
X j += page_width;
X }
X while (j < cur_width);
X i += page_height;
X }
X while (i < cur_height);
X (void) fclose(file1);
X prt("Completed.", 0, 0);
X }
X}
X
X
X/* Prints a list of random objects to a file. Note that -RAK- */
X/* the objects produced is a sampling of objects which */
X/* be expected to appear on that level. */
Xprint_objects()
X{
X int nobj, i, j, level;
X vtype filename1, tmp_str;
X FILE *file1;
X treasure_type *i_ptr;
X
X prt("Produce objects on what level?: ", 0, 0);
X level = 0;
X if (get_string(tmp_str, 0, 32, 10))
X (void) sscanf(tmp_str, "%d", &level);
X prt("Produce how many objects?: ", 0, 0);
X nobj = 0;
X if (!get_string(tmp_str, 0, 27, 10))
X (void) sscanf(tmp_str, "%d", &nobj);
X if ((nobj > 0) && (level > -1) && (level < 1201))
X {
X if (nobj > 9999)
X nobj = 9999;
X prt("File name: ", 0, 0);
X if (get_string(filename1, 0, 11, 64))
X {
X if (strlen(filename1) == 0)
X (void) strcpy(filename1, "MORIAOBJ.DAT");
X if ((file1 = fopen(filename1, "w")) != NULL)
X {
X (void) sprintf(tmp_str, "%d", nobj);
X prt(strcat(tmp_str, " random objects being produced..."), 0, 0);
X put_qio();
X (void) fprintf(file1, "*** Random Object Sampling:\n");
X (void) fprintf(file1, "*** %d objects\n", nobj);
X (void) fprintf(file1, "*** For Level %d\n", level);
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X popt(&j);
X for (i = 0; i < nobj; i++)
X {
X t_list[j] = object_list[get_obj_num(level)];
X magic_treasure(j, level);
X inventory[INVEN_MAX] = t_list[j];
X i_ptr = &inventory[INVEN_MAX];
X unquote(i_ptr->name);
X known1(i_ptr->name);
X known2(i_ptr->name);
X objdes(tmp_str, INVEN_MAX, TRUE);
X (void) fprintf(file1, "%s\n", tmp_str);
X }
X pusht(j);
X (void) fclose(file1);
X prt("Completed.", 0, 0);
X }
X else
X prt("File could not be opened.", 0, 0);
X }
X }
X}
X
X
X/* Prints a listing of monsters -RAK- */
Xprint_monsters()
X{
X int i, j, xpos, attype, adesc;
X FILE *file1;
X vtype out_val, filename1;
X vtype attstr, attx;
X dtype damstr;
X creature_type *c_ptr;
X char *string;
X
X prt("File name: ", 0, 0);
X if (get_string(filename1, 0, 11, 64))
X {
X if (strlen(filename1) == 0)
X (void) strcpy(filename1, "MORIAMON.DAT");
X if ((file1 = fopen(filename1, "w")) != NULL)
X {
X prt("Writing Monster Dictionary...", 0, 0);
X put_qio();
X for (i = 0; i < MAX_CREATURES; i++)
X {
X c_ptr = &c_list[i];
X /* Begin writing to file */
X (void) fprintf(file1, "--------------------------------------------\n");
X (void) strcpy(out_val, c_ptr->name);
X (void) strcat(out_val, " ");
X (void) fprintf(file1, "%d %s (%c)\n", i, out_val, c_ptr->cchar);
X (void) fprintf(file1, " Speed ==%d Level ==%d Exp ==%d\n",
X c_ptr->speed, c_ptr->level, (int)c_ptr->mexp);
X (void) fprintf(file1, " AC ==%d Eye-sight ==%d HD ==%s\n",
X c_ptr->ac, c_ptr->aaf, c_ptr->hd);
X if (0x80000000 & c_ptr->cmove)
X (void) fprintf(file1, " Creature is a ***Win Creature***\n");
X if (0x00080000 & c_ptr->cmove)
X (void) fprintf(file1, " Creature Eats/kills other creatures.\n");
X if (0x0001 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature is a dragon.\n");
X if (0x0002 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature is a monster.\n");
X if (0x0004 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature is evil.\n");
X if (0x0008 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature is undead.\n");
X if (0x0010 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature harmed by cold.\n");
X if (0x0020 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature harmed by fire.\n");
X if (0x0040 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature harmed by poison.\n");
X if (0x0080 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature harmed by acid.\n");
X if (0x0100 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature harmed by blue light.\n");
X if (0x0200 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature harmed by Stone-to-Mud.\n");
X if (0x1000 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature cannot be charmed or slept.\n");
X if (0x2000 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature seen with Infra-Vision.\n");
X if (0x4000 & c_ptr->cdefense)
X (void) fprintf(file1, " Creature has MAX hit points.\n");
X if (0x00010000 & c_ptr->cmove)
X (void) fprintf(file1, " Creature is invisible.\n");
X if (0x00100000 & c_ptr->cmove)
X (void) fprintf(file1, " Creature picks up objects.\n");
X if (0x00200000 & c_ptr->cmove)
X (void) fprintf(file1, " Creature multiplies.\n");
X if (0x01000000 & c_ptr->cmove)
X (void) fprintf(file1, " Carries object(s).\n");
X if (0x02000000 & c_ptr->cmove)
X (void) fprintf(file1, " Carries gold, gems, etc.\n");
X if (0x04000000 & c_ptr->cmove)
X (void) fprintf(file1, " Has object/gold 60%% of time.\n");
X if (0x08000000 & c_ptr->cmove)
X (void) fprintf(file1, " Has object/gold 90%% of time.\n");
X if (0x10000000 & c_ptr->cmove)
X (void) fprintf(file1, " Has 1d2 object(s)/gold.\n");
X if (0x20000000 & c_ptr->cmove)
X (void) fprintf(file1, " Has 2d2 object(s)/gold.\n");
X if (0x40000000 & c_ptr->cmove)
X (void) fprintf(file1, " Has 4d2 object(s)/gold.\n");
X /*
X * Creature casts spells / Breaths Dragon
X * breath...
X */
X if (c_ptr->spells != 0)
X {
X (void) fprintf(file1, " --Spells/Dragon Breath ==\n");
X (void) fprintf(file1, " Casts spells 1 out of %d turns.\n",
X (int)(0xF & c_ptr->spells));
X if (0x00000010 & c_ptr->spells)
X (void) fprintf(file1, " Can teleport short.\n");
X if (0x00000020 & c_ptr->spells)
X (void) fprintf(file1, " Can teleport long.\n");
X if (0x00000040 & c_ptr->spells)
X (void) fprintf(file1, " Teleport player to itself.\n");
X if (0x00000080 & c_ptr->spells)
X (void) fprintf(file1, " Cause light wounds.\n");
X if (0x00000100 & c_ptr->spells)
X (void) fprintf(file1, " Cause serious wounds.\n");
X if (0x00000200 & c_ptr->spells)
X (void) fprintf(file1, " Hold person.\n");
X if (0x00000400 & c_ptr->spells)
X (void) fprintf(file1, " Cause blindness.\n");
X if (0x00000800 & c_ptr->spells)
X (void) fprintf(file1, " Cause confusion.\n");
X if (0x00001000 & c_ptr->spells)
X (void) fprintf(file1, " Cause fear.\n");
X if (0x00002000 & c_ptr->spells)
X (void) fprintf(file1, " Summon a monster.\n");
X if (0x00004000 & c_ptr->spells)
X (void) fprintf(file1, " Summon an undead.\n");
X if (0x00008000 & c_ptr->spells)
X (void) fprintf(file1, " Slow person.\n");
X if (0x00010000 & c_ptr->spells)
X (void) fprintf(file1, " Drains mana for healing.\n");
X if (0x00020000 & c_ptr->spells)
X (void) fprintf(file1, " **Unknown spell value**\n");
X if (0x00040000 & c_ptr->spells)
X (void) fprintf(file1, " **Unknown spell value**\n");
X if (0x00080000 & c_ptr->spells)
X (void) fprintf(file1, " Breaths Lightning Dragon Breath.\n");
X if (0x00100000 & c_ptr->spells)
X (void) fprintf(file1, " Breaths Gas Dragon Breath.\n");
X if (0x00200000 & c_ptr->spells)
X (void) fprintf(file1, " Breaths Acid Dragon Breath.\n");
X if (0x00400000 & c_ptr->spells)
X (void) fprintf(file1, " Breaths Frost Dragon Breath.\n");
X if (0x00800000 & c_ptr->spells)
X (void) fprintf(file1, " Breaths Fire Dragon Breath.\n");
X }
X /* Movement for creature */
X (void) fprintf(file1, " --Movement ==\n");
X if (0x00000001 & c_ptr->cmove)
X (void) fprintf(file1, " Move only to attack.\n");
X if (0x00000002 & c_ptr->cmove)
X (void) fprintf(file1, " Move and attack normally.\n");
X if (0x00000008 & c_ptr->cmove)
X (void) fprintf(file1, " 20%% random movement.\n");
X if (0x00000010 & c_ptr->cmove)
X (void) fprintf(file1, " 40%% random movement.\n");
X if (0x00000020 & c_ptr->cmove)
X (void) fprintf(file1, " 75%% random movement.\n");
X if (0x00020000 & c_ptr->cmove)
X (void) fprintf(file1, " Can open doors.\n");
X if (0x00040000 & c_ptr->cmove)
X (void) fprintf(file1, " Can phase through walls.\n");
X
X (void) fprintf(file1, " --Creature attacks ==\n");
X (void) strcpy(attstr, c_ptr->damage);
X while (strlen(attstr) > 0)
X {
X string = index(attstr, '|');
X if (string)
X xpos = strlen(attstr) - strlen(string);
X else
X xpos = -1;
X if (xpos >= 0)
X {
X (void) strncpy(attx, attstr, xpos);
X attx[xpos] = '\0';
X (void) strcpy(attstr, &attstr[xpos + 1]);
X }
X else
X {
X (void) strcpy(attx, attstr);
X (void) strcpy(attstr, "");
X }
X (void) sscanf(attx, "%d%d%s", &attype, &adesc, damstr);
X (void) strcpy(out_val, "");
X switch (adesc)
X {
X case 1:
X (void) strcpy(out_val, " Hits for ");
X break;
X case 2:
X (void) strcpy(out_val, " Bites for ");
X break;
X case 3:
X (void) strcpy(out_val, " Claws for ");
X break;
X case 4:
X (void) strcpy(out_val, " Stings for ");
X break;
X case 5:
X (void) strcpy(out_val, " Touches for ");
X break;
X case 6:
X (void) strcpy(out_val, " Kicks for ");
X break;
X case 7:
X (void) strcpy(out_val, " Gazes for ");
X break;
X case 8:
X (void) strcpy(out_val, " Breathes for ");
X break;
X case 9:
X (void) strcpy(out_val, " Spits for ");
X break;
X case 10:
X (void) strcpy(out_val, " Wails for ");
X break;
X case 11:
X (void) strcpy(out_val, " Embraces for ");
X break;
X case 12:
X (void) strcpy(out_val, " Crawls on you for ");
X break;
X case 13:
X (void) strcpy(out_val, " Shoots spores for ");
X break;
X case 14:
X (void) strcpy(out_val, " Begs for money for ");
X break;
X case 15:
X (void) strcpy(out_val, " Slimes you for ");
X break;
X case 16:
X (void) strcpy(out_val, " Crushes you for ");
X break;
X case 17:
X (void) strcpy(out_val, " Tramples you for ");
X break;
X case 18:
X (void) strcpy(out_val, " Drools on you for ");
X break;
X case 19:
X (void) strcpy(out_val, " Insults you for ");
X break;
X case 99:
X (void) strcpy(out_val, " Is repelled...");
X break;
X default:
X (void) strcpy(out_val, " **Unknown value** ");
X break;
X }
X switch (attype)
X {
X case 1:
X (void) strcat(out_val, "normal damage.");
X break;
X case 2:
X (void) strcat(out_val, "lowering strength.");
X break;
X case 3:
X (void) strcat(out_val, "confusion.");
X break;
X case 4:
X (void) strcat(out_val, "fear.");
X break;
X case 5:
X (void) strcat(out_val, "fire damage.");
X break;
X case 6:
X (void) strcat(out_val, "acid damage.");
X break;
X case 7:
X (void) strcat(out_val, "cold damage.");
X break;
X case 8:
X (void) strcat(out_val, "lightning damage.");
X break;
X case 9:
X (void) strcat(out_val, "corrosion damage.");
X break;
X case 10:
X (void) strcat(out_val, "blindness.");
X break;
X case 11:
X (void) strcat(out_val, "paralyzation.");
X break;
X case 12:
X (void) strcat(out_val, "stealing money.");
X break;
X case 13:
X (void) strcat(out_val, "stealing object.");
X break;
X case 14:
X (void) strcat(out_val, "poison damage.");
X break;
X case 15:
X (void) strcat(out_val, "lose dexterity.");
X break;
X case 16:
X (void) strcat(out_val, "lose constitution.");
X break;
X case 17:
X (void) strcat(out_val, "lose intelligence.");
X break;
X case 18:
X (void) strcat(out_val, "lose wisdom.");
X break;
X case 19:
X (void) strcat(out_val, "lose experience.");
X break;
X case 20:
X (void) strcat(out_val, "aggravates monsters.");
X break;
X case 21:
X (void) strcat(out_val, "disenchants objects.");
X break;
X case 22:
X (void) strcat(out_val, "eating food.");
X break;
X case 23:
X (void) strcat(out_val, "eating light source.");
X break;
X case 24:
X (void) strcat(out_val, "absorbing charges.");
X break;
X case 99:
X (void) strcat(out_val, "blank message.");
X break;
X default:
X (void) strcat(out_val, "**Unknown value**");
X break;
X }
X (void) fprintf(file1, "%s (%s)\n", out_val, damstr);
X }
X for (j = 0; j < 2; j++)
X (void) fprintf(file1, "\n");
X }
X /* End writing to file */
X (void) fclose(file1);
X prt("Completed.", 0, 0);
X }
X }
X}
X
X
X/* Print the character to a file or device -RAK- */
Xfile_character()
X{
X int i, j, xbth, xbthb, xfos, xsrh, xstl, xdis;
X int xsave, xdev;
X vtype xinfra;
X FILE *file1;
X vtype out_val, filename1, prt1, prt2;
X stat_type out_str, out_int, out_wis, out_dex, out_con, out_chr;
X struct misc *p_ptr;
X treasure_type *i_ptr;
X
X prt("File name: ", 0, 0);
X if (get_string(filename1, 0, 11, 64))
X {
X if (strlen(filename1) == 0)
X (void) strcpy(filename1, "MORIACHR.DAT");
X if ((file1 = fopen(filename1, "w")) != NULL)
X {
X prt("Writing character sheet...", 0, 0);
X put_qio();
X (void) fprintf(file1, "%c", 12);
X cnv_stat(py.stats.cstr, out_str);
X cnv_stat(py.stats.cint, out_int);
X cnv_stat(py.stats.cwis, out_wis);
X cnv_stat(py.stats.cdex, out_dex);
X cnv_stat(py.stats.ccon, out_con);
X cnv_stat(py.stats.cchr, out_chr);
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, " Name :%s", pad(py.misc.name, " ", 25));
X (void) fprintf(file1, " Age :%4d", (int)py.misc.age);
X (void) fprintf(file1, " Strength :%s\n", out_str);
X (void) fprintf(file1, " Race :%s", pad(py.misc.race, " ", 25));
X (void) fprintf(file1, " Height :%4d", (int)py.misc.ht);
X (void) fprintf(file1, " Intelligence :%s\n", out_int);
X (void) fprintf(file1, " Sex :%s", pad(py.misc.sex, " ", 25));
X (void) fprintf(file1, " Weight :%4d", (int)py.misc.wt);
X (void) fprintf(file1, " Wisdom :%s\n", out_wis);
X (void) fprintf(file1, " Class :%s", pad(py.misc.tclass, " ", 25));
X (void) fprintf(file1, " Social Class:%4d", py.misc.sc);
X (void) fprintf(file1, " Dexterity :%s\n", out_dex);
X (void) fprintf(file1, " Title :%s", pad(py.misc.title, " ", 25));
X (void) fprintf(file1, " ");
X (void) fprintf(file1, " Constitution :%s\n", out_con);
X (void) fprintf(file1, " ");
X (void) fprintf(file1, " ");
X (void) fprintf(file1, " Charisma :%s\n", out_chr);
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X
X (void) fprintf(file1, " + To Hit :%6d", py.misc.dis_th);
X (void) fprintf(file1, " Level :%6d", (int)py.misc.lev);
X (void) fprintf(file1, " Max Hit Points :%6d\n", py.misc.mhp);
X (void) fprintf(file1, " + To Damage :%6d", py.misc.dis_td);
X (void) fprintf(file1, " Experience :%6d", py.misc.exp);
X (void) fprintf(file1, " Cur Hit Points :%6d\n", (int) (py.misc.chp));
X (void) fprintf(file1, " + To AC :%6d", py.misc.dis_tac);
X (void) fprintf(file1, " Gold :%6d", py.misc.au);
X (void) fprintf(file1, " Max Mana :%6d\n", py.misc.mana);
X (void) fprintf(file1, " Total AC :%6d", py.misc.dis_ac);
X (void) fprintf(file1, " ");
X (void) fprintf(file1, " Cur Mana :%6d\n", (int) (py.misc.cmana));
X
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X p_ptr = &py.misc;
X xbth = p_ptr->bth + p_ptr->lev * BTH_LEV_ADJ +
X p_ptr->ptohit * BTH_PLUS_ADJ;
X xbthb = p_ptr->bthb + p_ptr->lev * BTH_LEV_ADJ +
X p_ptr->ptohit * BTH_PLUS_ADJ;
X xfos = 27 - p_ptr->fos;
X if (xfos < 0)
X xfos = 0;
X xsrh = p_ptr->srh + int_adj();
X xstl = p_ptr->stl;
X xdis = p_ptr->disarm + p_ptr->lev + 2 * todis_adj() + int_adj();
X xsave = p_ptr->save + p_ptr->lev + wis_adj();
X xdev = p_ptr->save + p_ptr->lev + int_adj();
X (void) sprintf(xinfra, "%d feet", py.flags.see_infra * 10);
X
X (void) fprintf(file1, "(Miscellaneous Abilities)\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, " Fighting : %s", pad(likert(xbth, 12), " ", 10));
X (void) fprintf(file1, " Stealth : %s", pad(likert(xstl, 1), " ", 10));
X (void) fprintf(file1, " Perception : %s\n", pad(likert(xfos, 3), " ", 10));
X (void) fprintf(file1, " Throw/Bows : %s", pad(likert(xbthb, 12), " ", 10));
X (void) fprintf(file1, " Disarming : %s", pad(likert(xdis, 8), " ", 10));
X (void) fprintf(file1, " Searching : %s\n", pad(likert(xsrh, 6), " ", 10));
X (void) fprintf(file1, " Saving Throw: %s", pad(likert(xsave, 6), " ", 10));
X (void) fprintf(file1, " Magic Device: %s", pad(likert(xdev, 7), " ", 10));
X (void) fprintf(file1, " Infra-Vision: %s\n", pad(xinfra, " ", 10));
X /* Write out the character's history */
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "Character Background\n");
X for (i = 0; i < 5; i++)
X (void) fprintf(file1, "%s\n", pad(py.misc.history[i], " ", 71));
X /* Write out the equipment list... */
X j = 0;
X (void) fprintf(file1, " ");
X (void) fprintf(file1, " ");
X (void) fprintf(file1, " [Character's Equipment List]\n");
X (void) fprintf(file1, "\n");
X if (equip_ctr == 0)
X (void) fprintf(file1, " Character has no equipment in use.\n");
X else
X for (i = 22; i < INVEN_MAX; i++)
X {
X i_ptr = &inventory[i];
X if (i_ptr->tval != 0)
X {
X switch (i)
X {
X case 22:
X (void) strcpy(prt1, ") You are wielding : ");
X break;
X case 23:
X (void) strcpy(prt1, ") Worn on head : ");
X break;
X case 24:
X (void) strcpy(prt1, ") Worn around neck : ");
X break;
X case 25:
X (void) strcpy(prt1, ") Worn on body : ");
X break;
X case 26:
X (void) strcpy(prt1, ") Worn on shield arm : ");
X break;
X case 27:
X (void) strcpy(prt1, ") Worn on hands : ");
X break;
X case 28:
X (void) strcpy(prt1, ") Right ring finger : ");
X break;
X case 29:
X (void) strcpy(prt1, ") Left ring finger : ");
X break;
X case 30:
X (void) strcpy(prt1, ") Worn on feet : ");
X break;
X case 31:
X (void) strcpy(prt1, ") Worn about body : ");
X break;
X case 32:
X (void) strcpy(prt1, ") Light source is : ");
X break;
X case 33:
X (void) strcpy(prt1, ") Secondary weapon : ");
X break;
X default:
X (void) strcpy(prt1, ") *Unknown value* : ");
X break;
X }
X j++;
X objdes(prt2, i, TRUE);
X (void) sprintf(out_val, " %c%s%s", j + 97, prt1, prt2);
X (void) fprintf(file1, "%s\n", out_val);
X }
X }
X
X /* Write out the character's inventory... */
X (void) fprintf(file1, "%c", 12);
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, "\n");
X (void) fprintf(file1, " [General Inventory List]\n");
X (void) fprintf(file1, "\n");
X if (inven_ctr == 0)
X (void) fprintf(file1, " Character has no objects in inventory.\n");
X else
X {
X for (i = 0; i < inven_ctr; i++)
X {
X objdes(prt1, i, TRUE);
X (void) sprintf(out_val, "%c) %s", i + 97, prt1);
X (void) fprintf(file1, "%s\n", out_val);
X }
X }
X (void) fprintf(file1, "%c", 12);
X (void) fclose(file1);
X prt("Completed.", 0, 0);
X }
X }
X}
END_OF_files.c
if test 25891 -ne `wc -c <files.c`; then
echo shar: \"files.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f generate.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"generate.c\"
else
echo shar: Extracting \"generate.c\" \(26506 characters\)
sed "s/^X//" >generate.c <<'END_OF_generate.c'
X#include "constants.h"
X#include "types.h"
X#include "externs.h"
X
Xtypedef struct coords {
X int x, y;
X} coords;
X
Xcoords doorstk[100];
Xint doorptr;
X
X
X/* Always picks a correct direction */
Xcorrect_dir(rdir, cdir, y1, x1, y2, x2)
Xint *rdir, *cdir;
Xint y1, x1, y2, x2;
X{
X if (y1 < y2)
X *rdir = 1;
X else if (y1 == y2)
X *rdir = 0;
X else
X *rdir = -1;
X if (x1 < x2)
X *cdir = 1;
X else if (x1 == x2)
X *cdir = 0;
X else
X *cdir = -1;
X if ((*rdir != 0) && (*cdir != 0))
X switch(randint(2))
X {
X case 1:
X *rdir = 0;
X break;
X case 2:
X *cdir = 0;
X break;
X }
X}
X
X
X/* Chance of wandering direction */
Xrand_dir(rdir, cdir, y1, x1, y2, x2, chance)
Xint *rdir, *cdir;
Xint y1, x1, y2, x2;
Xint chance;
X{
X switch(randint(chance))
X {
X case 1:
X *rdir = -1;
X *cdir = 0;
X break;
X case 2:
X *rdir = 1;
X *cdir = 0;
X break;
X case 3:
X *rdir = 0;
X *cdir = -1;
X break;
X case 4:
X *rdir = 0;
X *cdir = 1;
X break;
X default:
X correct_dir(rdir, cdir, y1, x1, y2, x2);
X break;
X }
X}
X
X
X/* Blanks out entire cave -RAK- */
Xblank_cave()
X{
X int i, j;
X
X for (i = 0; i < MAX_HEIGHT; i++)
X for (j = 0; j < MAX_WIDTH; j++)
X cave[i][j] = blank_floor;
X}
X
X
X/* Fills in empty spots with desired rock -RAK- */
X/* Note: 9 is a temporary value. */
Xfill_cave(fill)
Xfloor_type fill;
X{
X int i, j;
X cave_type *c_ptr;
X
X for (i = 1; i < cur_height-1; i++)
X for (j = 1; j < cur_width-1; j++)
X {
X c_ptr = &cave[i][j];
X if ((c_ptr->fval == 0) || (c_ptr->fval == 8) || (c_ptr->fval == 9))
X {
X c_ptr->fval = fill.ftval;
X c_ptr->fopen = fill.ftopen;
X }
X }
X}
X
X
X/* Places indestructible rock around edges of dungeon -RAK- */
Xplace_boundary()
X{
X int i;
X
X for (i = 0; i < cur_height; i++)
X {
X cave[i][0].fval = boundary_wall.ftval;
X cave[i][0].fopen = boundary_wall.ftopen;
X cave[i][cur_width-1].fval = boundary_wall.ftval;
X cave[i][cur_width-1].fopen = boundary_wall.ftopen;
X }
X for (i = 0; i < cur_width; i++)
X {
X cave[0][i].fval = boundary_wall.ftval;
X cave[0][i].fopen = boundary_wall.ftopen;
X cave[cur_height-1][i].fval = boundary_wall.ftval;
X cave[cur_height-1][i].fopen = boundary_wall.ftopen;
X }
X}
X
X
X/* Places "streamers" of rock through dungeon -RAK- */
Xplace_streamer(rock, treas_chance)
Xfloor_type rock;
Xint treas_chance;
X{
X int i, y, x, dir, ty, tx, t1, t2;
X int flag;
X cave_type *c_ptr;
X
X /* Choose starting point and direction */
X y = (cur_height/2.0) + 11 - randint(23);
X x = (cur_width/2.0) + 16 - randint(33);
X
X dir = randint(8); /* Number 1-4, 6-9 */
X if (dir > 4)
X dir = dir + 1;
X
X /* Place streamer into dungeon */
X flag = FALSE; /* Set to true when y, x are out-of-bounds*/
X t1 = 2*DUN_STR_RNG + 1; /* Constants */
X t2 = DUN_STR_RNG + 1;
X do
X {
X for (i = 0; i < DUN_STR_DEN; i++)
X {
X ty = y + randint(t1) - t2;
X tx = x + randint(t1) - t2;
X if (in_bounds(ty, tx))
X {
X c_ptr = &cave[ty][tx];
X if (c_ptr->fval == rock_wall1.ftval)
X {
X c_ptr->fval = rock.ftval;
X c_ptr->fopen = rock.ftopen;
X if (randint(treas_chance) == 1)
X place_gold(ty, tx);
X }
X }
X }
X if (!move(dir, &y, &x))
X flag = TRUE;
X }
X while (!flag);
X}
X
X
X/* Place a trap with a given displacement of point -RAK- */
Xvault_trap(y, x, yd, xd, num)
Xint y, x, yd, xd, num;
X{
X int count, y1, x1, i;
X int flag;
X cave_type *c_ptr;
X
X for (i = 0; i < num; i++)
X {
X flag = FALSE;
X count = 0;
X do
X {
X y1 = y - yd - 1 + randint(2*yd+1);
X x1 = x - xd - 1 + randint(2*xd+1);
X c_ptr = &cave[y1][x1];
X if ((c_ptr->fval > 0) && (c_ptr->fval < 8) && (c_ptr->fval != 3))
X if (c_ptr->tptr == 0)
X {
X place_trap(y1, x1, 1, randint(MAX_TRAPA));
X flag = TRUE;
X }
X count++;
X }
X while ((!flag) && (count <= 5));
X }
X}
X
X
X/* Place a trap with a given displacement of point -RAK- */
Xvault_monster(y, x, num)
Xint y, x, num;
X{
X int i, y1, x1;
X
X for (i = 0; i < num; i++)
X {
X y1 = y;
X x1 = x;
X (void) summon_monster(&y1, &x1, TRUE);
X }
X}
X
X
X/* Builds a room at a row, column coordinate -RAK- */
Xbuild_room(yval, xval)
Xint yval, xval;
X{
X int y_height, y_depth;
X int x_left, x_right;
X int i, j;
X floor_type cur_floor;
X
X if (dun_level <= randint(25))
X cur_floor = lopen_floor; /* Floor with light */
X else
X cur_floor = dopen_floor; /* Dark floor */
X y_height = yval - randint(4);
X y_depth = yval + randint(3);
X x_left = xval - randint(11);
X x_right = xval + randint(11);
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X {
X cave[i][j].fval = cur_floor.ftval;
X cave[i][j].fopen = cur_floor.ftopen;
X }
X for (i = (y_height - 1); i <= (y_depth + 1); i++)
X {
X cave[i][x_left-1].fval = rock_wall1.ftval;
X cave[i][x_left-1].fopen = rock_wall1.ftopen;
X cave[i][x_right+1].fval = rock_wall1.ftval;
X cave[i][x_right+1].fopen = rock_wall1.ftopen;
X }
X for (i = x_left; i <= x_right; i++)
X {
X cave[y_height-1][i].fval = rock_wall1.ftval;
X cave[y_height-1][i].fopen = rock_wall1.ftopen;
X cave[y_depth+1][i].fval = rock_wall1.ftval;
X cave[y_depth+1][i].fopen = rock_wall1.ftopen;
X }
X}
X
X
X/* Builds a room at a row, column coordinate -RAK- */
X/* Type 1 unusual rooms are several overlapping rectangular ones */
Xbuild_type1(yval, xval)
Xint yval, xval;
X{
X int y_height, y_depth;
X int x_left, x_right;
X int i0, i, j;
X floor_type cur_floor;
X cave_type *c_ptr;
X
X if (dun_level <= randint(25))
X cur_floor = lopen_floor; /* Floor with light */
X else
X cur_floor = dopen_floor; /* Dark floor */
X for (i0 = 0; i0 < (1 + randint(2)); i0++)
X {
X y_height = yval - randint(4);
X y_depth = yval + randint(3);
X x_left = xval - randint(11);
X x_right = xval + randint(11);
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X {
X cave[i][j].fval = cur_floor.ftval;
X cave[i][j].fopen = cur_floor.ftopen;
X }
X for (i = (y_height - 1); i <= (y_depth + 1); i++)
X {
X c_ptr = &cave[i][x_left-1];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X c_ptr = &cave[i][x_right+1];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X }
X for (i = x_left; i <= x_right; i++)
X {
X c_ptr = &cave[y_height-1][i];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X c_ptr = &cave[y_depth+1][i];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X }
X }
X}
X
X
X/* Builds an unusual room at a row, column coordinate -RAK- */
X/* Type 2 unusual rooms all have an inner room: */
X/* 1 - Just an inner room with one door */
X/* 2 - An inner room within an inner room */
X/* 3 - An inner room with pillar(s) */
X/* 4 - Inner room has a maze */
X/* 5 - A set of four inner rooms */
Xbuild_type2(yval, xval)
Xint yval, xval;
X{
X int y_height, y_depth;
X int x_left, x_right;
X int i, j;
X floor_type cur_floor;
X
X if (dun_level <= randint(30))
X cur_floor = lopen_floor; /* Floor with light */
X else
X cur_floor = dopen_floor; /* Dark floor */
X y_height = yval - 4;
X y_depth = yval + 4;
X x_left = xval - 11;
X x_right = xval + 11;
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X {
X cave[i][j].fval = cur_floor.ftval;
X cave[i][j].fopen = cur_floor.ftopen;
X }
X for (i = (y_height - 1); i <= (y_depth + 1); i++)
X {
X cave[i][x_left-1].fval = rock_wall1.ftval;
X cave[i][x_left-1].fopen = rock_wall1.ftopen;
X cave[i][x_right+1].fval = rock_wall1.ftval;
X cave[i][x_right+1].fopen = rock_wall1.ftopen;
X }
X for (i = x_left; i <= x_right; i++)
X {
X cave[y_height-1][i].fval = rock_wall1.ftval;
X cave[y_height-1][i].fopen = rock_wall1.ftopen;
X cave[y_depth+1][i].fval = rock_wall1.ftval;
X cave[y_depth+1][i].fopen = rock_wall1.ftopen;
X }
X /* The inner room */
X y_height = y_height + 2;
X y_depth = y_depth - 2;
X x_left = x_left + 2;
X x_right = x_right - 2;
X for (i = (y_height - 1); i <= (y_depth + 1); i++)
X {
X cave[i][x_left-1].fval = 8;
X cave[i][x_right+1].fval = 8;
X }
X for (i = x_left; i <= x_right; i++)
X {
X cave[y_height-1][i].fval = 8;
X cave[y_depth+1][i].fval = 8;
X }
X /* Inner room variations */
X switch(randint(5))
X {
X case 1: /* Just an inner room... */
X switch(randint(4)) /* Place a door */
X {
X case 1: place_secret_door(y_height-1, xval); break;
X case 2: place_secret_door(y_depth+1, xval); break;
X case 3: place_secret_door(yval, x_left-1); break;
X case 4: place_secret_door(yval, x_right+1); break;
X }
X vault_monster(yval, xval, 1);
X break;
X case 2: /* Treasure Vault */
X switch(randint(4)) /* Place a door */
X {
X case 1: place_secret_door(y_height-1, xval); break;
X case 2: place_secret_door(y_depth+1, xval); break;
X case 3: place_secret_door(yval, x_left-1); break;
X case 4: place_secret_door(yval, x_right+1); break;
X }
X for (i = yval-1; i <= yval+1; i++)
X {
X cave[i][xval-1].fval = 8;
X cave[i][xval+1].fval = 8;
X }
X cave[yval-1][xval].fval = 8;
X cave[yval+1][xval].fval = 8;
X switch(randint(4)) /* Place a door */
X {
X case 1: place_locked_door(yval-1, xval); break;
X case 2: place_locked_door(yval+1, xval); break;
X case 3: place_locked_door(yval, xval-1); break;
X case 4: place_locked_door(yval, xval+1); break;
X }
X /* Place an object in the treasure vault */
X switch(randint(10))
X {
X case 1: place_up_stairs(yval, xval); break;
X case 2: place_down_stairs(yval, xval); break;
X default: place_object(yval, xval); break;
X }
X /* Guard the treasure well */
X vault_monster(yval, xval, 2+randint(3));
X /* If the monsters don't get 'em... */
X vault_trap(yval, xval, 4, 10, 2+randint(3));
X break;
X case 3: /* Inner pillar(s)... */
X switch(randint(4)) /* Place a door */
X {
X case 1: place_secret_door(y_height-1, xval); break;
X case 2: place_secret_door(y_depth+1, xval); break;
X case 3: place_secret_door(yval, x_left-1); break;
X case 4: place_secret_door(yval, x_right+1); break;
X }
X for (i = yval-1; i <= yval+1; i++)
X for (j = xval-1; j <= xval+1; j++)
X cave[i][j].fval = 8;
X if (randint(2) == 1)
X {
X switch(randint(2))
X {
X case 1:
X for (i = yval-1; i <= yval+1; i++)
X for (j = xval-6; j <= xval-4; j++)
X cave[i][j].fval = 8;
X for (i = yval-1; i <= yval+1; i++)
X for (j = xval+4; j <= xval+6; j++)
X cave[i][j].fval = 8;
X break;
X case 2:
X for (i = yval-1; i <= yval+1; i++)
X for (j = xval-7; j <= xval-5; j++)
X cave[i][j].fval = 8;
X for (i = yval-1; i <= yval+1; i++)
X for (j = xval+5; j <= xval+7; j++)
X cave[i][j].fval = 8;
X break;
X }
X }
X if (randint(3) == 1) /* Inner rooms */
X {
X for (i = xval-5; i <= xval+5; i++)
X {
X cave[yval-1][i].fval = 8;
X cave[yval+1][i].fval = 8;
X }
X cave[yval][xval-5].fval = 8;
X cave[yval][xval+5].fval = 8;
X switch(randint(2))
X {
X case 1: place_secret_door(yval+1, xval-3); break;
X case 2: place_secret_door(yval-1, xval-3); break;
X }
X switch(randint(2))
X {
X case 1: place_secret_door(yval+1, xval+3); break;
X case 2: place_secret_door(yval-1, xval+3); break;
X }
X if (randint(3) == 1) place_object(yval, xval-2);
X if (randint(3) == 1) place_object(yval, xval+2);
X vault_monster(yval, xval-2, randint(2));
X vault_monster(yval, xval+2, randint(2));
X }
X break;
X case 4: /* Maze inside... */
X switch(randint(4)) /* Place a door */
X {
X case 1: place_secret_door(y_height-1, xval); break;
X case 2: place_secret_door(y_depth+1, xval); break;
X case 3: place_secret_door(yval, x_left-1); break;
X case 4: place_secret_door(yval, x_right+1); break;
X }
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X if (0x1 & (j+i))
X cave[i][j].fval = 8;
X /* Monsters just love mazes... */
X vault_monster(yval, xval-5, randint(3));
X vault_monster(yval, xval+5, randint(3));
X /* Traps make them entertaining... */
X vault_trap(yval, xval-3, 2, 8, randint(3));
X vault_trap(yval, xval+3, 2, 8, randint(3));
X /* Mazes should have some treasure too.. */
X for (i = 0; i < 3; i++)
X random_object(yval, xval, 1);
X break;
X case 5: /* Four small rooms... */
X for (i = y_height; i <= y_depth; i++)
X cave[i][xval].fval = 8;
X for (i = x_left; i <= x_right; i++)
X cave[yval][i].fval = 8;
X switch(randint(2))
X {
X case 1:
X i = randint(10);
X place_secret_door(y_height-1, xval-i);
X place_secret_door(y_height-1, xval+i);
X place_secret_door(y_depth+1, xval-i);
X place_secret_door(y_depth+1, xval+i);
X break;
X case 2:
X i = randint(3);
X place_secret_door(yval+i, x_left-1);
X place_secret_door(yval-i, x_left-1);
X place_secret_door(yval+i, x_right+1);
X place_secret_door(yval-i, x_right+1);
X break;
X }
X /* Treasure in each one... */
X random_object(yval, xval, 2+randint(2));
X /* Gotta have some monsters... */
X vault_monster(yval+2, xval-4, randint(2));
X vault_monster(yval+2, xval+4, randint(2));
X vault_monster(yval-2, xval-4, randint(2));
X vault_monster(yval-2, xval+4, randint(2));
X break;
X }
X}
X
X
X/* Builds a room at a row, column coordinate -RAK- */
X/* Type 3 unusual rooms are cross shaped */
Xbuild_type3(yval, xval)
Xint yval, xval;
X{
X int y_height, y_depth;
X int x_left, x_right;
X int i0, i, j;
X floor_type cur_floor;
X cave_type *c_ptr;
X
X if (dun_level <= randint(25))
X cur_floor = lopen_floor; /* Floor with light */
X else
X cur_floor = dopen_floor; /* Dark floor */
X i0 = 2 + randint(2);
X y_height = yval - i0;
X y_depth = yval + i0;
X x_left = xval - 1;
X x_right = xval + 1;
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X {
X cave[i][j].fval = cur_floor.ftval;
X cave[i][j].fopen = cur_floor.ftopen;
X }
X for (i = (y_height - 1); i <= (y_depth + 1); i++)
X {
X c_ptr = &cave[i][x_left-1];
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X c_ptr = &cave[i][x_right+1];
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X for (i = x_left; i <= x_right; i++)
X {
X c_ptr = &cave[y_height-1][i];
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X c_ptr = &cave[y_depth+1][i];
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X i0 = 2 + randint(9);
X y_height = yval - 1;
X y_depth = yval + 1;
X x_left = xval - i0;
X x_right = xval + i0;
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X {
X cave[i][j].fval = cur_floor.ftval;
X cave[i][j].fopen = cur_floor.ftopen;
X }
X for (i = (y_height - 1); i <= (y_depth + 1); i++)
X {
X c_ptr = &cave[i][x_left-1];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X c_ptr = &cave[i][x_right+1];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X }
X for (i = x_left; i <= x_right; i++)
X {
X c_ptr = &cave[y_height-1][i];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X c_ptr = &cave[y_depth+1][i];
X if (c_ptr->fval != cur_floor.ftval)
X {
X c_ptr->fval = rock_wall1.ftval;
X c_ptr->fopen = rock_wall1.ftopen;
X }
X }
X /* Special features... */
X switch(randint(4))
X {
X case 1: /* Large middle pillar */
X for (i = yval-1; i <= yval+1; i++)
X for (j = xval-1; j <= xval+1; j++)
X cave[i][j].fval = 8;
X break;
X case 2: /* Inner treasure vault */
X for (i = yval-1; i <= yval+1; i++)
X {
X cave[i][xval-1].fval = 8;
X cave[i][xval+1].fval = 8;
X }
X cave[yval-1][xval].fval = 8;
X cave[yval+1][xval].fval = 8;
X switch(randint(4)) /* Place a door */
X {
X case 1: place_secret_door(yval-1, xval); break;
X case 2: place_secret_door(yval+1, xval); break;
X case 3: place_secret_door(yval, xval-1); break;
X case 4: place_secret_door(yval, xval+1); break;
X }
X /* Place a treasure in the vault */
X place_object(yval, xval);
X /* Let's guard the treasure well... */
X vault_monster(yval, xval, 2+randint(2));
X /* Traps naturally */
X vault_trap(yval, xval, 4, 4, 1+randint(3));
X break;
X case 3:
X if (randint(3) == 1)
X {
X cave[yval-1][xval-2].fval = 8;
X cave[yval+1][xval-2].fval = 8;
X cave[yval-1][xval+2].fval = 8;
X cave[yval-1][xval+2].fval = 8;
X cave[yval-2][xval-1].fval = 8;
X cave[yval-2][xval+1].fval = 8;
X cave[yval+2][xval-1].fval = 8;
X cave[yval+2][xval+1].fval = 8;
X if (randint(3) == 1)
X {
X place_secret_door(yval, xval-2);
X place_secret_door(yval, xval+2);
X place_secret_door(yval-2, xval);
X place_secret_door(yval+2, xval);
X }
X }
X else if (randint(3) == 1)
X {
X cave[yval][xval].fval = 8;
X cave[yval-1][xval].fval = 8;
X cave[yval+1][xval].fval = 8;
X cave[yval][xval-1].fval = 8;
X cave[yval][xval+1].fval = 8;
X }
X else if (randint(3) == 1)
X cave[yval][xval].fval = 8;
X break;
X case 4:
X break;
X }
X}
X
X
X/* Constructs a tunnel between two points */
Xbuild_tunnel(row1, col1, row2, col2)
Xint row1, col1, row2, col2;
X{
X int tmp_row, tmp_col;
X int row_dir, col_dir;
X int i, j;
X coords tunstk[1000];
X coords wallstk[1000];
X int tunptr;
X int wallptr;
X int stop_flag, door_flag;
X cave_type *c_ptr, *d_ptr;
X
X /* Main procedure for Tunnel */
X /* Note: 9 is a temporary value */
X stop_flag = FALSE;
X door_flag = FALSE;
X tunptr = 0;
X wallptr = 0;
X correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
X do
X {
X if (randint(100) > DUN_TUN_CHG)
X rand_dir(&row_dir, &col_dir, row1, col1, row2, col2, DUN_TUN_RND);
X tmp_row = row1 + row_dir;
X tmp_col = col1 + col_dir;
X while (!in_bounds(tmp_row, tmp_col))
X {
X rand_dir(&row_dir, &col_dir, row1, col1, row2, col2, DUN_TUN_RND);
X tmp_row = row1 + row_dir;
X tmp_col = col1 + col_dir;
X }
X c_ptr = &cave[tmp_row][tmp_col];
X if (c_ptr->fval == rock_wall1.ftval)
X {
X row1 = tmp_row;
X col1 = tmp_col;
X wallstk[wallptr].y = row1;
X wallstk[wallptr].x = col1;
X if (wallptr < 1000)
X wallptr++;
X for (i = row1-1; i <= row1+1; i++)
X for (j = col1-1; j <= col1+1; j++)
X if (in_bounds(i, j))
X {
X d_ptr = &cave[i][j];
X if ((d_ptr->fval >= 10) && (d_ptr->fval <= 12))
X d_ptr->fval = 9;
X }
X }
X else if (c_ptr->fval == corr_floor1.ftval)
X {
X row1 = tmp_row;
X col1 = tmp_col;
X if (!door_flag)
X {
X if (doorptr <= 100)
X {
X doorstk[doorptr].y = row1;
X doorstk[doorptr].x = col1;
X doorptr++;
X }
X door_flag = TRUE;
X }
X if (randint(100) > DUN_TUN_CON)
X stop_flag = TRUE;
X }
X else if (c_ptr->fval == 0)
X {
X row1 = tmp_row;
X col1 = tmp_col;
X tunstk[tunptr].y = row1;
X tunstk[tunptr].x = col1;
X if (tunptr < 1000)
X tunptr++;
X door_flag = FALSE;
X }
X else if (c_ptr->fval != 9)
X {
X row1 = tmp_row;
X col1 = tmp_col;
X }
X }
X while (((row1 != row2) || (col1 != col2)) && (!stop_flag));
X for (i = 0; i < tunptr; i++)
X {
X cave[tunstk[i].y][tunstk[i].x].fval = corr_floor1.ftval;
X cave[tunstk[i].y][tunstk[i].x].fopen = corr_floor1.ftopen;
X }
X for (i = 0; i < wallptr; i++)
X {
X c_ptr = &cave[wallstk[i].y][wallstk[i].x];
X if (c_ptr->fval == 9)
X {
X if (randint(100) < DUN_TUN_PEN)
X place_door(wallstk[i].y, wallstk[i].x);
X else
X {
X c_ptr->fval = corr_floor2.ftval;
X c_ptr->fopen = corr_floor2.ftopen;
X }
X }
X }
X}
X
X
Xint next_to(y, x)
Xint y, x;
X{
X int next;
X
X if (next_to8(y, x, 4, 5, 6) > 2)
X if (((cave[y-1][x].fval >= 10) && (cave[y-1][x].fval <= 12)) &&
X ((cave[y+1][x].fval >= 10) && (cave[y+1][x].fval <= 12)))
X next = TRUE;
X else if (((cave[y][x-1].fval >= 10) && (cave[y][x-1].fval <= 12)) &&
X ((cave[y][x+1].fval >= 10) && (cave[y][x+1].fval <= 12)))
X next = TRUE;
X else
X next = FALSE;
X else
X next = FALSE;
X return(next);
X}
X
X/* Places door at y, x position if at least 2 walls found */
Xtry_door(y, x)
Xint y, x;
X{
X if (randint(100) > DUN_TUN_JCT)
X if (cave[y][x].fval == corr_floor1.ftval)
X if (next_to(y, x))
X place_door(y, x);
X}
X
X
X/* Cave logic flow for generation of new dungeon */
Xcave_gen()
X{
X struct spot_type
X {
X int endx;
X int endy;
X };
X int room_map[20][20];
X int i, j, k, l;
X int y1, x1, y2, x2;
X int pick1, pick2;
X int row_rooms, col_rooms;
X int alloc_level;
X worlint yloc[400];
X worlint xloc[400];
X
X int set_1_2();
X int set_1_2_4();
X int set_4();
X
X row_rooms = 2*(cur_height/SCREEN_HEIGHT);
X col_rooms = 2*(cur_width /SCREEN_WIDTH);
X for (i = 0; i < row_rooms; i++)
X for (j = 0; j < col_rooms; j++)
X room_map[i][j] = FALSE;
X for (i = 0; i < randnor(DUN_ROO_MEA, 2); i++)
X room_map[randint(row_rooms)-1][randint(col_rooms)-1] = TRUE;
X k = 0;
X for (i = 0; i < row_rooms; i++)
X for (j = 0; j < col_rooms; j++)
X if (room_map[i][j] == TRUE)
X {
X yloc[k] = i * (quart_height * 2 + 1) + quart_height;
X xloc[k] = j * (quart_width * 2 + 1) + quart_width;
X if (dun_level > randint(DUN_UNUSUAL))
X switch(randint(3))
X {
X case 1: build_type1(yloc[k], xloc[k]); break;
X case 2: build_type2(yloc[k], xloc[k]); break;
X case 3: build_type3(yloc[k], xloc[k]); break;
X }
X else
X build_room(yloc[k], xloc[k]);
X k++;
X }
X for (l = 0; l < k; l++)
X {
X pick1 = randint(k) - 1;
X pick2 = randint(k) - 1;
X y1 = yloc[pick1];
X x1 = xloc[pick1];
X yloc[pick1] = yloc[pick2];
X xloc[pick1] = xloc[pick2];
X yloc[pick2] = y1;
X xloc[pick2] = x1;
X }
X doorptr = 0;
X for (l = 0; l < k-1; l++)
X {
X y1 = yloc[l];
X x1 = xloc[l];
X y2 = yloc[l+1];
X x2 = xloc[l+1];
X build_tunnel(y2, x2, y1, x1);
X }
X fill_cave(rock_wall1);
X for (i = 0; i < DUN_STR_MAG; i++)
X place_streamer(rock_wall2, DUN_STR_MC);
X for (i = 0; i < DUN_STR_QUA; i++)
X place_streamer(rock_wall3, DUN_STR_QC);
X place_boundary();
X /* Place intersection doors */
X for (i = 0; i < doorptr; i++)
X {
X try_door(doorstk[i].y, doorstk[i].x-1);
X try_door(doorstk[i].y, doorstk[i].x+1);
X try_door(doorstk[i].y-1, doorstk[i].x);
X try_door(doorstk[i].y+1, doorstk[i].x);
X }
X alloc_level = (dun_level/3);
X if (alloc_level < 2)
X alloc_level = 2;
X else if (alloc_level > 10)
X alloc_level = 10;
X place_stairs(2, randint(2)+2, 3);
X place_stairs(1, randint(2), 3);
X alloc_monster(set_1_2, (randint(8)+MIN_MALLOC_LEVEL+alloc_level), 0, TRUE);
X alloc_object(set_4, 3, randint(alloc_level));
X alloc_object(set_1_2, 5, randnor(TREAS_ROOM_ALLOC, 3));
X alloc_object(set_1_2_4, 5, randnor(TREAS_ANY_ALLOC, 3));
X alloc_object(set_1_2_4, 4, randnor(TREAS_GOLD_ALLOC, 3));
X alloc_object(set_1_2_4, 1, randint(alloc_level));
X if (dun_level >= WIN_MON_APPEAR) place_win_monster();
X}
X
X
X/* Builds a store at a row, column coordinate */
Xbuild_store(store_num, y, x)
Xint store_num, y, x;
X{
X int yval, y_height, y_depth;
X int xval, x_left, x_right;
X int i, j, cur_pos;
X cave_type *c_ptr;
X
X yval = y*10 + 5;
X xval = x*16 + 16;
X y_height = yval - randint(3);
X y_depth = yval + randint(4);
X x_left = xval - randint(6);
X x_right = xval + randint(6);
X for (i = y_height; i <= y_depth; i++)
X for (j = x_left; j <= x_right; j++)
X {
X cave[i][j].fval = boundary_wall.ftval;
X cave[i][j].fopen = boundary_wall.ftopen;
X }
X switch(randint(4))
X {
X case 1:
X i = randint(y_depth-y_height) + y_height - 1;
X j = x_left;
X break;
X case 2:
X i = randint(y_depth-y_height) + y_height - 1;
X j = x_right;
X break;
X case 3:
X i = y_depth;
X j = randint(x_right-x_left) + x_left - 1;
X break;
X case 4:
X i = y_height;
X j = randint(x_right-x_left) + x_left - 1;
X break;
X }
X c_ptr = &cave[i][j];
X c_ptr->fval = corr_floor3.ftval;
X c_ptr->fopen = corr_floor3.ftopen;
X popt(&cur_pos);
X c_ptr->tptr = cur_pos;
X t_list[cur_pos] = store_door[store_num];
X}
X
X
X/* Town logic flow for generation of new town */
Xtown_gen()
X{
X int i, j, k, l, m;
X int rooms[6];
X
X int set_1_2();
X
X set_seed(town_state, town_seed);
X for (i = 0; i < 6; i++)
X rooms[i] = i;
X l = 6;
X for (i = 0; i < 2; i++)
X for (j = 0; j < 3; j++)
X {
X k = randint(l) - 1;
X build_store(rooms[k], i, j);
X for (m = k; m < l-1; m++)
X rooms[m] = rooms[m+1];
X l--;
X }
X fill_cave(dopen_floor);
X place_boundary();
X reset_seed();
X if (0x1 & (turn / 5000))
X { /* Night */
X for (i = 0; i < cur_height; i++)
X for (j = 0; j < cur_width; j++)
X if (cave[i][j].fval != dopen_floor.ftval)
X cave[i][j].pl = TRUE;
X place_stairs(2, 1, 0);
X alloc_monster(set_1_2, MIN_MALLOC_TN, 3, TRUE);
X store_maint();
X }
X else
X { /* Day */
X for (i = 0; i < cur_height; i++)
X for (j = 0; j < cur_width; j++)
X cave[i][j].pl = TRUE;
X place_stairs(2, 1, 0);
X alloc_monster(set_1_2, MIN_MALLOC_TD, 3, TRUE);
X store_maint();
X }
X}
X
X
X/* Generates a random dungeon level -RAK- */
Xgenerate_cave()
X{
X panel_row_min = 0;
X panel_row_max = 0;
X panel_col_min = 0;
X panel_col_max = 0;
X char_row = -1;
X char_col = -1;
X
X tlink();
X mlink();
X blank_cave();
X
X if (dun_level == 0)
X {
X cur_height = SCREEN_HEIGHT;
X cur_width = SCREEN_WIDTH;
X max_panel_rows = (cur_height/SCREEN_HEIGHT)*2 - 2;
X max_panel_cols = (cur_width /SCREEN_WIDTH )*2 - 2;
X panel_row = max_panel_rows;
X panel_col = max_panel_cols;
X town_gen();
X }
X else
X {
X cur_height = MAX_HEIGHT;
X cur_width = MAX_WIDTH;
X max_panel_rows = (cur_height/SCREEN_HEIGHT)*2 - 2;
X max_panel_cols = (cur_width /SCREEN_WIDTH )*2 - 2;
X panel_row = max_panel_rows;
X panel_col = max_panel_cols;
X cave_gen();
X }
X}
END_OF_generate.c
if test 26506 -ne `wc -c <generate.c`; then
echo shar: \"generate.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 14 \(of 16\).
cp /dev/null ark14isdone
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/