home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / umoria / part05 / desc.c next >
C/C++ Source or Header  |  1987-11-04  |  8KB  |  369 lines

  1. #include <stdio.h>
  2. #ifdef USG
  3. #include <string.h>
  4. #else
  5. #include <strings.h>
  6. #endif
  7.  
  8. #include "constants.h"
  9. #include "types.h"
  10. #include "externs.h"
  11.  
  12. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  13. char *sprintf();
  14. #endif
  15.  
  16. /* Object descriptor routines                    */
  17.  
  18. int is_a_vowel(ch)
  19. char ch;
  20. {
  21.   switch(ch)
  22.     {
  23.     case 'a': case 'e': case 'i': case 'o': case 'u': 
  24.     case 'A': case 'E': case 'I': case 'O': case 'U':
  25.       return(TRUE);
  26.       break;
  27.     default:
  28.       return(FALSE);
  29.       break;
  30.     }
  31.   return(FALSE);
  32. }
  33.  
  34.  
  35. /* Randomize colors, woods, and metals                */
  36. randes()
  37. {
  38.   int i, j;
  39.   vtype tmp;
  40.  
  41.   for (i = 0; i < MAX_COLORS; i++)
  42.     {
  43.       j = randint(MAX_COLORS) - 1;
  44.       (void) strcpy(tmp, colors[i]);
  45.       (void) strcpy(colors[i], colors[j]);
  46.       (void) strcpy(colors[j], tmp);
  47.     }
  48.   for (i = 0; i < MAX_WOODS; i++)
  49.     {
  50.       j = randint(MAX_WOODS) - 1;
  51.       (void) strcpy(tmp, woods[i]);
  52.       (void) strcpy(woods[i], woods[j]);
  53.       (void) strcpy(woods[j], tmp);
  54.     }
  55.   for (i = 0; i < MAX_METALS; i++)
  56.     {
  57.       j = randint(MAX_METALS) - 1;
  58.       (void) strcpy(tmp, metals[i]);
  59.       (void) strcpy(metals[i], metals[j]);
  60.       (void) strcpy(metals[j], tmp);
  61.     }
  62.   for (i = 0; i < MAX_ROCKS; i++)
  63.     {
  64.       j = randint(MAX_ROCKS) - 1;
  65.       (void) strcpy(tmp, rocks[i]);
  66.       (void) strcpy(rocks[i], rocks[j]);
  67.       (void) strcpy(rocks[j], tmp);
  68.     }
  69.   for (i = 0; i < MAX_AMULETS; i++)
  70.     {
  71.       j = randint(MAX_AMULETS) - 1;
  72.       (void) strcpy(tmp, amulets[i]);
  73.       (void) strcpy(amulets[i], amulets[j]);
  74.       (void) strcpy(amulets[j], tmp);
  75.     }
  76.   for (i = 0; i < MAX_MUSH; i++)
  77.     {
  78.       j = randint(MAX_MUSH) - 1;
  79.       (void) strcpy(tmp, mushrooms[i]);
  80.       (void) strcpy(mushrooms[i], mushrooms[j]);
  81.       (void) strcpy(mushrooms[j], tmp);
  82.     }
  83. }
  84.  
  85.  
  86. /* Return random title                        */
  87. rantitle(title)
  88. char *title;
  89. {
  90.   int i, j, k;
  91.  
  92.   k = randint(2) + 1;
  93.   (void) strcpy(title, "Titled \"");
  94.   for (i = 0; i < k; i++)
  95.     {
  96.       for (j = 0; j < randint(2); j++)
  97.     (void) strcat(title, syllables[randint(MAX_SYLLABLES) - 1]);
  98.       if (i < k-1)
  99.     (void) strcat(title, " ");
  100.     }
  101.   (void) strcat(title, "\"");
  102. }
  103.  
  104.  
  105. /* Initialize all Potions, wands, staves, scrolls, ect...    */
  106. magic_init()
  107. {
  108.   int i, tmpv;
  109.   vtype tmps;
  110.  
  111.   set_seed(randes_state, randes_seed);
  112.   randes();
  113.   for (i = 0; i < MAX_OBJECTS; i++)
  114.     {
  115.       tmpv = (0xFF & object_list[i].subval);
  116.       switch(object_list[i].tval)
  117.     {
  118.     case 75: case 76:
  119.       if (tmpv < MAX_COLORS) 
  120.         insert_str(object_list[i].name, "%C", colors[tmpv]);
  121.       break;
  122.     case 70: case 71:
  123.       rantitle(tmps);
  124.       insert_str(object_list[i].name, "%T", tmps);
  125.       break;
  126.     case 45:
  127.       if (tmpv < MAX_ROCKS) 
  128.         insert_str(object_list[i].name, "%R", rocks[tmpv]);
  129.       break;
  130.     case 40: if (tmpv < MAX_AMULETS) 
  131.       insert_str(object_list[i].name, "%A", amulets[tmpv]);
  132.       break;
  133.     case 65:
  134.       if (tmpv < MAX_METALS) 
  135.         insert_str(object_list[i].name, "%M", metals[tmpv]);
  136.       break;
  137.     case 55:
  138.       if (tmpv < MAX_WOODS) 
  139.         insert_str(object_list[i].name, "%W", woods[tmpv]);
  140.       break;
  141.     case 80:
  142.       if (tmpv < MAX_MUSH) 
  143.         insert_str(object_list[i].name, "%M", mushrooms[tmpv]);
  144.       break;
  145.     case 60:
  146.       /*if (tmpv < MAX_RODS) 
  147.         insert_str(object_list[i].name, "%D", rods[tmpv])*/;
  148.       break;
  149.     default:
  150.       break;
  151.     }
  152.     }
  153.   reset_seed();
  154. }
  155.  
  156.  
  157. /* Remove "Secret" symbol for identity of object            */
  158. known1(object_str)
  159. char *object_str;
  160. {
  161.   int pos;
  162.   vtype str1, str2;
  163.   char *string;
  164.  
  165.   string = index(object_str, '|');
  166.   if (string)
  167.     pos = strlen(object_str) - strlen(string);
  168.   else
  169.     pos = -1;
  170.   if (pos >= 0) 
  171.     {
  172.       (void) strncpy(str1, object_str, pos);
  173.       str1[pos] = '\0';
  174.       (void) strcpy(str2, &object_str[pos+1]);
  175.       (void) strcpy(object_str, strcat(str1, str2));
  176.     }
  177. }
  178.  
  179.  
  180. /* Remove "Secret" symbol for identity of plusses            */
  181. known2(object_str)
  182. char *object_str;
  183. {
  184.   int pos;
  185.   vtype str1, str2;
  186.   char *string;
  187.  
  188.   string = index(object_str, '^');
  189.   if (string)
  190.     pos = strlen(object_str) - strlen(string);
  191.   else
  192.     pos = -1;
  193.   if (pos >= 0) 
  194.     {
  195.       (void) strncpy(str1, object_str, pos);
  196.       str1[pos] = '\0';
  197.       (void) strcpy(str2, &object_str[pos+1]);
  198.       (void) strcpy(object_str, strcat(str1, str2));
  199.     }
  200. }
  201.  
  202.  
  203. /* Return string without quoted portion                */
  204. unquote(object_str)
  205. char *object_str;
  206. {
  207.   int pos0, pos1, pos2;
  208.   vtype str1, str2;
  209.   char *string;
  210.  
  211.   string = index(object_str, '\"');
  212.   if (string)
  213.     pos0 = strlen(string) - strlen(object_str);
  214.   else
  215.     pos0 = -1;
  216.   if (pos0 >= 0) 
  217.     {
  218.       string = index(object_str, '~');
  219.       if (string)
  220.     pos1 = strlen(string) - strlen(object_str);
  221.       else
  222.     pos1 = 0;
  223.       string = index(object_str, '|');
  224.       if (string)
  225.     pos2 = strlen(string) - strlen(object_str);
  226.       else
  227.     pos2 = 0;
  228.       (void) strncpy(str1, object_str, pos1);
  229.       str1[pos1] = '\0';
  230.       (void) strcpy(str2, &object_str[pos2+1]);
  231.       (void) strcpy(object_str, strcat(str1, str2));
  232.     }
  233. }
  234.       
  235.  
  236. /* Somethings been identified                    */
  237. identify(item)
  238. treasure_type item;
  239. {
  240.   int i, x1, x2;
  241.   treasure_type *t_ptr;
  242.   char *string;
  243.  
  244.   x1 = item.tval;
  245.   x2 = item.subval;
  246.   if (index(item.name, '|') != 0) 
  247.     {
  248.       for (i = 0; i < MAX_TALLOC; i++)
  249.     {
  250.       t_ptr = &t_list[i];
  251.       if ((t_ptr->tval == x1) && (t_ptr->subval == x2)) 
  252.         {
  253.           unquote(t_ptr->name);
  254.           known1(t_ptr->name);
  255.         }
  256.     }
  257.       for (i = 0; i <= INVEN_MAX; i++)
  258.     {
  259.       t_ptr = &inventory[i];
  260.       if ((t_ptr->tval == x1) && (t_ptr->subval == x2)) 
  261.         {
  262.           unquote(t_ptr->name);
  263.           known1(t_ptr->name);
  264.         }
  265.     }
  266.       i = 0;
  267.       do
  268.     {
  269.       t_ptr = &object_list[i];
  270.       if ((t_ptr->tval == x1) && (t_ptr->subval == x2)) 
  271.         if ((string = index(t_ptr->name, '%')) && (string[0] == 'T'))
  272.           {
  273.         insert_str(t_ptr->name, " %T|", "");
  274.         object_ident[i] = TRUE;
  275.           }
  276.         else
  277.           {
  278.         unquote(t_ptr->name);
  279.         known1(t_ptr->name);
  280.         object_ident[i] = TRUE;
  281.           }
  282.       i++;
  283.     }
  284.       while (i != MAX_OBJECTS);
  285.     }
  286. }
  287.  
  288.  
  289. /* Returns a description of item for inventory            */
  290. objdes(out_val, ptr, pref)
  291. char *out_val;
  292. int ptr;
  293. int pref;
  294. {
  295.   int pos;
  296.   vtype tmp_val;
  297.   treasure_type *i_ptr;
  298.   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.       else
  360.     (void) strcpy(out_val, tmp_val);
  361.       (void) strcat(out_val, ".");
  362.     }
  363.   else
  364.     {
  365.       insert_str(tmp_val, "& ", "");
  366.       (void) strcpy(out_val, tmp_val);
  367.     }
  368. }
  369.