From 47b3f404b89e23918a3afd688c7865dc12e8f521 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 22 Jan 2016 17:18:49 +0100 Subject: WAGE: Moved all interaction-related methods from script.cpp to combat.cpp --- engines/wage/combat.cpp | 385 +++++++++++++++++++++++++++++++++++++++++++- engines/wage/entities.cpp | 16 +- engines/wage/entities.h | 14 -- engines/wage/gui.cpp | 3 +- engines/wage/gui.h | 2 +- engines/wage/script.cpp | 400 +++------------------------------------------- engines/wage/script.h | 25 --- engines/wage/wage.cpp | 12 +- engines/wage/wage.h | 41 ++++- 9 files changed, 462 insertions(+), 436 deletions(-) (limited to 'engines/wage') diff --git a/engines/wage/combat.cpp b/engines/wage/combat.cpp index b057b7e2ad..4bd62b81fc 100644 --- a/engines/wage/combat.cpp +++ b/engines/wage/combat.cpp @@ -77,7 +77,7 @@ void WageEngine::encounter(Chr *player, Chr *chr) { appendText(buf); if (!chr->_initialComment.empty()) - appendText(chr->_initialComment); + appendText(chr->_initialComment.c_str()); if (chr->_armor[Chr::HEAD_ARMOR] != NULL) { snprintf(buf, 512, "%s%s is wearing %s.", chr->getDefiniteArticle(true), chr->_name.c_str(), @@ -303,4 +303,387 @@ void WageEngine::regen() { } } +void WageEngine::takeObj(Obj *obj) { + if ((int)_world->_player->_inventory.size() >= _world->_player->_maximumCarriedObjects) { + appendText("Your pack is full, you must drop something."); + } else { + char buf[256]; + + _world->move(obj, _world->_player); + int type = _world->_player->wearObjIfPossible(obj); + if (type == Chr::HEAD_ARMOR) { + snprintf(buf, 256, "You are now wearing the %s.", obj->_name.c_str()); + appendText(buf); + } else if (type == Chr::BODY_ARMOR) { + snprintf(buf, 256, "You are now wearing the %s.", obj->_name.c_str()); + appendText(buf); + } else if (type == Chr::SHIELD_ARMOR) { + snprintf(buf, 256, "You are now wearing the %s.", obj->_name.c_str()); + appendText(buf); + } else if (type == Chr::MAGIC_ARMOR) { + snprintf(buf, 256, "You are now wearing the %s.", obj->_name.c_str()); + appendText(buf); + } else { + snprintf(buf, 256, "You now have the %s.", obj->_name.c_str()); + appendText(buf); + } + appendText(obj->_clickMessage.c_str()); + } +} + +static const int directionsX[] = { 0, 0, 1, -1 }; +static const int directionsY[] = { -1, 1, 0, 0 }; + +bool WageEngine::handleMoveCommand(Directions dir, const char *dirName) { + Scene *playerScene = _world->_player->_currentScene; + const char *msg = playerScene->_messages[dir].c_str(); + + warning("Dir: %s msg: %s", dirName, msg); + + if (!playerScene->_blocked[dir]) { + int destX = playerScene->_worldX + directionsX[dir]; + int destY = playerScene->_worldY + directionsY[dir]; + + Scene *scene = _world->getSceneAt(destX, destY); + + if (scene != NULL) { + if (strlen(msg) > 0) { + appendText(msg); + } + _world->move(_world->_player, scene); + return true; + } + } + if (strlen(msg) > 0) { + appendText(msg); + } else { + Common::String txt("You can't go "); + txt += dirName; + txt += "."; + appendText(txt.c_str()); + } + + return true; +} + +bool WageEngine::handleLookCommand() { + appendText(_world->_player->_currentScene->_text.c_str()); + + Common::String *items = getGroundItemsList(_world->_player->_currentScene); + if (items != NULL) { + appendText(items->c_str()); + + delete items; + } + + return true; +} + +Common::String *WageEngine::getGroundItemsList(Scene *scene) { + ObjArray objs; + + for (ObjList::const_iterator it = scene->_objs.begin(); it != scene->_objs.end(); ++it) + if ((*it)->_type != Obj::IMMOBILE_OBJECT) + objs.push_back(*it); + + if (objs.size()) { + Common::String *res = new Common::String("On the ground you see "); + appendObjNames(*res, objs); + return res; + } + return NULL; +} + +void WageEngine::appendObjNames(Common::String &str, ObjArray &objs) { + for (uint i = 0; i < objs.size(); i++) { + Obj *obj = objs[i]; + + if (!obj->_namePlural) + str += getIndefiniteArticle(obj->_name); + else + str += "some "; + + str += obj->_name; + + if (i == objs.size() - 1) { + str += "."; + } else if (i == objs.size() - 2) { + if (objs.size() > 2) + str += ","; + str += " and "; + } else { + str += ", "; + } + } +} + +bool WageEngine::handleInventoryCommand() { + Chr *player = _world->_player; + ObjArray objs; + + for (ObjArray::const_iterator it = player->_inventory.begin(); it != player->_inventory.end(); ++it) + if (!player->isWearing(*it)) + objs.push_back(*it); + + if (!objs.size()) { + appendText((char *)"Your pack is empty."); + } else { + Common::String res("Your pack contains "); + appendObjNames(res, objs); + appendText(res.c_str()); + } + + return true; +} + +static const char *armorMessages[] = { + "Head protection:", + "Chest protection:", + "Shield protection:", // TODO: check message + "Magical protection:" +}; + +bool WageEngine::handleStatusCommand() { + Chr *player = _world->_player; + char buf[512]; + + snprintf(buf, 512, "Character name: %s%s", player->getDefiniteArticle(false), player->_name.c_str()); + appendText(buf); + snprintf(buf, 512, "Experience: %d", player->_context._experience); + appendText(buf); + + int wealth = 0; + for (ObjArray::const_iterator it = player->_inventory.begin(); it != player->_inventory.end(); ++it) + wealth += (*it)->_value; + + snprintf(buf, 512, "Wealth: %d", wealth); + appendText(buf); + + for (int i = 0; i < Chr::NUMBER_OF_ARMOR_TYPES; i++) { + if (player->_armor[i] != NULL) { + snprintf(buf, 512, "%s %s", armorMessages[i], player->_armor[i]->_name.c_str()); + appendText(buf); + } + } + + for (ObjArray::const_iterator it = player->_inventory.begin(); it != player->_inventory.end(); ++it) { + int uses = (*it)->_numberOfUses; + + if (uses > 0) { + snprintf(buf, 512, "Your %s has %d uses left.", (*it)->_name.c_str(), uses); + } + } + + printPlayerCondition(player); + + _commandWasQuick = true; + + return true; +} + +bool WageEngine::handleRestCommand() { + if (getMonster() != NULL) { + appendText((char *)"This is no time to rest!"); + _commandWasQuick = true; + } else { + regen(); + printPlayerCondition(_world->_player); + } + + return true; +} + +bool WageEngine::handleAcceptCommand() { + Chr *chr = _offer->_currentOwner; + + char buf[512]; + snprintf(buf, 512, "%s%s lays the %s on the ground and departs peacefully.", + chr->getDefiniteArticle(true), chr->_name.c_str(), _offer->_name.c_str()); + appendText(buf); + + _world->move(_offer, chr->_currentScene); + _world->move(chr, _world->_storageScene); + + return true; +} + +bool WageEngine::handleTakeCommand(const char *target) { + Common::String t(target); + bool handled = false; + + for (ObjList::const_iterator it = _world->_player->_currentScene->_objs.begin(); it != _world->_player->_currentScene->_objs.end(); ++it) { + Common::String n((*it)->_name); + n.toLowercase(); + + if (t.contains(n)) { + if ((*it)->_type == Obj::IMMOBILE_OBJECT) { + appendText((char *)"You can't move it."); + } else { + takeObj(*it); + } + + handled = true; + break; + } + } + + return handled; +} + +bool WageEngine::handleDropCommand(const char *target) { + Common::String t(target); + bool handled = false; + + t.toLowercase(); + + for (ObjArray::const_iterator it = _world->_player->_inventory.begin(); it != _world->_player->_inventory.end(); ++it) { + Common::String n((*it)->_name); + n.toLowercase(); + + if (t.contains(n)) { + char buf[256]; + + snprintf(buf, 256, "You no longer have the %s.", (*it)->_name.c_str()); + _world->move(*it, _world->_player->_currentScene); + + handled = true; + break; + } + } + + return handled; +} + +bool WageEngine::handleAimCommand(const char *t) { + bool wasHandled = true; + Common::String target(t); + + target.toLowercase(); + + if (target.contains("head")) { + _aim = Chr::HEAD; + } else if (target.contains("chest")) { + _aim = Chr::CHEST; + } else if (target.contains("side")) { + _aim = Chr::SIDE; + } else { + wasHandled = false; + appendText((char *)"Please aim for the head, chest, or side."); + } + + _commandWasQuick = true; + + return wasHandled; +} + +bool WageEngine::handleWearCommand(const char *t) { + Chr *player = _world->_player; + char buf[512]; + Common::String target(t); + bool handled = false; + + target.toLowercase(); + + for (ObjArray::const_iterator it = _world->_player->_inventory.begin(); it != _world->_player->_inventory.end(); ++it) { + Common::String n((*it)->_name); + + if (target.contains(n)) { + if ((*it)->_type == Obj::HELMET) { + wearObj(*it, Chr::HEAD_ARMOR); + } else if ((*it)->_type == Obj::CHEST_ARMOR) { + wearObj(*it, Chr::BODY_ARMOR); + } else if ((*it)->_type == Obj::SHIELD) { + wearObj(*it, Chr::SHIELD_ARMOR); + } else if ((*it)->_type == Obj::SPIRITUAL_ARMOR) { + wearObj(*it, Chr::MAGIC_ARMOR); + } else { + appendText((char *)"You cannot wear that object."); + } + + handled = true; + break; + } + } + + for (ObjList::const_iterator it = player->_currentScene->_objs.begin(); it != player->_currentScene->_objs.end(); ++it) { + Common::String n((*it)->_name); + n.toLowercase(); + if (target.contains(n)) { + snprintf(buf, 512, "First you must get the %s.", (*it)->_name.c_str()); + appendText(buf); + + handled = true; + break; + } + } + + return handled; +} + +void WageEngine::wearObj(Obj *o, int pos) { + Chr *player = _world->_player; + char buf[512]; + + if (player->_armor[pos] == o) { + snprintf(buf, 512, "You are already wearing the %s.", o->_name.c_str()); + appendText(buf); + } else { + if (player->_armor[pos] != NULL) { + snprintf(buf, 512, "You are no longer wearing the %s.", player->_armor[pos]->_name.c_str()); + appendText(buf); + } + + player->_armor[pos] = o; + snprintf(buf, 512, "You are now wearing the %s.", o->_name.c_str()); + appendText(buf); + } +} + + +bool WageEngine::handleOfferCommand(const char *target) { + warning("STUB: handleOfferCommand"); + + return false; +} + +bool WageEngine::tryAttack(Obj *weapon, Common::String &input) { + warning("STUB: tryAttack"); + + return false; +} + +bool WageEngine::handleAttack(Obj *weapon) { + warning("STUB: handleAttack"); + + return true; +} + +const char *WageEngine::getPercentMessage(double percent) { + if (percent < 0.40) { + return "very bad"; + } else if (percent < 0.55) { + return "bad"; + } else if (percent < 0.70) { + return "average"; + } else if (percent < 0.85) { + return "good"; + } else if (percent <= 1.00) { + return "very good"; + } else { + return "enhanced"; + } +} + +void WageEngine::printPlayerCondition(Chr *player) { + double physicalPercent = (double)player->_context._statVariables[PHYS_HIT_CUR] / player->_context._statVariables[PHYS_HIT_BAS]; + double spiritualPercent = (double)player->_context._statVariables[SPIR_HIT_CUR] / player->_context._statVariables[SPIR_HIT_BAS]; + char buf[256]; + + snprintf(buf, 256, "Your physical condition is %s.", getPercentMessage(physicalPercent)); + appendText(buf); + + snprintf(buf, 256, "Your spiritual condition is %s.", getPercentMessage(spiritualPercent)); + appendText(buf); +} + } // End of namespace Wage diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp index 588a7cf47f..747d4861d4 100644 --- a/engines/wage/entities.cpp +++ b/engines/wage/entities.cpp @@ -109,17 +109,17 @@ Scene::Scene(String name, Common::SeekableReadStream *data) { setDesignBounds(readRect(data)); _worldY = data->readSint16BE(); _worldX = data->readSint16BE(); - _blocked[Scene::NORTH] = (data->readByte() != 0); - _blocked[Scene::SOUTH] = (data->readByte() != 0); - _blocked[Scene::EAST] = (data->readByte() != 0); - _blocked[Scene::WEST] = (data->readByte() != 0); + _blocked[NORTH] = (data->readByte() != 0); + _blocked[SOUTH] = (data->readByte() != 0); + _blocked[EAST] = (data->readByte() != 0); + _blocked[WEST] = (data->readByte() != 0); _soundFrequency = data->readSint16BE(); _soundType = data->readByte(); data->readByte(); // unknown - _messages[Scene::NORTH] = readPascalString(data); - _messages[Scene::SOUTH] = readPascalString(data); - _messages[Scene::EAST] = readPascalString(data); - _messages[Scene::WEST] = readPascalString(data); + _messages[NORTH] = readPascalString(data); + _messages[SOUTH] = readPascalString(data); + _messages[EAST] = readPascalString(data); + _messages[WEST] = readPascalString(data); _soundName = readPascalString(data); _visited = false; diff --git a/engines/wage/entities.h b/engines/wage/entities.h index b1101f93aa..58cc82a894 100644 --- a/engines/wage/entities.h +++ b/engines/wage/entities.h @@ -55,15 +55,8 @@ namespace Graphics { namespace Wage { class Design; -class Obj; -class Scene; class Script; -typedef Common::Array ObjArray; -typedef Common::Array ChrArray; -typedef Common::List ObjList; -typedef Common::List ChrList; - enum StatVariable { /** The base physical accuracy of the player. */ PHYS_ACC_BAS = 0, @@ -306,13 +299,6 @@ public: class Scene : public Designed { public: - enum Directions { - NORTH = 0, - SOUTH = 1, - EAST = 2, - WEST = 3 - }; - enum SceneTypes { PERIODIC = 0, RANDOM = 1 diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 02b735d9ea..5bebc396b8 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -214,7 +214,8 @@ void Gui::clearOutput() { _consoleFullRedraw = true; } -void Gui::appendText(String &str) { +void Gui::appendText(const char *s) { + Common::String str(s); _consoleDirty = true; if (!str.contains('\n')) { diff --git a/engines/wage/gui.h b/engines/wage/gui.h index 3f5a824a32..45ef50c12a 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -90,7 +90,7 @@ public: ~Gui(); void draw(); - void appendText(Common::String &str); + void appendText(const char *str); void clearOutput(); void mouseMove(int x, int y); void mouseClick(int x, int y); diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp index 152abe11ee..410186e6ff 100644 --- a/engines/wage/script.cpp +++ b/engines/wage/script.cpp @@ -118,7 +118,8 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i { Operand *op = readOperand(); // TODO check op type is string or number, or something good... - appendText(op->toString()); + _handled = true; + _engine->appendText(op->toString().c_str()); delete op; byte d = _data->readByte(); if (d != 0xFD) @@ -164,45 +165,45 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i } else if (!input.empty()) { input.toLowercase(); if (input.equals("n") || input.contains("north")) { - handleMoveCommand(Scene::NORTH, "north"); + _handled = _engine->handleMoveCommand(NORTH, "north"); } else if (input.equals("e") || input.contains("east")) { - handleMoveCommand(Scene::EAST, "east"); + _handled = _engine->handleMoveCommand(EAST, "east"); } else if (input.equals("s") || input.contains("south")) { - handleMoveCommand(Scene::SOUTH, "south"); + _handled = _engine->handleMoveCommand(SOUTH, "south"); } else if (input.equals("w") || input.contains("west")) { - handleMoveCommand(Scene::WEST, "west"); + _handled = _engine->handleMoveCommand(WEST, "west"); } else if (input.hasPrefix("take ")) { - handleTakeCommand(&input.c_str()[5]); + _handled = _engine->handleTakeCommand(&input.c_str()[5]); } else if (input.hasPrefix("get ")) { - handleTakeCommand(&input.c_str()[4]); + _handled = _engine->handleTakeCommand(&input.c_str()[4]); } else if (input.hasPrefix("pick up ")) { - handleTakeCommand(&input.c_str()[8]); + _handled = _engine->handleTakeCommand(&input.c_str()[8]); } else if (input.hasPrefix("drop ")) { - handleDropCommand(&input.c_str()[5]); + _handled = _engine->handleDropCommand(&input.c_str()[5]); } else if (input.hasPrefix("aim ")) { - handleAimCommand(&input.c_str()[4]); + _handled = _engine->handleAimCommand(&input.c_str()[4]); } else if (input.hasPrefix("wear ")) { - handleWearCommand(&input.c_str()[5]); + _handled = _engine->handleWearCommand(&input.c_str()[5]); } else if (input.hasPrefix("put on ")) { - handleWearCommand(&input.c_str()[7]); + _handled = _engine->handleWearCommand(&input.c_str()[7]); } else if (input.hasPrefix("offer ")) { - handleOfferCommand(&input.c_str()[6]); + _handled = _engine->handleOfferCommand(&input.c_str()[6]); } else if (input.contains("look")) { - handleLookCommand(); + _handled = _engine->handleLookCommand(); } else if (input.contains("inventory")) { - handleInventoryCommand(); + _handled = _engine->handleInventoryCommand(); } else if (input.contains("status")) { - handleStatusCommand(); + _handled = _engine->handleStatusCommand(); } else if (input.contains("rest") || input.equals("wait")) { - handleRestCommand(); + _handled = _engine->handleRestCommand(); } else if (_engine->getOffer() != NULL && input.contains("accept")) { - handleAcceptCommand(); + _handled = _engine->handleAcceptCommand(); } else { Chr *player = _world->_player; ObjArray *weapons = player->getWeapons(true); for (ObjArray::const_iterator weapon = weapons->begin(); weapon != weapons->end(); ++weapon) { - if (tryAttack(*weapon, input)) { - handleAttack(*weapon); + if (_engine->tryAttack(*weapon, input)) { + _handled = _engine->handleAttack(*weapon); break; } } @@ -213,10 +214,12 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i } else if (_inputClick->_classType == OBJ) { Obj *obj = (Obj *)_inputClick; if (obj->_type != Obj::IMMOBILE_OBJECT) { - takeObj(obj); + _engine->takeObj(obj); } else { - appendText(obj->_clickMessage); + _engine->appendText(obj->_clickMessage.c_str()); } + + _handled = true; } return _handled; @@ -858,27 +861,6 @@ bool Script::evalClickCondition(Operand *lhs, const char *op, Operand *rhs) { return result; } -void Script::takeObj(Obj *obj) { - if ((int)_world->_player->_inventory.size() >= _world->_player->_maximumCarriedObjects) { - appendText("Your pack is full, you must drop something."); - } else { - _world->move(obj, _world->_player); - int type = _world->_player->wearObjIfPossible(obj); - if (type == Chr::HEAD_ARMOR) { - appendText(String("You are now wearing the ") + obj->_name + "."); - } else if (type == Chr::BODY_ARMOR) { - appendText(String("You are now wearing the ") + obj->_name + "."); - } else if (type == Chr::SHIELD_ARMOR) { - appendText(String("You are now wearing the ") + obj->_name + "."); - } else if (type == Chr::MAGIC_ARMOR) { - appendText(String("You are now wearing the ") + obj->_name + "."); - } else { - appendText(String("You now have the ") + obj->_name + "."); - } - appendText(obj->_clickMessage); - } -} - void Script::processMove() { Operand *what = readOperand(); byte skip = _data->readByte(); @@ -938,338 +920,6 @@ void Script::processLet() { assign(operandType, uservar, result); } -void Script::appendText(String str) { - _handled = true; - _engine->appendText(str); -} - -static const int directionsX[] = { 0, 0, 1, -1 }; -static const int directionsY[] = { -1, 1, 0, 0 }; - -void Script::handleMoveCommand(Scene::Directions dir, const char *dirName) { - Scene *playerScene = _world->_player->_currentScene; - Common::String msg(playerScene->_messages[dir]); - - warning("Dir: %s msg: %s", dirName, msg.c_str()); - - if (!playerScene->_blocked[dir]) { - int destX = playerScene->_worldX + directionsX[dir]; - int destY = playerScene->_worldY + directionsY[dir]; - - Scene *scene = _world->getSceneAt(destX, destY); - - if (scene != NULL) { - if (msg.size() > 0) { - appendText(msg); - } - _world->move(_world->_player, scene); - return; - } - } - if (msg.size() > 0) { - appendText(msg); - } else { - Common::String txt("You can't go "); - txt += dirName; - txt += "."; - appendText(txt); - } -} - -void Script::handleLookCommand() { - appendText(_world->_player->_currentScene->_text); - - Common::String *items = getGroundItemsList(_world->_player->_currentScene); - if (items != NULL) { - appendText(*items); - - delete items; - } -} - -Common::String *Script::getGroundItemsList(Scene *scene) { - ObjArray objs; - - for (ObjList::const_iterator it = scene->_objs.begin(); it != scene->_objs.end(); ++it) - if ((*it)->_type != Obj::IMMOBILE_OBJECT) - objs.push_back(*it); - - if (objs.size()) { - Common::String *res = new Common::String("On the ground you see "); - appendObjNames(*res, objs); - return res; - } - return NULL; -} - -void Script::appendObjNames(Common::String &str, ObjArray &objs) { - for (uint i = 0; i < objs.size(); i++) { - Obj *obj = objs[i]; - - if (!obj->_namePlural) - str += getIndefiniteArticle(obj->_name); - else - str += "some "; - - str += obj->_name; - - if (i == objs.size() - 1) { - str += "."; - } else if (i == objs.size() - 2) { - if (objs.size() > 2) - str += ","; - str += " and "; - } else { - str += ", "; - } - } -} - -void Script::handleInventoryCommand() { - Chr *player = _world->_player; - ObjArray objs; - - for (ObjArray::const_iterator it = player->_inventory.begin(); it != player->_inventory.end(); ++it) - if (!player->isWearing(*it)) - objs.push_back(*it); - - if (!objs.size()) { - appendText("Your pack is empty."); - } else { - Common::String res("Your pack contains "); - appendObjNames(res, objs); - appendText(res); - } -} - -static const char *armorMessages[] = { - "Head protection:", - "Chest protection:", - "Shield protection:", // TODO: check message - "Magical protection:" -}; - -void Script::handleStatusCommand() { - Chr *player = _world->_player; - char buf[512]; - - snprintf(buf, 512, "Character name: %s%s", player->getDefiniteArticle(false), player->_name.c_str()); - appendText(buf); - snprintf(buf, 512, "Experience: %d", player->_context._experience); - appendText(buf); - - int wealth = 0; - for (ObjArray::const_iterator it = player->_inventory.begin(); it != player->_inventory.end(); ++it) - wealth += (*it)->_value; - - snprintf(buf, 512, "Wealth: %d", wealth); - appendText(buf); - - for (int i = 0; i < Chr::NUMBER_OF_ARMOR_TYPES; i++) { - if (player->_armor[i] != NULL) { - snprintf(buf, 512, "%s %s", armorMessages[i], player->_armor[i]->_name.c_str()); - appendText(buf); - } - } - - for (ObjArray::const_iterator it = player->_inventory.begin(); it != player->_inventory.end(); ++it) { - int uses = (*it)->_numberOfUses; - - if (uses > 0) { - snprintf(buf, 512, "Your %s has %d uses left.", (*it)->_name.c_str(), uses); - } - } - - printPlayerCondition(player); - - _engine->_commandWasQuick = true; -} - -void Script::handleRestCommand() { - if (_engine->getMonster() != NULL) { - appendText("This is no time to rest!"); - _engine->_commandWasQuick = true; - } else { - _engine->regen(); - printPlayerCondition(_world->_player); - } -} - -void Script::handleAcceptCommand() { - Obj *offer = _engine->_offer; - Chr *chr = offer->_currentOwner; - - char buf[512]; - snprintf(buf, 512, "%s%s lays the %s on the ground and departs peacefully.", - chr->getDefiniteArticle(true), chr->_name.c_str(), offer->_name.c_str()); - appendText(buf); - - _world->move(offer, chr->_currentScene); - _world->move(chr, _world->_storageScene); -} - -void Script::handleTakeCommand(const char *target) { - Common::String t(target); - - for (ObjList::const_iterator it = _world->_player->_currentScene->_objs.begin(); it != _world->_player->_currentScene->_objs.end(); ++it) { - Common::String n((*it)->_name); - n.toLowercase(); - - if (t.contains(n)) { - if ((*it)->_type == Obj::IMMOBILE_OBJECT) { - appendText((char *)"You can't move it."); - } else { - takeObj(*it); - } - break; - } - } -} - -void Script::handleDropCommand(const char *target) { - Common::String t(target); - - t.toLowercase(); - - for (ObjArray::const_iterator it = _world->_player->_inventory.begin(); it != _world->_player->_inventory.end(); ++it) { - Common::String n((*it)->_name); - n.toLowercase(); - - if (t.contains(n)) { - char buf[256]; - - snprintf(buf, 256, "You no longer have the %s.", (*it)->_name.c_str()); - _world->move(*it, _world->_player->_currentScene); - break; - } - } -} - -void Script::handleAimCommand(const char *t) { - bool wasHandled = true; - Common::String target(t); - - target.toLowercase(); - - if (target.contains("head")) { - _engine->_aim = Chr::HEAD; - } else if (target.contains("chest")) { - _engine->_aim = Chr::CHEST; - } else if (target.contains("side")) { - _engine->_aim = Chr::SIDE; - } else { - wasHandled = false; - appendText((char *)"Please aim for the head, chest, or side."); - } - - if (wasHandled) - _handled = true; - - _engine->_commandWasQuick = true; -} - -void Script::handleWearCommand(const char *t) { - Chr *player = _world->_player; - char buf[512]; - Common::String target(t); - - target.toLowercase(); - - for (ObjArray::const_iterator it = _world->_player->_inventory.begin(); it != _world->_player->_inventory.end(); ++it) { - Common::String n((*it)->_name); - - if (target.contains(n)) { - if ((*it)->_type == Obj::HELMET) { - wearObj(*it, Chr::HEAD_ARMOR); - } else if ((*it)->_type == Obj::CHEST_ARMOR) { - wearObj(*it, Chr::BODY_ARMOR); - } else if ((*it)->_type == Obj::SHIELD) { - wearObj(*it, Chr::SHIELD_ARMOR); - } else if ((*it)->_type == Obj::SPIRITUAL_ARMOR) { - wearObj(*it, Chr::MAGIC_ARMOR); - } else { - appendText((char *)"You cannot wear that object."); - } - break; - } - } - - for (ObjList::const_iterator it = player->_currentScene->_objs.begin(); it != player->_currentScene->_objs.end(); ++it) { - Common::String n((*it)->_name); - n.toLowercase(); - if (target.contains(n)) { - snprintf(buf, 512, "First you must get the %s.", (*it)->_name.c_str()); - appendText(buf); - break; - } - } -} - -void Script::wearObj(Obj *o, int pos) { - Chr *player = _world->_player; - char buf[512]; - - if (player->_armor[pos] == o) { - snprintf(buf, 512, "You are already wearing the %s.", o->_name.c_str()); - appendText(buf); - } else { - if (player->_armor[pos] != NULL) { - snprintf(buf, 512, "You are no longer wearing the %s.", player->_armor[pos]->_name.c_str()); - appendText(buf); - } - - player->_armor[pos] = o; - snprintf(buf, 512, "You are now wearing the %s.", o->_name.c_str()); - appendText(buf); - } -} - - -void Script::handleOfferCommand(const char *target) { - warning("STUB: handleOfferCommand"); -} - -bool Script::tryAttack(Obj *weapon, Common::String &input) { - warning("STUB: tryAttack"); - - return false; -} - -void Script::handleAttack(Obj *weapon) { - warning("STUB: handleAttack"); -} - -const char *Script::getPercentMessage(double percent) { - if (percent < 0.40) { - return "very bad"; - } else if (percent < 0.55) { - return "bad"; - } else if (percent < 0.70) { - return "average"; - } else if (percent < 0.85) { - return "good"; - } else if (percent <= 1.00) { - return "very good"; - } else { - return "enhanced"; - } -} - -void Script::printPlayerCondition(Chr *player) { - double physicalPercent = (double)player->_context._statVariables[PHYS_HIT_CUR] / player->_context._statVariables[PHYS_HIT_BAS]; - double spiritualPercent = (double)player->_context._statVariables[SPIR_HIT_CUR] / player->_context._statVariables[SPIR_HIT_BAS]; - - Common::String msg = "Your physical condition is "; - msg += getPercentMessage(physicalPercent); - msg += "."; - appendText(msg); - - msg = "Your spiritual condition is "; - msg += getPercentMessage(spiritualPercent); - msg += "."; - appendText(msg); -} - enum { BLOCK_START, BLOCK_END, diff --git a/engines/wage/script.h b/engines/wage/script.h index 5f34a2712a..143a93dc4d 100644 --- a/engines/wage/script.h +++ b/engines/wage/script.h @@ -164,38 +164,13 @@ private: Operand *convertOperand(Operand *operand, int type); bool evalClickCondition(Operand *lhs, const char *op, Operand *rhs); bool evalClickEquality(Operand *lhs, Operand *rhs, bool partialMatch); - void takeObj(Obj *obj); void processMove(); void processLet(); void assign(byte operandType, int uservar, uint16 value); - void appendText(String str); - void handleMoveCommand(Scene::Directions dir, const char *dirName); - void handleLookCommand(); - Common::String *getGroundItemsList(Scene *scene); - void appendObjNames(Common::String &str, ObjArray &objs); - void handleInventoryCommand(); - void handleStatusCommand(); - void handleRestCommand(); - void handleAcceptCommand(); - - void handleTakeCommand(const char *target); - void handleDropCommand(const char *target); - void handleAimCommand(const char *target); - void handleWearCommand(const char *target); - void handleOfferCommand(const char *target); - - void wearObj(Obj *o, int pos); - - bool tryAttack(Obj *weapon, Common::String &input); - void handleAttack(Obj *weapon); - Common::Array _scriptText; void convertToText(); - - void printPlayerCondition(Chr *player); - const char *getPercentMessage(double percent); }; } // End of namespace Wage diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index 7815ee0e06..310f0931cd 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -204,21 +204,15 @@ void WageEngine::setMenu(String soundName) { warning("STUB: WageEngine::setMenu"); } -void WageEngine::appendText(String &str) { +void WageEngine::appendText(const char *str) { if (_inputText.size()) - _gui->appendText(_inputText); + _gui->appendText(_inputText.c_str()); _inputText = ""; _gui->appendText(str); } -void WageEngine::appendText(char *str) { - Common::String s(str); - - appendText(s); -} - void WageEngine::gameOver() { DialogButtonArray buttons; @@ -456,7 +450,7 @@ void WageEngine::processTurnInternal(Common::String *textInput, Designed *clickI if (monsterWasNull && getMonster() != NULL) return; - Common::String rant(_rnd->getRandomNumber(1) ? "What?" : "Huh?"); + const char *rant = _rnd->getRandomNumber(1) ? "What?" : "Huh?"; appendText(rant); _commandWasQuick = true; diff --git a/engines/wage/wage.h b/engines/wage/wage.h index e5228e6ffc..af5766ea68 100644 --- a/engines/wage/wage.h +++ b/engines/wage/wage.h @@ -69,6 +69,11 @@ class Obj; class Scene; class World; +typedef Common::Array ObjArray; +typedef Common::Array ChrArray; +typedef Common::List ObjList; +typedef Common::List ChrList; + using Common::String; enum OperandType { @@ -82,6 +87,13 @@ enum OperandType { UNKNOWN = 100 }; +enum Directions { + NORTH = 0, + SOUTH = 1, + EAST = 2, + WEST = 3 +}; + // our engine debug levels enum { kWageDebugExample = 1 << 0, @@ -141,6 +153,32 @@ private: void doClose(); +public: + void takeObj(Obj *obj); + + bool handleMoveCommand(Directions dir, const char *dirName); + bool handleLookCommand(); + Common::String *getGroundItemsList(Scene *scene); + void appendObjNames(Common::String &str, ObjArray &objs); + bool handleInventoryCommand(); + bool handleStatusCommand(); + bool handleRestCommand(); + bool handleAcceptCommand(); + + bool handleTakeCommand(const char *target); + bool handleDropCommand(const char *target); + bool handleAimCommand(const char *target); + bool handleWearCommand(const char *target); + bool handleOfferCommand(const char *target); + + void wearObj(Obj *o, int pos); + + bool tryAttack(Obj *weapon, Common::String &input); + bool handleAttack(Obj *weapon); + + void printPlayerCondition(Chr *player); + const char *getPercentMessage(double percent); + public: Common::RandomSource *_rnd; @@ -163,8 +201,7 @@ public: void playSound(String soundName); void setMenu(String soundName); - void appendText(String &str); - void appendText(char *str); + void appendText(const char *str); void gameOver(); bool saveDialog(); Obj *getOffer(); -- cgit v1.2.3