From 2e6732171d6dcec60eaaead55de28d18d5427941 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 2 Jan 2016 00:55:45 +0100 Subject: [PATCH] WAGE: More work on object interaction --- engines/wage/entities.cpp | 10 ++++ engines/wage/entities.h | 1 + engines/wage/gui.cpp | 4 ++ engines/wage/gui.h | 1 + engines/wage/wage.cpp | 109 +++++++++++++++++++++++++++++++++++++- engines/wage/wage.h | 8 ++- 6 files changed, 131 insertions(+), 2 deletions(-) diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp index f9a68d652aa7..614b831f537a 100644 --- a/engines/wage/entities.cpp +++ b/engines/wage/entities.cpp @@ -390,5 +390,15 @@ int Chr::wearObjIfPossible(Obj *obj) { return -1; } +String &Chr::getNameWithDefiniteArticle(bool capitalize) { + Common::String *res = new Common::String; + + if (!_nameProperNoun) + *res += capitalize ? "The " : "the "; + *res += _name; + + return *res; +} + } // End of namespace Wage diff --git a/engines/wage/entities.h b/engines/wage/entities.h index 5c1a902bd249..f6cb525f43e2 100644 --- a/engines/wage/entities.h +++ b/engines/wage/entities.h @@ -215,6 +215,7 @@ class Chr : public Designed { Context _context; WeaponArray *getWeapons(); + String &getNameWithDefiniteArticle(bool capitalize); public: #if 0 diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 789c3503533d..8ec904eb902f 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -153,6 +153,10 @@ void Gui::setScene(Scene *scene) { _scene = scene; } +void Gui::clearOutput() { + _out.clear(); +} + void Gui::appendText(String &str) { if (!str.contains('\n')) { _out.push_back(str); diff --git a/engines/wage/gui.h b/engines/wage/gui.h index f5e1ef5c9bdd..25629f64b979 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -67,6 +67,7 @@ class Gui { void draw(); void setScene(Scene *scene); void appendText(Common::String &str); + void clearOutput(); void mouseMove(int x, int y); Designed *getClickTarget(int x, int y); diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index bc0aff734ac3..e492bdb8c904 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -73,8 +73,11 @@ WageEngine::WageEngine(OSystem *syst, const ADGameDescription *desc) : Engine(sy _temporarilyHidden = false; _isGameOver = false; _monster = NULL; + _running = NULL; _lastScene = NULL; + _commandWasQuick = false; + debug("WageEngine::WageEngine()"); } @@ -150,7 +153,7 @@ void WageEngine::processEvents() { { Designed *obj = _gui->getClickTarget(event.mouse.x, event.mouse.y); if (obj != NULL) - debug(0, "Clicked: %s", obj->_name.c_str()); + processTurn(NULL, obj); } default: break; @@ -305,6 +308,10 @@ void WageEngine::encounter(Chr *player, Chr *chr) { warning("STUB WageEngine::encounter()"); } +void WageEngine::performCombatAction(Chr *npc, Chr *player) { + warning("STUB WageEngine::performCombatAction()"); +} + void WageEngine::redrawScene() { Scene *currentScene = _world->_player->_currentScene; if (currentScene != NULL) { @@ -323,4 +330,104 @@ void WageEngine::redrawScene() { } } +void WageEngine::regen() { + warning("STUB WageEngine::regen()"); +} + +void WageEngine::processTurnInternal(Common::String *textInput, Designed *clickInput) { + Scene *playerScene = _world->_player->_currentScene; + if (playerScene == _world->_storageScene) + return; + + bool shouldEncounter = false; + + if (playerScene != _lastScene) { + _loopCount = 0; + _lastScene = playerScene; + _monster = NULL; + _running = NULL; + _offer = NULL; + + for (Common::List::const_iterator it = playerScene->_chrs.begin(); it != playerScene->_chrs.end(); ++it) { + if (!(*it)->_playerCharacter) { + _monster = *it; + shouldEncounter = true; + break; + } + } + } + + bool monsterWasNull = (_monster == NULL); + bool handled = playerScene->_script->execute(_world, _loopCount++, textInput, clickInput, this); + + playerScene = _world->_player->_currentScene; + + if (playerScene == _world->_storageScene) + return; + + if (playerScene != _lastScene) { + _temporarilyHidden = true; + _gui->clearOutput(); + regen(); + Common::String input("look"); + processTurnInternal(&input, NULL); + redrawScene(); + _temporarilyHidden = false; + } else if (_loopCount == 1) { + redrawScene(); + if (shouldEncounter && _monster != NULL) { + encounter(_world->_player, _monster); + } + } else if (textInput != NULL && !handled) { + if (monsterWasNull && _monster != NULL) + return; + + Common::String rant(_rnd->getRandomNumber(1) ? "What?" : "Huh?"); + + appendText(rant); + _commandWasQuick = true; + } +} + +void WageEngine::processTurn(Common::String *textInput, Designed *clickInput) { + _commandWasQuick = false; + Scene *prevScene = _world->_player->_currentScene; + Chr *prevMonster = _monster; + processTurnInternal(textInput, clickInput); + Scene *playerScene = _world->_player->_currentScene; + + if (prevScene != playerScene && playerScene != _world->_storageScene) { + if (prevMonster != NULL) { + bool followed = false; + if (_monster == NULL) { + warning("STUB: processTurn(), monster"); + //Set scenes = world.getAdjacentScenes(prevMonster.getState().getCurrentScene()); + // TODO: adjacent scenes doesn't contain up/down etc... verify that monsters can't follow these... + //if (scenes.contains(playerScene)) { + // int chance = (int) (Math.random() * 255); + // followed = (chance < prevMonster.getFollowsOpponent()); + //} + } + + Common::String msg; + + if (followed) { + msg = prevMonster->getNameWithDefiniteArticle(true); + msg += " follows you."; + appendText(msg); + _world->move(prevMonster, playerScene); + } else { + msg = "You escape "; + msg += prevMonster->getNameWithDefiniteArticle(false); + msg += "."; + appendText(msg); + } + } + } + if (!_commandWasQuick && _monster != NULL) { + performCombatAction(_monster, _world->_player); + } +} + + } // End of namespace Wage diff --git a/engines/wage/wage.h b/engines/wage/wage.h index 3e294712464f..e96e29821265 100644 --- a/engines/wage/wage.h +++ b/engines/wage/wage.h @@ -119,6 +119,10 @@ class WageEngine : public Engine { bool loadWorld(Common::MacResManager *resMan); void performInitialSetup(); void wearObjs(Chr *chr); + void processTurn(Common::String *textInput, Designed *clickInput); + void processTurnInternal(Common::String *textInput, Designed *clickInput); + void regen(); + void performCombatAction(Chr *npc, Chr *player); public: Common::RandomSource *_rnd; @@ -131,8 +135,8 @@ class WageEngine : public Engine { int _loopCount; int _turn; Chr *_monster; + Chr *_running; Obj *_offer; - bool _commandWasQuick; int _aim; bool _temporarilyHidden; bool _isGameOver; @@ -156,6 +160,8 @@ class WageEngine : public Engine { Common::MacResManager *_resManager; + bool _commandWasQuick; + }; // Example console class