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