annotate rogue5/main.c @ 275:aa0eefcd7df6

UltraRogue: build and install documentation in the Makefile.
author John "Elwin" Edwards
date Sat, 09 Sep 2017 07:25:23 -0400
parents 3d4252fa2ed3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
27 md_init();
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
28
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
29 #ifdef MASTER
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
30 /*
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
31 * Check to see if he is a wizard
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
32 */
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
33 if (argc >= 2 && argv[1][0] == '\0')
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
34 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
35 {
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
36 wizard = TRUE;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
37 player.t_flags |= SEEMONST;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
38 argv++;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
39 argc--;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
40 }
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 #endif
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
43
34
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
44 /* Check to see if savefiles should be stored in the system location */
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
45 #ifdef SAVEDIR
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
46 if (argc >= 3 && !strcmp(argv[1], "-n"))
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
47 {
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
48 use_savedir = TRUE;
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
49 strncpy(whoami, argv[2], MAXSTR);
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
50 whoami[MAXSTR-1] = '\0';
112
ee250e3646fd Don't truncate player name in savefile name or log message.
John "Elwin" Edwards
parents: 43
diff changeset
51 snprintf(file_name, MAXSTR, "%s/%d-%.80s.r5sav", SAVEDIR,
34
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
52 md_getuid(), whoami);
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
53 }
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
54 #endif
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
55
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
56 open_score();
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
57 open_log();
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
58
33
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
59 /*
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
60 * get home and options from environment
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
61 */
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
62
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
63 strcpy(home, md_gethomedir());
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
64
34
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
65 if (strlen(home) > MAXSTR - strlen("rogue5.save") - 1)
33
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
66 *home = 0;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
67
34
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
68 if (!use_savedir)
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
69 {
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
70 md_normaluser();
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
71 strcpy(file_name, home);
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
72 strcat(file_name, "rogue5.save");
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
73 }
33
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
74
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
75 if ((env = getenv("ROGUEOPTS")) != NULL)
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
76 parse_opts(env);
34
655c317b6237 rogue5: add savedir, logfile, bugfixes
elwin
parents: 33
diff changeset
77 if (!use_savedir && (env == NULL || whoami[0] == '\0'))
33
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
78 strucpy(whoami, md_getusername(), strlen(md_getusername()));
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
79 if (getenv("SEED") != NULL)
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
80 {
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
81 dnum = atoi(getenv("SEED"));
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
82 noscore = 1;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
83 }
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
84 else
252
3d4252fa2ed3 Use more portable random seed generation.
John "Elwin" Edwards
parents: 112
diff changeset
85 dnum = md_random_seed();
33
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
86 seed = dnum;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
87
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 * check for print-score option
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
90 */
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
91
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
92 if (argc == 2)
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
93 {
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
94 if (strcmp(argv[1], "-s") == 0)
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
95 {
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
96 noscore = TRUE;
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
97 score(0, -1, 0);
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
98 exit(0);
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
99 }
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
100 else if (strcmp(argv[1], "-d") == 0)
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
101 {
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
102 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
103 while (--dnum)
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
104 rnd(100);
f502bf60e6e4 Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset