Skip to content

Commit

Permalink
WAGE: More work on object interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 1, 2016
1 parent 1ef7beb commit 2e67321
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 2 deletions.
10 changes: 10 additions & 0 deletions engines/wage/entities.cpp
Expand Up @@ -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
1 change: 1 addition & 0 deletions engines/wage/entities.h
Expand Up @@ -215,6 +215,7 @@ class Chr : public Designed {
Context _context;

WeaponArray *getWeapons();
String &getNameWithDefiniteArticle(bool capitalize);

public:
#if 0
Expand Down
4 changes: 4 additions & 0 deletions engines/wage/gui.cpp
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions engines/wage/gui.h
Expand Up @@ -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);

Expand Down
109 changes: 108 additions & 1 deletion engines/wage/wage.cpp
Expand Up @@ -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()");
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<Chr *>::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<Scene> 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
8 changes: 7 additions & 1 deletion engines/wage/wage.h
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -156,6 +160,8 @@ class WageEngine : public Engine {

Common::MacResManager *_resManager;

bool _commandWasQuick;

};

// Example console class
Expand Down

0 comments on commit 2e67321

Please sign in to comment.