= Open Adventure Maintainer's Notes =
by Eric S. Raymond

In which we explain what has been done to this code since Don Woods
authorized us to ship it under an open-source license.  There's a
separate link:history.html[history] describing how it came to us.

== Who we are ==

The principal maintainers of this code are Eric S. Raymond and Jason
Ninneman.  Eric received Don Woods's encouragement to update and ship
the game; Jason signed on early in the process to help. The assistance
of Peje Nilsson in restructuring some particularly grotty gotos is
gratefully acknowledged. Petr Voropaev contributed fuzz testing and
code cleanups. Aaron Traas did a lot of painstaking work to improve
test coverage, and factored out the last handful of gotos.

== Nomenclature ==

This project is called "Open Adventure" because it's not at all clear
to number Adventure past 2.5 without misleading or causing
collisions. Various of the non-mainline versions have claimed to be
versions 3, 4, 5, 6, 7 and for all I know higher than that.  It seems
best just to start a new numbering series while acknowledging the
links back.

We have reverted to "advent" for the binary to avoid a name collision
with the BSD Games version.

== Philosophy ==

Extreme care has been taken not to make changes that would alter the
logic of the game as we received it from Don Woods, except to fix
glitches that were clearly bugs.  By policy, all user-visible
changes to gameplay must be revertible with the -o (oldstyle) option.

It is a goal of this project to exactly preserve the *intended
behavior* of 430-point Adventure, but the implementation of it is fair
game for improvement. In particular, we are concerned to move it to a
form that is (a) readable, and (b) friendly to forward translation to
future languages.  It has already survived a move from FORTRAN to C; a
future as a Python or Go translation seems possible, even probable.

== Functional changes ==

Bug fixes:

* The caged bird used to be counted as two items in your inventory.

* Reading the relocated Witt's End sign in the endgame didn't work right.

* Oyster was readable after first gotten even when not carried.

* Response to an attempt to unlock the oyster while carrying it was incorrect. 

* Behavior when saying the giant's magic words before having seen them wasn't
  quite correct - the game responded as though the player had already
  read them ("...can't you read?"). The new message is "Nothing happens."
  The -o option reverts this change.

* Attempting to extinguish an unlit urn caused it to lose its oil.

* "A crystal bridge now spans the fissure." (progressive present) was
  incorrect most places it appeared and has been replaced by "A crystal 
  bridge spans the fissure." (timeless present).

* A few minor typos have been corrected: absence of capitalization on
  "Swiss" and "Persian", inconsistent spelling of "imbedded" vs. "embedded",
  "eying" for "eyeing", "thresholds" for "threshholds".

* Under odd circumstances (dropping rug or vase outdoors) the game could
  formerly say "floor" when it should say "ground" (or "dirt", or something).

Enhancements:

By default, advent issues "> " as a command prompt.  This feature
became common in many variants after the original 350-point version,
but was never backported into Crowther & Woods's main line before now.
The "-o" (oldstyle) option reverts the behavior.

There is a set of standard one-letter command aliases conventional in modern
text adventure games; 'l' and 'x'; for 'look' (or 'examine'), 'z' to do nothing
for a turn, 'i' for 'inventory', 'g' for 'get', and 'd' for 'drop'.  The 'd'
alias collides with 'd' for 'down', but the others have been implemented.
The "-o" (oldstyle) option disables them.

Unrecognized words are no longer truncated to 5 characters and
uppercased when they are echoed. The "-o" (oldstyle) option restores
this behavior.

