From: Eric S. Raymond Date: Sat, 1 Jul 2017 16:34:44 +0000 (-0400) Subject: Ignore l g z i under oldstyle. X-Git-Tag: takebird~141 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=0d0b8df0a3f6dc7b765c35fa7cc2d2fe52406d87;p=open-adventure.git Ignore l g z i under oldstyle. --- diff --git a/NEWS b/NEWS index 563fd15..4a555ff 100644 --- a/NEWS +++ b/NEWS @@ -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. diff --git a/advent.adoc b/advent.adoc index cd4a8c2..01dded4 100644 --- a/advent.adoc +++ b/advent.adoc @@ -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 == diff --git a/adventure.yaml b/adventure.yaml index 5758a36..5a66e19 100644 --- a/adventure.yaml +++ b/adventure.yaml @@ -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'] diff --git a/make_dungeon.py b/make_dungeon.py index 7e18d76..5618e63 100755 --- a/make_dungeon.py +++ b/make_dungeon.py @@ -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( diff --git a/misc.c b/misc.c index c907d12..5eb1fa2 100644 --- a/misc.c +++ b/misc.c @@ -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); } } diff --git a/tests/oldstyle.chk b/tests/oldstyle.chk index f0ac27e..d8aa9bb 100644 --- a/tests/oldstyle.chk +++ b/tests/oldstyle.chk @@ -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. diff --git a/tests/oldstyle.log b/tests/oldstyle.log index ae6f7fe..97b452f 100644 --- a/tests/oldstyle.log +++ b/tests/oldstyle.log @@ -1,5 +1,9 @@ ## Simple quit #options: -o n +i +l +x +z quit yes