JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
06efba355093a0544bf16bfe5d9e26f0e373cbf6
[vor.git] / args.c
1 #include <errno.h>
2 #include "args.h"
3 #include "config.h"
4
5 // Gameplay Variations
6 float opt_bounciness;
7 float opt_gamespeed;
8 float opt_max_lead;
9
10 // Look and Feel
11 int opt_fullscreen;
12 int opt_music;
13 int opt_sound;
14
15
16 #ifndef WIN32
17
18 error_t parse_opt(int, char*, struct argp_state *);
19
20 const char *argp_program_version = "Variations on Rockdodger " VERSION;
21 const char *argp_program_bug_address = "<josh@qualdan.com>";
22 static char doc[] = "Dodge the rocks until you die.";
23 static struct argp_option opts[] = {
24         {0, 0, 0, 0, "Gameplay Variations:"},
25         {"bounciness", 'b', "N%", 0, "Keep N% of speed when hitting edges (default 50%)"},
26         {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"},
27         {"max-lead", 'l', "#SCREENS", OPTION_HIDDEN,
28                 "Max distance ahead you can get\n (default 1 screen; < 0 means no limit)"},
29         {0, 0, 0, 0, "Look and Feel:"},
30         {"full-screen", 'f', 0, 0, ""},
31         {"music", 'm', 0, 0, "Enable music"},
32         {"silent", 's', 0, 0, "No explosion sounds or music"},
33         {0, 0, 0, 0, "Informational:", -1},
34         {0}
35 };
36
37 struct argp argp = { opts, &parse_opt, 0, doc };
38
39 #endif // !WIN32
40
41 void
42 init_opts(void)
43 {
44         // Gameplay Variations
45         opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
46         opt_gamespeed = 1.00; // Run game at full speed.
47         opt_max_lead = 1.00*XSIZE;  // you can get 1 screen ahead.
48
49         // Look and Feel
50         opt_fullscreen = 0;
51         opt_sound = 1;
52         opt_music = 0;
53 }
54
55 #ifndef WIN32
56
57 error_t
58 parse_opt(int key, char *arg, struct argp_state *state)
59 {
60         int i;
61
62         switch(key) {
63                 case 'b': if(!sscanf(arg, "%d%%", &i)) {
64                                           fprintf(stderr, "bad --bounciness (-b) value (should be 0-100%%)\n");
65                                           argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
66                                           return EINVAL;
67                                   }
68                                   if(i < 50) i = 50; else if(i > 100) i = 100;
69                                   opt_bounciness = (float)i / 100;
70                                   break;
71                 case 'f': opt_fullscreen = 1; break;
72                 case 'g': if(!sscanf(arg, "%d%%", &i)) {
73                                           fprintf(stderr, "bad --gamespeed (-g) value (should be 50-100%%)\n");
74                                           argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
75                                           return EINVAL;
76                                   }
77                                   if(i < 0) i = 0; else if(i > 200) i = 100;
78                                   opt_gamespeed = (float)i / 100;
79                                   break;
80                 case 'l': if(!sscanf(arg, "%f", &opt_max_lead)) {
81                                           fprintf(stderr, "bad --max-lead (-l) value (must be a number)\n");
82                                           argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
83                                           return EINVAL;
84                                   }
85                                   opt_max_lead *= XSIZE;
86                                   break;
87                 case 'm': opt_music = 1; break;
88                 case 's': opt_sound = 0; opt_music = 0; break;
89                 default: return ARGP_ERR_UNKNOWN;
90         }
91         return 0;
92 }
93
94 #endif // !WIN32