comparison xrogue/main.c @ 133:e6179860cb76

Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Tue, 21 Apr 2015 08:55:20 -0400
parents
children ce0cf824c192
comparison
equal deleted inserted replaced
124:d10fc4a065ac 133:e6179860cb76
1 /*
2 main.c - setup code
3
4 XRogue: Expeditions into the Dungeons of Doom
5 Copyright (C) 1991 Robert Pietkivitch
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
10 All rights reserved.
11
12 Based on "Rogue: Exploring the Dungeons of Doom"
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
14 All rights reserved.
15
16 See the file LICENSE.TXT for full copyright and licensing information.
17 */
18
19 #include <curses.h>
20 #include <signal.h>
21 #include <time.h>
22
23 #include "mach_dep.h"
24 #include "network.h"
25 #include "rogue.h"
26
27 main(argc, argv, envp)
28 char **argv;
29 char **envp;
30 {
31 register char *env;
32 time_t now;
33
34 md_init();
35
36 /*
37 * get home and options from environment
38 */
39
40 strncpy(home, md_gethomedir(), LINELEN);
41
42 /* Get default save file */
43 strcpy(file_name, home);
44 strcat(file_name, "xrogue.sav");
45
46 /* Get default score file */
47 strcpy(score_file, md_getroguedir());
48
49 if (*score_file)
50 strcat(score_file,"/");
51
52 strcat(score_file, "xrogue.scr");
53
54 if ((env = getenv("ROGUEOPTS")) != NULL)
55 parse_opts(env);
56
57 if (whoami[0] == '\0')
58 strucpy(whoami, md_getusername(), strlen(md_getusername()));
59
60 /*
61 * check for print-score option
62 */
63 if (argc == 2 && strcmp(argv[1], "-s") == 0)
64 {
65 waswizard = TRUE;
66 score((long)0, SCOREIT, (short)0);
67 exit_game(0);
68 }
69
70 /*
71 * Check for a network update
72 */
73 if (argc == 2 && strcmp(argv[1], "-u") == 0) {
74 int errcheck, errors = 0;
75 unsigned long amount;
76 short monster;
77
78 /* Read in the amount and monster values to pass to score */
79 amount = netread(&errcheck, sizeof(unsigned long), stdin);
80 if (errcheck) errors++;
81
82 monster = (short) netread(&errcheck, sizeof(short), stdin);
83 if (errcheck) errors++;
84
85 /* Now do the update if there were no errors */
86 if (errors) exit_game(0);
87 else {
88 score((long)amount, UPDATE, (short)monster);
89 exit_game(0);
90 }
91 }
92
93 /*
94 * Check to see if he is a wizard
95 */
96 if (argc >= 2 && argv[1][0] == '\0')
97 if (strcmp(PASSWD, xcrypt(md_getpass("Wizard's password: "), "mT")) == 0)
98 {
99 wizard = TRUE;
100 argv++;
101 argc--;
102 }
103
104 if (betaover())
105 {
106 printf("Sorry, %s, but the test period of this prerelease version\n",whoami);
107 printf("of xrogue is over. Please acquire a new version. Sorry.\n");
108 exit_game(0);
109 }
110
111 if (!wizard && !author() && !playtime()) {
112 printf("Sorry, %s, but you can't play during working hours.\n", whoami);
113 printf("Try again later.\n");
114 exit_game(0);
115 }
116 if (!wizard && !author() && too_much()) {
117 printf("Sorry, %s, but the system is too loaded now.\n", whoami);
118 printf("Try again later.\n");
119 exit_game(0);
120 }
121
122 if (argc == 2)
123 if (!restore(argv[1], envp)) /* Note: restore will never return */
124 exit_game(0);
125
126 if (wizard && getenv("SEED") != NULL) {
127 seed = atoi(getenv("SEED"));
128 }
129 else {
130 seed = (int) time(&now) + getpid();
131 }
132 if (wizard)
133 printf("Hello %s, welcome to dungeon #%d", whoami, seed);
134 else
135 printf("Hello %s, just a moment while I dig the dungeon...", whoami);
136 fflush(stdout);
137
138 md_srand(seed);
139
140 init_things(); /* Set up probabilities of things */
141 init_colors(); /* Set up colors of potions */
142 init_stones(); /* Set up stone settings of rings */
143 init_materials(); /* Set up materials of wands */
144 init_names(); /* Set up names of scrolls */
145 init_misc(); /* Set up miscellaneous magic */
146 init_foods(); /* set up the food table */
147
148 initscr(); /* Start up cursor package */
149
150 typeahead(-1); /* turn off 3.2/4.0 curses feature */
151
152 if (COLS < MINCOLS)
153 {
154 printf("\n\nSorry, %s, but your terminal window has too few columns.\n", whoami);
155 printf("Your terminal has %d columns, needs 70.\n",COLS);
156 byebye(0);
157 }
158 if (LINES < MINLINES)
159 {
160 printf("\n\nSorry, %s, but your terminal window has too few lines.\n", whoami);
161 printf("Your terminal has %d lines, needs 22.\n",LINES);
162 byebye(0);
163 }
164
165 cols = COLS;
166 lines = LINES;
167
168 if ( cols % 2 != 0) cols -=1; /* must be even for maze code */
169 if (lines % 2 != 0) lines -=1; /* must be even for maze code */
170
171 /*
172 * Now that we have cols and lines, we can update our window
173 * structure for non-hardware windows.
174 */
175 setup();
176 /*
177 * Set up windows
178 */
179 cw = newwin(lines, cols, 0, 0);
180 mw = newwin(lines, cols, 0, 0);
181 hw = newwin(lines, cols, 0, 0);
182 msgw = newwin(4, cols, 0, 0);
183 if (cw == NULL || hw == NULL || mw == NULL || msgw == NULL) {
184 exit_game(EXIT_CLS | EXIT_ENDWIN);
185 }
186
187 keypad(cw, TRUE);
188 keypad(hw, TRUE);
189
190 init_player(); /* Roll up the rogue */
191 waswizard = wizard;
192
193 draw(cw);
194 /* A super wizard doesn't have to get equipped */
195 /* Check if "" option is TRUE and get environment flag */
196 if (wizard && strcmp(getenv("SUPER"),"YES") == 0 ||
197 def_attr == TRUE) {
198 level = 1;
199 new_level(NORMLEV);
200 }
201 else
202 new_level(STARTLEV); /* Draw current level */
203
204 /*
205 * Start up daemons and fuses
206 */
207 daemon(doctor, &player, AFTER);
208 fuse(swander, (VOID *)NULL, WANDERTIME, AFTER);
209 /* Give characters their innate abilities */
210 if (player.t_ctype == C_MAGICIAN || player.t_ctype == C_RANGER)
211 fuse(spell_recovery, (VOID *)NULL, SPELLTIME, AFTER);
212 if (player.t_ctype == C_DRUID || player.t_ctype == C_MONK)
213 fuse(chant_recovery, (VOID *)NULL, SPELLTIME, AFTER);
214 if (player.t_ctype == C_CLERIC || player.t_ctype == C_PALADIN)
215 fuse(prayer_recovery, (VOID *)NULL, SPELLTIME, AFTER);
216 daemon(stomach, (VOID *)NULL, AFTER);
217 if (player.t_ctype == C_THIEF ||
218 player.t_ctype == C_ASSASSIN ||
219 player.t_ctype == C_MONK)
220 daemon(trap_look, (VOID *)NULL, AFTER);
221
222 /* Does this character have any special knowledge? */
223 switch (player.t_ctype) {
224 case C_ASSASSIN:
225 /* Assassins automatically recognize poison */
226 p_know[P_POISON] = TRUE;
227 when C_FIGHTER:
228 /* Fighters automatically recognize skill */
229 p_know[P_SKILL] = TRUE;
230 }
231
232 /* Choose an initial quest item */
233 if (!wizard) {
234 if (def_attr == FALSE)
235 quest_item = rnd(MAXRELIC);
236 }
237 mpos = 0;
238 draw(cw);
239 msg("You have been quested to retrieve the %s....",
240 rel_magic[quest_item].mi_name);
241 mpos = 0;
242 playit();
243 }
244
245 /*
246 * endit:
247 * Exit the program abnormally.
248 */
249
250 /*UNUSED*/
251 void
252 endit(sig)
253 int sig;
254 {
255 NOOP(sig);
256 fatal("Ok, if you want to exit that badly, I'll have to allow it\n");
257 }
258
259 /*
260 * fatal:
261 * Exit the program, printing a message.
262 */
263
264 fatal(s)
265 char *s;
266 {
267 clear();
268 move(lines-2, 0);
269 printw("%s", s);
270 draw(stdscr);
271 printf("\n"); /* So the curser doesn't stop at the end of the line */
272 exit_game(EXIT_ENDWIN);
273 }
274
275 /*
276 * rnd:
277 * Pick a very random number.
278 */
279
280 rnd(range)
281 register int range;
282 {
283 return( md_rand(range) );
284 }
285
286 /*
287 * roll:
288 * roll a number of dice
289 */
290
291 roll(number, sides)
292 register int number, sides;
293 {
294 register int dtotal = 0;
295
296 while(number--)
297 dtotal += rnd(sides)+1;
298 return dtotal;
299 }
300
301 setup()
302 {
303 md_setup();
304 }
305
306 /*
307 * playit:
308 * The main loop of the program. Loop until the game is over,
309 * refreshing things and looking at the proper times.
310 */
311
312 playit()
313 {
314 register char *opts;
315
316 /*
317 * parse environment declaration of options
318 */
319 if ((opts = getenv("ROGUEOPTS")) != NULL)
320 parse_opts(opts);
321
322 player.t_oldpos = hero;
323 oldrp = roomin(&hero);
324 after = TRUE;
325 command(); /* Command execution */
326 endit(-1);
327 }
328
329 /*
330 * see if the system is being used too much for this game
331 */
332
333 too_much()
334 {
335 /* we no longer do load checking or user counts */
336 return(FALSE);
337 }
338
339 /*
340 * author:
341 * See if a user is an author of the program
342 */
343
344 author()
345 {
346 switch (md_getuid()) {
347 case 0: /* always OK for root to play */
348 return TRUE;
349 default:
350 return FALSE;
351 }
352 }
353
354 /*
355 * playtime:
356 * Returns TRUE when it is a good time to play rogue
357 */
358
359 playtime()
360 {
361 /* we no longer do playtime checking */
362
363 return TRUE;
364 }
365
366 /*
367 * betaover:
368 * Returns TRUE if the test period of this version of the game is over
369 */
370
371 betaover()
372 {
373 return(FALSE);
374 }
375
376
377 exit_game(flag)
378