833682c8476cd20817bfe181d1dafc255db75b13
[open-adventure.git] / notes.adoc
1 = Open Adventure Maintainer's Notes =
2 by Eric S. Raymond
3 // SPDX-FileCopyrightText: (C) Eric S. Raymond <esr@thyrsus.com>
4 // SPDX-License-Identifier: CC-BY-4.0
5
6 In which we explain what has been done to this code since Don Woods
7 authorized us to ship it under an open-source license.  There's a
8 separate link:history.html[history] describing how it came to us.
9
10 == Who we are ==
11
12 The principal maintainers of this code are Eric S. Raymond and Jason
13 Ninneman.  Eric received Don Woods's encouragement to update and ship
14 the game; Jason signed on early in the process to help. The assistance
15 of Peje Nilsson in restructuring some particularly grotty gotos is
16 gratefully acknowledged. Petr Voropaev contributed fuzz testing and
17 code cleanups. Aaron Traas did a lot of painstaking work to improve
18 test coverage, and factored out the last handful of gotos.  Ryan
19 Sarson nudged us into fixing a longstannding minor bug in the
20 handling of incorrect magic-word sequebcesm, 
21
22 == Nomenclature ==
23
24 This project is called "Open Adventure" because it's not at all clear
25 to number Adventure past 2.5 without misleading or causing
26 collisions. Various of the non-mainline versions have claimed to be
27 versions 3, 4, 5, 6, 7 and for all I know higher than that.  It seems
28 best just to start a new numbering series while acknowledging the
29 links back.
30
31 We have reverted to "advent" for the binary to avoid a name collision
32 with the BSD Games version.
33
34 == Philosophy ==
35
36 Extreme care has been taken not to make changes that would alter the
37 logic of the game as we received it from Don Woods, except to fix
38 glitches that were clearly bugs.  By policy, all user-visible
39 changes to gameplay must be revertible with the -o (oldstyle) option.
40
41 It is a goal of this project to exactly preserve the *intended
42 behavior* of 430-point Adventure, but the implementation of it is fair
43 game for improvement. In particular, we are concerned to move it to a
44 form that is (a) readable, and (b) friendly to forward translation to
45 future languages.  It has already survived a move from FORTRAN to C; a
46 future as a Python or Go translation seems possible, even probable.
47
48 Compatibility with the 2.5 source we found has been checked by
49 building a version patched minimally to support the seed command and
50 running it against the entire test suite, which has 100% code
51 coverage.
52
53 == Functional changes ==
54
55 Bug fixes:
56
57 * The caged bird used to be counted as two items in your inventory.
58
59 * Reading the relocated Witt's End sign in the endgame didn't work right.
60
61 * Oyster was readable after first gotten even when not carried.
62
63 * Response to an attempt to unlock the oyster while carrying it was incorrect. 
64
65 * Behavior when saying the giant's magic words before having seen them
66   wasn't quite correct - the game responded as though the player had
67   already read them ("...can't you read?"). The new message is "Well,
68   that was remarkably pointless!"  The -o option reverts this change.
69
70 * Attempting to extinguish an unlit urn caused it to lose its oil.
71
72 * "A crystal bridge now spans the fissure." (progressive present) was
73   incorrect most places it appeared and has been replaced by "A crystal 
74   bridge spans the fissure." (timeless present).
75
76 * A few minor typos have been corrected: absence of capitalization on
77   "Swiss" and "Persian", inconsistent spelling of "imbedded" vs. "embedded",
78   "eying" for "eyeing", "thresholds" for "threshholds".
79
80 * Under odd circumstances (dropping rug or vase outdoors) the game could
81   formerly say "floor" when it should say "ground" (or "dirt", or
82   something).
83
84 * The "knives vanish" message could formerly be emitted when "I see no
85   knife here." would be appropriate.
86
87 Enhancements:
88
89 By default, advent issues "> " as a command prompt.  This feature
90 became common in many variants after the original 350-point version,
91 but was never backported into Crowther & Woods's main line before now.
92 The "-o" (oldstyle) option reverts the behavior.
93
94 There is a set of standard one-letter command aliases conventional in modern
95 text adventure games; 'l' and 'x'; for 'look' (or 'examine'), 'z' to do nothing
96 for a turn, 'i' for 'inventory', 'g' for 'get', and 'd' for 'drop'.  The 'd'
97 alias collides with 'd' for 'down', but the others have been implemented.
98 The "-o" (oldstyle) option disables them.
99
100 Unrecognized words are no longer truncated to 5 characters and
101 uppercased when they are echoed. The "-o" (oldstyle) option restores
102 this behavior.
103
104 A "seed" command has been added.  This is not intended for human use
105 but as a way for game logs to set the PRNG (pseudorandom-number generator) so
106 that random events (dwarf & pirate appearances, the bird's magic word)
107 will be reproducible.
108
109 A "version" command has been added. This has no effect on gameplay.
110
111 The text displayed by the "news" command has been updated.
112
113 A -l command-line option has been added. When this is given (with a
114 file path argument) each command entered will be logged to the
115 specified file.  Additionally, a generated "seed" command will be put
116 early in the file capturing the randomized start state of the PRNG
117 so that replays of the log will be reproducible.
118
119 Using "seed" and -l, the distribution now includes a regression-test
120 suite for the game.  Any log captured with -l (and thus containing
121 a "seed" command) will replay reliably, including random events.
122
123 The adventure.text file is no longer required at runtime.  Instead, an
124 adventure.yaml file is compiled at build time to a source module
125 containing C structures, which is then linked to the advent
126 binary.  The YAML is drastically easier to read and edit than
127 the old ad-hoc format of adventure.txt.
128
129 The game-save format has changed.  This was done to simplify the
130 FORTRAN-derived code that formerly implemented the save/restore
131 functions; without C's fread(3)/fwrite() and structs it was
132 necessarily pretty ugly by modern standards. Encryption and
133 checksumming have been discarded - it's pointless to try
134 tamper-proofing saves when everyone has the source code. However
135 the game still integrity-checks savefiles on resume, including an
136 abort if the endianness of the restoring machine does not match that of
137 the saving machine.  There is a magic-cookie header on the saves so
138 in theory they could be identified by programs like file(1).
139
140 Save and resume filenames are stripped of leading and trailing
141 whitespace before processing.
142
143 A -r command-line option has been added. When it is given (with a file
144 path argument) it is functionally equivalent to a RESTORE command.
145
146 An -a command-line option has been added (conditionally on
147 ADVENT_AUTOSAVE) for use in BBS door systems.  When this option is
148 given, the game roads from the specified filename argument on startup
149 and saves to it on quit or a received signal. There is a new nmessage
150 to inform the user about this.
151
152 The game can be built in a mode that entirely disables save/resume
153 (-DADVENT_NOSAVE). If the game had been built this way, a diagnostic is
154 emitted if you try to save or resume.
155
156 == Translation ==
157
158 The 2.5 code was a mechanical C translation of a FORTRAN original.
159 There were gotos everywhere and the code was, though functional,
160 ugly and quite unreadable.
161
162 Jason Ninneman and I have moved it to what is almost, but not quite,
163 idiomatic modern C.  We refactored the right way, checking correctness
164 against a comprehensive test suite that we built first and verified
165 with coverage tools (there is effectively 100% code coverage). This is
166 what you are running when you do "make check".
167
168 The move to modern C entailed some structural changes.  The most
169 important was the refactoring of over 350 gotos into if/loop/break
170 structures.  We also abolished almost all shared globals; the main one
171 left is a struct holding the game's saveable/restorable state.
172
173 The original code was greatly complicated by a kind of bit-packing
174 that was performed because the FORTRAN it was written in had no string
175 type.  Text from the adventure.text file was compiled into sequences
176 of sixbit code points in a restricted character set, packed 5 to a
177 32-bit word (and it seems clear from the code that words were originally
178 *6* chars each packed into a PDP-10 36-bit word).  A command noun or
179 verb was one of these words, and what would be string operations in a
180 more recent language were all done on sequences of these words.
181
182 We have removed all this bit-packing cruft in favor of proper C
183 strings.  C strings may be a weak and leaky abstraction, but this is
184 one of the rare cases in which they are an obvious improvement over
185 what they're displacing...
186
187 We have also conducted extensive fuzz testing on the game using
188 afl (American Fuzzy Lop).  We've found and fixed some crashers in
189 our new code (which occasionally uses malloc(3)), but none as yet
190 in Don's old code (which didn't).
191
192 After version 1.11, correctness was carefully checked against the
193 behavior of a binary from before the big refactoring.
194
195 The code falls short of being fully modern C in the following
196 ways:
197
198 * We have not attempted to translate the old code to pointer-based
199   idioms (as opposed, in particular, to integer-based array indexing).
200   We don't need whatever minor performance gains this might collect,
201   and the choice to refrain will make forward translation into future
202   languages easier.
203
204 * Linked lists (for objects at a location) are implemented using an array
205   of link indices. This is a surviving FORTRANism that is quite unlike
206   normal practice in C or any more modern language.  We have not tried
207   to fix it because doing so would (a) be quite difficult, and (b)
208   compromise forward-portability to other languages.
209
210 * Much of the code still assumes one-origin array indexing.  Thus,
211   arrays are a cell larger than they strictly need to be and cell 0 is
212   unused.
213
214 We have made exactly one minor architectural change.  In addition to the
215 old code's per-object state-description messages, we now have a per-object
216 message series for state *changes*.  This makes it possible to pull a fair
217 amount of text out of the arbitrary-messages list and associate those
218 messages with the objects that conceptually own them.
219
220 == Development status ==
221
222 We consider this project finished. All issues and TODOs have been
223 cleared, behavior has been carefully checked against original ADVENT,
224 no future demand for new features is expected, and the test suite has
225 100% code coverage.  If new bugs appear as the toolchain bit-rots out
226 from under underneath, we will fix those problems.
227
228 // end