-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.cpp
150 lines (121 loc) · 3.85 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
#include "globals.h"
#include "window.h"
#include "rng.h"
#include "game.h"
#include "files.h"
#include <ctime>
#include <stdio.h> // Output errors on bad command line options
#include <getopt.h>
#include <unistd.h> // Required for getopt??
#include <string>
//#include "stringfunc.h"
const char* VERSION = "Cataclysm v2.0.0 alpha";
bool parse_options(int argc, char* argv[]);
void print_cli_help(std::string program_name);
void print_version();
bool prep_folders();
int main(int argc, char* argv[])
{
TESTING_MODE = 0;
if (!parse_options(argc, argv)) {
return 1;
}
srand(time(NULL)); // Seed the RNG - TODO: Wrap this up
init_display(); // See window.cpp
//split_string("Strength affects the amount of weight you can carry or drag",
//" \n", true);
set_default_dirs(); // See files.cpp
if (!prep_directories()) { // See globals.cpp - creates save dir & subdirs
printf("Errors creating save directory structure.");
return 1;
}
load_global_data(); // See globals.cpp
// See game.cpp for setup() and starting_menu()
if (!GAME.setup_ui() || !GAME.starting_menu()) {
endwin();
return 1;
}
do {} while (GAME.main_loop()); // See game.cpp
endwin(); // See window.cpp
return 0;
}
bool parse_options(int argc, char* argv[])
{
// extern variables used by getopt
extern char* optarg;
std::string argument;
int c;
// TODO: Move these long options (and this function?) to a different file (?)
static option long_options[] =
{
// These options set a flag
{ "test", no_argument, &TESTING_MODE, 1},
{ "debug", no_argument, &TESTING_MODE, 1},
// These options do not set a flag.
{ "data-dir", required_argument, 0, 'd' },
{ "cuss-dir", required_argument, 0, 'c' },
{ "save-dir", required_argument, 0, 's' },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
int opt_index;
while ( (c = getopt_long(argc, argv, "", long_options, &opt_index)) != -1) {
switch (c) {
case 0:
// If the option set a flag, don't do anything else.
break;
case 'd': // --data-dir <directory>
if (!set_dir(DATA_DIR, optarg)) {
printf("'%s' is not a valid data directory.\n", optarg);
return false;
}
break;
case 'c': // --cuss-dir <directory>
if (!set_dir(CUSS_DIR, optarg)) {
printf("'%s' is not a valid cuss directory.\n", optarg);
return false;
}
break;
case 's': // --save-dir <directory>
if (!set_dir(SAVE_DIR, optarg)) {
printf("'%s' is not a valid save directory.\n", optarg);
return false;
}
break;
case 'h':
print_cli_help(argv[0]);
return false; // Because we don't want to run the game.
case 'v':
print_version();
return false; // Because we don't want to run the game.
case '?':
// getopt_long handles printing these error messages.
return false;
}
}
return true;
}
/* I was going to make this load from a file, but I think that hardcoding it is
* better practice. We want it to work independently of the DATA_DIR setting,
* or of the presence of any files.
*/
void print_cli_help(std::string program_name)
{
print_version();
printf("\n\
Usage: %s [options]\n\
\n\
Options:\n\
--test Enable test mode (cheat commands, increased info)\n\
--debug Enable debug mode (for now, identical to --test)\n\
--data-dir <directory> Use <directory> as a source for game data\n\
--cuss-dir <directory> Use <directory> as a source for interface data\n\
--help Print this help message and exit.\n\
--version Print the version and exit.\n",
program_name.c_str() );
}
void print_version()
{
printf("%s\n", VERSION);
}