home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / mor4873s.lzh / DESC.C < prev    next >
C/C++ Source or Header  |  1988-12-14  |  9KB  |  382 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. #else
  11. #include <strings.h>
  12. #endif
  13.  
  14. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  15. char *sprintf();
  16. #endif
  17.  
  18. /* Object descriptor routines                    */
  19.  
  20. int is_a_vowel(ch)
  21. char ch;
  22. {
  23.   switch(ch)
  24.     {
  25.     case 'a': case 'e': case 'i': case 'o': case 'u':
  26.     case 'A': case 'E': case 'I': case 'O': case 'U':
  27.       return(TRUE);
  28.     default:
  29.       return(FALSE);
  30.     }
  31. }
  32.  
  33.  
  34. /* Randomize colors, woods, and metals                */
  35. randes()
  36. {
  37.   register int i, j;
  38.   vtype tmp;
  39.  
  40.   for (i = 0; i < MAX_COLORS; i++)
  41.     {
  42.       j = randint(MAX_COLORS) - 1;
  43.       (void) strcpy(tmp, colors[i]);
  44.       (void) strcpy(colors[i], colors[j]);
  45.       (void) strcpy(colors[j], tmp);
  46.     }
  47.   for (i = 0; i < MAX_WOODS; i++)
  48.     {
  49.       j = randint(MAX_WOODS) - 1;
  50.       (void) strcpy(tmp, woods[i]);
  51.       (void) strcpy(woods[i], woods[j]);
  52.       (void) strcpy(woods[j], tmp);
  53.     }
  54.   for (i = 0; i < MAX_METALS; i++)
  55.     {
  56.       j = randint(MAX_METALS) - 1;
  57.       (void) strcpy(tmp, metals[i]);
  58.       (void) strcpy(metals[i], metals[j]);
  59.       (void) strcpy(metals[j], tmp);
  60.     }
  61.   for (i = 0; i < MAX_ROCKS; i++)
  62.     {
  63.       j = randint(MAX_ROCKS) - 1;
  64.       (void) strcpy(tmp, rocks[i]);
  65.       (void) strcpy(rocks[i], rocks[j]);
  66.       (void) strcpy(rocks[j], tmp);
  67.     }
  68.   for (i = 0; i < MAX_AMULETS; i++)
  69.     {
  70.       j = randint(MAX_AMULETS) - 1;
  71.       (void) strcpy(tmp, amulets[i]);
  72.       (void) strcpy(amulets[i], amulets[j]);
  73.       (void) strcpy(amulets[j], tmp);
  74.     }
  75.   for (i = 0; i < MAX_MUSH; i++)
  76.     {
  77.       j = randint(MAX_MUSH) - 1;
  78.       (void) strcpy(tmp, mushrooms[i]);
  79.       (void) strcpy(mushrooms[i], mushrooms[j]);
  80.       (void) strcpy(mushrooms[j], tmp);
  81.     }
  82. }
  83.  
  84.  
  85. /* Return random title                        */
  86. rantitle(title)
  87. char *title;
  88. {
  89.   register int i, j, k;
  90.  
  91.   k = randint(2) + 1;
  92.   (void) strcpy(title, "Titled \"");
  93.   for (i = 0; i < k; i++)
  94.     {
  95.       for (j = 0; j < randint(2); j++)
  96.     (void) strcat(title, syllables[randint(MAX_SYLLABLES) - 1]);
  97.       if (i < k-1)
  98.     (void) strcat(title, " ");
  99.     }
  100.   (void) strcat(title, "\"");
  101. }
  102.  
  103.  
  104. /* Initialize all Potions, wands, staves, scrolls, ect...    */
  105. magic_init()
  106. {
  107.   register int i, tmpv;
  108.   vtype tmps;
  109.  
  110.   set_seed(randes_state, randes_seed);
  111.   randes();
  112.   for (i = 0; i < MAX_OBJECTS; i++)
  113.     {
  114.       tmpv = (0xFF & object_list[i].subval);
  115.       switch(object_list[i].tval)
  116.     {
  117.     case 75: case 76:
  118.       if (tmpv < MAX_COLORS)
  119.         insert_str(object_list[i].name, "%C", colors[tmpv]);
  120.       break;
  121.     case 70: case 71:
  122.       rantitle(tmps);
  123.       insert_str(object_list[i].name, "%T", tmps);
  124.       break;
  125.     case 45:
  126.       if (tmpv < MAX_ROCKS)
  127.         insert_str(object_list[i].name, "%R", rocks[tmpv]);
  128.       break;
  129.     case 40: if (tmpv < MAX_AMULETS)
  130.       insert_str(object_list[i].name, "%A", amulets[tmpv]);
  131.       break;
  132.     case 65:
  133.       if (tmpv < MAX_METALS)
  134.         insert_str(object_list[i].name, "%M", metals[tmpv]);
  135.       break;
  136.     case 55:
  137.       if (tmpv < MAX_WOODS)
  138.         insert_str(object_list[i].name, "%W", woods[tmpv]);
  139.       break;
  140.     case 80:
  141.       if (tmpv < MAX_MUSH)
  142.         insert_str(object_list[i].name, "%M", mushrooms[tmpv]);
  143.       break;
  144.     case 60:
  145.       /*if (tmpv < MAX_RODS)
  146.         insert_str(object_list[i].name, "%D", rods[tmpv])*/;
  147.       break;
  148.     default:
  149.       break;
  150.     }
  151.     }
  152.   reset_seed();
  153. }
  154.  
  155.  
  156. /* Remove "Secret" symbol for identity of object            */
  157. known1(object_str)
  158. char *object_str;
  159. {
  160.   register int pos;
  161.   vtype str1, str2;
  162.   register char *string;
  163.  
  164.   string = index(object_str, '|');
  165.   if (string)
  166.     pos = strlen(object_str) - strlen(string);
  167.   else
  168.     pos = -1;
  169.   if (pos >= 0)
  170.     {
  171.       (void) strncpy(str1, object_str, pos);
  172.       str1[pos] = '\0';
  173.       (void) strcpy(str2, &object_str[pos+1]);
  174.       (void) strcpy(object_str, strcat(str1, str2));
  175.     }
  176. }
  177.  
  178.  
  179. /* Remove "Secret" symbol for identity of plusses            */
  180. known2(object_str)
  181. char *object_str;
  182. {
  183.   register int pos;
  184.   vtype str1, str2;
  185.   register char *string;
  186.  
  187.   string = index(object_str, '^');
  188.   if (string)
  189.     pos = strlen(object_str) - strlen(string);
  190.   else
  191.     pos = -1;
  192.   if (pos >= 0)
  193.     {
  194.       (void) strncpy(str1, object_str, pos);
  195.       str1[pos] = '\0';
  196.       (void) strcpy(str2, &object_str[pos+1]);
  197.       (void) strcpy(object_str, strcat(str1, str2));
  198.     }
  199. }
  200.  
  201.  
  202. /* Return string without quoted portion                */
  203. unquote(object_str)
  204. char *object_str;
  205. {
  206.   register int pos0, pos1, pos2;
  207.   vtype str1, str2;
  208.   register char *string;
  209.  
  210.   string = index(object_str, '\"');
  211.   if (string)
  212.     pos0 = strlen(string) - strlen(object_str);
  213.   else
  214.     pos0 = -1;
  215.   if (pos0 >= 0)
  216.     {
  217.       string = index(object_str, '~');
  218.       if (string)
  219.     pos1 = strlen(string) - strlen(object_str);
  220.       else
  221.     pos1 = 0;
  222.       string = index(object_str, '|');
  223.       if (string)
  224.     pos2 = strlen(string) - strlen(object_str);
  225.       else
  226.     pos2 = 0;
  227.       (void) strncpy(str1, object_str, pos1);
  228.       str1[pos1] = '\0';
  229.       (void) strcpy(str2, &object_str[pos2+1]);
  230.       (void) strcpy(object_str, strcat(str1, str2));
  231.     }
  232. }
  233.     
  234.  
  235. /* Somethings been identified                    */
  236. identify(item)
  237. treasure_type item;
  238. {
  239.   register int i, x1, x2;
  240.   register treasure_type *t_ptr;
  241.   char *string;
  242.  
  243.   x1 = item.tval;
  244.   x2 = item.subval;
  245.   if (index(item.name, '|') != 0)
  246.     {
  247.       for (i = 0; i < MAX_TALLOC; i++)
  248.     {
  249.       t_ptr = &t_list[i];
  250.       if ((t_ptr->tval == x1) && (t_ptr->subval == x2))
  251.         {
  252.           unquote(t_ptr->name);
  253.           known1(t_ptr->name);
  254.         }
  255.     }
  256.       for (i = 0; i <= INVEN_MAX; i++)
  257.     {
  258.       t_ptr = &inventory[i];
  259.       if ((t_ptr->tval == x1) && (t_ptr->subval == x2))
  260.         {
  261.           unquote(t_ptr->name);
  262.           known1(t_ptr->name);
  263.         }
  264.     }
  265.       i = 0;
  266.       do
  267.     {
  268.       t_ptr = &object_list[i];
  269.       if ((t_ptr->tval == x1) && (t_ptr->subval == x2))
  270.         if ((string = index(t_ptr->name, '%')) && (string[0] == 'T'))
  271.           {
  272.         insert_str(t_ptr->name, " %T|", "");
  273.         object_ident[i] = TRUE;
  274.           }
  275.         else
  276.           {
  277.         unquote(t_ptr->name);
  278.         known1(t_ptr->name);
  279.         object_ident[i] = TRUE;
  280.           }
  281.       i++;
  282.     }
  283.       while (i != MAX_OBJECTS);
  284.     }
  285. }
  286.  
  287.  
  288. /* Returns a description of item for inventory            */
  289. /* pref indicates that there should be an article added (prefix) */
  290. objdes(out_val, ptr, pref)
  291. char *out_val;
  292. int ptr;
  293. int pref;
  294. {
  295.   register int pos;
  296.   bigvtype tmp_val;
  297.   register treasure_type *i_ptr;
  298.   register char *string;
  299.  
  300.   i_ptr = &inventory[ptr];
  301.   (void) strcpy(tmp_val, i_ptr->name);
  302.   string = index(tmp_val, '|');
  303.   if (string)
  304.     pos = strlen(tmp_val) - strlen(string);
  305.   else
  306.     pos = -1;
  307.   if (pos >= 0)
  308.     {
  309.       tmp_val[pos] = '\0';
  310.     }
  311.   string = index(tmp_val, '^');
  312.   if (string)
  313.     pos = strlen(tmp_val) - strlen(string);
  314.   else
  315.     pos = -1;
  316.   if (pos >= 0)
  317.     {
  318.       tmp_val[pos] = '\0';
  319.     }
  320.   if (!pref)
  321.     {
  322.       string = index(tmp_val, '(');
  323.       if (string)
  324.     pos = strlen(tmp_val) - strlen(string);
  325.       else
  326.     pos = -1;
  327.       if (pos >= 0)
  328.     {
  329.       tmp_val[pos] = '\0';
  330.     }
  331.     }
  332.   insert_num(tmp_val, "%P1", i_ptr->p1, TRUE);
  333.   insert_num(tmp_val, "%P2", i_ptr->tohit, TRUE);
  334.   insert_num(tmp_val, "%P3", i_ptr->todam, TRUE);
  335.   insert_num(tmp_val, "%P4", i_ptr->toac, TRUE);
  336.   insert_num(tmp_val, "%P5", i_ptr->p1, FALSE);
  337.   insert_num(tmp_val, "%P6", i_ptr->ac, FALSE);
  338.   if (i_ptr->number != 1)
  339.     {
  340.       insert_str(tmp_val, "ch~", "ches");
  341.       insert_str(tmp_val, "~", "s");
  342.     }
  343.   else
  344.     insert_str(tmp_val, "~", "");
  345.   if (pref)
  346.     {
  347.       if (index(tmp_val, '&') != 0)
  348.     {
  349.       insert_str(tmp_val, "&", "");
  350.       if (i_ptr->number > 1)
  351.         (void) sprintf(out_val, "%d%s", (int)i_ptr->number, tmp_val);
  352.       else if (i_ptr->number < 1)
  353.         (void) sprintf(out_val, "%s%s", "no more", tmp_val);
  354.       else if (is_a_vowel(tmp_val[1]))
  355.         (void) sprintf(out_val, "an%s", tmp_val);
  356.       else
  357.         (void) sprintf(out_val, "a%s", tmp_val);
  358.     }
  359.       /* handle 'no more' case specially */
  360.       else if (i_ptr->number < 1)
  361.     {
  362.       /* check for "some" at start */
  363.       if (!strncmp("some", tmp_val, 4))
  364.         (void) sprintf(out_val, "no more %s", &tmp_val[5]);
  365.       /* here if no article */
  366.       else
  367.         (void) sprintf(out_val, "no more %s", tmp_val);
  368.     }
  369.       else
  370.     (void) strcpy(out_val, tmp_val);
  371.       (void) strcat(out_val, ".");
  372.     }
  373.   else
  374.     {
  375.       insert_str(tmp_val, "& ", "");
  376.       if (!strncmp("some", tmp_val, 4))
  377.     (void) strcpy(out_val, &tmp_val[5]);
  378.       else
  379.     (void) strcpy(out_val, tmp_val);
  380.     }
  381. }
  382.