diff options
Diffstat (limited to 'engines/wage')
-rw-r--r-- | engines/wage/script.cpp | 55 | ||||
-rw-r--r-- | engines/wage/script.h | 1 | ||||
-rw-r--r-- | engines/wage/wage.cpp | 30 |
3 files changed, 58 insertions, 28 deletions
diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp index 1773fc1b5c..f7f7d92769 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 2cd4f11f0d..e796195b7f 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 923964b466..7f9fb073f5 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; |