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