Skip to content

Commit

Permalink
Implement '--start-pos' option.
Browse files Browse the repository at this point in the history
  • Loading branch information
oitofelix committed Feb 26, 2016
1 parent 133f905 commit 96ff41e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
11 changes: 11 additions & 0 deletions doc/mininim.texi
Expand Up @@ -133,6 +133,7 @@ fact that it's a really cool palindrome!}
@chapter Constructions
@cindex constructions

@cindex position
@cindex room
@cindex floor
@cindex place
Expand Down Expand Up @@ -1955,6 +1956,16 @@ The default is @samp{LEGACY}.
Make the kid start at level @var{n}. The default is @samp{1}. Valid
integers range from @samp{1} to @code{INT_MAX}. This can be changed
in-game by the @kbd{SHIFT+L} key binding.

@optindex --start-pos
@cindex position, option
@cindex option position
@item --start-pos=R,F,P
Make the kid start at room @var{r}, floor @var{f} and place @var{p}.
The default is to let this decision to the level module. @var{r} is an
integer ranging from 1 to @code{INT_MAX}, @var{f} is an integer ranging
from 0 to 2 and @var{p} is an integer ranging from 0 to 9.
@xref{Constructions}.
@end table

@cindex @file{LEVELS.DAT}
Expand Down
2 changes: 2 additions & 0 deletions doc/release/latest-news.texi
Expand Up @@ -30,6 +30,8 @@ the option @option{--legacy-level=PLV}.
@item Command line compatibility for the sake of applications
which use it.
@item @file{LEVELS.DAT} legacy loading behavior compatibility.
@item Kid start position can be specified using the
@option{--start-pos} option.
@item Disable screensaver by default.
@item Guards have infallible defense in refraction periods.
@item @strong{Bug fix:} spurious wall collision occurs in kid's
Expand Down
8 changes: 7 additions & 1 deletion src/levels/consistency-level.c
Expand Up @@ -34,7 +34,13 @@ play_consistency_level (int number)
static void
start (void)
{
struct pos p = {1,0,0};
struct pos p;
if ((start_pos.room != 0
|| start_pos.floor != 0
|| start_pos.place != 0)
&& start_pos.room <= LROOMS)
p = start_pos;
else p = (struct pos) {1,0,0};
create_anim (NULL, KID, &p, RIGHT);
create_anim (&anima[0], 0, NULL, 0);
anima[0].controllable = true;
Expand Down
9 changes: 8 additions & 1 deletion src/levels/legacy-level.c
Expand Up @@ -80,7 +80,14 @@ start (void)
else auto_rem_time_1st_cycle = 24;

/* create kid */
int id = create_anim (NULL, KID, &level.start_pos, level.start_dir);
struct pos kid_start_pos;
if ((start_pos.room != 0
|| start_pos.floor != 0
|| start_pos.place != 0)
&& start_pos.room <= LROOMS)
kid_start_pos = start_pos;
else kid_start_pos = level.start_pos;
int id = create_anim (NULL, KID, &kid_start_pos, level.start_dir);
struct anim *k = &anima[id];
k->total_lives = total_lives;
k->skill = skill;
Expand Down
18 changes: 16 additions & 2 deletions src/mininim.c
Expand Up @@ -63,6 +63,7 @@ bool immortal_mode;
int initial_total_lives = KID_INITIAL_TOTAL_LIVES, total_lives;
int initial_current_lives = KID_INITIAL_CURRENT_LIVES, current_lives;
int start_level = 1;
struct pos start_pos;
int time_limit = TIME_LIMIT;
int start_time = START_TIME;
struct skill skill = {.counter_attack_prob = INITIAL_KCA,
Expand Down Expand Up @@ -96,6 +97,7 @@ enum options {
LOAD_CONFIG_OPTION, IGNORE_MAIN_CONFIG_OPTION, IGNORE_ENVIRONMENT_OPTION,
JOYSTICK_AXIS_THRESHOLD_OPTION, JOYSTICK_BUTTON_THRESHOLD_OPTION,
JOYSTICK_AXIS_OPTION, JOYSTICK_BUTTON_OPTION, JOYSTICK_INFO_OPTION,
START_POS_OPTION,
};

enum level_module {
Expand All @@ -120,7 +122,7 @@ static struct argp_option options[] = {
{NULL, 0, NULL, 0, "Level:", 0},
{"level-module", LEVEL_MODULE_OPTION, "LEVEL-MODULE", 0, "Select level module. A level module determines a way to generate consecutive levels for use by the engine. Valid values for LEVEL-MODULE are: LEGACY, PLV, DAT and CONSISTENCY. LEGACY is the module designed to read the original PoP 1 raw level files. PLV is the module designed to read the original PoP 1 PLV extended level files. DAT is the module designed to read the original PoP 1 LEVELS.DAT file. CONSISTENCY is the module designed to generate random-corrected levels for accessing the engine robustness. The default is LEGACY.", 0},
{"start-level", START_LEVEL_OPTION, "N", 0, "Make the kid start at level N. The default is 1. Valid integers range from 1 to INT_MAX. This can be changed in-game by the SHIFT+L key binding.", 0},

{"start-pos", START_POS_OPTION, "R,F,P", 0, "Make the kid start at room R, floor F and place P. The default is to let this decision to the level module. R is an integer ranging from 1 to INT_MAX, F is an integer ranging from 0 to 2 and P is an integer ranging from 0 to 9.", 0},
{NULL, 0, NULL, OPTION_DOC, "If the option '--level-module' is not given and there is a LEVELS.DAT file in the resources directory, the DAT level module is automatically used to load that file. This is a compatibility measure for applications which depend upon this legacy behavior.", 0},

/* Time */
Expand Down Expand Up @@ -540,7 +542,7 @@ parser (int key, char *arg, struct argp_state *state)
int x, y, i, e;
struct config_info config_info;
float float_val;
int int_val0, int_val1;
int int_val0, int_val1, int_val2;

char *level_module_enum[] = {"LEGACY", "PLV", "DAT", "CONSISTENCY", NULL};

Expand Down Expand Up @@ -569,6 +571,9 @@ parser (int key, char *arg, struct argp_state *state)

struct int_range total_lives_range = {1, 10};
struct int_range start_level_range = {1, INT_MAX};
struct int_range start_pos_room_range = {1, INT_MAX};
struct int_range start_pos_floor_range = {0, 2};
struct int_range start_pos_place_range = {0, 9};
struct int_range time_limit_range = {1, INT_MAX};
struct int_range start_time_range = {0, INT_MAX};
struct int_range kca_range = {0, 100};
Expand Down Expand Up @@ -701,6 +706,15 @@ parser (int key, char *arg, struct argp_state *state)
if (e) return e;
start_level = i;
break;
case START_POS_OPTION:
e = option_get_args (key, arg, state, ',', ARG_TYPE_INT, ARG_TYPE_INT, ARG_TYPE_INT, 0,
&int_val0, &int_val1, &int_val2,
&start_pos_room_range, &start_pos_floor_range, &start_pos_place_range);
if (e) return e;
start_pos.room = int_val0;
start_pos.floor = int_val1;
start_pos.place = int_val2;
break;
case TIME_LIMIT_OPTION:
e = optval_to_int (&i, key, arg, state, &time_limit_range, 0);
if (e) return e;
Expand Down
1 change: 1 addition & 0 deletions src/mininim.h
Expand Up @@ -173,6 +173,7 @@ extern bool immortal_mode;
extern int initial_total_lives, total_lives,
initial_current_lives, current_lives;
extern int start_level;
extern struct pos start_pos;
extern int time_limit;
extern struct skill skill;
extern char *resources_dir,
Expand Down

0 comments on commit 96ff41e

Please sign in to comment.