Mercurial > hg > early-roguelike
annotate rogue5/main.c @ 33:f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
author | elwin |
---|---|
date | Mon, 24 May 2010 20:10:59 +0000 |
parents | |
children | 655c317b6237 |
rev | line source |
---|---|
33
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
1 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
2 * Rogue: Exploring the Dungeons of Doom |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
3 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
4 * All rights reserved. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
5 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
6 * See the file LICENSE.TXT for full copyright and licensing information. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
7 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
8 * @(#)main.c 4.22 (Berkeley) 02/05/99 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
9 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
10 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
11 #include <stdlib.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
12 #include <string.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
13 #include <signal.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
14 #include <time.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
15 #include <curses.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
16 #include "rogue.h" |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
17 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
18 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
19 * main: |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
20 * The main program, of course |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
21 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
22 int |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
23 main(int argc, char **argv) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
24 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
25 char *env; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
26 time_t lowtime; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
27 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
28 md_init(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
29 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
30 #ifdef MASTER |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
31 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
32 * Check to see if he is a wizard |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
33 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
34 if (argc >= 2 && argv[1][0] == '\0') |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
35 if (strcmp(PASSWD, md_crypt(md_getpass("wizard's password: "), "mT")) == 0) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
36 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
37 wizard = TRUE; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
38 player.t_flags |= SEEMONST; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
39 argv++; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
40 argc--; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
41 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
42 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
43 #endif |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
44 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
45 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
46 * get home and options from environment |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
47 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
48 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
49 strcpy(home, md_gethomedir()); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
50 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
51 if (strlen(home) > MAXSTR - strlen("rogue.save") - 1) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
52 *home = 0; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
53 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
54 strcpy(file_name, home); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
55 strcat(file_name, "rogue.save"); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
56 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
57 if ((env = getenv("ROGUEOPTS")) != NULL) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
58 parse_opts(env); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
59 if (env == NULL || whoami[0] == '\0') |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
60 strucpy(whoami, md_getusername(), strlen(md_getusername())); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
61 lowtime = time(NULL); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
62 if (getenv("SEED") != NULL) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
63 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
64 dnum = atoi(getenv("SEED")); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
65 noscore = 1; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
66 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
67 else |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
68 dnum = (unsigned int) lowtime + md_getpid(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
69 seed = dnum; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
70 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
71 open_score(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
72 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
73 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
74 * Drop setuid/setgid after opening the scoreboard file. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
75 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
76 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
77 md_normaluser(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
78 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
79 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
80 * check for print-score option |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
81 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
82 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
83 md_normaluser(); /* we drop any setgid/setuid priveldges here */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
84 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
85 if (argc == 2) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
86 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
87 if (strcmp(argv[1], "-s") == 0) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
88 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
89 noscore = TRUE; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
90 score(0, -1, 0); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
91 exit(0); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
92 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
93 else if (strcmp(argv[1], "-d") == 0) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
94 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
95 dnum = rnd(100); /* throw away some rnd()s to break patterns */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
96 while (--dnum) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
97 rnd(100); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
98 purse = rnd(100) + 1; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
99 level = rnd(100) + 1; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
100 initscr(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
101 getltchars(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
102 death(death_monst()); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
103 exit(0); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
104 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
105 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
106 |