Rev 9 | Go to most recent revision | Details | 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; |
||
| 32 | int sysarg_args_nosound = 0; |
||
| 33 | int sysarg_args_vol = 0; |
||
| 34 | |||
| 35 | |||
| 36 | extern U8 want_infinitelives; |
||
| 37 | |||
| 38 | |||
| 39 | /* |
||
| 40 | * Fail |
||
| 41 | */ |
||
| 42 | void sysarg_fail (char *msg) |
||
| 43 | { |
||
| 44 | sys_printf ("Rick Dangerous: %s\n" |
||
| 45 | "usage: Rick Dangerous [<options>]\n" |
||
| 46 | "options:\n" |
||
| 47 | " -h, --help : Display this information.\n" |
||
| 48 | " -episode <1-4> : Start directly at the first map of the specified episode.\n" |
||
| 49 | " -map <1-47> : Start directly at the specified map.\n" |
||
| 50 | " -s <0-99>, --speed <0-99> : Set the game speed to a given value.\n" |
||
| 51 | " -vol <0-10> : Set the sound volume to a given value.\n" |
||
| 52 | " -n, --nosound : Disable sound completely.\n" |
||
| 53 | " -i, --infinitelives : Enable infinite lives.\n", |
||
| 54 | msg); |
||
| 55 | exit (1); |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | /* |
||
| 60 | * Read and process arguments |
||
| 61 | */ |
||
| 62 | void sysarg_init (int argc, char **argv) |
||
| 63 | { |
||
| 64 | int i; |
||
| 65 | |||
| 66 | for (i = 1; i < argc; i++) |
||
| 67 | { |
||
| 68 | if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) |
||
| 69 | sysarg_fail ("help"); |
||
| 70 | |||
| 71 | else if (!strcmp(argv[i], "-episode")) |
||
| 72 | { |
||
| 73 | if (++i == argc) |
||
| 74 | sysarg_fail ("missing episode number"); |
||
| 75 | sysarg_args_map = atoi(argv[i]) - 1; |
||
| 76 | if (sysarg_args_map < 0 || sysarg_args_map >= MAP_NBR_MAPS-1) |
||
| 77 | sysarg_fail ("invalid episode number"); |
||
| 78 | } |
||
| 79 | |||
| 80 | else if (!strcmp(argv[i], "-map")) |
||
| 81 | { |
||
| 82 | if (++i == argc) |
||
| 83 | sysarg_fail ("missing submap number"); |
||
| 84 | sysarg_args_submap = atoi(argv[i]) - 1; |
||
| 85 | if (sysarg_args_submap < 0 || sysarg_args_submap >= MAP_NBR_SUBMAPS) |
||
| 86 | sysarg_fail ("invalid submap number"); |
||
| 87 | } |
||
| 88 | |||
| 89 | else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--speed")) |
||
| 90 | { |
||
| 91 | if (++i == argc) |
||
| 92 | sysarg_fail ("missing speed value"); |
||
| 93 | sysarg_args_period = atoi(argv[i]) - 1; |
||
| 94 | if (sysarg_args_period < 0 || sysarg_args_period > 99) |
||
| 95 | sysarg_fail ("invalid speed value"); |
||
| 96 | } |
||
| 97 | |||
| 98 | else if (!strcmp(argv[i], "-vol")) |
||
| 99 | { |
||
| 100 | if (++i == argc) |
||
| 101 | sysarg_fail ("missing volume"); |
||
| 102 | sysarg_args_vol = atoi(argv[i]) - 1; |
||
| 103 | if (sysarg_args_submap < 0 || sysarg_args_submap >= SYSSND_MAXVOL) |
||
| 104 | sysarg_fail ("invalid volume"); |
||
| 105 | } |
||
| 106 | |||
| 107 | else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--nosound")) |
||
| 108 | sysarg_args_nosound = 1; |
||
| 109 | |||
| 110 | else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--infinitelives")) |
||
| 111 | want_infinitelives = TRUE; |
||
| 112 | |||
| 113 | else |
||
| 114 | sysarg_fail ("invalid argument(s)"); |
||
| 115 | } |
||
| 116 | |||
| 117 | // this is dirty (sort of) |
||
| 118 | if (sysarg_args_submap >= 0 && sysarg_args_submap < 9) |
||
| 119 | sysarg_args_map = 0; |
||
| 120 | if (sysarg_args_submap >= 9 && sysarg_args_submap < 20) |
||
| 121 | sysarg_args_map = 1; |
||
| 122 | if (sysarg_args_submap >= 20 && sysarg_args_submap < 38) |
||
| 123 | sysarg_args_map = 2; |
||
| 124 | if (sysarg_args_submap >= 38) |
||
| 125 | sysarg_args_map = 3; |
||
| 126 | |||
| 127 | if (sysarg_args_submap == 9 || sysarg_args_submap == 20 || sysarg_args_submap == 38) |
||
| 128 | sysarg_args_submap = 0; |
||
| 129 | if (sysarg_args_submap == 18) |
||
| 130 | sysarg_args_submap = 19; |
||
| 131 | } |