annotate xrogue/main.c @ 310:827441d05b3e

Advanced Rogue family: fix some potential buffer overflows. Some code for determining the score file location assumed that PATH_MAX would be less than 1024, which cannot be guaranteed. Advanced Rogue 5 and 7, and XRogue, have had the buffers for the file name enlarged. UltraRogue never called the functions, so the code has been deleted instead.
author John "Elwin" Edwards
date Mon, 03 May 2021 19:05:37 -0400
parents e52a8a7ad4c5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
1 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
2 main.c - setup code
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
3
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
4 XRogue: Expeditions into the Dungeons of Doom
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
5 Copyright (C) 1991 Robert Pietkivitch
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
6 All rights reserved.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
7
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
8 Based on "Advanced Rogue"
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
10 All rights reserved.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
11
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
12 Based on "Rogue: Exploring the Dungeons of Doom"
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
14 All rights reserved.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
15
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
16 See the file LICENSE.TXT for full copyright and licensing information.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
17 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
18
135
ce0cf824c192 xrogue: add missing includes.
John "Elwin" Edwards
parents: 133
diff changeset
19 #include <stdlib.h>
ce0cf824c192 xrogue: add missing includes.
John "Elwin" Edwards
parents: 133
diff changeset
20 #include <string.h>
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
21 #include <curses.h>
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
22 #include <signal.h>
310
827441d05b3e Advanced Rogue family: fix some potential buffer overflows.
John "Elwin" Edwards
parents: 304
diff changeset
23 #include <limits.h>
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
24 #include <time.h>
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
25
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
26 #include "mach_dep.h"
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
27 #include "network.h"
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
28 #include "rogue.h"
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
29
143
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
30 void open_records(void);
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
31 bool too_much(void);
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
32 bool author(void);
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
33 bool playtime(void);
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
34 bool betaover(void);
136
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
35
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
36 int
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
37 main(int argc, char *argv[], char *envp[])
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
38 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
39 register char *env;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
40
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
41 md_init();
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
42
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
43 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
44 * get home and options from environment
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
45 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
46
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
47 strncpy(home, md_gethomedir(), LINELEN);
310
827441d05b3e Advanced Rogue family: fix some potential buffer overflows.
John "Elwin" Edwards
parents: 304
diff changeset
48 home[LINELEN-1] = '\0';
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
49
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
50 /* Get default save file */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
51 strcpy(file_name, home);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
52 strcat(file_name, "xrogue.sav");
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
53
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
54 /* Get default score file */
136
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
55 #ifdef SCOREFILE
310
827441d05b3e Advanced Rogue family: fix some potential buffer overflows.
John "Elwin" Edwards
parents: 304
diff changeset
56 strncpy(score_file, SCOREFILE, PATH_MAX);
827441d05b3e Advanced Rogue family: fix some potential buffer overflows.
John "Elwin" Edwards
parents: 304
diff changeset
57 score_file[PATH_MAX-1] = '\0';
136
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
58 #else
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
59 strcpy(score_file, md_getroguedir());
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
60
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
61 if (*score_file)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
62 strcat(score_file,"/");
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
63
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
64 strcat(score_file, "xrogue.scr");
136
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
65 #endif
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
66
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
67 #ifdef SAVEDIR
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
68 /* Check for common save location */
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
69 if (argc >= 3 && strcmp(argv[1], "-n") == 0)
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
70 {
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
71 strncpy(whoami, argv[2], 79);
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
72 whoami[79] = '\0';
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
73 use_savedir = TRUE;
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
74 if (LINELEN <= snprintf(file_name, LINELEN, "%s/%d-%s.xrsav", SAVEDIR,
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
75 md_getuid(), whoami))
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
76 {
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
77 strcpy(file_name, "xrogue.sav");
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
78 use_savedir = FALSE;
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
79 }
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
80 }
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
81 #endif
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
82
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
83 if ((env = getenv("ROGUEOPTS")) != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
84 parse_opts(env);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
85
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
86 if (whoami[0] == '\0')
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
87 strucpy(whoami, md_getusername(), strlen(md_getusername()));
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
88
143
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
89 open_records();
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
90 if (!use_savedir)
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
91 md_normaluser();
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
92 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
93 * check for print-score option
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
94 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
95 if (argc == 2 && strcmp(argv[1], "-s") == 0)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
96 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
97 waswizard = TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
98 score((long)0, SCOREIT, (short)0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
99 exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
100 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
101
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
102 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
103 * Check for a network update
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
104 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
105 if (argc == 2 && strcmp(argv[1], "-u") == 0) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
106 int errcheck, errors = 0;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
107 unsigned long amount;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
108 short monster;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
109
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
110 /* Read in the amount and monster values to pass to score */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
111 amount = netread(&errcheck, sizeof(unsigned long), stdin);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
112 if (errcheck) errors++;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
113
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
114 monster = (short) netread(&errcheck, sizeof(short), stdin);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
115 if (errcheck) errors++;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
116
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
117 /* Now do the update if there were no errors */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
118 if (errors) exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
119 else {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
120 score((long)amount, UPDATE, (short)monster);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
121 exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
122 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
123 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
124
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
125 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
126 * Check to see if he is a wizard
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
127 */
139
0d151573bdb0 xrogue: compile out wizard mode by default.
John "Elwin" Edwards
parents: 136
diff changeset
128 #ifdef WIZARD
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
129 if (argc >= 2 && argv[1][0] == '\0')
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
130 if (strcmp(PASSWD, xcrypt(md_getpass("Wizard's password: "), "mT")) == 0)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
131 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
132 wizard = TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
133 argv++;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
134 argc--;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
135 }
139
0d151573bdb0 xrogue: compile out wizard mode by default.
John "Elwin" Edwards
parents: 136
diff changeset
136 #endif
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
137
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
138 if (betaover())
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
139 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
140 printf("Sorry, %s, but the test period of this prerelease version\n",whoami);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
141 printf("of xrogue is over. Please acquire a new version. Sorry.\n");
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
142 exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
143 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
144
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
145 if (!wizard && !author() && !playtime()) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
146 printf("Sorry, %s, but you can't play during working hours.\n", whoami);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
147 printf("Try again later.\n");
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
148 exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
149 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
150 if (!wizard && !author() && too_much()) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
151 printf("Sorry, %s, but the system is too loaded now.\n", whoami);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
152 printf("Try again later.\n");
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
153 exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
154 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
155
136
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
156 if (use_savedir)
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
157 {
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
158 /* restore() will return TRUE if a new game should be started. */
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
159 if (!restore(file_name, envp))
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
160 exit_game(0);
1fbdefa82533 xrogue: initial support for the -n option.
John "Elwin" Edwards
parents: 135
diff changeset
161 }
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
162 if (argc == 2)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
163 if (!restore(argv[1], envp)) /* Note: restore will never return */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
164 exit_game(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
165
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
166 if (wizard && getenv("SEED") != NULL) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
167 seed = atoi(getenv("SEED"));
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
168 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
169 else {
252
3d4252fa2ed3 Use more portable random seed generation.
John "Elwin" Edwards
parents: 236
diff changeset
170 seed = md_random_seed();
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
171 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
172 if (wizard)
147
301ed6992c2e arogue7, xrogue: put newlines at the end of startup messages.
John "Elwin" Edwards
parents: 145
diff changeset
173 printf("Hello %s, welcome to dungeon #%d\n", whoami, seed);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
174 else
147
301ed6992c2e arogue7, xrogue: put newlines at the end of startup messages.
John "Elwin" Edwards
parents: 145
diff changeset
175 printf("Hello %s, just a moment while I dig the dungeon...\n", whoami);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
176 fflush(stdout);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
177
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
178 md_srand(seed);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
179
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
180 init_things(); /* Set up probabilities of things */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
181 init_colors(); /* Set up colors of potions */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
182 init_stones(); /* Set up stone settings of rings */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
183 init_materials(); /* Set up materials of wands */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
184 init_names(); /* Set up names of scrolls */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
185 init_misc(); /* Set up miscellaneous magic */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
186 init_foods(); /* set up the food table */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
187
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
188 initscr(); /* Start up cursor package */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
189
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
190 typeahead(-1); /* turn off 3.2/4.0 curses feature */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
191
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
192 if (COLS < MINCOLS)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
193 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
194 printf("\n\nSorry, %s, but your terminal window has too few columns.\n", whoami);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
195 printf("Your terminal has %d columns, needs 70.\n",COLS);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
196 byebye(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
197 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
198 if (LINES < MINLINES)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
199 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
200 printf("\n\nSorry, %s, but your terminal window has too few lines.\n", whoami);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
201 printf("Your terminal has %d lines, needs 22.\n",LINES);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
202 byebye(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
203 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
204
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
205 cols = COLS;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
206 lines = LINES;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
207
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
208 if ( cols % 2 != 0) cols -=1; /* must be even for maze code */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
209 if (lines % 2 != 0) lines -=1; /* must be even for maze code */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
210
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
211 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
212 * Now that we have cols and lines, we can update our window
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
213 * structure for non-hardware windows.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
214 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
215 setup();
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
216 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
217 * Set up windows
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
218 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
219 cw = newwin(lines, cols, 0, 0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
220 mw = newwin(lines, cols, 0, 0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
221 hw = newwin(lines, cols, 0, 0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
222 msgw = newwin(4, cols, 0, 0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
223 if (cw == NULL || hw == NULL || mw == NULL || msgw == NULL) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
224 exit_game(EXIT_CLS | EXIT_ENDWIN);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
225 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
226
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
227 keypad(cw, TRUE);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
228 keypad(hw, TRUE);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
229
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
230 init_player(); /* Roll up the rogue */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
231 waswizard = wizard;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
232
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
233 draw(cw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
234 /* A super wizard doesn't have to get equipped */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
235 /* Check if "" option is TRUE and get environment flag */
304
e52a8a7ad4c5 Fix many compiler warnings.
John "Elwin" Edwards
parents: 252
diff changeset
236 if ((wizard && strcmp(getenv("SUPER"),"YES") == 0) || def_attr == TRUE) {
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
237 level = 1;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
238 new_level(NORMLEV);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
239 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
240 else
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
241 new_level(STARTLEV); /* Draw current level */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
242
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
243 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
244 * Start up daemons and fuses
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
245 */
151
cadff8f047a1 arogue7, xrogue: rename daemon() to start_daemon().
John "Elwin" Edwards
parents: 147
diff changeset
246 start_daemon(doctor, &player, AFTER);
236
7c1cb43f346e XRogue: get rid of VOID as an alias for long.
John "Elwin" Edwards
parents: 220
diff changeset
247 fuse(swander, NULL, WANDERTIME, AFTER);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
248 /* Give characters their innate abilities */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
249 if (player.t_ctype == C_MAGICIAN || player.t_ctype == C_RANGER)
236
7c1cb43f346e XRogue: get rid of VOID as an alias for long.
John "Elwin" Edwards
parents: 220
diff changeset
250 fuse(spell_recovery, NULL, SPELLTIME, AFTER);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
251 if (player.t_ctype == C_DRUID || player.t_ctype == C_MONK)
236
7c1cb43f346e XRogue: get rid of VOID as an alias for long.
John "Elwin" Edwards
parents: 220
diff changeset
252 fuse(chant_recovery, NULL, SPELLTIME, AFTER);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
253 if (player.t_ctype == C_CLERIC || player.t_ctype == C_PALADIN)
236
7c1cb43f346e XRogue: get rid of VOID as an alias for long.
John "Elwin" Edwards
parents: 220
diff changeset
254 fuse(prayer_recovery, NULL, SPELLTIME, AFTER);
7c1cb43f346e XRogue: get rid of VOID as an alias for long.
John "Elwin" Edwards
parents: 220
diff changeset
255 start_daemon(stomach, NULL, AFTER);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
256 if (player.t_ctype == C_THIEF ||
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
257 player.t_ctype == C_ASSASSIN ||
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
258 player.t_ctype == C_MONK)
236
7c1cb43f346e XRogue: get rid of VOID as an alias for long.
John "Elwin" Edwards
parents: 220
diff changeset
259 start_daemon(trap_look, NULL, AFTER);
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
260
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
261 /* Does this character have any special knowledge? */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
262 switch (player.t_ctype) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
263 case C_ASSASSIN:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
264 /* Assassins automatically recognize poison */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
265 p_know[P_POISON] = TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
266 when C_FIGHTER:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
267 /* Fighters automatically recognize skill */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
268 p_know[P_SKILL] = TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
269 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
270
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
271 /* Choose an initial quest item */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
272 if (!wizard) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
273 if (def_attr == FALSE)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
274 quest_item = rnd(MAXRELIC);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
275 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
276 mpos = 0;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
277 draw(cw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
278 msg("You have been quested to retrieve the %s....",
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
279 rel_magic[quest_item].mi_name);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
280 mpos = 0;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
281 playit();
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
282 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
283
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
284 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
285 * endit:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
286 * Exit the program abnormally.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
287 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
288
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
289 void
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
290 endit(int sig)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
291 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
292 NOOP(sig);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
293 fatal("Ok, if you want to exit that badly, I'll have to allow it\n");
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
294 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
295
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
296 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
297 * fatal:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
298 * Exit the program, printing a message.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
299 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
300
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
301 void
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
302 fatal(char *s)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
303 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
304 clear();
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
305 move(lines-2, 0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
306 printw("%s", s);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
307 draw(stdscr);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
308 printf("\n"); /* So the curser doesn't stop at the end of the line */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
309 exit_game(EXIT_ENDWIN);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
310 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
311
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
312 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
313 * rnd:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
314 * Pick a very random number.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
315 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
316
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
317 int
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
318 rnd(int range)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
319 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
320 return( md_rand(range) );
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
321 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
322
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
323 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
324 * roll:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
325 * roll a number of dice
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
326 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
327
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
328 int
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
329 roll(int number, int sides)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
330 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
331 register int dtotal = 0;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
332
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
333 while(number--)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
334 dtotal += rnd(sides)+1;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
335 return dtotal;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
336 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
337
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
338 void
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
339 setup(void)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
340 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
341 md_setup();
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
342 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
343
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
344 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
345 * playit:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
346 * The main loop of the program. Loop until the game is over,
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
347 * refreshing things and looking at the proper times.
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
348 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
349
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
350 void
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
351 playit(void)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
352 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
353 register char *opts;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
354
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
355 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
356 * parse environment declaration of options
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
357 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
358 if ((opts = getenv("ROGUEOPTS")) != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
359 parse_opts(opts);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
360
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
361 player.t_oldpos = hero;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
362 oldrp = roomin(&hero);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
363 after = TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
364 command(); /* Command execution */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
365 endit(-1);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
366 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
367
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
368 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
369 * see if the system is being used too much for this game
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
370 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
371
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
372 bool
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
373 too_much(void)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
374 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
375 /* we no longer do load checking or user counts */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
376 return(FALSE);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
377 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
378
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
379 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
380 * author:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
381 * See if a user is an author of the program
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
382 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
383
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
384 bool
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
385 author(void)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
386 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
387 switch (md_getuid()) {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
388 case 0: /* always OK for root to play */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
389 return TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
390 default:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
391 return FALSE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
392 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
393 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
394
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
395 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
396 * playtime:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
397 * Returns TRUE when it is a good time to play rogue
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
398 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
399
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
400 bool
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
401 playtime(void)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
402 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
403 /* we no longer do playtime checking */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
404
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
405 return TRUE;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
406 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
407
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
408 /*
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
409 * betaover:
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
410 * Returns TRUE if the test period of this version of the game is over
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
411 */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
412
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
413 bool
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
414 betaover(void)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
415 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
416 return(FALSE);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
417 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
418
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
419
220
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
420 void
f54901b9c39b XRogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 151
diff changeset
421 exit_game(int flag)
133
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
422 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
423 int i;
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
424
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
425 if (flag & EXIT_CLS) /* Clear Screen */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
426 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
427 wclear(cw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
428 draw(cw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
429 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
430
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
431 if (flag & EXIT_ENDWIN) /* Shutdown Curses */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
432 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
433 keypad(cw,FALSE);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
434 keypad(hw,FALSE);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
435 delwin(cw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
436 delwin(mw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
437 delwin(hw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
438 delwin(msgw);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
439 if (!isendwin())
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
440 endwin();
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
441 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
442 o_free_list(player.t_pack);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
443 t_free_list(mlist);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
444 t_free_list(rlist);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
445 t_free_list(tlist);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
446 o_free_list(lvl_obj); /* Free up previous objects (if any) */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
447 for (i = 0; i < MAXROOMS; i++)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
448 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
449 r_free_list(rooms[i].r_exit); /* Free up the exit lists */
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
450 _r_free_fire_list(&rooms[i].r_fires);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
451 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
452
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
453 for(i=0; i<MAXSCROLLS; i++)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
454 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
455 if (s_names[i] != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
456 free( s_names[i] );
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
457 if (s_guess[i] != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
458 free( s_guess[i] );
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
459 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
460
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
461 for(i=0; i<MAXPOTIONS; i++)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
462 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
463 if (p_guess[i] != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
464 free( p_guess[i] );
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
465 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
466
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
467 for(i=0; i<MAXRINGS; i++)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
468 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
469 if (r_guess[i] != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
470 free( r_guess[i] );
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
471 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
472
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
473 for(i=0; i<MAXSTICKS; i++)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
474 {
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
475 if (ws_guess[i] != NULL)
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
476 free( ws_guess[i] );
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
477 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
478
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
479 exit(0);
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
480 }
e6179860cb76 Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
John "Elwin" Edwards
parents:
diff changeset
481
143
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
482 void
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
483 open_records(void)
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
484 {
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
485 if (scorefi == NULL)
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
486 scorefi = fopen(score_file, "rb+");
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
487 if (scorefi == NULL)
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
488 scorefi = fopen(score_file, "wb+");
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
489 /* If opening fails, that will be handled when trying to write. */
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
490 #ifdef LOGFILE
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
491 if (logfile == NULL)
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
492 logfile = fopen(LOGFILE, "a");
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
493 #endif
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
494 return;
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
495 }
7faf4568c295 Advanced Rogue family: overhaul privilege handling.
John "Elwin" Edwards
parents: 139
diff changeset
496