[Scummvm-git-logs] scummvm master -> a5b9eeb7abd93245fd9db0aba56fb8b60c9409f6

dreammaster paulfgilbert at gmail.com
Sat Oct 31 18:17:13 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a5b9eeb7ab GLK: COMPREHEND: Fix answering rhetorical questions


Commit: a5b9eeb7abd93245fd9db0aba56fb8b60c9409f6
    https://github.com/scummvm/scummvm/commit/a5b9eeb7abd93245fd9db0aba56fb8b60c9409f6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-10-31T11:02:34-07:00

Commit Message:
GLK: COMPREHEND: Fix answering rhetorical questions

Changed paths:
    engines/glk/comprehend/debugger_dumper.cpp
    engines/glk/comprehend/game.cpp
    engines/glk/comprehend/game.h
    engines/glk/comprehend/game_data.h
    engines/glk/comprehend/game_opcodes.cpp


diff --git a/engines/glk/comprehend/debugger_dumper.cpp b/engines/glk/comprehend/debugger_dumper.cpp
index 87a2be610c..4754900629 100644
--- a/engines/glk/comprehend/debugger_dumper.cpp
+++ b/engines/glk/comprehend/debugger_dumper.cpp
@@ -75,6 +75,7 @@ DebuggerDumper::DebuggerDumper() : _game(nullptr) {
 	_opcodes[OPCODE_INVENTORY] = "inventory";
 	_opcodes[OPCODE_MOVE_OBJECT_TO_ROOM] = "move_object_to_room";
 	_opcodes[OPCODE_SAVE_ACTION] = "save_action";
+	_opcodes[OPCODE_CLEAR_LINE] = "clear_line";
 	_opcodes[OPCODE_MOVE_TO_ROOM] = "move_to_room";
 	_opcodes[OPCODE_VAR_ADD] = "var_add";
 	_opcodes[OPCODE_SET_ROOM_DESCRIPTION] = "set_room_description";
diff --git a/engines/glk/comprehend/game.cpp b/engines/glk/comprehend/game.cpp
index acded887a8..5df71610b7 100644
--- a/engines/glk/comprehend/game.cpp
+++ b/engines/glk/comprehend/game.cpp
@@ -42,6 +42,11 @@ void Sentence::clear() {
 	_specialOpcodeVal2 = 0;
 }
 
+void Sentence::copyFrom(const Sentence &src, bool copyNoun) {
+	for (uint idx = (copyNoun ? 0 : 1); idx < 6; ++idx)
+		_formattedWords[idx] = src._formattedWords[idx];
+}
+
 void Sentence::format() {
 	for (uint idx = 0; idx < 6; ++idx)
 		_formattedWords[idx] = 0;
@@ -110,7 +115,8 @@ void Sentence::format() {
 /*-------------------------------------------------------*/
 
 
-ComprehendGame::ComprehendGame() : _gameStrings(nullptr), _ended(false) {
+ComprehendGame::ComprehendGame() : _gameStrings(nullptr), _ended(false),
+		_nounState(NOUNSTATE_INITIAL) {
 }
 
 ComprehendGame::~ComprehendGame() {
@@ -798,7 +804,7 @@ void ComprehendGame::doAfterTurn() {
 }
 
 void ComprehendGame::read_input() {
-	Sentence sentence;
+	Sentence tempSentence;
 	char *line = NULL, buffer[1024];
 	bool handled;
 
@@ -835,8 +841,13 @@ void ComprehendGame::read_input() {
 	line = &buffer[0];
 
 	while (1) {
-		read_sentence(&line, &sentence);
-		handled = handle_sentence(&sentence);
+		NounState prevNounState = _nounState;
+		_nounState = NOUNSTATE_STANDARD;
+
+		read_sentence(&line, &tempSentence);
+		_sentence.copyFrom(tempSentence, tempSentence._formattedWords[0] || prevNounState != NOUNSTATE_QUERY);
+
+		handled = handle_sentence(&_sentence);
 		if (handled)
 			doAfterTurn();
 
diff --git a/engines/glk/comprehend/game.h b/engines/glk/comprehend/game.h
index b117d4303e..fcaeb1fb2d 100644
--- a/engines/glk/comprehend/game.h
+++ b/engines/glk/comprehend/game.h
@@ -34,6 +34,8 @@ namespace Comprehend {
 #define ROOM_IS_DARK 1
 #define ROOM_IS_TOO_BRIGHT 2
 
+enum NounState { NOUNSTATE_STANDARD = 0, NOUNSTATE_QUERY = 1, NOUNSTATE_INITIAL = 2 };
+
 struct GameStrings;
 struct Sentence;
 
@@ -48,11 +50,19 @@ struct Sentence {
 	}
 
 	bool empty() const {
-		return _nr_words == 0;
+		return !_formattedWords[0];
 	}
 
+	/**
+	 * Clears the sentence
+	 */
 	void clear();
 
+	/**
+	 * Copies from another sentence to this one
+	 */
+	void copyFrom(const Sentence &src, bool copyNoun = true);
+
 	/**
 	 * Splits up the array of _words into a _formattedWords
 	 * array, placing the words in appropriate noun, verb, etc.
@@ -64,6 +74,8 @@ struct Sentence {
 class ComprehendGame : public GameData {
 protected:
 	bool _ended;
+	NounState _nounState;
+	Sentence _sentence;
 public:
 	const GameStrings *_gameStrings;
 
diff --git a/engines/glk/comprehend/game_data.h b/engines/glk/comprehend/game_data.h
index 11fadd46c4..0eee066adb 100644
--- a/engines/glk/comprehend/game_data.h
+++ b/engines/glk/comprehend/game_data.h
@@ -89,6 +89,7 @@ enum ScriptOpcode {
 	OPCODE_TAKE_OBJECT,
 	OPCODE_MOVE_OBJECT_TO_ROOM,
 	OPCODE_SAVE_ACTION,
+	OPCODE_CLEAR_LINE,
 	OPCODE_MOVE_TO_ROOM,
 	OPCODE_VAR_ADD,
 	OPCODE_SET_ROOM_DESCRIPTION,
diff --git a/engines/glk/comprehend/game_opcodes.cpp b/engines/glk/comprehend/game_opcodes.cpp
index 97fd97fd2d..7e0ee309ce 100644
--- a/engines/glk/comprehend/game_opcodes.cpp
+++ b/engines/glk/comprehend/game_opcodes.cpp
@@ -188,16 +188,14 @@ void ComprehendGameOpcodes::execute_opcode(const Instruction *instr, const Sente
 		break;
 
 	case OPCODE_SAVE_ACTION:
-		/*
-		 * FIXME - This saves the current verb and allows the next
-		 * command to use just the noun. This is used to allow
-		 * responses to ask the player what they meant, e.g:
-		 *
-		 *   > drop
-		 *   I don't understand what you want to drop.
-		 *   > gun
-		 *   Okay.
-		 */
+		// Causes the next sentence inputed to re-use the first word of the current one.
+		// As far as I'm aware, this is only used for handling responses to rhethorical questions
+		_nounState = NOUNSTATE_QUERY;
+		// fall-through
+
+	case OPCODE_CLEAR_LINE:
+		// Resets the input line, removing any pending further actions that were specified
+		// TODO: Make input line a class field, and reset it here
 		break;
 
 	case OPCODE_SET_CAN_TAKE:
@@ -394,6 +392,7 @@ ComprehendGameV1::ComprehendGameV1() {
 	_opcodeMap[0x85] = OPCODE_MOVE_TO_ROOM;
 	_opcodeMap[0x86] = OPCODE_VAR_ADD;
 	_opcodeMap[0x87] = OPCODE_SET_ROOM_DESCRIPTION;
+	_opcodeMap[0x88] = OPCODE_CLEAR_LINE;
 	_opcodeMap[0x89] = OPCODE_MOVE_OBJECT_TO_CURRENT_ROOM;
 	_opcodeMap[0x8a] = OPCODE_VAR_SUB;
 	_opcodeMap[0x8b] = OPCODE_SET_OBJECT_DESCRIPTION;
@@ -696,6 +695,7 @@ ComprehendGameV2::ComprehendGameV2() {
 	_opcodeMap[0x85] = OPCODE_MOVE_TO_ROOM;
 	_opcodeMap[0x86] = OPCODE_VAR_ADD;
 	_opcodeMap[0x87] = OPCODE_SET_ROOM_DESCRIPTION;
+	_opcodeMap[0x88] = OPCODE_CLEAR_LINE;
 	_opcodeMap[0x89] = OPCODE_SPECIAL;
 	_opcodeMap[0x8a] = OPCODE_VAR_SUB;
 	_opcodeMap[0x8c] = OPCODE_MOVE_DEFAULT;




More information about the Scummvm-git-logs mailing list