Ignore l g z i under oldstyle.

This commit is contained in:
Eric S. Raymond 2017-07-01 12:34:44 -04:00
parent 3c8482a613
commit 0d0b8df0a3
7 changed files with 56 additions and 19 deletions

5
NEWS
View file

@ -1,5 +1,10 @@
= Open Adventure project news =
Repository head:
Under oldstyle, new-school single-letter command synonyms are ignored.
Switched from linenoise to editline for new-style line input.
The -s option is no longer required to paste command input; it is removed.
1.1: 2017-06-29::
There is a 'version' command.
Include tests directory in generated tarball.

View file

@ -40,11 +40,10 @@ There have been no gameplay changes.
-l:: Log commands to specified file.
-s:: Suppress Emacs-like line editing and command history.
-r:: Restore game from specified file
-o:: Old-style. Restores original interface, no prompt or line editing.
Also ignores new-school one-letter commands l, x, g, z, i.
== BUGS ==

View file

@ -6,17 +6,12 @@
#
# We define a bunch of YAML structures:
#
# vocabulary: - This structure is unused, and will eventually be removed. -
# Almost all the words the game knows - one of them (the
# reservoir magic word) gets replaced with a randomly-generated
# cookie. For each word there is a type (motion, action, object,
# or special) and a numeric value. Multiple synonyms may have the
# same value.
#
# motions: Motion words, grouped into synonyms.
#
# motions: Motion words, grouped into synonyms. The 'oldstyle'
# attribute, if false, means that single-letter synonyms should be
# accepted in oldstyle mode; it defaults to truie.
# actions: Action words, grouped into synonyms, and their corresponding
# default messages.
# default messages. The 'oldstyle' attribute is as for motions.
#
# hints: Each item contains a hint number, a hint label (used to
# generate the value macro for the hint) the number of turns he
@ -243,6 +238,7 @@ motions: !!omap
words: ['climb']
- LOOK:
words: ['l', 'x', 'look', 'exami', 'touch', 'descr']
oldstyle: false
- MOT_58:
words: ['floor']
- MOT_59:
@ -290,6 +286,7 @@ actions: !!omap
message: ALREADY_CARRYING
words: ['g', 'carry', 'take', 'keep', 'catch',
'steal', 'captu', 'get', 'tote', 'snarf']
oldstyle: false
- DROP:
message: ARENT_CARRYING
words: ['drop', 'relea', 'free', 'disca', 'dump']
@ -302,6 +299,7 @@ actions: !!omap
- NOTHING:
message: NO_MESSAGE
words: ['z', 'nothi']
oldstyle: false
- LOCK:
message: NOT_LOCKABLE
words: ['lock', 'close']
@ -348,6 +346,7 @@ actions: !!omap
- INVENTORY:
message: NEARBY
words: ['i', 'inven']
oldstyle: false
- FEED:
message: NO_EDIBLES
words: ['feed']

View file

@ -175,6 +175,7 @@ extern const action_t actions[];
extern const action_t specials[];
extern const travelop_t travel[];
extern const long tkey[];
extern const char *ignore;
#define NLOCATIONS {}
#define NOBJECTS {}
@ -266,12 +267,14 @@ const action_t specials[] = {{
{}
}};
{}
const long tkey[] = {{{}}};
const travelop_t travel[] = {{
{}
}};
const char *ignore = \"{}\";
/* end */
"""
@ -519,6 +522,11 @@ def get_motions(motions):
else:
words_str = get_string_group(contents["words"])
mot_str += template.format(words_str)
global ignore
if contents.get("oldstyle", True) == False:
for word in contents["words"]:
if len(word) == 1:
ignore += word.upper()
return mot_str
def get_actions(actions):
@ -542,6 +550,11 @@ def get_actions(actions):
message = contents["message"]
act_str += template.format(words_str, message)
global ignore
if contents.get("oldstyle", True) == False:
for word in contents["words"]:
if len(word) == 1:
ignore += word.upper()
act_str = act_str[:-1] # trim trailing newline
return act_str
@ -552,7 +565,7 @@ def bigdump(arr):
if out and out[-1] == ' ':
out = out[:-1]
out += "\n "
out += str(arr[i]) + ", "
out += str(arr[i]).lower() + ", "
out = out[:-2] + "\n"
return out
@ -697,7 +710,7 @@ if __name__ == "__main__":
(travel, tkey) = buildtravel(db["locations"],
db["objects"])
ignore = ""
c = c_template.format(
h_name,
get_arbitrary_messages(db["arbitrary_messages"]),
@ -711,8 +724,9 @@ if __name__ == "__main__":
get_motions(db["motions"]),
get_actions(db["actions"]),
get_actions(db["specials"]),
"const long tkey[] = {%s};" % bigdump(tkey),
bigdump(tkey),
get_travel(travel),
ignore,
)
h = h_template.format(

4
misc.c
View file

@ -459,7 +459,7 @@ int get_motion_vocab_id(const char* word)
{
for (int i = 0; i < NMOTIONS; ++i) {
for (int j = 0; j < motions[i].words.n; ++j) {
if (strcasecmp(word, motions[i].words.strs[j]) == 0)
if (strcasecmp(word, motions[i].words.strs[j]) == 0 && (strlen(word) > 1 || strchr(ignore, word[0]) == NULL || !oldstyle))
return (i);
}
}
@ -485,7 +485,7 @@ int get_action_vocab_id(const char* word)
{
for (int i = 0; i < NACTIONS; ++i) {
for (int j = 0; j < actions[i].words.n; ++j) {
if (strcasecmp(word, actions[i].words.strs[j]) == 0)
if (strcasecmp(word, actions[i].words.strs[j]) == 0 && (strlen(word) > 1 || strchr(ignore, word[0]) == NULL || !oldstyle))
return (i);
}
}

View file

@ -8,6 +8,22 @@ You are standing at the end of a road before a small brick building.
Around you is a forest. A small stream flows out of the building and
down a gully.
i
Sorry, I don't know the word "I".
l
Sorry, I don't know the word "L".
x
Sorry, I don't know the word "X".
z
Sorry, I don't know the word "Z".
quit
Do you really want to quit now?
@ -16,7 +32,7 @@ yes
OK
You scored 32 out of a possible 430, using 1 turn.
You scored 32 out of a possible 430, using 5 turns.
You are obviously a rank amateur. Better luck next time.

View file

@ -1,5 +1,9 @@
## Simple quit
#options: -o
n
i
l
x
z
quit
yes