home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / umoria / part09 / misc2.c < prev   
C/C++ Source or Header  |  1987-11-05  |  41KB  |  1,928 lines

  1. #include <stdio.h>
  2. #ifdef USG
  3. #include <string.h>
  4. #else
  5. #include <strings.h>
  6. #endif
  7. #include <sys/types.h>
  8.  
  9. #include "config.h"
  10. #include "constants.h"
  11. #include "types.h"
  12. #include "externs.h"
  13.  
  14. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  15. char *sprintf();
  16. #endif
  17.  
  18. #if defined(ultrix) || defined(sun) || defined(USG)
  19. int getuid();
  20. #else
  21. uid_t getuid();
  22. #endif
  23.  
  24. /* Places a particular trap at location y, x        -RAK-    */
  25. place_trap(y, x, typ, subval)
  26. int y, x, typ, subval;
  27. {
  28.   int cur_pos;
  29.   treasure_type cur_trap;
  30.  
  31.   if (typ == 1) 
  32.     cur_trap = trap_lista[subval];
  33.   else
  34.     cur_trap = trap_listb[subval];
  35.   popt(&cur_pos);
  36.   cave[y][x].tptr  = cur_pos;
  37.   t_list[cur_pos] = cur_trap;
  38. }
  39.  
  40.  
  41. /* Places rubble at location y, x             -RAK-    */
  42. place_rubble(y, x)
  43. int y, x;
  44. {
  45.   int cur_pos;
  46.   cave_type *cave_ptr;
  47.  
  48.   popt(&cur_pos);
  49.   cave_ptr = &cave[y][x];
  50.   cave_ptr->tptr = cur_pos;
  51.   cave_ptr->fopen = FALSE;
  52.   t_list[cur_pos] = rubble;
  53. }
  54.  
  55.  
  56. place_open_door(y, x)
  57. int y, x;
  58. {
  59.   int cur_pos;
  60.   cave_type *cave_ptr;
  61.  
  62.   popt(&cur_pos);
  63.   cave_ptr = &cave[y][x];
  64.   cave_ptr->tptr = cur_pos;
  65.   t_list[cur_pos] = door_list[0];
  66.   cave_ptr->fval  = corr_floor3.ftval;
  67.   cave_ptr->fopen = TRUE;
  68. }
  69.  
  70.  
  71. place_broken_door(y, x)
  72. int y, x;
  73. {
  74.   int cur_pos;
  75.   cave_type *cave_ptr;
  76.  
  77.   popt(&cur_pos);
  78.   cave_ptr = &cave[y][x];
  79.   cave_ptr->tptr = cur_pos;
  80.   t_list[cur_pos] = door_list[0];
  81.   cave_ptr->fval  = corr_floor3.ftval;
  82.   cave_ptr->fopen = TRUE;
  83.   t_list[cur_pos].p1 = 1;
  84. }
  85.  
  86.  
  87. place_closed_door(y, x)
  88. int y, x;
  89. {
  90.   int cur_pos;
  91.   cave_type *cave_ptr;
  92.  
  93.   popt(&cur_pos);
  94.   cave_ptr = &cave[y][x];
  95.   cave_ptr->tptr = cur_pos;
  96.   t_list[cur_pos] = door_list[1];
  97.   cave_ptr->fval  = corr_floor3.ftval;
  98.   cave_ptr->fopen = FALSE;
  99. }
  100.  
  101.  
  102. place_locked_door(y, x)
  103. int y, x;
  104. {
  105.   int cur_pos;
  106.   cave_type *cave_ptr;
  107.  
  108.   popt(&cur_pos);
  109.   cave_ptr = &cave[y][x];
  110.   cave_ptr->tptr = cur_pos;
  111.   t_list[cur_pos] = door_list[1];
  112.   cave_ptr->fval  = corr_floor3.ftval;
  113.   cave_ptr->fopen = FALSE;
  114.   t_list[cur_pos].p1 = randint(10) + 10;
  115. }
  116.  
  117.  
  118. place_stuck_door(y, x)
  119. int y, x;
  120. {
  121.   int cur_pos;
  122.   cave_type *cave_ptr;
  123.  
  124.   popt(&cur_pos);
  125.   cave_ptr = &cave[y][x];
  126.   cave_ptr->tptr = cur_pos;
  127.   t_list[cur_pos] = door_list[1];
  128.   cave_ptr->fval  = corr_floor3.ftval;
  129.   cave_ptr->fopen = FALSE;
  130.   t_list[cur_pos].p1 = -randint(10) - 10;
  131. }
  132.  
  133.  
  134. place_secret_door(y, x)
  135. int y, x;
  136. {
  137.   int cur_pos;
  138.   cave_type *cave_ptr;
  139.  
  140.   popt(&cur_pos);
  141.   cave_ptr = &cave[y][x];
  142.   cave_ptr->tptr = cur_pos;
  143.   t_list[cur_pos] = door_list[2];
  144.   cave_ptr->fval  = corr_floor4.ftval;
  145.   cave_ptr->fopen = FALSE;
  146. }
  147.  
  148.  
  149. place_door(y, x)
  150. int y, x;
  151. {
  152.   switch(randint(3))
  153.     {
  154.     case 1: 
  155.       switch(randint(4))
  156.     {
  157.     case 1: 
  158.       place_broken_door(y, x);
  159.       break;
  160.     default:
  161.       place_open_door(y, x);
  162.       break;
  163.     }
  164.       break;
  165.     case 2: 
  166.       switch(randint(12))
  167.     {
  168.     case 1: case 2:
  169.       place_locked_door(y, x);
  170.       break;
  171.     case 3:
  172.       place_stuck_door(y, x);
  173.       break;
  174.     default:
  175.       place_closed_door(y, x);
  176.       break;
  177.     }
  178.     case 3:
  179.       place_secret_door(y, x);
  180.       break;
  181.     }
  182. }
  183.  
  184.  
  185. /* Place an up staircase at given y, x            -RAK-    */
  186. place_up_stairs(y, x)
  187. int y, x;
  188. {
  189.   int cur_pos;
  190.   cave_type *cave_ptr;
  191.  
  192.   cave_ptr = &cave[y][x];
  193.   if (cave_ptr->tptr != 0) 
  194.     {
  195.       pusht((int)cave_ptr->tptr);
  196.       cave_ptr->tptr = 0;
  197.       cave_ptr->fopen = TRUE;
  198.     }
  199.   popt(&cur_pos);
  200.   cave[y][x].tptr = cur_pos;
  201.   t_list[cur_pos] = up_stair;
  202. }
  203.  
  204.  
  205. /* Place a down staircase at given y, x            -RAK-    */
  206. place_down_stairs(y, x)
  207. int y, x;
  208. {
  209.   int cur_pos;
  210.   cave_type *cave_ptr;
  211.  
  212.   cave_ptr = &cave[y][x];
  213.   if (cave_ptr->tptr != 0) 
  214.     {
  215.       pusht((int)cave_ptr->tptr);
  216.       cave_ptr->tptr = 0;
  217.       cave_ptr->fopen = TRUE;
  218.     }
  219.   popt(&cur_pos);
  220.   cave[y][x].tptr = cur_pos;
  221.   t_list[cur_pos] = down_stair;
  222. }
  223.  
  224. /* Places a staircase 1==up, 2==down            -RAK-    */
  225. place_stairs(typ, num, walls)
  226. int typ, num, walls;
  227. {
  228.   int i, j, y1, x1, y2, x2;
  229.   int flag;
  230.   cave_type *cave_ptr;
  231.  
  232.   for (i = 0; i < num; i++)
  233.     {
  234.       flag = FALSE;
  235.       do
  236.     {
  237.       j = 0;
  238.       do
  239.         {
  240.           y1 = randint(cur_height - 12) - 1;
  241.           x1 = randint(cur_width  - 12) - 1;
  242.           y2 = y1 + 12;
  243.           x2 = x1 + 12;
  244.           do
  245.         {
  246.           do
  247.             {
  248.               cave_ptr = &cave[y1][x1];
  249.               if ((cave_ptr->fval == 1) || (cave_ptr->fval == 2) ||
  250.               (cave_ptr->fval == 4))
  251.             if (cave_ptr->tptr == 0) 
  252.               if (next_to4(y1, x1, 10, 11, 12) >= walls) 
  253.                 {
  254.                   flag = TRUE;
  255.                   switch(typ)
  256.                 {
  257.                 case 1:
  258.                   place_up_stairs(y1, x1);
  259.                   break;
  260.                 case 2:
  261.                   place_down_stairs(y1, x1);
  262.                   break;
  263.                 }
  264.                 }
  265.               x1++;
  266.             }
  267.           while ((x1 != x2) && (!flag));
  268.           x1 = x2 - 12;
  269.           y1++;
  270.         }
  271.           while ((y1 != y2) && (!flag));
  272.           j++;
  273.         }
  274.       while ((!flag) && (j <= 30));
  275.       walls--;
  276.     }
  277.       while (!flag);
  278.     }
  279. }
  280.  
  281.  
  282. /* Places a treasure (Gold or Gems) at given row, column -RAK-    */
  283. place_gold(y, x)
  284. int y, x;
  285. {
  286.   int cur_pos, i;
  287.   treasure_type *t_ptr;
  288.  
  289.   popt(&cur_pos);
  290.   i = ((randint(dun_level+2)+2)/2.0) - 1;
  291.   if (randint(OBJ_GREAT) == 1) 
  292.     i += randint(dun_level+1);
  293.   if (i >= MAX_GOLD) 
  294.     i = MAX_GOLD - 1;
  295.   cave[y][x].tptr = cur_pos;
  296.   t_list[cur_pos] = gold_list[i];
  297.   t_ptr = &t_list[cur_pos];
  298.   t_ptr->cost += randint(8*t_ptr->cost);
  299. }
  300.  
  301.  
  302. /* Returns the array number of a random object        -RAK-    */
  303. int get_obj_num(level)
  304. int level;
  305. {
  306.   int i;
  307.  
  308.   if (level >= MAX_OBJ_LEVEL)
  309.     level = MAX_OBJ_LEVEL - 1;
  310.   if (randint(OBJ_GREAT) == 1)
  311.     level = MAX_OBJ_LEVEL - 1;
  312.   if (level == 0) 
  313.     i = randint(t_level[0]) - 1;
  314.   else
  315.     i = randint(t_level[level]) - 1;
  316.   return(i);
  317. }
  318.  
  319.  
  320. /* Places an object at given row, column co-ordinate    -RAK-    */
  321. place_object(y, x)
  322. int y, x;
  323. {
  324.   int cur_pos;
  325.  
  326.   popt(&cur_pos);
  327.   cave[y][x].tptr = cur_pos;
  328.   t_list[cur_pos] = object_list[get_obj_num(dun_level)];
  329.   magic_treasure(cur_pos, dun_level);
  330. }
  331.  
  332.  
  333. /* Allocates an object for tunnels and rooms        -RAK-    */
  334. alloc_object(alloc_set, typ, num)
  335. int (*alloc_set)();
  336. int typ, num;
  337. {
  338.   int i, j, k;
  339.  
  340.   for (k = 0; k < num; k++)
  341.     {
  342.       do
  343.     {
  344.       i = randint(cur_height) - 1;
  345.       j = randint(cur_width) - 1;
  346.     }
  347.       while ((!(*alloc_set)(cave[i][j].fval)) ||
  348.          (cave[i][j].tptr != 0));
  349.       switch(typ)
  350.     {
  351.     case 1:
  352.       place_trap(i, j, 1, randint(MAX_TRAPA)-1);
  353.       break;
  354.     case 2:
  355.       place_trap(i, j, 2, randint(MAX_TRAPB)-1);
  356.       break;
  357.     case 3:
  358.       place_rubble(i, j);
  359.       break;
  360.     case 4:
  361.       place_gold(i, j);
  362.       break;
  363.     case 5:
  364.       place_object(i, j);
  365.       break;
  366.     }
  367.     }
  368. }
  369.  
  370.  
  371. /* Creates objects nearby the coordinates given        -RAK-    */
  372. random_object(y, x, num)
  373. int y, x, num;
  374. {
  375.   int i, j, k;
  376.   cave_type *cave_ptr;
  377.  
  378.   do
  379.     {
  380.       i = 0;
  381.       do
  382.     {
  383.       j = y - 3 + randint(5);
  384.       k = x - 4 + randint(7);
  385.       cave_ptr = &cave[j][k];
  386.       if ((cave_ptr->fval <= 7) && (cave_ptr->fval >= 1))
  387.         if (cave_ptr->tptr == 0) 
  388.           {
  389.         if (randint(100) < 75) 
  390.           place_object(j, k);
  391.         else
  392.           place_gold(j, k);
  393.         i = 9;
  394.           }
  395.       i++;
  396.     }
  397.       while(i <= 10);
  398.       num--;
  399.     }
  400.   while (num != 0);
  401. }
  402.  
  403.  
  404. /* Converts stat num into string             -RAK-    */
  405. cnv_stat(stat, out_val)
  406. byteint stat;
  407. char *out_val;
  408. {
  409.   vtype tmp_str;
  410.   int part1, part2;
  411.  
  412.   if (stat > 18)
  413.     {
  414.       part1 = 18;
  415.       part2 = stat - 18;
  416.       if (part2 == 100)
  417.     (void) strcpy(tmp_str, "18/100");
  418.       else if (part2 < 10)
  419.     (void) sprintf(tmp_str, " %2d/0%d", part1, part2);
  420.       else
  421.     (void) sprintf(tmp_str, " %2d/%2d", part1, part2);
  422.     }
  423.   else
  424.     (void) sprintf(tmp_str, "%6d", stat);
  425.   if (strlen(tmp_str) < 6)
  426.     (void) strcpy(tmp_str, pad(tmp_str, " ", 6));
  427.   (void) strcpy(out_val, tmp_str);
  428. }
  429.  
  430.  
  431. /* Print character stat in given row, column        -RAK-    */
  432. prt_stat(stat_name, stat, row, column)
  433. vtype stat_name;
  434. byteint stat;
  435. int row, column;
  436. {
  437.   stat_type out_val1;
  438.   vtype out_val2;
  439.  
  440.   cnv_stat(stat, out_val1);
  441.   (void) strcpy(out_val2, stat_name);
  442.   (void) strcat(out_val2, out_val1);
  443.   put_buffer(out_val2, row, column);
  444. }
  445.  
  446.  
  447. /* Print character info in given row, column        -RAK-    */
  448. prt_field(info, row, column)
  449. vtype info;
  450. int row, column;
  451. {
  452.   put_buffer(pad(info, " ", 14), row, column);
  453. }
  454.  
  455.  
  456. /* Print number with header at given row, column     -RAK-    */
  457. prt_num(header, num, row, column)
  458. vtype header;
  459. int num, row, column;
  460. {
  461.   vtype out_val;
  462.  
  463.   (void) sprintf(out_val, "%s%6d ", header, num);
  464.   put_buffer(out_val, row, column);
  465. }
  466.  
  467.  
  468. /* Adjustment for wisdom                 -JWT-    */
  469. int wis_adj()
  470. {
  471.   if (py.stats.cwis > 117) 
  472.     return(7);
  473.   else if (py.stats.cwis > 107) 
  474.     return(6);
  475.   else if (py.stats.cwis > 87) 
  476.     return(5);
  477.   else if (py.stats.cwis > 67) 
  478.     return(4);
  479.   else if (py.stats.cwis > 17) 
  480.     return(3);
  481.   else if (py.stats.cwis > 14) 
  482.     return(2);
  483.   else if (py.stats.cwis > 7) 
  484.     return(1);
  485.   else
  486.     return(0);
  487. }  
  488.  
  489. /* adjustment for intelligence                -JWT-    */
  490. int int_adj()
  491. {
  492.   if (py.stats.cint > 117) 
  493.     return(7);
  494.   else if (py.stats.cint > 107) 
  495.     return(6);
  496.   else if (py.stats.cint > 87) 
  497.     return(5);
  498.   else if (py.stats.cint > 67) 
  499.     return(4);
  500.   else if (py.stats.cint > 17) 
  501.     return(3);
  502.   else if (py.stats.cint > 14) 
  503.     return(2);
  504.   else if (py.stats.cint > 7) 
  505.     return(1);
  506.   else
  507.     return(0);
  508. }
  509.  
  510.  
  511. /* Adjustment for charisma                -RAK-    */
  512. /* Percent decrease or increase in price of goods                */
  513. double chr_adj()
  514. {
  515.   if (py.stats.cchr > 117) 
  516.     return(-0.10);
  517.   else if (py.stats.cchr > 107) 
  518.     return(-0.08);
  519.   else if (py.stats.cchr > 87) 
  520.     return(-0.06);
  521.   else if (py.stats.cchr > 67) 
  522.     return(-0.04);
  523.   else if (py.stats.cchr > 18) 
  524.     return(-0.02);
  525.   else
  526.     switch(py.stats.cchr)
  527.       {
  528.       case 18:  return(0.00);  break;
  529.       case 17:  return(0.01);  break;
  530.       case 16:  return(0.02);  break;
  531.       case 15:  return(0.03);  break;
  532.       case 14:  return(0.04);  break;
  533.       case 13:  return(0.06);  break;
  534.       case 12:  return(0.08);  break;
  535.       case 11:  return(0.10);  break;
  536.       case 10:  return(0.12);  break;
  537.       case 9:  return(0.14);  break;
  538.       case 8:  return(0.16);  break;
  539.       case 7:  return(0.18);  break;
  540.       case 6:  return(0.20);  break;
  541.       case 5:  return(0.22);  break;
  542.       case 4:  return(0.24);  break;
  543.       case 3:  return(0.25);  break;
  544.       default: return(0.00);  break;   /* Error trap    */
  545.       }
  546.   return(0.00);
  547. }
  548.  
  549.  
  550. /* Returns a character's adjustment to hit points        -JWT-   */
  551. int con_adj()
  552. {
  553.   if (py.stats.ccon == 3)
  554.     return(-4);
  555.   else if (py.stats.ccon == 4)
  556.     return(-3);
  557.   else if (py.stats.ccon == 5)
  558.     return(-2);
  559.   else if (py.stats.ccon == 6)
  560.     return(-1);
  561.   else if (py.stats.ccon < 17)
  562.     return(0);
  563.   else if (py.stats.ccon ==  17) 
  564.     return(1);
  565.   else if (py.stats.ccon <  94) 
  566.     return(2);
  567.   else if (py.stats.ccon < 117) 
  568.     return(3);
  569.   else
  570.     return(4);
  571. }
  572.  
  573.  
  574. /* Calculates hit points for each level that is gained.    -RAK-    */
  575. int get_hitdie()
  576. {
  577.   return(randint((int)py.misc.hitdie) + con_adj());
  578. }
  579.  
  580.  
  581. /* Prints title of character                -RAK-    */
  582. prt_title()
  583. {
  584.   prt_field(py.misc.title, 4, stat_column);
  585. }
  586.  
  587.  
  588. /* Prints strength                    -RAK-    */
  589. prt_strength()
  590. {
  591.   prt_stat("\0", py.stats.cstr, 6, stat_column+6);
  592. }
  593.  
  594.  
  595. /* Prints intelligence                    -RAK-    */
  596. prt_intelligence()
  597. {
  598.   prt_stat("\0", py.stats.cint, 7, stat_column+6);
  599. }
  600.  
  601.  
  602. /* Prints wisdom                     -RAK-    */
  603. prt_wisdom()
  604. {
  605.   prt_stat("\0", py.stats.cwis, 8, stat_column+6);
  606. }
  607.  
  608.  
  609. /* Prints dexterity                    -RAK-    */
  610. prt_dexterity()
  611. {
  612.   prt_stat("\0", py.stats.cdex, 9, stat_column+6);
  613. }
  614.  
  615.  
  616. /* Prints constitution                    -RAK-    */
  617. prt_constitution()
  618. {
  619.   prt_stat("\0", py.stats.ccon, 10, stat_column+6);
  620. }
  621.  
  622.  
  623. /* Prints charisma                    -RAK-    */
  624. prt_charisma()
  625. {
  626.   prt_stat("\0", py.stats.cchr, 11, stat_column+6);
  627. }
  628.  
  629.  
  630. /* Prints level                        -RAK-    */
  631. prt_level()
  632. {
  633.   prt_num("\0", (int)py.misc.lev, 13, stat_column+6);
  634. }
  635.  
  636.  
  637. /* Prints players current mana points (a real number...) -RAK-    */
  638. prt_cmana()
  639. {
  640.   prt_num("\0", (int)(py.misc.cmana), 15, stat_column+6);
  641. }
  642.  
  643.  
  644. /* Prints Max hit points                 -RAK-    */
  645. prt_mhp()
  646. {
  647.   prt_num("\0", py.misc.mhp, 16, stat_column+6);
  648. }
  649.  
  650.  
  651. /* Prints players current hit points (a real number...)    -RAK-    */
  652. prt_chp()
  653. {
  654.   prt_num("\0", (int)(py.misc.chp), 17, stat_column+6);
  655. }
  656.  
  657.  
  658. /* prints current AC                    -RAK-    */
  659. prt_pac()
  660. {
  661.   prt_num("\0", py.misc.dis_ac, 19, stat_column+6);
  662. }
  663.  
  664.  
  665. /* Prints current gold                    -RAK-    */
  666. prt_gold()
  667. {
  668.   prt_num("\0", py.misc.au, 20, stat_column+6);
  669. }
  670.  
  671.  
  672. /* Prints depth in stat area                -RAK-    */
  673. prt_depth()
  674. {
  675.   vtype depths;
  676.   int depth;
  677.  
  678.   depth = dun_level*50;
  679.   if (depth == 0) 
  680.     (void) strcpy(depths, "Town level");
  681.   else
  682.     (void) sprintf(depths, "Depth: %d (feet)", depth);
  683.   prt(depths, 23, 60);
  684. }
  685.  
  686.  
  687. /* Prints status of hunger                -RAK-    */
  688. prt_hunger()
  689. {
  690.   if (0x000002 & py.flags.status)
  691.     put_buffer("Weak    ", 23, 0);
  692.   else if (0x000001 & py.flags.status)
  693.     put_buffer("Hungry  ", 23, 0);
  694.   else
  695.     put_buffer("        ", 23, 0);
  696. }
  697.  
  698.  
  699. /* Prints Blind status                    -RAK-    */
  700. prt_blind()
  701. {
  702.   if (0x000004 & py.flags.status)
  703.     put_buffer("Blind  ", 23, 8);
  704.   else
  705.     put_buffer("       ", 23, 8);
  706. }
  707.  
  708.  
  709. /* Prints Confusion status                -RAK-    */
  710. prt_confused()
  711. {
  712.   if (0x000008 & py.flags.status)
  713.     put_buffer("Confused  ", 23, 15);
  714.   else
  715.     put_buffer("          ", 23, 15);
  716. }
  717.  
  718.  
  719. /* Prints Fear status                    -RAK-    */
  720. prt_afraid()
  721. {
  722.   if (0x000010 & py.flags.status)
  723.     put_buffer("Afraid  ", 23, 25);
  724.   else
  725.     put_buffer("        ", 23, 25);
  726. }
  727.  
  728.  
  729. /* Prints Poisoned status                -RAK-    */
  730. prt_poisoned()
  731. {
  732.   if (0x000020 & py.flags.status)
  733.     put_buffer("Poisoned  ", 23, 33);
  734.   else
  735.     put_buffer("          ", 23, 33);
  736. }
  737.  
  738.  
  739. /* Prints Searching status                -RAK-    */
  740. prt_search()
  741. {
  742.   if (0x000100 & py.flags.status)
  743.     put_buffer("Searching  ", 23, 43);
  744.   else
  745.     put_buffer("           ", 23, 43);
  746. }
  747.  
  748.  
  749. /* Prints Resting status                 -RAK-    */
  750. prt_rest()
  751. {
  752.   if (0x000200 & py.flags.status)
  753.     put_buffer("Resting    ", 23, 43);
  754.   else
  755.     put_buffer("           ", 23, 43);
  756. }
  757.  
  758.  
  759. /* Prints winner status on display            -RAK-    */
  760. prt_winner()
  761. {
  762.   put_buffer("*Winner*", 22, 0);
  763. }
  764.  
  765.  
  766. /* Increases a stat by one randomized level        -RAK-    */
  767. byteint in_statp(stat)
  768. byteint stat;
  769. {
  770.   if (stat < 18) 
  771.     stat++;
  772.   else if (stat < 88) 
  773.     stat += randint(25);
  774.   else if (stat < 108) 
  775.     stat += randint(10);
  776.   else
  777.     stat++;
  778.   if (stat > 118) 
  779.     stat = 118;
  780.   return(stat);
  781. }
  782.  
  783.  
  784. /* Decreases a stat by one randomized level        -RAK-    */
  785. byteint de_statp(stat)
  786. byteint stat;
  787. {
  788.   if (stat < 19) 
  789.     stat--;
  790.   else if (stat < 109) 
  791.     {
  792.       stat += -randint(10) - 5;
  793.       if (stat < 18)
  794.     stat = 18;
  795.      } 
  796.   else
  797.     stat -= randint(3);
  798.   if (stat < 3)
  799.     stat = 3;
  800.   return(stat);
  801. }
  802.  
  803.  
  804. /* Increases a stat by one true level            -RAK-    */
  805. byteint in_statt(stat)
  806. byteint stat;
  807. {
  808.   if (stat < 18) 
  809.     stat++;
  810.   else
  811.     {
  812.       stat += 10;
  813.       if (stat > 118) 
  814.     stat = 118;
  815.     }
  816.   return(stat);
  817. }
  818.  
  819.  
  820. /* Decreases a stat by true level            -RAK-    */
  821. byteint de_statt(stat)
  822. byteint stat;
  823. {
  824.   if (stat > 27) 
  825.     stat -= 10;
  826.   else if (stat > 18) 
  827.     stat = 18;
  828.   else
  829.     {
  830.       stat--;
  831.       if (stat < 3)
  832.     stat = 3;
  833.     }
  834.   return(stat);
  835. }
  836.  
  837.  
  838. /* Returns a character's adjustment to hit.              -JWT-   */
  839. int tohit_adj()
  840. {
  841.   int total;
  842.  
  843.   if      (py.stats.cdex <   4)  total = -3;
  844.   else if (py.stats.cdex <   6)  total = -2;
  845.   else if (py.stats.cdex <   8)  total = -1;
  846.   else if (py.stats.cdex <  16)  total =  0;
  847.   else if (py.stats.cdex <  17)  total =  1;
  848.   else if (py.stats.cdex <  18)  total =  2;
  849.   else if (py.stats.cdex <  69)  total =  3;
  850.   else if (py.stats.cdex < 118)  total =  4;
  851.   else                          total =  5;
  852.   if      (py.stats.cstr <   4)  total -= 3;
  853.   else if (py.stats.cstr <   5)  total -= 2;
  854.   else if (py.stats.cstr <   7)  total -= 1;
  855.   else if (py.stats.cstr <  18)  total -= 0;
  856.   else if (py.stats.cstr <  94)  total += 1;
  857.   else if (py.stats.cstr < 109)  total += 2;
  858.   else if (py.stats.cstr < 117)  total += 3;
  859.   else                          total += 4;
  860.   return(total);
  861. }
  862.  
  863.  
  864. /* Returns a character's adjustment to armor class       -JWT-   */
  865. int toac_adj()
  866. {
  867.   if      (py.stats.cdex <   4)  return(-4);
  868.   else if (py.stats.cdex ==  4)  return(-3);
  869.   else if (py.stats.cdex ==  5)  return(-2);
  870.   else if (py.stats.cdex ==  6)  return(-1);
  871.   else if (py.stats.cdex <  15)  return( 0);
  872.   else if (py.stats.cdex <  18)  return( 1);
  873.   else if (py.stats.cdex <  59)  return( 2);
  874.   else if (py.stats.cdex <  94)  return( 3);
  875.   else if (py.stats.cdex < 117)  return( 4);
  876.   else                          return( 5);
  877. }
  878.  
  879.  
  880. /* Returns a character's adjustment to disarm            -RAK-   */
  881. int todis_adj()
  882. {
  883.   if      (py.stats.cdex ==  3)  return(-8);
  884.   else if (py.stats.cdex ==  4)  return(-6);
  885.   else if (py.stats.cdex ==  5)  return(-4);
  886.   else if (py.stats.cdex ==  6)  return(-2);
  887.   else if (py.stats.cdex ==  7)  return(-1);
  888.   else if (py.stats.cdex <  13)  return( 0);
  889.   else if (py.stats.cdex <  16)  return( 1);
  890.   else if (py.stats.cdex <  18)  return( 2);
  891.   else if (py.stats.cdex <  59)  return( 4);
  892.   else if (py.stats.cdex <  94)  return( 5);
  893.   else if (py.stats.cdex < 117)  return( 6);
  894.   else                          return( 8);
  895. }
  896.  
  897.  
  898. /* Returns a character's adjustment to damage            -JWT-   */
  899. int todam_adj()
  900. {
  901.   if      (py.stats.cstr <   4)  return(-2);
  902.   else if (py.stats.cstr <   5)  return(-1);
  903.   else if (py.stats.cstr <  16)  return( 0);
  904.   else if (py.stats.cstr <  17)  return( 1);
  905.   else if (py.stats.cstr <  18)  return( 2);
  906.   else if (py.stats.cstr <  94)  return( 3);
  907.   else if (py.stats.cstr < 109)  return( 4);
  908.   else if (py.stats.cstr < 117)  return( 5);
  909.   else                          return( 6);
  910. }
  911.  
  912.  
  913. /* Prints character-screen info                -RAK-    */
  914. prt_stat_block()
  915. {
  916.   prt_field(py.misc.race,                  2, stat_column);
  917.   prt_field(py.misc.tclass,                3, stat_column);
  918.   prt_field(py.misc.title,                 4, stat_column);
  919.   prt_stat("STR : ", py.stats.cstr,         6, stat_column);
  920.   prt_stat("INT : ", py.stats.cint,         7, stat_column);
  921.   prt_stat("WIS : ", py.stats.cwis,         8, stat_column);
  922.   prt_stat("DEX : ", py.stats.cdex,         9, stat_column);
  923.   prt_stat("CON : ", py.stats.ccon,        10, stat_column);
  924.   prt_stat("CHR : ", py.stats.cchr,        11, stat_column);
  925.   prt_num( "LEV : ", (int)py.misc.lev,    13, stat_column);
  926.   prt_num( "EXP : ", py.misc.exp,         14, stat_column);
  927.   prt_num( "MANA: ", (int)(py.misc.cmana), 15, stat_column);
  928.   prt_num( "MHP : ", py.misc.mhp,         16, stat_column);
  929.   prt_num( "CHP : ", (int)(py.misc.chp),  17, stat_column);
  930.   prt_num( "AC  : ", py.misc.dis_ac,      19, stat_column);
  931.   prt_num( "GOLD: ", py.misc.au,          20, stat_column);
  932.   if (total_winner)  prt_winner();
  933.   if (0x000003 & py.flags.status)
  934.     prt_hunger();
  935.   if (0x000004 & py.flags.status)
  936.     prt_blind();
  937.   if (0x000008 & py.flags.status)
  938.     prt_confused();
  939.   if (0x000010 & py.flags.status)
  940.     prt_afraid();
  941.   if (0x000020 & py.flags.status)
  942.     prt_poisoned();
  943.   if (0x000100 & py.flags.status)
  944.     prt_search();
  945.   if (0x000200 & py.flags.status)
  946.     prt_rest();
  947. }
  948.  
  949.  
  950. /* Draws entire screen                    -RAK-    */
  951. draw_cave()
  952. {
  953.   clear_screen(0, 0);
  954.   prt_stat_block();
  955.   prt_map();
  956.   prt_depth();
  957. }
  958.  
  959.  
  960. /* Prints the following information on the screen.    -JWT-    */
  961. put_character()
  962. {
  963.   char tmp_str[80];
  964.  
  965.   clear_screen(0, 0);
  966.   prt(strcat(strcpy(tmp_str, "Name      : "), py.misc.name), 2, 2);
  967.   prt(strcat(strcpy(tmp_str, "Race      : "), py.misc.race), 3, 2);
  968.   prt(strcat(strcpy(tmp_str, "Sex       : "), py.misc.sex), 4, 2);
  969.   prt(strcat(strcpy(tmp_str, "Class     : "), py.misc.tclass), 5, 2);
  970. }
  971.  
  972.  
  973. /* Prints the following information on the screen.    -JWT-    */
  974. put_stats()
  975. {
  976.   prt_stat("STR : ", py.stats.cstr, 2, 64);
  977.   prt_stat("INT : ", py.stats.cint, 3, 64);
  978.   prt_stat("WIS : ", py.stats.cwis, 4, 64);
  979.   prt_stat("DEX : ", py.stats.cdex, 5, 64);
  980.   prt_stat("CON : ", py.stats.ccon, 6, 64);
  981.   prt_stat("CHR : ", py.stats.cchr, 7, 64);
  982.   prt_num("+ To Hit   : ", py.misc.dis_th,  9, 3);
  983.   prt_num("+ To Damage: ", py.misc.dis_td, 10, 3);
  984.   prt_num("+ To AC    : ", py.misc.dis_tac, 11, 3);
  985.   prt_num("  Total AC : ", py.misc.dis_ac, 12, 3);
  986. }
  987.  
  988.  
  989. /* Returns a rating of x depending on y            -JWT-    */
  990. char *likert(x, y)
  991. int x, y;
  992. {
  993.   switch((x/y))
  994.     {
  995.       case -3: case -2: case -1: return("Very Bad");
  996.       case 0: case 1:            return("Bad");
  997.       case 2:                    return("Poor");
  998.       case 3: case 4:            return("Fair");
  999.       case  5:                   return("Good");
  1000.       case 6:                    return("Very Good");
  1001.       case 7: case 8:            return("Superb");
  1002.       default:                   return("Excellent");
  1003.       }
  1004. }
  1005.  
  1006.  
  1007. /* Prints age, height, weight, and SC            -JWT-    */
  1008. put_misc1()
  1009. {
  1010.   prt_num("Age          : ", (int)py.misc.age, 2, 39);
  1011.   prt_num("Height       : ", (int)py.misc.ht, 3, 39);
  1012.   prt_num("Weight       : ", (int)py.misc.wt, 4, 39);
  1013.   prt_num("Social Class : ", (int)py.misc.sc, 5, 39);
  1014. }
  1015.  
  1016.  
  1017. /* Prints the following information on the screen.    -JWT-    */
  1018. put_misc2()
  1019. {
  1020.   prt_num("Level      : ", (int)py.misc.lev, 9, 30);
  1021.   prt_num("Experience : ", py.misc.exp, 10, 30);
  1022.   prt_num("Gold       : ", py.misc.au, 11, 30);
  1023.   prt_num("Max Hit Points : ", py.misc.mhp, 9, 53);
  1024.   prt_num("Cur Hit Points : ", (int)py.misc.chp, 10, 53);
  1025.   prt_num("Max Mana       : ", py.misc.mana, 11, 53);
  1026.   prt_num("Cur Mana       : ", (int)py.misc.cmana, 12, 53);
  1027. }
  1028.  
  1029.  
  1030. /* Prints ratings on certain abilities            -RAK-    */
  1031. put_misc3()
  1032. {
  1033.   int xbth, xbthb, xfos, xsrh, xstl, xdis, xsave, xdev;
  1034.   vtype xinfra;
  1035.   struct misc *p_ptr;
  1036.   char tmp_str[80];
  1037.  
  1038.   clear_screen(13, 0);
  1039.   p_ptr = &py.misc;
  1040.   xbth  = p_ptr->bth + p_ptr->lev*BTH_LEV_ADJ + p_ptr->ptohit*BTH_PLUS_ADJ;
  1041.   xbthb = p_ptr->bthb + p_ptr->lev*BTH_LEV_ADJ + p_ptr->ptohit*BTH_PLUS_ADJ;
  1042.   xfos  = 27 - p_ptr->fos;
  1043.   if (xfos < 0)  xfos = 0;
  1044.   xsrh  = p_ptr->srh + int_adj();
  1045.   xstl  = p_ptr->stl;
  1046.   xdis  = p_ptr->disarm + p_ptr->lev + 2*todis_adj() + int_adj();
  1047.   xsave = p_ptr->save + p_ptr->lev + wis_adj();
  1048.   xdev  = p_ptr->save + p_ptr->lev + int_adj();
  1049.   (void) sprintf(xinfra, "%d feet", py.flags.see_infra*10);
  1050.  
  1051.   prt("(Miscellaneous Abilities)", 15, 23);
  1052.   put_buffer(strcat(strcpy(tmp_str, "Fighting    : "),
  1053.             likert(xbth, 12)), 16, 1);
  1054.   put_buffer(strcat(strcpy(tmp_str, "Bows/Throw  : "), 
  1055.             likert(xbthb, 12)), 17, 1);
  1056.   put_buffer(strcat(strcpy(tmp_str, "Saving Throw: "),
  1057.             likert(xsave, 6)), 18, 1);
  1058.   put_buffer(strcat(strcpy(tmp_str, "Stealth     : "),
  1059.             likert(xstl, 1)), 16, 26);
  1060.   put_buffer(strcat(strcpy(tmp_str, "Disarming   : "),
  1061.             likert(xdis, 8)), 17, 26);
  1062.   put_buffer(strcat(strcpy(tmp_str, "Magic Device: "),
  1063.             likert(xdev, 7)), 18, 26);
  1064.   put_buffer(strcat(strcpy(tmp_str, "Perception  : "),
  1065.             likert(xfos, 3)), 16, 51);
  1066.   put_buffer(strcat(strcpy(tmp_str, "Searching   : "),
  1067.             likert(xsrh, 6)), 17, 51);
  1068.   put_buffer(strcat(strcpy(tmp_str, "Infra-Vision: "), xinfra), 18, 51);
  1069. }
  1070.  
  1071.  
  1072. /* Used to display the character on the screen.        -RAK-    */
  1073. display_char()
  1074. {
  1075.   put_character();
  1076.   put_misc1();
  1077.   put_stats();
  1078.   put_misc2();
  1079.   put_misc3();
  1080. }
  1081.  
  1082.  
  1083. /* Gets a name for the character             -JWT-    */
  1084. get_name()
  1085. {
  1086.   prt("Enter your player's name  [press <RETURN> when finished]", 21, 2);
  1087.   (void) get_string(py.misc.name, 2, 14, 24);
  1088.   clear_screen(20, 0);
  1089. }
  1090.  
  1091.  
  1092. /* Chances the name of the character            -JWT-    */
  1093. change_name()
  1094. {
  1095.   char c;
  1096.   int flag;
  1097.  
  1098.   flag = FALSE;
  1099.   display_char();
  1100.   do
  1101.     {
  1102.       prt("<c>hange character name.     <ESCAPE> to continue.", 21, 2);
  1103.       inkey(&c);
  1104.       switch(c)
  1105.     {
  1106.     case 99:
  1107.       get_name();
  1108.       break;
  1109.     case 0: case 27:
  1110.       flag = TRUE;
  1111.       break;
  1112.     default:
  1113.       break;
  1114.     }
  1115.     }
  1116.   while (!flag);
  1117. }
  1118.  
  1119.  
  1120. /* Builds passwords                    -RAK-    */
  1121. bpswd()
  1122. {
  1123.   (void) strcpy(password1, PASSWD1);
  1124.   (void) strcpy(password2, PASSWD2);
  1125. }
  1126.  
  1127.  
  1128. /* Destroy an item in the inventory            -RAK-    */
  1129. inven_destroy(item_val)
  1130. int item_val;
  1131. {
  1132.   int j;
  1133.   treasure_type *i_ptr;
  1134.  
  1135.   inventory[INVEN_MAX] = inventory[item_val];
  1136.   i_ptr = &inventory[item_val];
  1137.   if ((i_ptr->number > 1) && (i_ptr->subval < 512))  
  1138.     {
  1139.       i_ptr->number--;
  1140.       inven_weight -= i_ptr->weight;
  1141.       inventory[INVEN_MAX].number = 1;
  1142.     }
  1143.   else
  1144.     {
  1145.       inven_weight -= i_ptr->weight*i_ptr->number;
  1146.       for (j = item_val; j < inven_ctr-1; j++)
  1147.     inventory[j] = inventory[j+1];
  1148.       inventory[inven_ctr-1] = blank_treasure;
  1149.       inven_ctr--;
  1150.     }
  1151. }
  1152.  
  1153.  
  1154. /* Drops an item from inventory to given location    -RAK-    */
  1155. inven_drop(item_val, y, x)
  1156. int item_val, y, x;
  1157. {
  1158.   int i;
  1159.   cave_type *cave_ptr;
  1160.  
  1161.   cave_ptr = &cave[y][x];
  1162.   if (cave_ptr->tptr != 0)
  1163.     pusht((int)cave_ptr->tptr);
  1164.   inven_destroy(item_val);
  1165.   popt(&i);
  1166.   t_list[i] = inventory[INVEN_MAX];
  1167.   cave_ptr->tptr = i;
  1168. }
  1169.  
  1170.  
  1171. /* Destroys a type of item on a given percent chance    -RAK-    */
  1172. int inven_damage(typ, perc)
  1173. int (*typ)();
  1174. int perc;
  1175. {
  1176.   int i, j;
  1177.  
  1178.   j = 0;
  1179.   for (i = 0; i < inven_ctr; i++)
  1180.     if ((*typ)(inventory[i].tval))
  1181.       if (randint(100) < perc) 
  1182.     {
  1183.       inven_destroy(i);
  1184.       j++;
  1185.     }
  1186.   return(j);
  1187. }
  1188.  
  1189.  
  1190. /* Computes current weight limit             -RAK-    */
  1191. int weight_limit()
  1192. {
  1193.   int weight_cap;
  1194.  
  1195.   weight_cap = py.stats.cstr * PLAYER_WEIGHT_CAP + py.misc.wt;
  1196.   if (weight_cap > 3000)  weight_cap = 3000;
  1197.   return(weight_cap);
  1198. }
  1199.  
  1200.  
  1201. /* Check inventory for too much weight            -RAK-    */
  1202. int inven_check_weight()
  1203. {
  1204.   int item_wgt, max_weight;
  1205.   int check_weight;
  1206.  
  1207.   check_weight = FALSE;
  1208.   max_weight = weight_limit();
  1209.   item_wgt = inventory[INVEN_MAX].number*inventory[INVEN_MAX].weight;
  1210.   /* Now, check to see if player can carry object  */
  1211.   if ((inven_weight + item_wgt) <= max_weight) 
  1212.     check_weight = TRUE;   /* Can carry weight      */
  1213.   return(check_weight);
  1214. }
  1215.  
  1216.  
  1217. /* Check to see if he will be carrying too many objects    -RAK-    */
  1218. int inven_check_num()
  1219. {
  1220.   int i;
  1221.   int check_num;
  1222.  
  1223.   check_num = FALSE;
  1224.   if (inven_ctr < 22) 
  1225.     check_num = TRUE;
  1226.   else if (inventory[INVEN_MAX].subval > 255) 
  1227.     for (i = 0; i < inven_ctr; i++)
  1228.       if (inventory[i].tval == inventory[INVEN_MAX].tval) 
  1229.     if (inventory[i].subval == inventory[INVEN_MAX].subval) 
  1230.       check_num = TRUE;
  1231.   return(check_num);
  1232. }
  1233.  
  1234.  
  1235. /* Insert INVEN_MAX at given location    */
  1236. insert_inv(pos, wgt)
  1237. int pos, wgt;
  1238. {
  1239.   int i;
  1240.  
  1241.   for (i = inven_ctr-1; i >= pos; i--)
  1242.     inventory[i+1] = inventory[i];
  1243.   inventory[pos] = inventory[INVEN_MAX];
  1244.   inven_ctr++;
  1245.   inven_weight += wgt;
  1246. }
  1247.  
  1248.  
  1249. /* Add the item in INVEN_MAX to players inventory.  Return the    */
  1250. /* item position for a description if needed...          -RAK-   */
  1251. inven_carry(item_val)
  1252. int *item_val;
  1253. {
  1254.   int item_num, wgt;
  1255.   int typ, subt;
  1256.   int flag;
  1257.   treasure_type *i_ptr;
  1258.  
  1259.   /* Now, check to see if player can carry object  */
  1260.   *item_val = 0;
  1261.   flag = FALSE;
  1262.   i_ptr = &inventory[INVEN_MAX];
  1263.   item_num = i_ptr->number;
  1264.   typ = i_ptr->tval;
  1265.   subt = i_ptr->subval;
  1266.   wgt = i_ptr->number*i_ptr->weight;
  1267.  
  1268.   do
  1269.     {
  1270.       i_ptr = &inventory[*item_val];
  1271.       if (typ == i_ptr->tval) 
  1272.     {
  1273.       if (subt == i_ptr->subval)  /* Adds to other item    */
  1274.         if (subt > 255) 
  1275.           {
  1276.         i_ptr->number += item_num;
  1277.         inven_weight += wgt;
  1278.         flag = TRUE;
  1279.           }
  1280.     }
  1281.       else if (typ > i_ptr->tval) 
  1282.     {             /* Insert into list              */
  1283.       insert_inv(*item_val, wgt);
  1284.       flag = TRUE;
  1285.     }
  1286.       (*item_val)++;
  1287.     }
  1288.   while ((*item_val < inven_ctr) && (!flag));
  1289.   if (!flag)      /* Becomes last item in list     */
  1290.     {
  1291.       insert_inv(inven_ctr, wgt);
  1292.       *item_val = inven_ctr - 1;
  1293.     }
  1294.   else
  1295.     (*item_val)--;
  1296. }
  1297.  
  1298.  
  1299. /* Returns spell chance of failure for spell        -RAK-    */
  1300. spell_chance(spell)
  1301. spl_rec *spell;
  1302. {
  1303.   spell_type *s_ptr;
  1304.  
  1305.   s_ptr = &magic_spell[py.misc.pclass][spell->splnum];
  1306.   spell->splchn = s_ptr->sfail - 3*(py.misc.lev-s_ptr->slevel);
  1307.   if (class[py.misc.pclass].mspell) 
  1308.     spell->splchn -= 3*(int_adj()-1);
  1309.   else
  1310.     spell->splchn -= 3*(wis_adj()-1);
  1311.   if (s_ptr->smana > py.misc.cmana)
  1312.     spell->splchn += 5*(s_ptr->smana-(int)py.misc.cmana);
  1313.   if (spell->splchn > 95) 
  1314.     spell->splchn = 95;
  1315.   else if (spell->splchn < 5) 
  1316.     spell->splchn = 5;
  1317. }
  1318.  
  1319.  
  1320. /* Print list of spells                    -RAK-    */
  1321. print_new_spells(spell, num, redraw)
  1322. spl_type spell;
  1323. int num;
  1324. int *redraw;
  1325. {
  1326.   int i;
  1327.   vtype out_val;
  1328.   spell_type *s_ptr;
  1329.  
  1330.   *redraw = TRUE;
  1331.   clear_screen(0, 0);
  1332.   prt("   Name                          Level  Mana  %Failure", 1, 0);
  1333.   for (i = 0; i < num; i++)
  1334.     {
  1335.       s_ptr = &magic_spell[py.misc.pclass][spell[i].splnum];
  1336.       spell_chance(&spell[i]);
  1337.       (void) sprintf(out_val, "%c) %s%d    %d      %d", 97+i,
  1338.           pad(s_ptr->sname, " ", 30),
  1339.           s_ptr->slevel, s_ptr->smana, spell[i].splchn);
  1340.       prt(out_val, 2+i, 0);
  1341.     }
  1342. }
  1343.  
  1344.  
  1345. /* Returns spell pointer                 -RAK-    */
  1346. int get_spell(spell, num, sn, sc, prompt, redraw)
  1347. spl_type spell;
  1348. int num;
  1349. int *sn, *sc;
  1350. vtype prompt;
  1351. int *redraw;
  1352. {
  1353.   int flag;
  1354.   char choice;
  1355.   vtype out_val1;
  1356.  
  1357.   *sn = -1;
  1358.   flag = TRUE;
  1359.   (void) sprintf(out_val1, "(Spells a-%c, *==List, <ESCAPE>=exit) %s",
  1360.       num+96, prompt);
  1361.   while (((*sn < 0) || (*sn >= num)) && (flag))
  1362.     {
  1363.       prt(out_val1, 0, 0);
  1364.       inkey(&choice);
  1365.       *sn = (choice);
  1366.       switch(*sn)
  1367.     {
  1368.     case 0: case 27:
  1369.       flag = FALSE;
  1370.       reset_flag = TRUE;
  1371.       break;
  1372.     case 42:
  1373.       print_new_spells(spell, num, redraw);
  1374.           break;
  1375.     default:
  1376.       *sn -= 97;
  1377.       break;
  1378.     }
  1379.     }
  1380.   msg_flag = FALSE;
  1381.   if (flag) 
  1382.     {
  1383.       spell_chance(&spell[*sn]);
  1384.       *sc = spell[*sn].splchn;
  1385.       *sn = spell[*sn].splnum;
  1386.     }
  1387.   return(flag);
  1388. }
  1389.  
  1390.  
  1391. /* Learn some magic spells (Mage)            -RAK-    */
  1392. int learn_spell(redraw)
  1393. int *redraw;
  1394. {
  1395.   unsigned int j;
  1396.   int i, k, sn, sc;
  1397.   int new_spells;
  1398.   unsigned int spell_flag;
  1399.   spl_type spell;
  1400.   int learn;
  1401.   spell_type *s_ptr;
  1402.  
  1403.   learn = FALSE;
  1404.   switch(int_adj())
  1405.     {
  1406.     case 0: new_spells = 0; break;
  1407.     case 1: new_spells = 1; break;
  1408.     case 2: new_spells = 1; break;
  1409.     case 3: new_spells = 1; break;
  1410.     case 4: new_spells = randint(2); break;
  1411.     case 5: new_spells = randint(2); break;
  1412.     case 6: new_spells = randint(3); break;
  1413.     case 7: new_spells = randint(2)+1; break;
  1414.     default: new_spells = 0; break;
  1415.     }
  1416.   i = 0;
  1417.   spell_flag = 0;
  1418.   do
  1419.     {
  1420.       if (inventory[i].tval == 90) 
  1421.     spell_flag |= inventory[i].flags;
  1422.       i++;
  1423.     }
  1424.   while (i < inven_ctr);
  1425.   while ((new_spells > 0) && (spell_flag != 0))
  1426.     {
  1427.       i = 0;
  1428.       j = spell_flag;
  1429.       do
  1430.     {
  1431.       k = bit_pos(&j);
  1432.       s_ptr = &magic_spell[py.misc.pclass][k];
  1433.       if (s_ptr->slevel <= py.misc.lev) 
  1434.         if (!s_ptr->learned) 
  1435.           {
  1436.         spell[i].splnum = k;
  1437.         i++;
  1438.           }
  1439.     }
  1440.       while(j != 0);
  1441.       if (i > 0) 
  1442.     {
  1443.       print_new_spells(spell, i, redraw);
  1444.       if (get_spell(spell, i, &sn, &sc, "Learn which spell?", redraw)) 
  1445.         {
  1446.           magic_spell[py.misc.pclass][sn].learned = TRUE;
  1447.           learn = TRUE;
  1448.           if (py.misc.mana == 0) 
  1449.         {
  1450.           py.misc.mana  = 1;
  1451.           py.misc.cmana = 1.0;
  1452.         }
  1453.         }
  1454.       else
  1455.         new_spells = 0;
  1456.     }
  1457.       else
  1458.     new_spells = 0;
  1459.       new_spells--;
  1460.     }
  1461.   return(learn);
  1462. }
  1463.  
  1464.  
  1465. /* Learn some prayers (Priest)                -RAK-    */
  1466. int learn_prayer()
  1467. {
  1468.   int i, j, k, l, new_spell;
  1469.   int test_array[32];
  1470.   unsigned int spell_flag;
  1471.   int learn;
  1472.   spell_type *s_ptr;
  1473.  
  1474.   i = 0;
  1475.   spell_flag = 0;
  1476.   do
  1477.     {
  1478.       if (inventory[i].tval == 91) 
  1479.     spell_flag |= inventory[i].flags;
  1480.       i++;
  1481.     }
  1482.   while(i < inven_ctr);
  1483.   i = 0;
  1484.   while (spell_flag != 0)
  1485.     {
  1486.       j = bit_pos(&spell_flag);
  1487.       s_ptr = &magic_spell[py.misc.pclass][j];
  1488.       if (s_ptr->slevel <= py.misc.lev) 
  1489.     if (!s_ptr->learned) 
  1490.       {
  1491.         test_array[i] = j;
  1492.         i++;
  1493.       }
  1494.     }
  1495.   switch(wis_adj())
  1496.     {
  1497.     case 0: j = 0; break;
  1498.     case 1: j = 1; break;
  1499.     case 2: j = 1; break;
  1500.     case 3: j = 1; break;
  1501.     case 4: j = randint(2); break;
  1502.     case 5: j = randint(2); break;
  1503.     case 6: j = randint(3); break;
  1504.     case 7: j = randint(2)+1; break;
  1505.     }
  1506.   new_spell = 0;
  1507.   while ((i > 0) && (j > 0))
  1508.     {
  1509.       k = randint(i) - 1;
  1510.       magic_spell[py.misc.pclass][test_array[k]].learned = TRUE;
  1511.       new_spell++;
  1512.       for (l = k; l <= i-1; l++)
  1513.     test_array[l] = test_array[l+1];
  1514.       i--;       /* One less spell to learn       */
  1515.       j--;       /* Learned one                   */
  1516.     }
  1517.   if (new_spell > 0) 
  1518.     {
  1519.       if (new_spell > 1) 
  1520.     msg_print("You learned new prayers!");
  1521.       else
  1522.     msg_print("You learned a new prayer!");
  1523.       if (py.misc.exp == 0)  msg_print(" ");
  1524.       if (py.misc.mana == 0) 
  1525.     {
  1526.       py.misc.mana  = 1;
  1527.       py.misc.cmana = 1.0;
  1528.     }
  1529.       learn = TRUE;
  1530.     }
  1531.   else
  1532.     learn = FALSE;
  1533.   return(learn);
  1534. }
  1535.  
  1536.  
  1537. /* Gain some mana if you knows at least one spell    -RAK-    */
  1538. gain_mana(amount)
  1539. int amount;
  1540. {
  1541.   int i, new_mana;
  1542.   int knows_spell;
  1543.   
  1544.   knows_spell = FALSE;
  1545.   for (i = 0; i < 31; i++)
  1546.     if (magic_spell[py.misc.pclass][i].learned) 
  1547.       knows_spell = TRUE;
  1548.   if (knows_spell) 
  1549.     {
  1550.       if (0x1 & py.misc.lev) 
  1551.     switch(amount)
  1552.       {
  1553.       case 0: new_mana = 0; break;
  1554.       case 1: new_mana = 1; break;
  1555.       case 2: new_mana = 1; break;
  1556.       case 3: new_mana = 1; break;
  1557.       case 4: new_mana = 2; break;
  1558.       case 5: new_mana = 2; break;
  1559.       case 6: new_mana = 3; break;
  1560.       case 7: new_mana = 4; break;
  1561.       default: new_mana = 0; break;
  1562.       }
  1563.       else
  1564.     switch(amount)
  1565.       {
  1566.       case 0: new_mana = 0; break;
  1567.       case 1: new_mana = 1; break;
  1568.       case 2: new_mana = 1; break;
  1569.       case 3: new_mana = 2; break;
  1570.       case 4: new_mana = 2; break;
  1571.       case 5: new_mana = 3; break;
  1572.       case 6: new_mana = 3; break;
  1573.       case 7: new_mana = 4; break;
  1574.       default: new_mana = 0; break;
  1575.       }
  1576.       py.misc.mana  += new_mana;
  1577.       py.misc.cmana += new_mana;
  1578.     }
  1579. }
  1580.  
  1581.  
  1582. /* Increases hit points and level            -RAK-    */
  1583. gain_level()
  1584. {
  1585.   int nhp, dif_exp, need_exp;
  1586.   int redraw;
  1587.   vtype out_val;
  1588.   struct misc *p_ptr;
  1589.   class_type *c_ptr;
  1590.  
  1591.   p_ptr = &py.misc;
  1592.   nhp = get_hitdie();
  1593.   p_ptr->mhp += nhp;
  1594.   p_ptr->chp += (double)nhp;
  1595.   p_ptr->lev++;
  1596.   need_exp = (player_exp[p_ptr->lev]*p_ptr->expfact);
  1597.   if (py.misc.exp > need_exp) 
  1598.     {
  1599.       dif_exp = py.misc.exp - need_exp;
  1600.       py.misc.exp = need_exp + (dif_exp / 2);
  1601.     }
  1602.   (void) strcpy(p_ptr->title, player_title[p_ptr->pclass][p_ptr->lev-1]);
  1603.   (void) sprintf(out_val, "Welcome to level %d.", (int)p_ptr->lev);
  1604.   msg_print(out_val);
  1605.   msg_print(" ");
  1606.   msg_flag = FALSE;
  1607.   prt_mhp();
  1608.   prt_chp();
  1609.   prt_level();
  1610.   prt_title();
  1611.   c_ptr = &class[p_ptr->pclass];
  1612.   if (c_ptr->mspell) 
  1613.     {
  1614.       redraw = FALSE;
  1615.       (void) learn_spell(&redraw);
  1616.       if (redraw)  draw_cave();
  1617.       gain_mana(int_adj());
  1618.       prt_cmana();
  1619.     }
  1620.   else if (c_ptr->pspell) 
  1621.     {
  1622.       (void) learn_prayer();
  1623.       gain_mana(wis_adj());
  1624.       prt_cmana();
  1625.     }
  1626. }
  1627.  
  1628. /* Prints experience                    -RAK-    */
  1629. prt_experience()
  1630. {
  1631.   struct misc *p_ptr;
  1632.  
  1633.   p_ptr = &py.misc;
  1634.   if (p_ptr->exp > player_max_exp) 
  1635.     p_ptr->exp = player_max_exp;
  1636.   if (p_ptr->lev < MAX_PLAYER_LEVEL) 
  1637.     {
  1638.       while ((player_exp[p_ptr->lev]*p_ptr->expfact) <= p_ptr->exp)
  1639.     gain_level();
  1640.       if (p_ptr->exp > p_ptr->max_exp)
  1641.     p_ptr->max_exp = p_ptr->exp;
  1642.     }
  1643.   prt_num("", py.misc.exp, 14, stat_column+6);
  1644. }
  1645.  
  1646.  
  1647. /* Inserts a string into a string                */
  1648. insert_str(object_str, mtc_str, insert)
  1649. char *object_str, *mtc_str, *insert;
  1650. {
  1651.   int mtc_len, obj_len;
  1652.   int bound, pc, i;
  1653.   char *temp_obj, *temp_mtc;
  1654.   char out_val[80];
  1655.  
  1656.   mtc_len = strlen(mtc_str);
  1657.   obj_len = strlen(object_str);
  1658.   bound = (int)object_str + obj_len - mtc_len;
  1659.   for (pc = (int)object_str; pc <= bound; pc++)
  1660.     {
  1661.       temp_obj = (char *)pc;
  1662.       temp_mtc = mtc_str;
  1663.       for (i = 0; i < mtc_len; i++)
  1664.     if (*temp_obj++ != *temp_mtc++)
  1665.       break;
  1666.       if (i == mtc_len)
  1667.     break;
  1668.     }
  1669.  
  1670.   if (pc <= bound)
  1671.     {
  1672.       (void) strncpy(out_val, object_str, (pc-(int)object_str));
  1673.       out_val[(pc-(int)object_str)] = '\0';
  1674.       (void) strcat(out_val, insert);
  1675.       (void) strcat(out_val, (char *)(pc+mtc_len));
  1676.       (void) strcpy(object_str, out_val);
  1677.     }
  1678. }
  1679.  
  1680.  
  1681. /* Inserts a number into a string                */
  1682. insert_num(object_str, mtc_str, number, show_sign)
  1683. char *object_str;
  1684. char *mtc_str;
  1685. int number;
  1686. int show_sign;
  1687. {
  1688.   int pos, mlen;
  1689.   vtype str1, str2;
  1690.   char *string, *tmp_str;
  1691.   int flag;
  1692.  
  1693.   flag = 1;
  1694.   tmp_str = object_str;
  1695.   do
  1696.     {
  1697.       string = index(tmp_str, mtc_str[0]);
  1698.       if (string == 0)
  1699.     flag = 0;
  1700.       else 
  1701.     {
  1702.       flag = strncmp(string, mtc_str, strlen(mtc_str));
  1703.       if (flag)
  1704.         tmp_str = string+1;
  1705.     }
  1706.     }
  1707.   while (flag);
  1708.   if (string)
  1709.     pos = strlen(object_str) - strlen(string);
  1710.   else
  1711.     pos = -1;
  1712.   if (pos >= 0) 
  1713.     {
  1714.       mlen = strlen(mtc_str);
  1715.       (void) strncpy(str1, object_str, pos);
  1716.       str1[pos] = '\0';
  1717.       (void) strcpy(str2, &object_str[pos+mlen]);
  1718.       if ((number >= 0) && (show_sign)) 
  1719.     (void) sprintf(object_str, "%s+%d%s", str1, number, str2);
  1720.       else
  1721.     (void) sprintf(object_str, "%s%d%s", str1, number, str2);
  1722.     }
  1723. }
  1724.  
  1725.  
  1726. /* Checks to see if user is a wizard            -RAK-    */
  1727. int check_pswd()
  1728. {
  1729.   int i;
  1730.   char x;
  1731.   char tpw[12];
  1732.   int check;
  1733.  
  1734.   check = FALSE;
  1735.   if (getuid() != UID)
  1736.     return(FALSE);
  1737.   i = 0;
  1738.   (void) strcpy(tpw, "            ");
  1739.   prt("Password : ", 0, 0);
  1740.   do
  1741.     {
  1742.       inkey(&x);
  1743.       switch(x)
  1744.     {
  1745.     case 13:
  1746.       break;
  1747.     default:
  1748.       tpw[i] = x;
  1749.       i++;
  1750.       break;
  1751.     }
  1752.     }
  1753.   while ((i != 12) && (x != 13));
  1754.   tpw[i] = '\0';
  1755.   if (!strcmp(tpw, password1)) 
  1756.     {
  1757.       wizard1 = TRUE;
  1758.       check = TRUE;
  1759.     }
  1760.   else if (!strcmp(tpw, password2)) 
  1761.     {
  1762.       wizard1 = TRUE;
  1763.       wizard2 = TRUE;
  1764.       check = TRUE;
  1765.     }
  1766.   msg_flag = FALSE;
  1767.   erase_line(msg_line, msg_line);
  1768.   return(check);
  1769. }
  1770.  
  1771.  
  1772. /* Weapon weight VS strength and dexterity        -RAK-    */
  1773. int attack_blows(weight, wtohit)
  1774. int weight;
  1775. int *wtohit;
  1776. {
  1777.   int adj_weight, blows;
  1778.   struct stats *p_ptr;
  1779.  
  1780.   blows  = 1;
  1781.   *wtohit = 0;
  1782.   p_ptr = &py.stats;
  1783.   if ((p_ptr->cstr*15) < weight)
  1784.     *wtohit = p_ptr->cstr*15 - weight;
  1785.   else
  1786.     {
  1787.       if      (p_ptr->cdex <  10)  blows = 1;
  1788.       else if (p_ptr->cdex <  19)  blows = 2;
  1789.       else if (p_ptr->cdex <  68)  blows = 3;
  1790.       else if (p_ptr->cdex < 108)  blows = 4;
  1791.       else if (p_ptr->cdex < 118)  blows = 5;
  1792.       else                         blows = 6;
  1793.       adj_weight = ((p_ptr->cstr*10)/weight);
  1794.       if      (adj_weight < 2)  blows = 1;
  1795.       else if (adj_weight < 3)  blows = (blows/3.0) + 1;
  1796.       else if (adj_weight < 4)  blows = (blows/2.5) + 1;
  1797.       else if (adj_weight < 5)  blows = (blows/2.25) + 1;
  1798.       else if (adj_weight < 7)  blows = (blows/2.00) + 1;
  1799.       else if (adj_weight < 9)  blows = (blows/1.75) + 1;
  1800.       else                      blows = (blows/1.50) + 1;
  1801.     }
  1802.   return(blows);
  1803. }
  1804.  
  1805.  
  1806. /* Critical hits, Nasty way to die...            -RAK-    */
  1807. int critical_blow(weight, plus, dam)
  1808. int weight, plus, dam;
  1809. {
  1810.   int critical;
  1811.  
  1812.   critical = dam;
  1813.   /* Weight of weapon, plusses to hit, and character level all      */
  1814.   /* contribute to the chance of a critical                        */
  1815.   if (randint(5000) <= (int)(weight+5*plus+3*py.misc.lev))
  1816.     {
  1817.       weight += randint(650);
  1818.       if (weight < 400) 
  1819.     {
  1820.       critical = 2*dam + 5;
  1821.       msg_print("It was a good hit! (x2 damage)");
  1822.     }
  1823.       else if (weight < 700) 
  1824.     {
  1825.       critical = 3*dam + 10;
  1826.       msg_print("It was an excellent hit! (x3 damage)");
  1827.     }
  1828.       else if (weight < 900) 
  1829.     {
  1830.       critical = 4*dam + 15;
  1831.       msg_print("It was a superb hit! (x4 damage)");
  1832.     }
  1833.       else
  1834.     {
  1835.       critical = 5*dam + 20;
  1836.       msg_print("It was a *GREAT* hit! (x5 damage)");
  1837.     }
  1838.     }
  1839.   return(critical);
  1840. }
  1841.  
  1842.  
  1843. /* Given direction "dir", returns new row, column location -RAK- */
  1844. int move(dir, y, x)
  1845. int dir;
  1846. int *y, *x;
  1847. {
  1848.   int new_row, new_col;
  1849.   int bool;
  1850.  
  1851.   switch(dir)
  1852.     {
  1853.     case 1:
  1854.       new_row = *y + 1;
  1855.       new_col = *x - 1;
  1856.       break;
  1857.     case 2:
  1858.       new_row = *y + 1;
  1859.       new_col = *x;
  1860.       break;
  1861.     case 3:
  1862.       new_row = *y + 1;
  1863.       new_col = *x + 1;
  1864.       break;
  1865.     case 4:
  1866.       new_row = *y;
  1867.       new_col = *x - 1;
  1868.       break;
  1869.     case 5:
  1870.       new_row = *y;
  1871.       new_col = *x;
  1872.       break;
  1873.     case 6:
  1874.       new_row = *y;
  1875.       new_col = *x + 1;
  1876.       break;
  1877.     case 7:
  1878.       new_row = *y - 1;
  1879.       new_col = *x - 1;
  1880.       break;
  1881.     case 8:
  1882.       new_row = *y - 1;
  1883.       new_col = *x;
  1884.       break;
  1885.     case 9:
  1886.       new_row = *y - 1;
  1887.       new_col = *x + 1;
  1888.       break;
  1889.     }
  1890.   bool = FALSE;
  1891.   if ((new_row >= 0) && (new_row < cur_height)) 
  1892.     if ((new_col >= 0) && (new_col < cur_width)) 
  1893.       {
  1894.     *y = new_row;
  1895.     *x = new_col;
  1896.     bool = TRUE;
  1897.       }
  1898.   return(bool);
  1899. }
  1900.  
  1901. /* Saving throws for player character...         -RAK-    */
  1902. int player_saves(adjust)
  1903. int adjust;
  1904. {
  1905.   if (randint(100) <= (py.misc.save + adjust)) 
  1906.     return(TRUE);
  1907.   else
  1908.     return(FALSE);
  1909. }
  1910.  
  1911.  
  1912. /* Init players with some belongings            -RAK-    */
  1913. char_inven_init()
  1914. {
  1915.   int i, j, dummy;
  1916.  
  1917.   /* this is needed for bash to work right, it can't hurt anyway */
  1918.   for (i = 0; i < INVEN_ARRAY_SIZE; i++)
  1919.     inventory[i] = blank_treasure;
  1920.  
  1921.   for (i = 0; i < 5; i++)
  1922.     {
  1923.       j = player_init[py.misc.pclass][i];
  1924.       inventory[INVEN_MAX] = inventory_init[j];
  1925.       inven_carry(&dummy);
  1926.     }
  1927. }
  1928.