Rev 1 | Rev 10 | Go to most recent revision | 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 | |||
| 21 | #include <SDL.h> |
||
| 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; |
||
| 1 | pmbaty | 40 | |
| 41 | |||
| 42 | /* |
||
| 43 | * Fail |
||
| 44 | */ |
||
| 45 | void sysarg_fail (char *msg) |
||
| 46 | { |
||
| 47 | sys_printf ("Rick Dangerous: %s\n" |
||
| 48 | "usage: Rick Dangerous [<options>]\n" |
||
| 49 | "options:\n" |
||
| 50 | " -h, --help : Display this information.\n" |
||
| 9 | pmbaty | 51 | " -f, --fullscreen : Start fullscreen.\n" |
| 1 | pmbaty | 52 | " -episode <1-4> : Start directly at the first map of the specified episode.\n" |
| 53 | " -map <1-47> : Start directly at the specified map.\n" |
||
| 9 | pmbaty | 54 | " -score <N> : Start directly with score N.\n" |
| 1 | pmbaty | 55 | " -s <0-99>, --speed <0-99> : Set the game speed to a given value.\n" |
| 56 | " -vol <0-10> : Set the sound volume to a given value.\n" |
||
| 57 | " -n, --nosound : Disable sound completely.\n" |
||
| 9 | pmbaty | 58 | " -x, --togglefilter : Start with xBRZ filter disabled (F7 to enable).\n" |
| 1 | pmbaty | 59 | " -i, --infinitelives : Enable infinite lives.\n", |
| 60 | msg); |
||
| 61 | exit (1); |
||
| 62 | } |
||
| 63 | |||
| 64 | |||
| 65 | /* |
||
| 66 | * Read and process arguments |
||
| 67 | */ |
||
| 68 | void sysarg_init (int argc, char **argv) |
||
| 69 | { |
||
| 70 | int i; |
||
| 71 | |||
| 72 | for (i = 1; i < argc; i++) |
||
| 73 | { |
||
| 74 | if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) |
||
| 75 | sysarg_fail ("help"); |
||
| 76 | |||
| 9 | pmbaty | 77 | else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--fullscreen")) |
| 78 | want_fullscreen = TRUE; |
||
| 79 | |||
| 1 | pmbaty | 80 | else if (!strcmp(argv[i], "-episode")) |
| 81 | { |
||
| 82 | if (++i == argc) |
||
| 83 | sysarg_fail ("missing episode number"); |
||
| 84 | sysarg_args_map = atoi(argv[i]) - 1; |
||
| 85 | if (sysarg_args_map < 0 || sysarg_args_map >= MAP_NBR_MAPS-1) |
||
| 86 | sysarg_fail ("invalid episode number"); |
||
| 87 | } |
||
| 88 | |||
| 89 | else if (!strcmp(argv[i], "-map")) |
||
| 90 | { |
||
| 91 | if (++i == argc) |
||
| 92 | sysarg_fail ("missing submap number"); |
||
| 93 | sysarg_args_submap = atoi(argv[i]) - 1; |
||
| 94 | if (sysarg_args_submap < 0 || sysarg_args_submap >= MAP_NBR_SUBMAPS) |
||
| 95 | sysarg_fail ("invalid submap number"); |
||
| 96 | } |
||
| 97 | |||
| 9 | pmbaty | 98 | // Pierre-Marie Baty -- addition: start score |
| 99 | else if (!strcmp(argv[i], "-score")) |
||
| 100 | { |
||
| 101 | if (++i == argc) |
||
| 102 | sysarg_fail ("missing start score number"); |
||
| 103 | sysarg_args_score = atoi(argv[i]) - 1; |
||
| 104 | } |
||
| 105 | |||
| 1 | pmbaty | 106 | else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--speed")) |
| 107 | { |
||
| 108 | if (++i == argc) |
||
| 109 | sysarg_fail ("missing speed value"); |
||
| 110 | sysarg_args_period = atoi(argv[i]) - 1; |
||
| 111 | if (sysarg_args_period < 0 || sysarg_args_period > 99) |
||
| 112 | sysarg_fail ("invalid speed value"); |
||
| 113 | } |
||
| 114 | |||
| 115 | else if (!strcmp(argv[i], "-vol")) |
||
| 116 | { |
||
| 117 | if (++i == argc) |
||
| 118 | sysarg_fail ("missing volume"); |
||
| 119 | sysarg_args_vol = atoi(argv[i]) - 1; |
||
| 9 | pmbaty | 120 | if (sysarg_args_vol < 0 || sysarg_args_vol >= SYSSND_MAXVOL) |
| 1 | pmbaty | 121 | sysarg_fail ("invalid volume"); |
| 122 | } |
||
| 123 | |||
| 124 | else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--nosound")) |
||
| 125 | sysarg_args_nosound = 1; |
||
| 126 | |||
| 9 | pmbaty | 127 | else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--togglefilter")) |
| 128 | want_filter = FALSE; |
||
| 129 | |||
| 1 | pmbaty | 130 | else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--infinitelives")) |
| 131 | want_infinitelives = TRUE; |
||
| 132 | |||
| 133 | else |
||
| 134 | sysarg_fail ("invalid argument(s)"); |
||
| 135 | } |
||
| 136 | |||
| 137 | // this is dirty (sort of) |
||
| 138 | if (sysarg_args_submap >= 0 && sysarg_args_submap < 9) |
||
| 139 | sysarg_args_map = 0; |
||
| 140 | if (sysarg_args_submap >= 9 && sysarg_args_submap < 20) |
||
| 141 | sysarg_args_map = 1; |
||
| 142 | if (sysarg_args_submap >= 20 && sysarg_args_submap < 38) |
||
| 143 | sysarg_args_map = 2; |
||
| 144 | if (sysarg_args_submap >= 38) |
||
| 145 | sysarg_args_map = 3; |
||
| 146 | |||
| 147 | if (sysarg_args_submap == 9 || sysarg_args_submap == 20 || sysarg_args_submap == 38) |
||
| 148 | sysarg_args_submap = 0; |
||
| 9 | pmbaty | 149 | //if (sysarg_args_submap == 18) |
| 150 | // sysarg_args_submap = 19; |
||
| 1 | pmbaty | 151 | } |