JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
We now limit how far ahead you can get. This is measured in screen
[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 int opt_friction;
10
11 // Look and Feel
12 int opt_fullscreen;
13 int opt_music;
14 int opt_sound;
15 int opt_tail_engine;
16
17 error_t parse_opt(int, char*, struct argp_state *);
18
19 const char *argp_program_version = "Variations on Rockdodger " VERSION;
20 const char *argp_program_bug_address = "<josh@qualdan.com>";
21 static char doc[] = "Dodge the rocks until you die.";
22 static struct argp_option opts[] = {
23         {0, 0, 0, 0, "Gameplay Variations:"},
24         {"bounciness", 'b', "N%", 0, "Keep N% of speed when hitting edges (default 50%)"},
25         {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"},
26         {"max-lead", 'l', "#SCREENS", 0, "Max dist. ahead you can get (default 1 screen)\n(negative value means no limit)"},
27         {"bad-physics", 'p', 0, 0, "Bad physics (i.e. friction)"},
28         {0, 0, 0, 0, "Look and Feel:"},
29         {"engine", 'e', 0, 0, "Display large tail plume"},
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 void
40 init_opts(void)
41 {
42         // Gameplay Variations
43         opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
44         opt_gamespeed = 1.00; // Run game at full speed.
45         opt_max_lead = 1.00*XSIZE;  // you can get 1 screen ahead.
46         opt_friction = 0;
47
48         // Look and Feel
49         opt_fullscreen = 0;
50         opt_sound = 1;
51         opt_music = 0;
52         opt_tail_engine = 0;
53 }
54
55 error_t
56 parse_opt(int key, char *arg, struct argp_state *state)
57 {
58         int i;
59
60         switch(key) {
61                 case 'b': if(!sscanf(arg, "%d%%", &i)) {
62                                           argp_error(state, "bad --bounciness (-b) value (should be 0-100%%)");
63                                           return EINVAL;
64                                   }
65                                   if(i < 50) i = 50; else if(i > 100) i = 100;
66                                   opt_bounciness = (float)i / 100;
67                                   break;
68                 case 'e': opt_tail_engine = 1; break;
69                 case 'f': opt_fullscreen = 1; break;
70                 case 'g': if(!sscanf(arg, "%d%%", &i)) {
71                                           argp_error(state, "bad --gamespeed (-g) value (should be 50-100%%)");
72                                           return EINVAL;
73                                   }
74                                   if(i < 0) i = 0; else if(i > 100) i = 100;
75                                   opt_gamespeed = (float)i / 100;
76                                   break;
77                 case 'l': if(!sscanf(arg, "%f", &opt_max_lead)) {
78                                           argp_error(state, "bad --max-limit (-l) value (must be a number)");
79                                           return EINVAL;
80                                   }
81                                   opt_max_lead *= XSIZE;
82                                   break;
83                 case 'm': opt_music = 1; break;
84                 case 'p': opt_friction = 1; break;
85                 case 's': opt_sound = 0; opt_music = 0; break;
86                 default: break;
87         }
88         return 0;
89 }