home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / umoria / part14 / files.c next >
C/C++ Source or Header  |  1987-11-05  |  26KB  |  802 lines

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