This repository has been archived by the owner on Nov 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
149 lines (128 loc) · 3.47 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <direct.h>
#include <io.h>
#define getcwd _getcwd
#define access _access
#else
#include <unistd.h>
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#ifndef _WIN32
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include "Global.h"
#include "Util.h"
#include "Map.h"
#include "Interface.h"
#include "Monster.h"
#include "Hero.h"
#include "Game.h"
shInterface *I;
shMapLevel *Level;
char DataDir[ZAPM_PATH_LENGTH];
int GodMode = 0;
static void
usage ()
{
fprintf (stdout, "usage: zapm [-u username]\n"
" A science fiction themed \"roguelike\" game\n"
" http://zapm.org\n");
}
int
main (int argc, char **argv)
{
int rlimitresult = 0;
#ifndef _WIN32
struct rlimit coredumpsize;
coredumpsize.rlim_cur = RLIM_INFINITY;
coredumpsize.rlim_max = RLIM_INFINITY;
rlimitresult = setrlimit (RLIMIT_CORE, &coredumpsize);
#endif
snprintf (DataDir, ZAPM_PATH_LENGTH, "%s", DATADIR);
const char *name = NULL;
char namebuf[HERO_NAME_LENGTH+2];
int c;
int g = 0, o = 0, d = 0;
//FIXME: should probably stat() it and make sure it's a directory...
//FIXME: access() doesn't work for setuid install
if (0 && access (DataDir, O_RDWR)) {
fprintf (stderr, "Couldn't open \"%s\" directory: %s.\n", DataDir, strerror (errno));
fprintf (stderr, "ZAPM needs this directory for saved games and other data.\n"
"Perhaps you were running it from a strange directory?\n");
exitZapm (-1);
}
#ifndef _WIN32
while (-1 != (c = getopt (argc, argv, "u:dgo"))) {
switch (c) {
case 'd': d++; break;
case 'g': g++; break;
case 'o': o++; break;
case 'u':
name = strdup (optarg);
if (!nameOK (name)) {
fprintf (stderr, "Sorry, can't play a game as \"%s\".\n",
name);
return -1;
}
break;
case '?':
default:
usage ();
return 0;
}
}
#else
//windows doesn't have getopt()
if (2 == argc && !strcmp("-god", argv[1]))
d = g = o = 1;
#endif
if (d && g && o)
GodMode = 1;
utilInitialize ();
I = new shInterface ();
if (rlimitresult) {
I->debug ("Couldn't adjust coredumpsize.");
}
initializeOptions ();
initializeProfessions ();
initializeMonsters ();
I->showVersion ();
if (!name) {
int tries = 5;
name = getenv ("USER");
if (!name)
name = getenv ("USERNAME");
do {
if (!tries--) {
I->p ("Too many tries!");
I->pause ();
I->p ("");
goto done;
}
I->p ("Welcome to ZAPM!");
I->getStr (namebuf, HERO_NAME_LENGTH+1,
"What is your name?", name);
I->pageLog ();
} while (!nameOK (namebuf));
name = namebuf;
}
if (0 == loadGame (name) ||
0 == newGame (name))
{
I->p ("Welcome to \"ZapM\". Press '?' for help.");
I->p ("Please submit bug reports at http://zapm.org/bb/");
if (GodMode) {
I->p ("God Mode is on.");
}
gameLoop ();
}
done:
delete I;
fprintf (stdout, "Thanks for playing!\n");
fprintf (stdout, "Please submit bug reports at http://zapm.org/bb/\n");
exitZapm (0);
}