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