projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Magic-number elimination.
[open-adventure.git]
/
main.c
diff --git
a/main.c
b/main.c
index 94f2b45b9fe30d5c2251e9d9b431cee7af9c028e..80689e3f5c14f314fdd04c0b3dd4d51e1c1bdd8b 100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-1,7
+1,7
@@
/*
/*
- *
Copyright (c)
1977, 2005 by Will Crowther and Don Woods
- *
Copyright (c)
2017 by Eric S. Raymond
- * SPDX-License-Identifier: BSD-2-
c
lause
+ *
SPDX-FileCopyrightText:
1977, 2005 by Will Crowther and Don Woods
+ *
SPDX-FileCopyrightText:
2017 by Eric S. Raymond
+ * SPDX-License-Identifier: BSD-2-
C
lause
*/
#include <stdlib.h>
*/
#include <stdlib.h>
@@
-55,8
+55,13
@@
char *myreadline(const char *prompt)
* logfiles for testing purposes.
*/
/* Normal case - no script arguments */
* logfiles for testing purposes.
*/
/* Normal case - no script arguments */
- if (settings.argc == 0)
- return readline(prompt);
+ if (settings.argc == 0) {
+ char *ln = readline(prompt);
+ if (ln == NULL) {
+ fputs(prompt, stdout);
+ }
+ return ln;
+ }
char *buf = malloc(LINESIZE + 1);
for (;;) {
char *buf = malloc(LINESIZE + 1);
for (;;) {
@@
-82,9
+87,9
@@
char *myreadline(const char *prompt)
} else {
char *ln = fgets(buf, LINESIZE, settings.scriptfp);
if (ln != NULL) {
} else {
char *ln = fgets(buf, LINESIZE, settings.scriptfp);
if (ln != NULL) {
-
fputs(PROMPT
, stdout);
+
fputs(prompt
, stdout);
fputs(ln, stdout);
fputs(ln, stdout);
-
return ln;
+ return ln;
}
}
}
}
}
}
@@
-458,8
+463,7
@@
static void describe_location(void)
{
const char* msg = locations[game.loc].description.small;
{
const char* msg = locations[game.loc].description.small;
- if (MOD(game.abbrev[game.loc], game.abbnum) == 0 ||
- msg == NO_MESSAGE)
+ if (MOD(game.abbrev[game.loc], game.abbnum) == 0 || msg == NO_MESSAGE)
msg = locations[game.loc].description.big;
if (!FORCED(game.loc) && DARK(game.loc)) {
msg = locations[game.loc].description.big;
if (!FORCED(game.loc) && DARK(game.loc)) {
@@
-930,6
+934,8
@@
static void listobjects(void)
game.prop[RUG] = RUG_DRAGON;
if (obj == CHAIN)
game.prop[CHAIN] = CHAINING_BEAR;
game.prop[RUG] = RUG_DRAGON;
if (obj == CHAIN)
game.prop[CHAIN] = CHAINING_BEAR;
+ if (obj == EGGS)
+ game.seenbigwords = true;
--game.tally;
/* Note: There used to be a test here to see whether the
* player had blown it so badly that he could never ever see
--game.tally;
/* Note: There used to be a test here to see whether the
* player had blown it so badly that he could never ever see
@@
-1064,7
+1070,7
@@
static bool do_move(void)
/* The easiest way to get killed is to fall into a pit in
* pitch darkness. */
/* The easiest way to get killed is to fall into a pit in
* pitch darkness. */
- if (!FORCED(game.loc) && DARK(game.loc) && game.wzdark && PCT(
35)) { // FIXME: magic number
+ if (!FORCED(game.loc) && DARK(game.loc) && game.wzdark && PCT(
PIT_KILL_PROB)) {
rspeak(PIT_FALL);
game.oldlc2 = game.loc;
croak();
rspeak(PIT_FALL);
game.oldlc2 = game.loc;
croak();
@@
-1074,7
+1080,7
@@
static bool do_move(void)
return true;
}
return true;
}
-static bool do_command()
+static bool do_command(
void
)
/* Get and execute a command */
{
static command_t command;
/* Get and execute a command */
{
static command_t command;
@@
-1125,6
+1131,12
@@
static bool do_command()
if (!get_command_input(&command))
return false;
if (!get_command_input(&command))
return false;
+ /* Every input, check "foobar" flag. If zero, nothing's going
+ * on. If pos, make neg. If neg, he skipped a word, so make it
+ * zero.
+ */
+ game.foobar = (game.foobar > WORD_EMPTY) ? -game.foobar : WORD_EMPTY;
+
++game.turns;
preprocess_command(&command);
}
++game.turns;
preprocess_command(&command);
}
@@
-1250,20
+1262,23
@@
int main(int argc, char *argv[])
/* Options. */
#if defined ADVENT_AUTOSAVE
/* Options. */
#if defined ADVENT_AUTOSAVE
- const char* opts = "l:oa:";
+ const char* opts = "
d
l:oa:";
const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n";
FILE *rfp = NULL;
const char* autosave_filename = NULL;
#elif !defined ADVENT_NOSAVE
const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n";
FILE *rfp = NULL;
const char* autosave_filename = NULL;
#elif !defined ADVENT_NOSAVE
- const char* opts = "l:or:";
+ const char* opts = "
d
l:or:";
const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n";
FILE *rfp = NULL;
#else
const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n";
FILE *rfp = NULL;
#else
- const char* opts = "l:o";
+ const char* opts = "
d
l:o";
const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n";
#endif
while ((ch = getopt(argc, argv, opts)) != EOF) {
switch (ch) {
const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n";
#endif
while ((ch = getopt(argc, argv, opts)) != EOF) {
switch (ch) {
+ case 'd': // LCOV_EXCL_LINE
+ settings.debug +=1; // LCOV_EXCL_LINE
+ break; // LCOV_EXCL_LINE
case 'l':
settings.logfp = fopen(optarg, "w");
if (settings.logfp == NULL)
case 'l':
settings.logfp = fopen(optarg, "w");
if (settings.logfp == NULL)