A "seed" command has been added.  This is not intended for human use
but as a way for game logs to set the PRNG (pseudorandom-number generator) so
that random events (dwarf & pirate appearances, the bird's magic word)
will be reproducible.

A "version" command has been added. This has no effect on gameplay.

The text displayed by the "news" command has been updated.

A -l command-line option has been added. When this is given (with a
file path argument) each command entered will be logged to the
specified file.  Additionally, a generated "seed" command will be put
early in the file capturing the randomized start state of the PRNG
so that replays of the log will be reproducible.

Using "seed" and -l, the distribution now includes a regression-test
suite for the game.  Any log captured with -l (and thus containing
a "seed" command) will replay reliably, including random events.

The adventure.text file is no longer required at runtime.  Instead, an
adventure.yaml file is compiled at build time to a source module
containing C structures, which is then linked to the advent
binary.  The YAML is drastically easier to read and edit than
the old ad-hoc format of adventure.txt.

The game-save format has changed.  This was done to simplify the
FORTRAN-derived code that formerly implemented the save/restore
functions; without C's fread(3)/fwrite() and structs it was
necessarily pretty ugly by modern standards. Encryption and
checksumming have been discarded - it's pointless to try
tamper-proofing saves when everyone has the source code. However
the game still integrity-checks savefiles on resume.

Save and resume filenames are stripped of leading and trailing
whitespace before processing.

A -r command-line option has been added. When it is given (with a file
path argument) it is functionally equivalent to a RESTORE command.

An -a command-line option has been added (comditionally on
ADVENT_AUTOSAVE) for use in BBS door systems.  When this option is
given, the game roads from the specified filename argument on startup
and saves to it on quit or a received signal. There is a new nmessage
to inform the user about this.

The game can be built in a mode that entirely disables save/resume
(-DADVENT_NOSAVE). If the game had been built this way, a diagnostic is
emitted if you try to save or resume.

== Translation ==

The 2.5 code was a mechanical C translation of a FORTRAN original.
There were gotos everywhere and the code was, though functional,
ugly and quite unreadable.

Jason Ninneman and I have moved it to what is almost, but not quite,
idiomatic modern C.  We refactored the right way, checking correctness
against a comprehensive test suite that we built first and verified
with coverage tools (there is effectively 100% code coverage). This is
what you are running when you do "make check".

The move to modern C entailed some structural changes.  The most
important was the refactoring of over 350 gotos into if/loop/break
structures.  We also abolished almost all shared globals; the main one
left is a struct holding the game's saveable/restorable state.

The original code was greatly complicated by a kind of bit-packing
that was performed because the FORTRAN it was written in had no string
type.  Text from the adventure.text file was compiled into sequences
of sixbit code points in a restricted character set, packed 5 to a
32-bit word (and it seems clear from the code that words were originally
*6* chars each packed into a PDP-10 36-bit word).  A command noun or
verb was one of these words, and what would be string operations in a
more recent language were all done on sequences of these words.

We have removed all this bit-packing cruft in favor of proper C
strings.  C strings may be a weak and leaky abstraction, but this is
one of the rare cases in which they are an obvious improvement over
what they're displacing...

We have also conducted extensive fuzz testing on the game using
afl (American Fuzzy Lop).  We've found and fixed some crashers in
our new code (which occasionally uses malloc(3)), but none as yet
in Don's old code (which didn't).

After version 1.11, correctness was carefully checked against the
behavior of a binary from before the big refactoring.

The code falls short of being fully modern C in the following
ways:

* We have not attempted to translate the old code to pointer-based
  idioms (as opposed, in particular, to integer-based array indexing).
  We don't need whatever minor performance gains this might collect,
  and the choice to refrain will make forward translation into future
  languages easier.

* Linked lists (for objects at a location) are implemented using an array
  of link indices. This is a surviving FORTRANism that is quite unlike
  normal practice in C or any more modern language.  We have not tried
  to fix it because doing so would (a) be quite difficult, and (b)
  compromise forward-portability to other languages.

* Much of the code still assumes one-origin array indexing.  Thus,
  arrays are a cell larger than they strictly need to be and cell 0 is
  unused.

We have made exactly one minor architectural change.  In addition to the
old code's per-object state-description messages, we now have a per-object
message series for state *changes*.  This makes it possible to pull a fair
amount of text out of the arbitrary-messages list and associate those
messages with the objects that conceptually own them.

== Development status ==

We consider this project finished. All issues and TODOs have been
cleared, behavior has been carefully checked against original ADVENT,
no future demand for new features is expected, and the test suite has
100% code coverage.  If new bugs appear the toolchain bit-rots out
from under underneath, we will fix those problems.

// end
