Mercurial > hg > early-roguelike
comparison arogue5/main.c @ 63:0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Thu, 09 Aug 2012 22:58:48 +0000 |
| parents | |
| children | a98834ce7e04 |
comparison
equal
deleted
inserted
replaced
| 62:0ef99244acb8 | 63:0ed67132cf10 |
|---|---|
| 1 /* | |
| 2 * Rogue | |
| 3 * | |
| 4 * Advanced Rogue | |
| 5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
| 6 * All rights reserved. | |
| 7 * | |
| 8 * Based on "Rogue: Exploring the Dungeons of Doom" | |
| 9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 10 * All rights reserved. | |
| 11 * | |
| 12 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 13 */ | |
| 14 | |
| 15 #include "curses.h" | |
| 16 #include <fcntl.h> | |
| 17 #include <sys/stat.h> | |
| 18 #include <limits.h> | |
| 19 #include <signal.h> | |
| 20 #include <time.h> | |
| 21 #include "mach_dep.h" | |
| 22 #include "network.h" | |
| 23 #include "rogue.h" | |
| 24 | |
| 25 #ifdef CHECKTIME | |
| 26 static int num_checks; /* times we've gone over in checkout() */ | |
| 27 #endif | |
| 28 | |
| 29 /* | |
| 30 * fruits that you get at startup | |
| 31 */ | |
| 32 static char *funfruit[] = { | |
| 33 "candleberry", "caprifig", "dewberry", "elderberry", | |
| 34 "gooseberry", "guanabana", "hagberry", "ilama", | |
| 35 "imbu", "jaboticaba", "jujube", "litchi", | |
| 36 "mombin", "pitanga", "prickly pear", "rambutan", | |
| 37 "sapodilla", "soursop", "sweetsop", "whortleberry", | |
| 38 "jellybean", "apple", "strawberry", "blueberry", | |
| 39 "peach", "banana" | |
| 40 }; | |
| 41 #define NFRUIT (sizeof(funfruit) / sizeof (char *)) | |
| 42 | |
| 43 main(argc, argv, envp) | |
| 44 char **argv; | |
| 45 char **envp; | |
| 46 { | |
| 47 register char *env; | |
| 48 int lowtime; | |
| 49 time_t now; | |
| 50 char *roguedir = md_getroguedir(); | |
| 51 | |
| 52 md_init(); | |
| 53 | |
| 54 /* | |
| 55 * get home and options from environment | |
| 56 */ | |
| 57 | |
| 58 strncpy(home,md_gethomedir(),LINELEN); | |
| 59 | |
| 60 /* Get default save file */ | |
| 61 strcpy(file_name, home); | |
| 62 strcat(file_name, "arogue58.sav"); | |
| 63 | |
| 64 /* Get default score file */ | |
| 65 strcpy(score_file, roguedir); | |
| 66 | |
| 67 if (*score_file) | |
| 68 strcat(score_file,"/"); | |
| 69 | |
| 70 strcat(score_file, "arogue58.scr"); | |
| 71 | |
| 72 if ((env = getenv("ROGUEOPTS")) != NULL) | |
| 73 parse_opts(env); | |
| 74 | |
| 75 if (whoami[0] == '\0') | |
| 76 strucpy(whoami, md_getusername(), strlen(md_getusername())); | |
| 77 | |
| 78 if (env == NULL || fruit[0] == '\0') { | |
| 79 md_srand((long)(getpid()+time(0))); | |
| 80 strcpy(fruit, funfruit[rnd(NFRUIT)]); | |
| 81 } | |
| 82 | |
| 83 /* | |
| 84 * check for print-score option | |
| 85 */ | |
| 86 if (argc == 2 && strcmp(argv[1], "-s") == 0) | |
| 87 { | |
| 88 waswizard = TRUE; | |
| 89 score(0, SCOREIT, 0); | |
| 90 exit(0); | |
| 91 } | |
| 92 | |
| 93 #ifdef NUMNET | |
| 94 /* | |
| 95 * Check for a network update | |
| 96 */ | |
| 97 if (argc == 2 && strcmp(argv[1], "-u") == 0) { | |
| 98 unsigned long netread(); | |
| 99 int errcheck, errors = 0; | |
| 100 unsigned long amount; | |
| 101 short monster; | |
| 102 | |
| 103 /* Read in the amount and monster values to pass to score */ | |
| 104 amount = netread(&errcheck, sizeof(unsigned long), stdin); | |
| 105 if (errcheck) errors++; | |
| 106 | |
| 107 monster = (short) netread(&errcheck, sizeof(short), stdin); | |
| 108 if (errcheck) errors++; | |
| 109 | |
| 110 /* Now do the update if there were no errors */ | |
| 111 if (errors) exit(1); | |
| 112 else { | |
| 113 score(amount, UPDATE, monster); | |
| 114 exit(0); | |
| 115 } | |
| 116 } | |
| 117 #endif | |
| 118 | |
| 119 #ifdef WIZARD | |
| 120 /* | |
| 121 * Check to see if he is a wizard | |
| 122 */ | |
| 123 if (argc >= 2 && argv[1][0] == '\0') | |
| 124 if (strcmp(PASSWD, md_crypt(md_getpass("Wizard's password: "), "Si")) == 0) | |
| 125 { | |
| 126 printf("Hail Mighty Wizard\n"); | |
| 127 wizard = TRUE; | |
| 128 argv++; | |
| 129 argc--; | |
| 130 } | |
| 131 #endif | |
| 132 | |
| 133 #if MAXLOAD|MAXUSERS | |
| 134 if (too_much() && !wizard && !author()) | |
| 135 { | |
| 136 printf("Sorry, %s, but the system is too loaded now.\n", whoami); | |
| 137 printf("Try again later. Meanwhile, why not enjoy a%s %s?\n", | |
| 138 vowelstr(fruit), fruit); | |
| 139 exit(1); | |
| 140 } | |
| 141 #endif | |
| 142 if (argc == 2) | |
| 143 if (!restore(argv[1], envp)) /* Note: restore will never return */ | |
| 144 exit(1); | |
| 145 lowtime = (int) time(&now); | |
| 146 dnum = (wizard && getenv("SEED") != NULL ? | |
| 147 atoi(getenv("SEED")) : | |
| 148 lowtime + getpid()); | |
| 149 if (wizard) | |
| 150 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum); | |
| 151 else | |
| 152 printf("Hello %s, just a moment while I dig the dungeon...\n", whoami); | |
| 153 fflush(stdout); | |
| 154 seed = dnum; | |
| 155 md_srand(seed); | |
| 156 | |
| 157 init_things(); /* Set up probabilities of things */ | |
| 158 init_colors(); /* Set up colors of potions */ | |
| 159 init_stones(); /* Set up stone settings of rings */ | |
| 160 init_materials(); /* Set up materials of wands */ | |
| 161 initscr(); /* Start up cursor package */ | |
| 162 init_names(); /* Set up names of scrolls */ | |
| 163 init_misc(); /* Set up miscellaneous magic */ | |
| 164 if (LINES < 24 || COLS < 80) { | |
| 165 printf("\nERROR: screen size to small for rogue\n"); | |
| 166 byebye(-1); | |
| 167 } | |
| 168 | |
| 169 if ((whoami == NULL) || (*whoami == '\0') || (strcmp(whoami,"dosuser")==0)) | |
| 170 { | |
| 171 echo(); | |
| 172 mvaddstr(23,2,"Rogue's Name? "); | |
| 173 wgetnstr(stdscr,whoami,LINELEN); | |
| 174 noecho(); | |
