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

sev- sev at scummvm.org
Wed Aug 9 09:28:28 CEST 2017


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:
a83dd4c3fc WAGE: Handle command aliases in the same quirky way wb does


Commit: a83dd4c3fc064fb9e40a8fda42e646fea596559f
    https://github.com/scummvm/scummvm/commit/a83dd4c3fc064fb9e40a8fda42e646fea596559f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-08-09T09:28:13+02:00

Commit Message:
WAGE: Handle command aliases in the same quirky way wb does

Changed paths:
    engines/wage/script.cpp
    engines/wage/script.h
    engines/wage/wage.cpp


diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp
index 1773fc1..f7f7d92 100644
--- a/engines/wage/script.cpp
+++ b/engines/wage/script.cpp
@@ -109,6 +109,46 @@ void Script::printLine(int offset) {
 		}
 }
 
+Common::String Script::preprocessInputText(Common::String inputText) {
+	if (inputText.empty())
+		return inputText;
+
+	// "take " and "pick up " are mapped to "get " before script
+	// execution, so scripts see them as "get ", but only if there's
+	// a trailing space
+	inputText.toLowercase();
+
+	if (inputText.hasPrefix("take "))
+		return Common::String("get ") + (inputText.c_str() + strlen("take "));
+
+	if (inputText.hasPrefix("pick up "))
+		return Common::String("get ") + (inputText.c_str() + strlen("pick up "));
+
+	if (inputText.hasPrefix("put on "))
+		return Common::String("wear ") + (inputText.c_str() + strlen("put on "));
+
+	// exact aliases:
+	if (inputText.size() == 1) {
+		if (inputText.equals("n"))
+			return "north";
+
+		if (inputText.equals("e"))
+			return "east";
+
+		if (inputText.equals("s"))
+			return "south";
+
+		if (inputText.equals("w"))
+			return "west";
+	}
+
+	if (inputText.equals("wait")) {
+		return "rest";
+	}
+
+	return inputText;
+}
+
 bool Script::execute(World *world, int loopCount, Common::String *inputText, Designed *inputClick, WageEngine *engine) {
 	_world = world;
 	_loopCount = loopCount;
@@ -118,8 +158,11 @@ bool Script::execute(World *world, int loopCount, Common::String *inputText, Des
 	_handled = false;
 	Common::String input;
 
-	if (inputText)
-		input = *inputText;
+	if (inputText) {
+		input = preprocessInputText(*_inputText);
+		warning("Input was: '%s' is '%s'", _inputText->c_str(), input.c_str());
+		_inputText = new Common::String(input);
+	}
 
 	_data->seek(12);
 	while (_data->pos() < _data->size()) {
@@ -201,20 +244,14 @@ bool Script::execute(World *world, int loopCount, Common::String *inputText, Des
 			_handled = _engine->handleMoveCommand(SOUTH, "south");
 		} else if (input.contains("west")) {
 			_handled = _engine->handleMoveCommand(WEST, "west");
-		} else if (input.hasPrefix("take ")) {
-			_handled = _engine->handleTakeCommand(&input.c_str()[5]);
 		} else if (input.hasPrefix("get ")) {
 			_handled = _engine->handleTakeCommand(&input.c_str()[4]);
-		} else if (input.hasPrefix("pick up ")) {
-			_handled = _engine->handleTakeCommand(&input.c_str()[8]);
 		} else if (input.hasPrefix("drop ")) {
 			_handled = _engine->handleDropCommand(&input.c_str()[5]);
 		} else if (input.hasPrefix("aim ")) {
 			_handled = _engine->handleAimCommand(&input.c_str()[4]);
 		} else if (input.hasPrefix("wear ")) {
 			_handled = _engine->handleWearCommand(&input.c_str()[5]);
-		} else if (input.hasPrefix("put on ")) {
-			_handled = _engine->handleWearCommand(&input.c_str()[7]);
 		} else if (input.hasPrefix("offer ")) {
 			_handled = _engine->handleOfferCommand(&input.c_str()[6]);
 		} else if (input.contains("look")) {
@@ -223,7 +260,7 @@ bool Script::execute(World *world, int loopCount, Common::String *inputText, Des
 			_handled = _engine->handleInventoryCommand();
 		} else if (input.contains("status")) {
 			_handled = _engine->handleStatusCommand();
-		} else if (input.contains("rest") || input.equals("wait")) {
+		} else if (input.contains("rest")) {
 			_handled = _engine->handleRestCommand();
 		} else if (_engine->getOffer() != NULL && input.contains("accept")) {
 			_handled = _engine->handleAcceptCommand();
diff --git a/engines/wage/script.h b/engines/wage/script.h
index 2cd4f11..e796195 100644
--- a/engines/wage/script.h
+++ b/engines/wage/script.h
@@ -133,6 +133,7 @@ public:
 	bool execute(World *world, int loopCount, Common::String *inputText, Designed *inputClick, WageEngine *engine);
 
 private:
+	Common::String preprocessInputText(Common::String inputText);
 	Operand *readOperand();
 	Operand *readStringOperand();
 	const char *readOperator();
diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp
index 923964b..7f9fb07 100644
--- a/engines/wage/wage.cpp
+++ b/engines/wage/wage.cpp
@@ -169,21 +169,21 @@ void WageEngine::processEvents() {
 			break;
 		case Common::EVENT_KEYDOWN:
 			switch (event.kbd.keycode) {
-			case Common::KEYCODE_RETURN:
-				_inputText = _gui->_consoleWindow->getInput();
-				_inputText += '\n';
+			case Common::KEYCODE_RETURN: {
+					_inputText = _gui->_consoleWindow->getInput();
+					Common::String inp = _inputText + '\n';
 
-				_gui->appendText(_inputText.c_str());
+					_gui->appendText(inp.c_str());
 
-				_gui->_consoleWindow->clearInput();
+					_gui->_consoleWindow->clearInput();
 
-				if (_inputText.empty())
-					break;
-
-				processTurn(&_inputText, NULL);
-				_gui->disableUndo();
-				break;
+					if (_inputText.empty())
+						break;
 
+					processTurn(&_inputText, NULL);
+					_gui->disableUndo();
+					break;
+				}
 			default:
 				if (event.kbd.ascii == '~') {
 					_debugger->attach();
@@ -473,14 +473,6 @@ void WageEngine::processTurn(Common::String *textInput, Designed *clickInput) {
 		input = *textInput;
 
 	input.toLowercase();
-	if (input.equals("e"))
-		input = "east";
-	else if (input.equals("w"))
-		input = "west";
-	else if (input.equals("n"))
-		input = "north";
-	else if (input.equals("s"))
-		input = "south";
 
 	processTurnInternal(&input, clickInput);
 	Scene *playerScene = _world->_player->_currentScene;





More information about the Scummvm-git-logs mailing list