home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / umoria / part15 / main.c < prev    next >
C/C++ Source or Header  |  1987-11-05  |  5KB  |  172 lines

  1. /* Moria Version 4.8    COPYRIGHT (c) Robert Alan Koeneke        */
  2. /*                       Public Domain                                   */
  3. /*                                                                       */
  4. /*       I lovingly dedicate this game to hackers and adventurers        */
  5. /*       everywhere...                                                   */
  6. /*                                                                       */
  7. /*                                                                       */
  8. /*       Designer and Programmer : Robert Alan Koeneke                   */
  9. /*                                 University of Oklahoma                */
  10. /*                                                                       */
  11. /*       Assistant Programmers   : Jimmey Wayne Todd                     */
  12. /*                                 University of Oklahoma                */
  13. /*                                                                       */
  14. /*                                 Gary D. McAdoo                        */
  15. /*                                 University of Oklahoma                */
  16. /*                                                                       */
  17. /*       UNIX Port               : James E. Wilson                       */
  18. /*                                 UC Berkeley                           */
  19. /*                                 wilson@ernie.Berkeley.EDU             */
  20. /*                                 ucbvax!ucbernie!wilson                */
  21. /*                                                                       */
  22. /*       Moria may be copied and modified freely as long as the above    */
  23. /*       credits are retained.  No one who-so-ever may sell or market    */
  24. /*       this software in any form without the expressed written consent */
  25. /*       of the author Robert Alan Koeneke.                              */
  26. /*                                                                       */
  27.  
  28. #include <curses.h>
  29. #ifdef USG
  30. #include <string.h>
  31. #else
  32. #include <strings.h>
  33. #endif
  34. #include <sys/types.h>
  35.  
  36. #include "constants.h"
  37. #include "types.h"
  38. #include "externs.h"
  39.  
  40. #if defined(ultrix) || defined(sun) || defined(USG)
  41. int getuid();
  42. #else
  43. uid_t getuid();
  44. #endif
  45.  
  46. #if defined(ultrix) || defined(USG)
  47. void perror();
  48. void exit();
  49. #endif
  50.  
  51. extern int key_bindings;
  52.  
  53. /* Initialize, restore, and get the ball rolling...    -RAK-    */
  54. main(argc, argv)
  55. int argc;
  56. char *argv[];
  57. {
  58.   /* call this routine to grab a file pointer to the highscore file *
  59.   /* and prepare things to relinquish setuid privileges */
  60.   init_scorefile();
  61.  
  62.   if (0 != setuid(getuid()))
  63.     {
  64.       perror("Gack!  Can't set permissions correctly!  Exiting!\n");
  65.       exit(0);
  66.     }
  67.  
  68.   /* use curses */
  69.   init_curses();
  70.   
  71.   /* catch those nasty signals */
  72.   /* must come after init_curses as some of the signal handlers use curses */
  73.   init_signals();
  74.  
  75.   /* Build the secret wizard and god passwords    */
  76.   bpswd();
  77.   
  78.   /* check for user interface option */
  79.   key_bindings = KEY_BINDINGS;
  80.   if (argc >= 2)
  81.     {
  82.       if (!strcmp(argv[1], "-r"))
  83.         {
  84.           key_bindings = ROGUE_LIKE;
  85.           argv[1][0] = '\0';
  86.         }
  87.       if (!strcmp(argv[1], "-o"))
  88.     {
  89.       key_bindings = ORIGINAL;
  90.       argv[1][0] = '\0';
  91.     }
  92.       if (!strcmp(argv[1], "-s"))
  93.     {
  94.       display_scores();
  95.       exit_game();
  96.     }
  97.     }
  98.  
  99.   /* Check operating hours             */
  100.   /* If not wizard  No_Control_Y               */
  101.   /* Check or create hours.dat, print message    */
  102.   /* if last arg is ^ then start as wizard, can not restore game also */
  103.   if (argc >= 2)
  104.     intro(argv[argc - 1]);
  105.   else
  106.     intro("");
  107.   
  108.   /* Some necessary initializations        */
  109.   msg_line       = 0;
  110.   quart_height   = SCREEN_HEIGHT / 4;
  111.   quart_width    = SCREEN_WIDTH / 4;
  112.   dun_level      = 0;
  113.   
  114.   /* Grab a random seed from the clock        */
  115.   init_seeds();
  116.   
  117.   /* Sort the objects by level            */
  118.   sort_objects();
  119.   
  120.   /* Init monster and treasure levels for allocate */
  121.   init_m_level();
  122.   init_t_level();
  123.   
  124.   /* Init the store inventories            */
  125.   store_init();
  126.   if (COST_ADJ != 1.00)  price_adjust();
  127.   
  128.   /* Generate a character, or retrieve old one...    */
  129.   if ((argc > 1) && strlen(argv[argc-1]))
  130.     {     /* Retrieve character    */
  131.       generate = get_char(argv[argc-1]);
  132.       change_name();
  133.       magic_init();
  134.     }
  135.   else
  136.     {     /* Create character      */
  137.       create_character();
  138.       char_inven_init();
  139.       if (class[py.misc.pclass].mspell) 
  140.     {         /* Magic realm   */
  141.       (void) learn_spell(&msg_flag);
  142.       gain_mana(int_adj());
  143.     }
  144.       else if (class[py.misc.pclass].pspell) 
  145.     {         /* Clerical realm*/
  146.       (void) learn_prayer();
  147.       gain_mana(wis_adj());
  148.     }
  149.       py.misc.cmana = (double)py.misc.mana;
  150.       magic_init();
  151.       generate = TRUE;
  152.     }
  153.   
  154.   /* Begin the game                */
  155.   /*    This determines the maximum player level    */
  156.   player_max_exp = (player_exp[MAX_PLAYER_LEVEL-1]*py.misc.expfact);
  157.   clear_screen(0, 0);
  158.   prt_stat_block();
  159.   /* prevent ^c quit from entering score into scoreboard until this point */
  160.   character_generated = 1;
  161.   
  162.   /* Loop till dead, or exit            */
  163.   while(!death) {
  164.     if (generate)  generate_cave();         /* New level     */
  165.     dungeon();                                  /* Dungeon logic */
  166.     generate = TRUE;
  167.   }
  168.   upon_death();                         /* Character gets buried */
  169.   /* should never reach here, but just in case */
  170.   return (0);
  171. }
  172.