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