~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/params.c

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * OpenTyrian: A modern cross-platform port of Tyrian
 
3
 * Copyright (C) 2007-2009  The OpenTyrian Development Team
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
#include "arg_parse.h"
 
20
#include "file.h"
 
21
#include "joystick.h"
 
22
#include "loudness.h"
 
23
#include "network.h"
 
24
#include "opentyr.h"
 
25
#include "params.h"
 
26
#include "varz.h"
 
27
#include "xmas.h"
 
28
 
 
29
#include <assert.h>
 
30
#include <ctype.h>
 
31
#include <errno.h>
 
32
#include <stdint.h>
 
33
#include <string.h>
 
34
 
 
35
JE_boolean richMode = false, constantPlay = false, constantDie = false;
 
36
 
 
37
/* YKS: Note: LOOT cheat had non letters removed. */
 
38
const char pars[][9] = {
 
39
        "LOOT", "RECORD", "NOJOY", "CONSTANT", "DEATH", "NOSOUND", "NOXMAS", "YESXMAS"
 
40
};
 
41
 
 
42
void JE_paramCheck( int argc, char *argv[] )
 
43
{
 
44
        const Options options[] =
 
45
        {
 
46
                { 'h', 'h', "help",              false },
 
47
                
 
48
                { 's', 's', "no-sound",          false },
 
49
                { 'j', 'j', "no-joystick",       false },
 
50
                { 'x', 'x', "no-xmas",           false },
 
51
                
 
52
                { 't', 't', "data",              true },
 
53
                
 
54
                { 'n', 'n', "net",               true },
 
55
                { 256, 0,   "net-player-name",   true }, // TODO: no short codes because there should
 
56
                { 257, 0,   "net-player-number", true }, //       be a menu for entering these in the future
 
57
                { 'p', 'p', "net-port",          true },
 
58
                { 'd', 'd', "net-delay",         true },
 
59
                
 
60
                { 'X', 'X', "xmas",              false },
 
61
                { 'c', 'c', "constant",          false },
 
62
                { 'k', 'k', "death",             false },
 
63
                { 'r', 'r', "record",            false },
 
64
                { 'l', 'l', "loot",              false },
 
65
                
 
66
                { 0, 0, NULL, false}
 
67
        };
 
68
        
 
69
        Option option;
 
70
        
 
71
        for (; ; )
 
72
        {
 
73
                option = parse_args(argc, (const char **)argv, options);
 
74
                
 
75
                if (option.value == NOT_OPTION)
 
76
                        break;
 
77
                
 
78
                switch (option.value)
 
79
                {
 
80
                case INVALID_OPTION:
 
81
                case AMBIGUOUS_OPTION:
 
82
                case OPTION_MISSING_ARG:
 
83
                        fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
 
84
                        exit(EXIT_FAILURE);
 
85
                        break;
 
86
                        
 
87
                case 'h':
 
88
                        printf("Usage: %s [OPTION...]\n\n"
 
89
                               "Options:\n"
 
90
                               "  -h, --help                   Show help about options\n\n"
 
91
                               "  -s, --no-sound               Disable audio\n"
 
92
                               "  -j, --no-joystick            Disable joystick/gamepad input\n"
 
93
                               "  -x, --no-xmas                Disable Christmas mode\n\n"
 
94
                               "  -t, --data=DIR               Set Tyrian data directory\n\n"
 
95
                               "  -n, --net=HOST[:PORT]        Start a networked game\n"
 
96
                               "  --net-player-name=NAME       Sets local player name in a networked game\n"
 
97
                               "  --net-player-number=NUMBER   Sets local player number in a networked game\n"
 
98
                               "                               (1 or 2)\n"
 
99
                               "  -p, --net-port=PORT          Local port to bind (default is 1333)\n"
 
100
                               "  -d, --net-delay=FRAMES       Set lag-compensation delay (default is 1)\n", argv[0]);
 
101
                        exit(0);
 
102
                        break;
 
103
                        
 
104
                case 's':
 
105
                        // Disables sound/music usage
 
106
                        audio_disabled = true;
 
107
                        break;
 
108
                        
 
109
                case 'j':
 
110
                        // Disables joystick detection
 
111
                        ignore_joystick = true;
 
112
                        break;
 
113
                        
 
114
                case 'x':
 
115
                        xmas = false;
 
116
                        break;
 
117
                        
 
118
                // set custom Tyrian data directory
 
119
                case 't':
 
120
                        custom_data_dir = option.arg;
 
121
                        break;
 
122
                        
 
123
                case 'n':
 
124
                        isNetworkGame = true;
 
125
                        
 
126
                        intptr_t temp = (intptr_t)strchr(option.arg, ':');
 
127
                        if (temp)
 
128
                        {
 
129
                                temp -= (intptr_t)option.arg;
 
130
                                
 
131
                                int temp_port = atoi(&option.arg[temp + 1]);
 
132
                                if (temp_port > 0 && temp_port < 49152)
 
133
                                        network_opponent_port = temp_port;
 
134
                                else
 
135
                                {
 
136
                                        fprintf(stderr, "%s: error: invalid network port number\n", argv[0]);
 
137
                                        exit(EXIT_FAILURE);
 
138
                                }
 
139
                                
 
140
                                network_opponent_host = malloc(temp + 1);
 
141
                                strnztcpy(network_opponent_host, option.arg, temp);
 
142
                        }
 
143
                        else
 
144
                        {
 
145
                                network_opponent_host = malloc(strlen(option.arg) + 1);
 
146
                                strcpy(network_opponent_host, option.arg);
 
147
                        }
 
148
                        break;
 
149
                        
 
150
                case 256: // --net-player-name
 
151
                        network_player_name = malloc(strlen(option.arg) + 1);
 
152
                        strcpy(network_player_name, option.arg);
 
153
                        break;
 
154
                        
 
155
                case 257: // --net-player-number
 
156
                {
 
157
                        int temp = atoi(option.arg);
 
158
                        if (temp >= 1 && temp <= 2)
 
159
                                thisPlayerNum = temp;
 
160
                        else
 
161
                        {
 
162
                                fprintf(stderr, "%s: error: invalid network player number\n", argv[0]);
 
163
                                exit(EXIT_FAILURE);
 
164
                        }
 
165
                        break;
 
166
                }
 
167
                case 'p':
 
168
                {
 
169
                        int temp = atoi(option.arg);
 
170
                        if (temp > 0 && temp < 49152)
 
171
                                network_player_port = temp;
 
172
                        else
 
173
                        {
 
174
                                fprintf(stderr, "%s: error: invalid network port number\n", argv[0]);
 
175
                                exit(EXIT_FAILURE);
 
176
                        }
 
177
                        break;
 
178
                }
 
179
                case 'd':
 
180
                {
 
181
                        int temp;
 
182
                        if (sscanf(option.arg, "%d", &temp) == 1)
 
183
                                network_delay = 1 + temp;
 
184
                        else
 
185
                        {
 
186
                                fprintf(stderr, "%s: error: invalid network delay value\n", argv[0]);
 
187
                                exit(EXIT_FAILURE);
 
188
                        }
 
189
                        break;
 
190
                }
 
191
                case 'X':
 
192
                        xmas = true;
 
193
                        break;
 
194
                        
 
195
                case 'c':
 
196
                        /* Constant play for testing purposes (C key activates invincibility)
 
197
                           This might be useful for publishers to see everything - especially
 
198
                           those who can't play it */
 
199
                        constantPlay = true;
 
200
                        break;
 
201
                        
 
202
                case 'k':
 
203
                        constantDie = true;
 
204
                        break;
 
205
                        
 
206
                case 'r':
 
207
                        record_demo = true;
 
208
                        break;
 
209
                        
 
210
                case 'l':
 
211
                        // Gives you mucho bucks
 
212
                        richMode = true;
 
213
                        break;
 
214
                        
 
215
                default:
 
216
                        assert(false);
 
217
                        break;
 
218
                }
 
219
        }
 
220
        
 
221
        // legacy parameter support
 
222
        for (int i = option.argn; i < argc; ++i)
 
223
        {
 
224
                for (uint j = 0; j < strlen(argv[i]); ++j)
 
225
                        argv[i][j] = toupper((unsigned char)argv[i][j]);
 
226
                
 
227
                for (uint j = 0; j < COUNTOF(pars); ++j)
 
228
                {
 
229
                        if (strcmp(argv[i], pars[j]) == 0)
 
230
                        {
 
231
                                switch (j)
 
232
                                {
 
233
                                case 0:
 
234
                                        richMode = true;
 
235
                                        break;
 
236
                                case 1:
 
237
                                        record_demo = true;
 
238
                                        break;
 
239
                                case 2:
 
240
                                        ignore_joystick = true;
 
241
                                        break;
 
242
                                case 3:
 
243
                                        constantPlay = true;
 
244
                                        break;
 
245
                                case 4:
 
246
                                        constantDie = true;
 
247
                                        break;
 
248
                                case 5:
 
249
                                        audio_disabled = true;
 
250
                                        break;
 
251
                                case 6:
 
252
                                        xmas = false;
 
253
                                        break;
 
254
                                case 7:
 
255
                                        xmas = true;
 
256
                                        break;
 
257
                                        
 
258
                                default:
 
259
                                        assert(false);
 
260
                                        break;
 
261
                                }
 
262
                        }
 
263
                }
 
264
        }
 
265
}
 
266