Commit 1fcceb43 authored by Chris R's avatar Chris R 👍

Fixed various bugs.

Specifically:

1. `make install` now creates an empty, world-readable scorefile.

2. Moving while confused was triggering an assertion failure by
   sometimes indexing past the array of allowed directions.

3. End-of-game codes were overlapping with monster IDs, resulting in
   some incorrect game endings.  In particular, getting killed by a
   Demon Prince would win the game.

4. Some code was still using the system `assert` rather than the
   internal one and these remained when building for production.  They
   also exit without first restoring the original TTY settings.
parent 3fa98067
......@@ -11,7 +11,7 @@
/* Death codes to pass to die. */
enum GAME_ENDING {
DD_DUMMY = MAXCREATURE + 1, // Ensure count doesn't overlap a creature
DD_DUMMY = NUM_MONSTERS + 1, // Ensure count doesn't overlap a creature
#define ENDING(id, name) id,
# include "game_endings.h"
......
......@@ -30,8 +30,10 @@ for d in Umaps Ufortune Uhelp Uintro Ujunkmail; do
chmod 664 "$LIBDIR/$d"
done
# Create the score directory
# Create the score directory and empty scorefile.
mkdir -p "$SCOREDIR"
touch "$SCOREDIR/Relarn-scoreboard" # TODO: derive this from sources
chmod a+rw "$SCOREDIR/Relarn-scoreboard"
# Create the executable directories and install the executable and
# launch script.
......
// This file is part of ReLarn; Copyright (C) 1986 - 2018; GPLv2; NO WARRANTY!
// See Copyright.txt, LICENSE.txt and AUTHORS.txt for terms.
#include <assert.h>
#include "internal_assert.h"
#include "display.h"
......@@ -393,7 +391,8 @@ moveplayer (DIRECTION dir, bool* success) {
}/* if */
if (UU.confuse && UU.level < rnd(30) && dir != DIR_STAY) {
dir=rund(9) + DIR_NORTH; /*if confused any dir*/
// If confused, any dir.
dir = rund(DIR_MAX - DIR_MIN_DIR) + DIR_MIN_DIR;
}/* if */
adjpoint(UU.x, UU.y, dir, &new_x, &new_y);
......@@ -446,7 +445,7 @@ statfor(int slot) {
struct Object obj;
if (slot < 0) return 0;
assert(slot < IVENSIZE);
ASSERT(slot < IVENSIZE);
obj = Invent[slot];
if (!obj.type) return 0; /* Probably not needed. */
......
#include "stringbuilder.h"
#include <assert.h>
#include <limits.h>
#include "internal_assert.h"
#include "util.h"
......@@ -34,8 +35,8 @@ sb_append(struct StringBuilder *sb, const char *text) {
sb->buffer = xrealloc(sb->buffer, sb->length + 1);
strcat(sb->buffer, text);
assert(sb->length == strlen(sb->buffer));
assert(sb->length < LONG_MAX);
ASSERT(sb->length == strlen(sb->buffer));
ASSERT(sb->length < LONG_MAX);
}
// Append a single char to 'sb'.
......@@ -51,7 +52,7 @@ sb_append_char(struct StringBuilder *sb, char c) {
// Free the builder, returning the alloc'd content.
char *
sb_str_and_free(struct StringBuilder *sb) {
assert(sb);
ASSERT(sb);
const char *str = sb->buffer;
free(sb);
......
......@@ -5,8 +5,6 @@
#include "internal_assert.h"
#include <assert.h>
/* Test if 'filename' is a file that exists and is readable. */
bool
......@@ -126,9 +124,9 @@ void
adjpoint(int x, int y, DIRECTION dir, int *outx, int *outy) {
static const int offx[] = { 0, 0, 0, 1, 0, -1, 1, -1, 1, -1 };
static const int offy[] = { 0, 0, -1, 0, 1, 0, -1, -1, 1, 1 };
assert(dir < sizeof(offx)/sizeof(offx[0]) && dir < sizeof(offy)/sizeof(offy[0]));
ASSERT(dir < sizeof(offx)/sizeof(offx[0]) && dir < sizeof(offy)/sizeof(offy[0]));
*outx = x + offx[dir];
*outy = y + offy[dir];
}// adjpoint
......
......@@ -26,6 +26,9 @@ typedef enum {
DIR_NORTHWEST = 7,
DIR_SOUTHEAST = 8,
DIR_SOUTHWEST = 9,
DIR_MIN_DIR = DIR_NORTH, // First dir. that's a real direction
DIR_MAX = DIR_SOUTHWEST, // Last dir. that's a real direction
} DIRECTION;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment