1 /* 2 * init.c 3 * 4 * This source herein may be modified and/or distributed by anybody who 5 * so desires, with the following restrictions: 6 * 1.) No portion of this notice shall be removed. 7 * 2.) Credit shall not be taken for the creation of this source. 8 * 3.) This code is not to be traded, sold, or used for personal 9 * gain or profit. 10 * 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)init.c 5.1 (Berkeley) 11/25/87"; 15 #endif /* not lint */ 16 17 #include <stdio.h> 18 #include "rogue.h" 19 20 char login_name[MAX_OPT_LEN]; 21 char *nick_name = (char *) 0; 22 char *rest_file = 0; 23 boolean cant_int = 0; 24 boolean did_int = 0; 25 boolean score_only; 26 boolean init_curses = 0; 27 boolean save_is_interactive = 1; 28 boolean ask_quit = 1; 29 boolean no_skull = 0; 30 boolean passgo = 0; 31 char *error_file = "rogue.esave"; 32 char *byebye_string = "Okay, bye bye!"; 33 34 extern char *fruit; 35 extern char *save_file; 36 extern short party_room; 37 extern boolean jump; 38 39 init(argc, argv) 40 int argc; 41 char *argv[]; 42 { 43 char *pn; 44 int seed; 45 46 pn = md_gln(); 47 if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) { 48 clean_up("Hey! Who are you?"); 49 } 50 (void) strcpy(login_name, pn); 51 52 do_args(argc, argv); 53 do_opts(); 54 55 if (!score_only && !rest_file) { 56 printf("Hello %s, just a moment while I dig the dungeon...", 57 nick_name); 58 fflush(stdout); 59 } 60 61 initscr(); 62 if ((LINES < DROWS) || (COLS < DCOLS)) { 63 clean_up("must be played on 24 x 80 screen"); 64 } 65 start_window(); 66 init_curses = 1; 67 68 md_heed_signals(); 69 70 if (score_only) { 71 put_scores((object *) 0, 0); 72 } 73 seed = md_gseed(); 74 (void) srrandom(seed); 75 if (rest_file) { 76 restore(rest_file); 77 return(1); 78 } 79 mix_colors(); 80 get_wand_and_ring_materials(); 81 make_scroll_titles(); 82 83 level_objects.next_object = (object *) 0; 84 level_monsters.next_monster = (object *) 0; 85 player_init(); 86 ring_stats(0); 87 return(0); 88 } 89 90 player_init() 91 { 92 object *obj; 93 94 rogue.pack.next_object = (object *) 0; 95 96 obj = alloc_object(); 97 get_food(obj, 1); 98 (void) add_to_pack(obj, &rogue.pack, 1); 99 100 obj = alloc_object(); /* initial armor */ 101 obj->what_is = ARMOR; 102 obj->which_kind = RINGMAIL; 103 obj->class = RINGMAIL+2; 104 obj->is_protected = 0; 105 obj->d_enchant = 1; 106 (void) add_to_pack(obj, &rogue.pack, 1); 107 do_wear(obj); 108 109 obj = alloc_object(); /* initial weapons */ 110 obj->what_is = WEAPON; 111 obj->which_kind = MACE; 112 obj->damage = "2d3"; 113 obj->hit_enchant = obj->d_enchant = 1; 114 obj->identified = 1; 115 (void) add_to_pack(obj, &rogue.pack, 1); 116 do_wield(obj); 117 118 obj = alloc_object(); 119 obj->what_is = WEAPON; 120 obj->which_kind = BOW; 121 obj->damage = "1d2"; 122 obj->hit_enchant = 1; 123 obj->d_enchant = 0; 124 obj->identified = 1; 125 (void) add_to_pack(obj, &rogue.pack, 1); 126 127 obj = alloc_object(); 128 obj->what_is = WEAPON; 129 obj->which_kind = ARROW; 130 obj->quantity = get_rand(25, 35); 131 obj->damage = "1d2"; 132 obj->hit_enchant = 0; 133 obj->d_enchant = 0; 134 obj->identified = 1; 135 (void) add_to_pack(obj, &rogue.pack, 1); 136 } 137 138 clean_up(estr) 139 char *estr; 140 { 141 if (save_is_interactive) { 142 if (init_curses) { 143 move(DROWS-1, 0); 144 refresh(); 145 stop_window(); 146 } 147 printf("\n%s\n", estr); 148 } 149 md_exit(0); 150 } 151 152 start_window() 153 { 154 crmode(); 155 noecho(); 156 #ifndef BAD_NONL 157 nonl(); 158 #endif 159 md_control_keybord(0); 160 } 161 162 stop_window() 163 { 164 endwin(); 165 md_control_keybord(1); 166 } 167 168 byebye() 169 { 170 md_ignore_signals(); 171 if (ask_quit) { 172 quit(1); 173 } else { 174 clean_up(byebye_string); 175 } 176 md_heed_signals(); 177 } 178 179 onintr() 180 { 181 md_ignore_signals(); 182 if (cant_int) { 183 did_int = 1; 184 } else { 185 check_message(); 186 message("interrupt", 1); 187 } 188 md_heed_signals(); 189 } 190 191 error_save() 192 { 193 save_is_interactive = 0; 194 save_into_file(error_file); 195 clean_up(""); 196 } 197 198 do_args(argc, argv) 199 int argc; 200 char *argv[]; 201 { 202 short i, j; 203 204 for (i = 1; i < argc; i++) { 205 if (argv[i][0] == '-') { 206 for (j = 1; argv[i][j]; j++) { 207 switch(argv[i][j]) { 208 case 's': 209 score_only = 1; 210 break; 211 } 212 } 213 } else { 214 rest_file = argv[i]; 215 } 216 } 217 } 218 219 do_opts() 220 { 221 char *eptr; 222 223 if (eptr = md_getenv("ROGUEOPTS")) { 224 for (;;) { 225 while ((*eptr) == ' ') { 226 eptr++; 227 } 228 if (!(*eptr)) { 229 break; 230 } 231 if (!strncmp(eptr, "fruit=", 6)) { 232 eptr += 6; 233 env_get_value(&fruit, eptr, 1); 234 } else if (!strncmp(eptr, "file=", 5)) { 235 eptr += 5; 236 env_get_value(&save_file, eptr, 0); 237 } else if (!strncmp(eptr, "jump", 4)) { 238 jump = 1; 239 } else if (!strncmp(eptr, "name=", 5)) { 240 eptr += 5; 241 env_get_value(&nick_name, eptr, 0); 242 } else if (!strncmp(eptr, "noaskquit", 9)) { 243 ask_quit = 0; 244 } else if (!strncmp(eptr, "noskull", 5) || 245 !strncmp(eptr,"notomb", 6)) { 246 no_skull = 1; 247 } else if (!strncmp(eptr, "passgo", 5)) { 248 passgo = 1; 249 } 250 while ((*eptr) && (*eptr != ',')) { 251 eptr++; 252 } 253 if (!(*(eptr++))) { 254 break; 255 } 256 } 257 } 258 /* If some strings have not been set through ROGUEOPTS, assign defaults 259 * to them so that the options editor has data to work with. 260 */ 261 init_str(&nick_name, login_name); 262 init_str(&save_file, "rogue.save"); 263 init_str(&fruit, "slime-mold"); 264 } 265 266 env_get_value(s, e, add_blank) 267 char **s, *e; 268 boolean add_blank; 269 { 270 short i = 0; 271 char *t; 272 273 t = e; 274 275 while ((*e) && (*e != ',')) { 276 if (*e == ':') { 277 *e = ';'; /* ':' reserved for score file purposes */ 278 } 279 e++; 280 if (++i >= MAX_OPT_LEN) { 281 break; 282 } 283 } 284 *s = md_malloc(MAX_OPT_LEN + 2); 285 (void) strncpy(*s, t, i); 286 if (add_blank) { 287 (*s)[i++] = ' '; 288 } 289 (*s)[i] = '\0'; 290 } 291 292 init_str(str, dflt) 293 char **str, *dflt; 294 { 295 if (!(*str)) { 296 *str = md_malloc(MAX_OPT_LEN + 2); 297 (void) strcpy(*str, dflt); 298 } 299 } 300