forked from Draradech/NewtonWars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
270 lines (255 loc) · 7.09 KB
/
config.c
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "config.h"
#define A 2e6
Config conf;
void help(void)
{
printf("\n");
printf("Usage: nw [OPTION VALUE] [OPTION VALUE] ...\n");
printf("\n");
printf("Valid options:\n");
printf(" players maximum number of players, default: 12\n");
printf(" planets number of planets, default: 24\n");
printf(" shots number of displayed past shots, default: 16\n");
printf(" rate energy increase rate (default 1.0/s)\n");
printf(" limit energy limit (default 200.0)\n");
printf(" roundtime time limit per round in s (default 600)\n");
printf(" extrapoints selects the extrapoint mode (one out of: default, prefered, oldest, best\n");
printf("\n");
printf(" fullscreen fullscreen enabled, default: 1\n");
printf(" ratio aspect ratio of battlefield (1.33, 4:3 and 4/3 are valid formats), default: 16:9\n");
printf(" playersize radius of players (default: 4.0)\n");
printf(" margin margin around the battlefield before shots are voided (default: 500.0)\n");
printf("\n");
printf(" ip if set and a free slot exists, display 'to play, telnet \"ip\" 3490', default: empty\n");
printf(" message if set and a free slot exists, display message, supersedes ip, default: empty\n");
printf("\n");
printf("\n");
printf("Debug options\n");
printf(" debug debug output, default: 0\n");
printf(" fastmode render only every 100th frame, default: 0\n");
printf(" throttle delay for every step in ms, default: 0.0\n");
printf("\n");
}
void config(int* argc, char** argv)
{
int i;
char *b, *c;
// changeable via cmd line
conf.maxPlayers = 12;
conf.numPlanets = 24;
conf.numShots = 16;
conf.rate = 1.0;
conf.limit = 200.01;
conf.roundTime = 600;
conf.fullscreen = 1;
conf.battlefieldW = sqrt(A * 16 / 9); /* 1885 */
conf.battlefieldH = sqrt(A * 9 / 16); /* 1060 */
conf.playerSize = 4.0;
conf.margin = 500;
conf.ip = 0;
conf.message = 0;
conf.extrapoints = CONFIG_EXTRAPOINTS_DEFAULT;
//debug
conf.debug = 0;
conf.fastmode = 0;
conf.throttle = 0;
//fixed
conf.maxSegments = 2000;
conf.segmentSteps = 25;
for(i = 1; i < *argc; ++i)
{
b = argv[i++];
c = argv[i];
if(!c)
{
help();
exit(0);
}
if (*b == '-' || *b == '/') b++; /* allow -para and /para */
if (*b == '-') b++; /* allow --para */
if (strcmp(b, "players") == 0)
{
conf.maxPlayers = atoi(c);
if(conf.maxPlayers > 12 || conf.maxPlayers < 1)
{
printf("players need to be between 1 and 12\n");
exit(0);
}
}
else if (strcmp(b, "planets") == 0)
{
conf.numPlanets = atoi(c);
if(conf.numPlanets > 64 || conf.numPlanets < 1)
{
printf("planets need to be between 1 and 64\n");
exit(0);
}
}
else if (strcmp(b, "shots") == 0)
{
conf.numShots = atoi(c);
if(conf.numShots > 64 || conf.numShots < 1)
{
printf("shots need to be between 1 and 64\n");
exit(0);
}
}
else if (strcmp(b, "rate") == 0)
{
conf.rate = atof(c);
if(conf.rate > 10.0 || conf.rate < 0.1)
{
printf("rate needs to be >= 0.1 and <= 10.0\n");
exit(0);
}
}
else if (strcmp(b, "limit") == 0)
{
conf.limit = atof(c);
if(conf.limit > 10000.0 || conf.limit < 10.0)
{
printf("limit needs to be >= 0.0 and <= 10.0\n");
exit(0);
}
}
else if (strcmp(b, "roundtime") == 0)
{
conf.roundTime = atof(c);
if(conf.roundTime > 3600 || conf.limit < 0)
{
printf("roundtime needs to be >= 0 and <= 3600\n");
exit(0);
}
}
else if (strcmp(b, "fullscreen") == 0)
{
conf.fullscreen = atoi(c);
if(conf.fullscreen > 1 || conf.fullscreen < 0)
{
printf("fullscreen needs to be 0 or 1\n");
exit(0);
}
}
else if (strcmp(b, "ratio") == 0)
{
double ratio = atof(c);
char *d;
d = strstr(c, "/");
if(d)
{
d++;
ratio /= atof(d);
}
else
{
d = strstr(c, ":");
if(d)
{
d++;
ratio /= atof(d);
}
}
if(ratio > 5. || ratio < .5)
{
printf("ratio needs to be between 5.0 and 0.5\n");
exit(0);
}
conf.battlefieldW = sqrt(A * ratio);
conf.battlefieldH = sqrt(A / ratio);
}
else if (strcmp(b, "playersize") == 0)
{
conf.playerSize = atof(c);
if(conf.playerSize > 10 || conf.playerSize <= 0)
{
printf("playersize needs to be > 0.0 and <= 10.0\n");
exit(0);
}
}
else if (strcmp(b, "margin") == 0)
{
conf.margin = atoi(c);
if(conf.margin < 0 || conf.margin > 10000)
{
printf("margin needs to be between 0 and 10000\n");
exit(0);
}
}
else if (strcmp(b, "ip") == 0)
{
if(c[0])
{
conf.ip = c;
}
}
else if (strcmp(b, "message") == 0)
{
if(c[0])
{
conf.message = c;
}
}
else if (strcmp(b, "debug") == 0)
{
conf.debug = atoi(c);
if(conf.debug > 1 || conf.debug < 0)
{
printf("debug needs to be 0 or 1\n");
exit(0);
}
}
else if (strcmp(b, "fastmode") == 0)
{
conf.fastmode = atoi(c);
if(conf.fastmode > 1 || conf.fastmode < 0)
{
printf("fastmode needs to be 0 or 1\n");
exit(0);
}
}
else if (strcmp(b, "throttle") == 0)
{
conf.throttle = atoi(c);
if(conf.throttle > 10000 || conf.throttle < 0)
{
printf("throttle needs to be >= 0 and <= 10000\n");
exit(0);
}
}
else if ( (strcmp(b, "h") == 0)
|| (strcmp(b, "help") == 0)
|| (strcmp(b, "?") == 0)
)
{
help();
exit(0);
}
else if ( (strcmp(b, "extrapoints") == 0) )
{
if( strcmp(c,"prefered") == 0 )
{
conf.extrapoints = CONFIG_EXTRAPOINTS_PREFERED_TARGET;
}
else if( strcmp(c,"oldest") == 0 )
{
conf.extrapoints = CONFIG_EXTRAPOINTS_KILL_OLDEST;
}
else if( strcmp(c,"best") == 0 )
{
conf.extrapoints = CONFIG_EXTRAPOINTS_KILL_BEST;
}
else
{
conf.extrapoints = CONFIG_EXTRAPOINTS_DEFAULT;
}
}
else
{
printf("warning: nw ignored parameter %s %s\n", b, c);
}
}
}