home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / mor4873s.lzh / FILES.C < prev    next >
C/C++ Source or Header  |  1988-12-14  |  27KB  |  821 lines

  1. #include <stdio.h>
  2.  
  3. #include "constant.h"
  4. #include "config.h"
  5. #include "types.h"
  6. #include "externs.h"
  7.  
  8. #ifdef USG
  9. #include <string.h>
  10. #include <fcntl.h>
  11. #else
  12. #include <strings.h>
  13. #include <sys/file.h>
  14. #endif
  15.  
  16. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  17. char *sprintf();
  18. #endif
  19.  
  20. #if defined(ultrix) || defined(USG)
  21. void exit();
  22. #endif
  23.  
  24. /*
  25.  *  init_scorefile
  26.  *  Open the score file while we still have the setuid privileges.  Later
  27.  *  when the score is being written out, you must be sure to flock the file
  28.  *  so we don't have multiple people trying to write to it at the same time.
  29.  *  Craig Norborg (doc)        Mon Aug 10 16:41:59 EST 1987
  30.  */
  31. init_scorefile()
  32. {
  33.   if (1 > (highscore_fd = open(MORIA_TOP, O_RDWR | O_CREAT, 0644)))
  34.     {
  35.       (void) fputs("Can't open score file!\n", stderr);
  36.       exit(1);
  37.     }
  38. #ifdef MSDOS
  39.   (void) setmode(highscore_fd, O_BINARY);
  40. #endif
  41. }
  42.  
  43. /* Attempt to open the intro file            -RAK-     */
  44. /* This routine also checks the hours file vs. what time it is    -Doc */
  45. intro(finam)
  46. char *finam;
  47. {
  48.   register int xpos, i;
  49.   vtype in_line;
  50.   FILE *file1;
  51.   register char *string;
  52.  
  53. #ifdef MORIA_HOU
  54.   /* Attempt to read hours.dat.  If it does not exist,     */
  55.   /* inform the user so he can tell the wizard about it     */
  56.   if ((file1 = fopen(MORIA_HOU, "r")) != NULL)
  57.     {
  58.       while (fgets(in_line, 80, file1) != NULL)
  59.     if (strlen(in_line) > 3)
  60.       {
  61.         if (!strncmp(in_line, "SUN:", 4))
  62.           (void) strcpy(days[0], in_line);
  63.         else if (!strncmp(in_line, "MON:", 4))
  64.           (void) strcpy(days[1], in_line);
  65.         else if (!strncmp(in_line, "TUE:", 4))
  66.           (void) strcpy(days[2], in_line);
  67.         else if (!strncmp(in_line, "WED:", 4))
  68.           (void) strcpy(days[3], in_line);
  69.         else if (!strncmp(in_line, "THU:", 4))
  70.           (void) strcpy(days[4], in_line);
  71.         else if (!strncmp(in_line, "FRI:", 4))
  72.           (void) strcpy(days[5], in_line);
  73.         else if (!strncmp(in_line, "SAT:", 4))
  74.           (void) strcpy(days[6], in_line);
  75.       }
  76.       (void) fclose(file1);
  77.     }
  78.   else
  79.     {
  80.       (void) fprintf(stderr, "There is no hours file.\nPlease inform the wizard, %s, so he can correct this!\n", WIZARD);
  81.       exit_game();
  82.     }
  83. #endif
  84.  
  85.   /* Check the hours, if closed  require password     */
  86.   if (finam != NULL && ((string = index(finam, '^')) != NULL))
  87.     xpos = strlen(finam) - strlen(string);
  88.   else
  89.     xpos = -1;
  90.   if (xpos >= 0)
  91.     if (check_pswd())
  92.       insert_str(finam, "^", "");
  93. #ifdef MORIA_HOU
  94.   if (!check_time())
  95.     {
  96.       if (!wizard1)
  97.     {
  98.       if ((file1 = fopen(MORIA_HOU, "r")) != NULL)
  99.         {
  100.           clear_screen(0, 0);
  101.           for (i = 0; fgets(in_line, 80, file1) != NULL; i++)
  102.         prt(in_line, i, 0);
  103.           (void) fclose(file1);
  104.         }
  105.       exit_game();
  106.     }
  107.     }
  108. #endif
  109.  
  110. #ifdef MSDOS
  111.     msdos_intro();            /* Print a canned message */
  112. #else
  113.   /* Print the introduction message, news, etc...         */
  114.   if ((file1 = fopen(MORIA_MOR, "r")) != NULL)
  115.     {
  116.       clear_screen(0, 0);
  117.       for (i = 0; fgets(in_line, 80, file1) != NULL; i++)
  118.     prt(in_line, i, 0);
  119.       pause_line(23);
  120.       (void) fclose(file1);
  121.     }
  122. #endif
  123. }
  124.  
  125.  
  126. /* Prints dungeon map to external file            -RAK-     */
  127. print_map()
  128. {
  129. #ifdef SCREENMAP
  130.   msdos_print_map();
  131. #else
  132.   register int i, j, m, n;
  133.   register k, l;
  134.   register i7, i8;
  135.   char dun_line[MAX_WIDTH];
  136.   char *dun_ptr;
  137.   vtype filename1;
  138.   char tmp_str[80];
  139.   FILE *file1;
  140.   int page_width = OUTPAGE_WIDTH;
  141.   int page_height = OUTPAGE_HEIGHT;
  142.  
  143.   /* this allows us to strcat each character in the inner loop,
  144.      instead of using the expensive sprintf */
  145.   prt("File name: ", 0, 0);
  146.   if (get_string(filename1, 0, 11, 64))
  147.     {
  148.       if (strlen(filename1) == 0)
  149.     (void) strcpy(filename1, "MORIAMAP.DAT");
  150.       if ((file1 = fopen(filename1, "w")) == NULL)
  151.     {
  152.       (void) sprintf(dun_line, "Cannot open file %s", filename1);
  153.       prt(dun_line, 0, 0);
  154.       put_qio();
  155.       return;
  156.     }
  157.       (void) sprintf(tmp_str, "section width (default = %d char):", page_width);
  158.       prt(tmp_str, 0, 0);
  159.       (void) get_string(tmp_str, 0, strlen(tmp_str), 10);
  160.       (void) sscanf(tmp_str, "%d", &page_width);
  161.       if (page_width < 10)
  162.     page_width = 10;
  163.  
  164.       (void) sprintf(tmp_str, "section height (default = %d lines):", page_height);
  165.       prt(tmp_str, 0, 0);
  166.       (void) get_string(tmp_str, 0, strlen(tmp_str), 10);
  167.       (void) sscanf(tmp_str, "%d", &page_height);
  168.       if (page_height < 10)
  169.     page_height = 10;
  170.  
  171.       prt("Writing Moria Dungeon Map...", 0, 0);
  172.       put_qio();
  173.  
  174.       i = 0;
  175.       i7 = 0;
  176.       do
  177.     {
  178.       j = 0;
  179.       k = i + page_height - 1;
  180.       if (k >= cur_height)
  181.         k = cur_height - 1;
  182.       i7++;
  183.       i8 = 0;
  184.       do
  185.         {
  186.           l = j + page_width - 1;
  187.           if (l >= cur_width)
  188.         l = cur_width - 1;
  189.           i8++;
  190.           (void) fprintf(file1, "%c\n", 12);
  191.           (void) fprintf(file1, "Section[%d,%d];     ", i7, i8);
  192.           (void) fprintf(file1, "Depth : %d (feet)\n\n   ",
  193.                  (dun_level * 50));
  194.           for (m = j; m <= l; m++)
  195.         {
  196.           n = (m / 100);
  197.           (void) fprintf(file1, "%d", n);
  198.         }
  199.           (void) fputs("\n   ", file1);
  200.           for (m = j; m <= l; m++)
  201.         {
  202.           n = (m / 10) - (m / 100) * 10;
  203.           (void) fprintf(file1, "%d", n);
  204.         }
  205.           (void) fputs("\n   ", file1);
  206.           for (m = j; m <= l; m++)
  207.         {
  208.           n = m - (m / 10) * 10;
  209.           (void) fprintf(file1, "%d", n);
  210.         }
  211.           (void) fprintf(file1, "\n");
  212.           for (m = i; m <= k; m++)
  213.         {
  214.           (void) sprintf(dun_line, "%2d ", m);
  215.           dun_ptr = &dun_line[3];
  216.           for (n = j; n <= l; n++)
  217.             {
  218.               if (test_light(m, n))
  219.             loc_symbol(m, n, dun_ptr++);
  220.               else
  221.             *dun_ptr++ = ' ';
  222.             }
  223.           *dun_ptr++ = '\n';
  224.           (void) fputs(dun_line, file1);
  225.         }
  226.           j += page_width;
  227.         }
  228.       while (j < cur_width);
  229.       i += page_height;
  230.     }
  231.       while (i < cur_height);
  232.       (void) fclose(file1);
  233.       prt("Completed.", 0, 0);
  234.     }
  235. #endif
  236. }
  237.  
  238.  
  239. /* Prints a list of random objects to a file.  Note that -RAK-     */
  240. /* the objects produced is a sampling of objects which           */
  241. /* be expected to appear on that level.                          */
  242. print_objects()
  243. {
  244.   register int i;
  245.   int nobj, j, level;
  246.   vtype filename1; bigvtype tmp_str;
  247.   register FILE *file1;
  248.   register treasure_type *i_ptr;
  249.  
  250.   prt("Produce objects on what level?: ", 0, 0);
  251.   level = 0;
  252.   if (get_string(tmp_str, 0, 32, 10))
  253.     (void) sscanf(tmp_str, "%d", &level);
  254.   prt("Produce how many objects?: ", 0, 0);
  255.   nobj = 0;
  256.   if (get_string(tmp_str, 0, 27, 10))
  257.     (void) sscanf(tmp_str, "%d", &nobj);
  258.   if ((nobj > 0) && (level > -1) && (level < 1201))
  259.     {
  260.       if (nobj > 9999)
  261.     nobj = 9999;
  262.       prt("File name: ", 0, 0);
  263.       if (get_string(filename1, 0, 11, 64))
  264.     {
  265.       if (strlen(filename1) == 0)
  266.         (void) strcpy(filename1, "MORIAOBJ.DAT");
  267.       if ((file1 = fopen(filename1, "w")) != NULL)
  268.         {
  269.           (void) sprintf(tmp_str, "%d", nobj);
  270.           prt(strcat(tmp_str, " random objects being produced..."), 0, 0);
  271.           put_qio();
  272.           (void) fprintf(file1, "*** Random Object Sampling:\n");
  273.           (void) fprintf(file1, "*** %d objects\n", nobj);
  274.           (void) fprintf(file1, "*** For Level %d\n", level);
  275.           (void) fprintf(file1, "\n");
  276.           (void) fprintf(file1, "\n");
  277.           popt(&j);
  278.           for (i = 0; i < nobj; i++)
  279.         {
  280.           t_list[j] = object_list[get_obj_num(level)];
  281.           magic_treasure(j, level);
  282.           inventory[INVEN_MAX] = t_list[j];
  283.           i_ptr = &inventory[INVEN_MAX];
  284.           unquote(i_ptr->name);
  285.           known1(i_ptr->name);
  286.           known2(i_ptr->name);
  287.           objdes(tmp_str, INVEN_MAX, TRUE);
  288.           (void) fprintf(file1, "%s\n", tmp_str);
  289.         }
  290.           pusht(j);
  291.           (void) fclose(file1);
  292.           prt("Completed.", 0, 0);
  293.         }
  294.       else
  295.         prt("File could not be opened.", 0, 0);
  296.     }
  297.     }
  298. }
  299.  
  300.  
  301. /* Prints a listing of monsters                -RAK-     */
  302. print_monsters()
  303. {
  304.   register int i;
  305.   int j, xpos, attype, adesc;
  306.   register FILE *file1;
  307.   vtype out_val, filename1;
  308.   vtype attstr, attx;
  309.   dtype damstr;
  310.   register creature_type *c_ptr;
  311.   register char *string;
  312.  
  313.   prt("File name: ", 0, 0);
  314.   if (get_string(filename1, 0, 11, 64))
  315.     {
  316.       if (strlen(filename1) == 0)
  317.     (void) strcpy(filename1, "MORIAMON.DAT");
  318.       if ((file1 = fopen(filename1, "w")) != NULL)
  319.     {
  320.       prt("Writing Monster Dictionary...", 0, 0);
  321.       put_qio();
  322.       for (i = 0; i < MAX_CREATURES; i++)
  323.         {
  324.           c_ptr = &c_list[i];
  325.           /* Begin writing to file                                 */
  326.           (void) fprintf(file1, "--------------------------------------------\n");
  327.           (void) strcpy(out_val, c_ptr->name);
  328.           (void) strcat(out_val, "                              ");
  329.           (void) fprintf(file1, "%d  %s     (%c)\n", i, out_val, c_ptr->cchar);
  330.           (void) fprintf(file1, "     Speed ==%d  Level     ==%d  Exp ==%u\n",
  331.               c_ptr->speed, c_ptr->level, c_ptr->mexp);
  332.           (void) fprintf(file1, "     AC    ==%d  Eye-sight ==%d  HD  ==%s\n",
  333.               c_ptr->ac, c_ptr->aaf, c_ptr->hd);
  334.           if (0x80000000 & c_ptr->cmove)
  335.         (void) fprintf(file1, "     Creature is a ***Win Creature***\n");
  336.           if (0x00080000 & c_ptr->cmove)
  337.         (void) fprintf(file1, "     Creature Eats/kills other creatures.\n");
  338.           if (0x0001 & c_ptr->cdefense)
  339.         (void) fprintf(file1, "     Creature is a dragon.\n");
  340.           if (0x0002 & c_ptr->cdefense)
  341.         (void) fprintf(file1, "     Creature is a monster.\n");
  342.           if (0x0004 & c_ptr->cdefense)
  343.         (void) fprintf(file1, "     Creature is evil.\n");
  344.           if (0x0008 & c_ptr->cdefense)
  345.         (void) fprintf(file1, "     Creature is undead.\n");
  346.           if (0x0010 & c_ptr->cdefense)
  347.         (void) fprintf(file1, "     Creature harmed by cold.\n");
  348.           if (0x0020 & c_ptr->cdefense)
  349.         (void) fprintf(file1, "     Creature harmed by fire.\n");
  350.           if (0x0040 & c_ptr->cdefense)
  351.         (void) fprintf(file1, "     Creature harmed by poison.\n");
  352.           if (0x0080 & c_ptr->cdefense)
  353.         (void) fprintf(file1, "     Creature harmed by acid.\n");
  354.           if (0x0100 & c_ptr->cdefense)
  355.         (void) fprintf(file1, "     Creature harmed by blue light.\n");
  356.           if (0x0200 & c_ptr->cdefense)
  357.         (void) fprintf(file1, "     Creature harmed by Stone-to-Mud.\n");
  358.           if (0x1000 & c_ptr->cdefense)
  359.         (void) fprintf(file1, "     Creature cannot be charmed or slept.\n");
  360.           if (0x2000 & c_ptr->cdefense)
  361.         (void) fprintf(file1, "     Creature seen with Infra-Vision.\n");
  362.           if (0x4000 & c_ptr->cdefense)
  363.         (void) fprintf(file1, "     Creature has MAX hit points.\n");
  364.           if (0x00010000 & c_ptr->cmove)
  365.         (void) fprintf(file1, "     Creature is invisible.\n");
  366.           if (0x00100000 & c_ptr->cmove)
  367.         (void) fprintf(file1, "     Creature picks up objects.\n");
  368.           if (0x00200000 & c_ptr->cmove)
  369.         (void) fprintf(file1, "     Creature multiplies.\n");
  370.           if (0x01000000 & c_ptr->cmove)
  371.         (void) fprintf(file1, "     Carries object(s).\n");
  372.           if (0x02000000 & c_ptr->cmove)
  373.         (void) fprintf(file1, "     Carries gold, gems, etc.\n");
  374.           if (0x04000000 & c_ptr->cmove)
  375.         (void) fprintf(file1, "       Has object/gold 60%% of time.\n");
  376.           if (0x08000000 & c_ptr->cmove)
  377.         (void) fprintf(file1, "       Has object/gold 90%% of time.\n");
  378.           if (0x10000000 & c_ptr->cmove)
  379.         (void) fprintf(file1, "       Has 1d2 object(s)/gold.\n");
  380.           if (0x20000000 & c_ptr->cmove)
  381.         (void) fprintf(file1, "       Has 2d2 object(s)/gold.\n");
  382.           if (0x40000000 & c_ptr->cmove)
  383.         (void) fprintf(file1, "       Has 4d2 object(s)/gold.\n");
  384.           /*
  385.            * Creature casts spells / Breathes Dragon
  386.            * breath...
  387.            */
  388.           if (c_ptr->spells != 0)
  389.         {
  390.           (void) fprintf(file1, "   --Spells/Dragon Breath ==\n");
  391.           (void) fprintf(file1, "       Casts spells 1 out of %d turns.\n",
  392.               (int)(0xF & c_ptr->spells));
  393.           if (0x00000010 & c_ptr->spells)
  394.             (void) fprintf(file1, "       Can teleport short.\n");
  395.           if (0x00000020 & c_ptr->spells)
  396.             (void) fprintf(file1, "       Can teleport long.\n");
  397.           if (0x00000040 & c_ptr->spells)
  398.             (void) fprintf(file1, "       Teleport player to itself.\n");
  399.           if (0x00000080 & c_ptr->spells)
  400.             (void) fprintf(file1, "       Cause light wounds.\n");
  401.           if (0x00000100 & c_ptr->spells)
  402.             (void) fprintf(file1, "       Cause serious wounds.\n");
  403.           if (0x00000200 & c_ptr->spells)
  404.             (void) fprintf(file1, "       Hold person.\n");
  405.           if (0x00000400 & c_ptr->spells)
  406.             (void) fprintf(file1, "       Cause blindness.\n");
  407.           if (0x00000800 & c_ptr->spells)
  408.             (void) fprintf(file1, "       Cause confusion.\n");
  409.           if (0x00001000 & c_ptr->spells)
  410.             (void) fprintf(file1, "       Cause fear.\n");
  411.           if (0x00002000 & c_ptr->spells)
  412.             (void) fprintf(file1, "       Summon a monster.\n");
  413.           if (0x00004000 & c_ptr->spells)
  414.             (void) fprintf(file1, "       Summon an undead.\n");
  415.           if (0x00008000 & c_ptr->spells)
  416.             (void) fprintf(file1, "       Slow person.\n");
  417.           if (0x00010000 & c_ptr->spells)
  418.             (void) fprintf(file1, "       Drains mana for healing.\n");
  419.           if (0x00020000 & c_ptr->spells)
  420.             (void) fprintf(file1, "       **Unknown spell value**\n");
  421.           if (0x00040000 & c_ptr->spells)
  422.             (void) fprintf(file1, "       **Unknown spell value**\n");
  423.           if (0x00080000 & c_ptr->spells)
  424.             (void) fprintf(file1, "       Breathes Lightning Dragon Breath.\n");
  425.           if (0x00100000 & c_ptr->spells)
  426.             (void) fprintf(file1, "       Breathes Gas Dragon Breath.\n");
  427.           if (0x00200000 & c_ptr->spells)
  428.             (void) fprintf(file1, "       Breathes Acid Dragon Breath.\n");
  429.           if (0x00400000 & c_ptr->spells)
  430.             (void) fprintf(file1, "       Breathes Frost Dragon Breath.\n");
  431.           if (0x00800000 & c_ptr->spells)
  432.             (void) fprintf(file1, "       Breathes Fire Dragon Breath.\n");
  433.         }
  434.           /* Movement for creature                                 */
  435.           (void) fprintf(file1, "   --Movement ==\n");
  436.           if (0x00000001 & c_ptr->cmove)
  437.         (void) fprintf(file1, "       Move only to attack.\n");
  438.           if (0x00000002 & c_ptr->cmove)
  439.         (void) fprintf(file1, "       Move and attack normally.\n");
  440.           if (0x00000008 & c_ptr->cmove)
  441.         (void) fprintf(file1, "       20%% random movement.\n");
  442.           if (0x00000010 & c_ptr->cmove)
  443.         (void) fprintf(file1, "       40%% random movement.\n");
  444.           if (0x00000020 & c_ptr->cmove)
  445.         (void) fprintf(file1, "       75%% random movement.\n");
  446.           if (0x00020000 & c_ptr->cmove)
  447.         (void) fprintf(file1, "       Can open doors.\n");
  448.           if (0x00040000 & c_ptr->cmove)
  449.         (void) fprintf(file1, "       Can phase through walls.\n");
  450.     
  451.           (void) fprintf(file1, "   --Creature attacks ==\n");
  452.           (void) strcpy(attstr, c_ptr->damage);
  453.           while (strlen(attstr) > 0)
  454.         {
  455.           string = index(attstr, '|');
  456.           if (string)
  457.             xpos = strlen(attstr) - strlen(string);
  458.           else
  459.             xpos = -1;
  460.           if (xpos >= 0)
  461.             {
  462.               (void) strncpy(attx, attstr, xpos);
  463.               attx[xpos] = '\0';
  464.               (void) strcpy(attstr, &attstr[xpos + 1]);
  465.             }
  466.           else
  467.             {
  468.               (void) strcpy(attx, attstr);
  469.               attstr[0] = '\0';
  470.             }
  471.           (void) sscanf(attx, "%d%d%s", &attype, &adesc, damstr);
  472.           out_val[0] = '\0';
  473.           switch (adesc)
  474.             {
  475.             case 1:
  476.               (void) strcpy(out_val, "       Hits for ");
  477.               break;
  478.             case 2:
  479.               (void) strcpy(out_val, "       Bites for ");
  480.               break;
  481.             case 3:
  482.               (void) strcpy(out_val, "       Claws for ");
  483.               break;
  484.             case 4:
  485.               (void) strcpy(out_val, "       Stings for ");
  486.               break;
  487.             case 5:
  488.               (void) strcpy(out_val, "       Touches for ");
  489.               break;
  490.             case 6:
  491.               (void) strcpy(out_val, "       Kicks for ");
  492.               break;
  493.             case 7:
  494.               (void) strcpy(out_val, "       Gazes for ");
  495.               break;
  496.             case 8:
  497.               (void) strcpy(out_val, "       Breathes for ");
  498.               break;
  499.             case 9:
  500.               (void) strcpy(out_val, "       Spits for ");
  501.               break;
  502.             case 10:
  503.               (void) strcpy(out_val, "       Wails for ");
  504.               break;
  505.             case 11:
  506.               (void) strcpy(out_val, "       Embraces for ");
  507.               break;
  508.             case 12:
  509.               (void) strcpy(out_val, "       Crawls on you for ");
  510.               break;
  511.             case 13:
  512.               (void) strcpy(out_val, "       Shoots spores for ");
  513.               break;
  514.             case 14:
  515.               (void) strcpy(out_val, "       Begs for money for ");
  516.               break;
  517.             case 15:
  518.               (void) strcpy(out_val, "       Slimes you for ");
  519.               break;
  520.             case 16:
  521.               (void) strcpy(out_val, "       Crushes you for ");
  522.               break;
  523.             case 17:
  524.               (void) strcpy(out_val, "       Tramples you for ");
  525.               break;
  526.             case 18:
  527.               (void) strcpy(out_val, "       Drools on you for ");
  528.               break;
  529.             case 19:
  530.               (void) strcpy(out_val, "       Insults you for ");
  531.               break;
  532.             case 99:
  533.               (void) strcpy(out_val, "       Is repelled...");
  534.               break;
  535.             default:
  536.               (void) strcpy(out_val, "     **Unknown value** ");
  537.               break;
  538.             }
  539.           switch (attype)
  540.             {
  541.             case 1:
  542.               (void) strcat(out_val, "normal damage.");
  543.               break;
  544.             case 2:
  545.               (void) strcat(out_val, "lowering strength.");
  546.               break;
  547.             case 3:
  548.               (void) strcat(out_val, "confusion.");
  549.               break;
  550.             case 4:
  551.               (void) strcat(out_val, "fear.");
  552.               break;
  553.             case 5:
  554.               (void) strcat(out_val, "fire damage.");
  555.               break;
  556.             case 6:
  557.               (void) strcat(out_val, "acid damage.");
  558.               break;
  559.             case 7:
  560.               (void) strcat(out_val, "cold damage.");
  561.               break;
  562.             case 8:
  563.               (void) strcat(out_val, "lightning damage.");
  564.               break;
  565.             case 9:
  566.               (void) strcat(out_val, "corrosion damage.");
  567.               break;
  568.             case 10:
  569.               (void) strcat(out_val, "blindness.");
  570.               break;
  571.             case 11:
  572.               (void) strcat(out_val, "paralyzation.");
  573.               break;
  574.             case 12:
  575.               (void) strcat(out_val, "stealing money.");
  576.               break;
  577.             case 13:
  578.               (void) strcat(out_val, "stealing object.");
  579.               break;
  580.             case 14:
  581.               (void) strcat(out_val, "poison damage.");
  582.               break;
  583.             case 15:
  584.               (void) strcat(out_val, "lose dexterity.");
  585.               break;
  586.             case 16:
  587.               (void) strcat(out_val, "lose constitution.");
  588.               break;
  589.             case 17:
  590.               (void) strcat(out_val, "lose intelligence.");
  591.               break;
  592.             case 18:
  593.               (void) strcat(out_val, "lose wisdom.");
  594.               break;
  595.             case 19:
  596.               (void) strcat(out_val, "lose experience.");
  597.               break;
  598.             case 20:
  599.               (void) strcat(out_val, "aggravates monsters.");
  600.               break;
  601.             case 21:
  602.               (void) strcat(out_val, "disenchants objects.");
  603.               break;
  604.             case 22:
  605.               (void) strcat(out_val, "eating food.");
  606.               break;
  607.             case 23:
  608.               (void) strcat(out_val, "eating light source.");
  609.               break;
  610.             case 24:
  611.               (void) strcat(out_val, "absorbing charges.");
  612.               break;
  613.             case 99:
  614.               (void) strcat(out_val, "blank message.");
  615.               break;
  616.             default:
  617.               (void) strcat(out_val, "**Unknown value**");
  618.               break;
  619.             }
  620.           (void) fprintf(file1, "%s (%s)\n", out_val, damstr);
  621.         }
  622.           for (j = 0; j < 2; j++)
  623.         (void) fprintf(file1, "\n");
  624.         }
  625.       /* End writing to file                                   */
  626.       (void) fclose(file1);
  627.       prt("Completed.", 0, 0);
  628.     }
  629.     }
  630. }
  631.  
  632.  
  633. /* Print the character to a file or device        -RAK-     */
  634. file_character()
  635. {
  636.   register int i;
  637.   int j, xbth, xbthb, xfos, xsrh, xstl, xdis, xsave, xdev;
  638.   vtype xinfra;
  639.   register FILE *file1;
  640.   vtype out_val, filename1; bigvtype prt1, prt2;
  641.   stat_type out_str, out_int, out_wis, out_dex, out_con, out_chr;
  642.   register struct misc *p_ptr;
  643.   register treasure_type *i_ptr;
  644.  
  645.   prt("File name: ", 0, 0);
  646.   if (get_string(filename1, 0, 11, 64))
  647.     {
  648.       if (strlen(filename1) == 0)
  649.     (void) strcpy(filename1, "MORIACHR.DAT");
  650.       if ((file1 = fopen(filename1, "w")) != NULL)
  651.     {
  652.       prt("Writing character sheet...", 0, 0);
  653.       put_qio();
  654.       (void) fprintf(file1, "%c", 12);
  655.       cnv_stat(py.stats.cstr, out_str);
  656.       cnv_stat(py.stats.cint, out_int);
  657.       cnv_stat(py.stats.cwis, out_wis);
  658.       cnv_stat(py.stats.cdex, out_dex);
  659.       cnv_stat(py.stats.ccon, out_con);
  660.       cnv_stat(py.stats.cchr, out_chr);
  661.       (void) fprintf(file1, "\n");
  662.       (void) fprintf(file1, "\n");
  663.       (void) fprintf(file1, "\n");
  664.       (void) fprintf(file1, "  Name  :%s", pad(py.misc.name, " ", 25));
  665.       (void) fprintf(file1, "  Age         :%4d", (int)py.misc.age);
  666.       (void) fprintf(file1, "     Strength     :%s\n", out_str);
  667.       (void) fprintf(file1, "  Race  :%s", pad(py.misc.race, " ", 25));
  668.       (void) fprintf(file1, "  Height      :%4d", (int)py.misc.ht);
  669.       (void) fprintf(file1, "     Intelligence :%s\n", out_int);
  670.       (void) fprintf(file1, "  Sex   :%s", pad(py.misc.sex, " ", 25));
  671.       (void) fprintf(file1, "  Weight      :%4d", (int)py.misc.wt);
  672.       (void) fprintf(file1, "     Wisdom       :%s\n", out_wis);
  673.       (void) fprintf(file1, "  Class :%s", pad(py.misc.tclass, " ", 25));
  674.       (void) fprintf(file1, "  Social Class:%4d", py.misc.sc);
  675.       (void) fprintf(file1, "     Dexterity    :%s\n", out_dex);
  676.       (void) fprintf(file1, "  Title :%s", pad(py.misc.title, " ", 25));
  677.       (void) fprintf(file1, "                   ");
  678.       (void) fprintf(file1, "     Constitution :%s\n", out_con);
  679.       (void) fprintf(file1, "                                  ");
  680.       (void) fprintf(file1, "                   ");
  681.       (void) fprintf(file1, "     Charisma     :%s\n", out_chr);
  682.       (void) fprintf(file1, "\n");
  683.       (void) fprintf(file1, "\n");
  684.       (void) fprintf(file1, "\n");
  685.       (void) fprintf(file1, "\n");
  686.     
  687.       (void) fprintf(file1, "  + To Hit    :%6d", py.misc.dis_th);
  688.       (void) fprintf(file1, "     Level      :%6d", (int)py.misc.lev);
  689.       (void) fprintf(file1, "     Max Hit Points :%6d\n", py.misc.mhp);
  690.       (void) fprintf(file1, "  + To Damage :%6d", py.misc.dis_td);
  691.       (void) fprintf(file1, "     Experience :%6ld", py.misc.exp);
  692.       (void) fprintf(file1, "     Cur Hit Points :%6d\n", (int) (py.misc.chp));
  693.       (void) fprintf(file1, "  + To AC     :%6d", py.misc.dis_tac);
  694.       (void) fprintf(file1, "     Gold       :%6ld", py.misc.au);
  695.       (void) fprintf(file1, "     Max Mana       :%6d\n", py.misc.mana);
  696.       (void) fprintf(file1, "    Total AC  :%6d", py.misc.dis_ac);
  697.       (void) fprintf(file1, "                       ");
  698.       (void) fprintf(file1, "     Cur Mana       :%6d\n", (int) (py.misc.cmana));
  699.     
  700.       (void) fprintf(file1, "\n");
  701.       (void) fprintf(file1, "\n");
  702.       p_ptr = &py.misc;
  703.       xbth = p_ptr->bth + p_ptr->lev * BTH_LEV_ADJ +
  704.         p_ptr->ptohit * BTH_PLUS_ADJ;
  705.       xbthb = p_ptr->bthb + p_ptr->lev * BTH_LEV_ADJ +
  706.         p_ptr->ptohit * BTH_PLUS_ADJ;
  707.       /* this results in a range from 0 to 29 */
  708.       xfos = 40 - p_ptr->fos;
  709.       if (xfos < 0)
  710.         xfos = 0;
  711.       xsrh = p_ptr->srh + int_adj();
  712.       /* this results in a range from 0 to 9 */
  713.       xstl = p_ptr->stl + 1;
  714.       xdis = p_ptr->disarm + p_ptr->lev + 2 * todis_adj() + int_adj();
  715.       xsave = p_ptr->save + p_ptr->lev + wis_adj();
  716.       xdev = p_ptr->save + p_ptr->lev + int_adj();
  717.       (void) sprintf(xinfra, "%d feet", py.flags.see_infra * 10);
  718.  
  719.       (void) fprintf(file1, "(Miscellaneous Abilities)\n");
  720.       (void) fprintf(file1, "\n");
  721.       (void) fprintf(file1, "  Fighting    : %s", pad(likert(xbth, 12), " ", 10));
  722.       (void) fprintf(file1, "  Stealth     : %s", pad(likert(xstl, 1), " ", 10));
  723.       (void) fprintf(file1, "  Perception  : %s\n", pad(likert(xfos, 3), " ", 10));
  724.       (void) fprintf(file1, "  Throw/Bows  : %s", pad(likert(xbthb, 12), " ", 10));
  725.       (void) fprintf(file1, "  Disarming   : %s", pad(likert(xdis, 8), " ", 10));
  726.       (void) fprintf(file1, "  Searching   : %s\n", pad(likert(xsrh, 6), " ", 10));
  727.       (void) fprintf(file1, "  Saving Throw: %s", pad(likert(xsave, 6), " ", 10));
  728.       (void) fprintf(file1, "  Magic Device: %s", pad(likert(xdev, 6), " ", 10));
  729.       (void) fprintf(file1, "  Infra-Vision: %s\n", pad(xinfra, " ", 10));
  730.       /* Write out the character's history     */
  731.       (void) fprintf(file1, "\n");
  732.       (void) fprintf(file1, "\n");
  733.       (void) fprintf(file1, "Character Background\n");
  734.       for (i = 0; i < 5; i++)
  735.         (void) fprintf(file1, "%s\n", pad(py.misc.history[i], " ", 71));
  736.       /* Write out the equipment list...       */
  737.       j = 0;
  738.       (void) fprintf(file1, "\n");
  739.       (void) fprintf(file1, "\n");
  740.       (void) fprintf(file1, "  [Character's Equipment List]\n");
  741.       (void) fprintf(file1, "\n");
  742.       if (equip_ctr == 0)
  743.         (void) fprintf(file1, "  Character has no equipment in use.\n");
  744.       else
  745.         for (i = 22; i < INVEN_MAX; i++)
  746.           {
  747.         i_ptr = &inventory[i];
  748.         if (i_ptr->tval != 0)
  749.           {
  750.             switch (i)
  751.               {
  752.               case 22:
  753.             (void) strcpy(prt1, ") You are wielding   : ");
  754.             break;
  755.               case 23:
  756.             (void) strcpy(prt1, ") Worn on head       : ");
  757.             break;
  758.               case 24:
  759.             (void) strcpy(prt1, ") Worn around neck   : ");
  760.             break;
  761.               case 25:
  762.             (void) strcpy(prt1, ") Worn on body       : ");
  763.             break;
  764.               case 26:
  765.             (void) strcpy(prt1, ") Worn on shield arm : ");
  766.             break;
  767.               case 27:
  768.             (void) strcpy(prt1, ") Worn on hands      : ");
  769.             break;
  770.               case 28:
  771.             (void) strcpy(prt1, ") Right ring finger  : ");
  772.             break;
  773.               case 29:
  774.             (void) strcpy(prt1, ") Left  ring finger  : ");
  775.             break;
  776.               case 30:
  777.             (void) strcpy(prt1, ") Worn on feet       : ");
  778.             break;
  779.               case 31:
  780.             (void) strcpy(prt1, ") Worn about body    : ");
  781.             break;
  782.               case 32:
  783.             (void) strcpy(prt1, ") Light source is    : ");
  784.             break;
  785.               case 33:
  786.             (void) strcpy(prt1, ") Secondary weapon   : ");
  787.             break;
  788.               default:
  789.             (void) strcpy(prt1, ") *Unknown value*    : ");
  790.             break;
  791.               }
  792.             objdes(prt2, i, TRUE);
  793.             (void) fprintf(file1, "  %c%s%s\n", j + 97, prt1, prt2);
  794.             j++;
  795.           }
  796.           }
  797.     
  798.       /* Write out the character's inventory...        */
  799.       (void) fprintf(file1, "%c", 12);
  800.       (void) fprintf(file1, "\n");
  801.       (void) fprintf(file1, "\n");
  802.       (void) fprintf(file1, "\n");
  803.       (void) fprintf(file1, "  [General Inventory List]\n");
  804.       (void) fprintf(file1, "\n");
  805.       if (inven_ctr == 0)
  806.         (void) fprintf(file1, "  Character has no objects in inventory.\n");
  807.       else
  808.         {
  809.           for (i = 0; i < inven_ctr; i++)
  810.         {
  811.           objdes(prt1, i, TRUE);
  812.           (void) fprintf(file1, "%c) %s\n", i + 97, prt1);
  813.         }
  814.         }
  815.       (void) fprintf(file1, "%c", 12);
  816.       (void) fclose(file1);
  817.       prt("Completed.", 0, 0);
  818.     }
  819.     }
  820. }
  821.