/*
* src/sysarg.c
*
* Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
*
* The use and distribution terms for this software are contained in the file
* named README, which can be found in the root of this distribution. By
* using this software in any fashion, you are agreeing to be bound by the
* terms of this license.
*
* You must not remove this notice, or any other, from this software.
*/
/*
* 20021010 added test to prevent buffer overrun in -keys parsing.
*/
#include <stdlib.h> // atoi
#include <string.h> // strcmp
#include <SDL.h>
#include "system.h"
#include "game.h"
#include "maps.h"
#include "syssnd.h"
int sysarg_args_period = 0;
int sysarg_args_map = 0;
int sysarg_args_submap = 0;
int sysarg_args_score = 0;
int sysarg_args_nosound = 0;
int sysarg_args_vol = 0;
extern U8 want_infinitelives;
extern U8 want_fullscreen;
extern U8 want_filter;
extern U8 enable_endkey;
/*
* Fail
*/
void sysarg_fail (char *msg)
{
sys_printf ("Rick Dangerous: %s\n"
"usage: Rick Dangerous [<options>]\n"
"options:\n"
" -h, --help : Display this information.\n"
" -f, --fullscreen : Start fullscreen.\n"
" -episode <1-4> : Start directly at the first map of the specified episode.\n"
" -map <1-47> : Start directly at the specified map.\n"
" -score <N> : Start directly with score N.\n"
" -s <0-99>, --speed <0-99> : Set the game speed to a given value.\n"
" -vol <0-10> : Set the sound volume to a given value.\n"
" -n, --nosound : Disable sound completely.\n"
" -x, --togglefilter : Start with xBRZ filter disabled (F7 to enable).\n"
" -i, --infinitelives : Enable infinite lives.\n"
" -e, --noendkey : Disable END key.\n",
msg);
}
/*
* Read and process arguments
*/
void sysarg_init (int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++)
{
sysarg_fail ("help");
else if (!strcmp(argv
[i
], "-f") || !strcmp(argv
[i
], "--fullscreen"))
want_fullscreen = TRUE;
else if (!strcmp(argv
[i
], "-episode"))
{
if (++i == argc)
sysarg_fail ("missing episode number");
sysarg_args_map
= atoi(argv
[i
]) - 1;
if (sysarg_args_map < 0 || sysarg_args_map >= MAP_NBR_MAPS-1)
sysarg_fail ("invalid episode number");
}
else if (!strcmp(argv
[i
], "-map"))
{
if (++i == argc)
sysarg_fail ("missing submap number");
sysarg_args_submap
= atoi(argv
[i
]) - 1;
if (sysarg_args_submap < 0 || sysarg_args_submap >= MAP_NBR_SUBMAPS)
sysarg_fail ("invalid submap number");
}
// Pierre-Marie Baty -- addition: start score
else if (!strcmp(argv
[i
], "-score"))
{
if (++i == argc)
sysarg_fail ("missing start score number");
sysarg_args_score
= atoi(argv
[i
]) - 1;
}
else if (!strcmp(argv
[i
], "-s") || !strcmp(argv
[i
], "--speed"))
{
if (++i == argc)
sysarg_fail ("missing speed value");
sysarg_args_period
= atoi(argv
[i
]) - 1;
if (sysarg_args_period < 0 || sysarg_args_period > 99)
sysarg_fail ("invalid speed value");
}
else if (!strcmp(argv
[i
], "-vol"))
{
if (++i == argc)
sysarg_fail ("missing volume");
sysarg_args_vol
= atoi(argv
[i
]) - 1;
if (sysarg_args_vol < 0 || sysarg_args_vol >= SYSSND_MAXVOL)
sysarg_fail ("invalid volume");
}
else if (!strcmp(argv
[i
], "-n") || !strcmp(argv
[i
], "--nosound"))
sysarg_args_nosound = 1;
else if (!strcmp(argv
[i
], "-x") || !strcmp(argv
[i
], "--togglefilter"))
want_filter = FALSE;
else if (!strcmp(argv
[i
], "-i") || !strcmp(argv
[i
], "--infinitelives"))
want_infinitelives = TRUE;
else if (!strcmp(argv
[i
], "-e") || !strcmp(argv
[i
], "--disableendkey"))
enable_endkey = FALSE;
else
sysarg_fail ("invalid argument(s)");
}
// this is dirty (sort of)
if (sysarg_args_submap >= 0 && sysarg_args_submap < 9)
sysarg_args_map = 0;
if (sysarg_args_submap >= 9 && sysarg_args_submap < 20)
sysarg_args_map = 1;
if (sysarg_args_submap >= 20 && sysarg_args_submap < 38)
sysarg_args_map = 2;
if (sysarg_args_submap >= 38)
sysarg_args_map = 3;
if (sysarg_args_submap == 9 || sysarg_args_submap == 20 || sysarg_args_submap == 38)
sysarg_args_submap = 0;
//if (sysarg_args_submap == 18)
// sysarg_args_submap = 19;
}