Rev 10 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | /* |
| 2 | * src/sysarg.c |
||
| 3 | * |
||
| 4 | * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved. |
||
| 5 | * |
||
| 6 | * The use and distribution terms for this software are contained in the file |
||
| 7 | * named README, which can be found in the root of this distribution. By |
||
| 8 | * using this software in any fashion, you are agreeing to be bound by the |
||
| 9 | * terms of this license. |
||
| 10 | * |
||
| 11 | * You must not remove this notice, or any other, from this software. |
||
| 12 | */ |
||
| 13 | |||
| 14 | /* |
||
| 15 | * 20021010 added test to prevent buffer overrun in -keys parsing. |
||
| 16 | */ |
||
| 17 | |||
| 18 | #include <stdlib.h> // atoi |
||
| 19 | #include <string.h> // strcmp |
||
| 20 | |||
| 11 | pmbaty | 21 | #include <SDL2/SDL.h> |
| 1 | pmbaty | 22 | |
| 23 | #include "system.h" |
||
| 24 | #include "game.h" |
||
| 25 | |||
| 26 | #include "maps.h" |
||
| 27 | #include "syssnd.h" |
||
| 28 | |||
| 29 | int sysarg_args_period = 0; |
||
| 30 | int sysarg_args_map = 0; |
||
| 31 | int sysarg_args_submap = 0; |
||
| 9 | pmbaty | 32 | int sysarg_args_score = 0; |
| 1 | pmbaty | 33 | int sysarg_args_nosound = 0; |
| 34 | int sysarg_args_vol = 0; |
||
| 35 | |||
| 36 | |||
| 37 | extern U8 want_infinitelives; |
||
| 9 | pmbaty | 38 | extern U8 want_fullscreen; |
| 39 | extern U8 want_filter; |
||
| 10 | pmbaty | 40 | extern U8 enable_endkey; |
| 1 | pmbaty | 41 | |
| 42 | |||
| 43 | /* |
||
| 44 | * Fail |
||
| 45 | */ |
||
| 46 | void sysarg_fail (char *msg) |
||
| 47 | { |
||
| 48 | sys_printf ("Rick Dangerous: %s\n" |
||
| 49 | "usage: Rick Dangerous [<options>]\n" |
||
| 50 | "options:\n" |
||
| 51 | " -h, --help : Display this information.\n" |
||
| 9 | pmbaty | 52 | " -f, --fullscreen : Start fullscreen.\n" |
| 1 | pmbaty | 53 | " -episode <1-4> : Start directly at the first map of the specified episode.\n" |
| 54 | " -map <1-47> : Start directly at the specified map.\n" |
||
| 9 | pmbaty | 55 | " -score <N> : Start directly with score N.\n" |
| 1 | pmbaty | 56 | " -s <0-99>, --speed <0-99> : Set the game speed to a given value.\n" |
| 57 | " -vol <0-10> : Set the sound volume to a given value.\n" |
||
| 58 | " -n, --nosound : Disable sound completely.\n" |
||
| 9 | pmbaty | 59 | " -x, --togglefilter : Start with xBRZ filter disabled (F7 to enable).\n" |
| 10 | pmbaty | 60 | " -i, --infinitelives : Enable infinite lives.\n" |
| 61 | " -e, --noendkey : Disable END key.\n", |
||
| 1 | pmbaty | 62 | msg); |
| 63 | exit (1); |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /* |
||
| 68 | * Read and process arguments |
||
| 69 | */ |
||
| 70 | void sysarg_init (int argc, char **argv) |
||
| 71 | { |
||
| 72 | int i; |
||
| 73 | |||
| 74 | for (i = 1; i < argc; i++) |
||
| 75 | { |
||
| 76 | if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) |
||
| 77 | sysarg_fail ("help"); |
||
| 78 | |||
| 9 | pmbaty | 79 | else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--fullscreen")) |
| 80 | want_fullscreen = TRUE; |
||
| 81 | |||
| 1 | pmbaty | 82 | else if (!strcmp(argv[i], "-episode")) |
| 83 | { |
||
| 84 | if (++i == argc) |
||
| 85 | sysarg_fail ("missing episode number"); |
||
| 86 | sysarg_args_map = atoi(argv[i]) - 1; |
||
| 87 | if (sysarg_args_map < 0 || sysarg_args_map >= MAP_NBR_MAPS-1) |
||
| 88 | sysarg_fail ("invalid episode number"); |
||
| 89 | } |
||
| 90 | |||
| 91 | else if (!strcmp(argv[i], "-map")) |
||
| 92 | { |
||
| 93 | if (++i == argc) |
||
| 94 | sysarg_fail ("missing submap number"); |
||
| 95 | sysarg_args_submap = atoi(argv[i]) - 1; |
||
| 96 | if (sysarg_args_submap < 0 || sysarg_args_submap >= MAP_NBR_SUBMAPS) |
||
| 97 | sysarg_fail ("invalid submap number"); |
||
| 98 | } |
||
| 99 | |||
| 9 | pmbaty | 100 | // Pierre-Marie Baty -- addition: start score |
| 101 | else if (!strcmp(argv[i], "-score")) |
||
| 102 | { |
||
| 103 | if (++i == argc) |
||
| 104 | sysarg_fail ("missing start score number"); |
||
| 105 | sysarg_args_score = atoi(argv[i]) - 1; |
||
| 106 | } |
||
| 107 | |||
| 1 | pmbaty | 108 | else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--speed")) |
| 109 | { |
||
| 110 | if (++i == argc) |
||
| 111 | sysarg_fail ("missing speed value"); |
||
| 112 | sysarg_args_period = atoi(argv[i]) - 1; |
||
| 113 | if (sysarg_args_period < 0 || sysarg_args_period > 99) |
||
| 114 | sysarg_fail ("invalid speed value"); |
||
| 115 | } |
||
| 116 | |||
| 117 | else if (!strcmp(argv[i], "-vol")) |
||
| 118 | { |
||
| 119 | if (++i == argc) |
||
| 120 | sysarg_fail ("missing volume"); |
||
| 121 | sysarg_args_vol = atoi(argv[i]) - 1; |
||
| 9 | pmbaty | 122 | if (sysarg_args_vol < 0 || sysarg_args_vol >= SYSSND_MAXVOL) |
| 1 | pmbaty | 123 | sysarg_fail ("invalid volume"); |
| 124 | } |
||
| 125 | |||
| 126 | else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--nosound")) |
||
| 127 | sysarg_args_nosound = 1; |
||
| 128 | |||
| 9 | pmbaty | 129 | else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--togglefilter")) |
| 130 | want_filter = FALSE; |
||
| 131 | |||
| 1 | pmbaty | 132 | else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--infinitelives")) |
| 133 | want_infinitelives = TRUE; |
||
| 134 | |||
| 10 | pmbaty | 135 | else if (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--disableendkey")) |
| 136 | enable_endkey = FALSE; |
||
| 137 | |||
| 1 | pmbaty | 138 | else |
| 139 | sysarg_fail ("invalid argument(s)"); |
||
| 140 | } |
||
| 141 | |||
| 142 | // this is dirty (sort of) |
||
| 143 | if (sysarg_args_submap >= 0 && sysarg_args_submap < 9) |
||
| 144 | sysarg_args_map = 0; |
||
| 145 | if (sysarg_args_submap >= 9 && sysarg_args_submap < 20) |
||
| 146 | sysarg_args_map = 1; |
||
| 147 | if (sysarg_args_submap >= 20 && sysarg_args_submap < 38) |
||
| 148 | sysarg_args_map = 2; |
||
| 149 | if (sysarg_args_submap >= 38) |
||
| 150 | sysarg_args_map = 3; |
||
| 151 | |||
| 152 | if (sysarg_args_submap == 9 || sysarg_args_submap == 20 || sysarg_args_submap == 38) |
||
| 153 | sysarg_args_submap = 0; |
||
| 9 | pmbaty | 154 | //if (sysarg_args_submap == 18) |
| 155 | // sysarg_args_submap = 19; |
||
| 1 | pmbaty | 156 | } |