From 2a16cef20e6d2686bbeae466cc74f772e7c4f66e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 17 Jan 2016 23:25:47 +0100 Subject: WAGE: Simplified message output formation --- engines/wage/combat.cpp | 64 +++++++++++++++++++++---------------------------- engines/wage/wage.cpp | 22 +++++++++-------- engines/wage/wage.h | 1 + 3 files changed, 40 insertions(+), 47 deletions(-) (limited to 'engines/wage') diff --git a/engines/wage/combat.cpp b/engines/wage/combat.cpp index 2d1e02a955..17b03d1d4a 100644 --- a/engines/wage/combat.cpp +++ b/engines/wage/combat.cpp @@ -70,41 +70,31 @@ Chr *WageEngine::getMonster() { } void WageEngine::encounter(Chr *player, Chr *chr) { - Common::String msg("You encounter "); - if (!chr->_nameProperNoun) - msg += getIndefiniteArticle(chr->_name); - msg += chr->_name; - msg += "."; - appendText(msg); + char buf[512]; + + snprintf(buf, 512, "You encounter %s%s.", chr->_nameProperNoun ? "" : getIndefiniteArticle(chr->_name), + chr->_name.c_str()); + appendText(buf); if (!chr->_initialComment.empty()) appendText(chr->_initialComment); if (chr->_armor[Chr::HEAD_ARMOR] != NULL) { - msg = chr->getDefiniteArticle(true); - msg += chr->_name; - msg += " is wearing "; - msg += getIndefiniteArticle(chr->_armor[Chr::HEAD_ARMOR]->_name); - msg += "."; - appendText(msg); + snprintf(buf, 512, "%s%s is wearing %s.", chr->getDefiniteArticle(true), chr->_name.c_str(), + getIndefiniteArticle(chr->_armor[Chr::HEAD_ARMOR]->_name)); + appendText(buf); } if (chr->_armor[Chr::BODY_ARMOR] != NULL) { - msg = getGenderSpecificPronoun(chr->_gender, true); - msg += " is protected by "; - msg += prependGenderSpecificPronoun(chr->_gender); - msg += chr->_armor[Chr::BODY_ARMOR]->_name; - msg += "."; - appendText(msg); + snprintf(buf, 512, "%s is protected by %s%s.", getGenderSpecificPronoun(chr->_gender, true), + prependGenderSpecificPronoun(chr->_gender), chr->_armor[Chr::BODY_ARMOR]->_name.c_str()); + appendText(buf); } if (chr->_armor[Chr::SHIELD_ARMOR] != NULL) { Obj *obj = chr->_armor[Chr::SHIELD_ARMOR]; - msg = getGenderSpecificPronoun(chr->_gender, true); - msg += " carries "; - if (!obj->_namePlural) - msg += getIndefiniteArticle(obj->_name); - msg += obj->_name; - msg += "."; - appendText(msg); + + snprintf(buf, 512, "%s carries %s%s.", getGenderSpecificPronoun(chr->_gender, true), + obj->_namePlural ? "" : getIndefiniteArticle(obj->_name), obj->_name.c_str()); + appendText(buf); } } @@ -202,23 +192,23 @@ void WageEngine::performMove(Chr *chr, int validMoves) { void WageEngine::performOffer(Chr *attacker, Chr *victim) { /* TODO: choose in a smarter way? */ Obj *obj = attacker->_inventory[0]; - Common::String msg(attacker->getDefiniteArticle(true)); - msg += attacker->_name; - msg += " offers "; - msg += obj->_namePlural ? "some " : getIndefiniteArticle(obj->_name); - msg += obj->_name; - msg += "."; + char buf[512]; + + snprintf(buf, 512, "%s%s offers %s%s.", attacker->getDefiniteArticle(true), attacker->_name.c_str(), + obj->_namePlural ? "some " : getIndefiniteArticle(obj->_name), obj->_name.c_str()); + + appendText(buf); _offer = obj; } void WageEngine::performTake(Chr *npc, Obj *obj) { - Common::String msg(npc->getDefiniteArticle(true)); - msg += npc->_name; - msg += " picks up the "; - msg += getIndefiniteArticle(obj->_name); - msg += obj->_name; - msg += "."; + char buf[512]; + + snprintf(buf, 512, "%s%s picks up the %s%s.", npc->getDefiniteArticle(true), npc->_name.c_str(), + getIndefiniteArticle(obj->_name), obj->_name.c_str()); + + appendText(buf); _world->move(obj, npc); } diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index 960f155206..db7e364fab 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -210,6 +210,12 @@ void WageEngine::appendText(String &str) { _gui->appendText(str); } +void WageEngine::appendText(char *str) { + Common::String s(str); + + appendText(s); +} + void WageEngine::gameOver() { warning("STUB: WageEngine::gameOver()"); } @@ -434,20 +440,16 @@ void WageEngine::processTurn(Common::String *textInput, Designed *clickInput) { } } - Common::String msg; + char buf[512]; if (followed) { - msg = prevMonster->getDefiniteArticle(true); - msg += prevMonster->_name; - msg += " follows you."; - appendText(msg); + snprintf(buf, 512, "%s%s follows you.", prevMonster->getDefiniteArticle(true), prevMonster->_name.c_str()); + appendText(buf); + _world->move(prevMonster, playerScene); } else { - msg = "You escape "; - msg += prevMonster->getDefiniteArticle(false); - msg += prevMonster->_name; - msg += "."; - appendText(msg); + snprintf(buf, 512, "You escape %s%s.", prevMonster->getDefiniteArticle(false), prevMonster->_name.c_str()); + appendText(buf); } } } diff --git a/engines/wage/wage.h b/engines/wage/wage.h index 10541b3c12..245fc9ba18 100644 --- a/engines/wage/wage.h +++ b/engines/wage/wage.h @@ -157,6 +157,7 @@ public: void playSound(String soundName); void setMenu(String soundName); void appendText(String &str); + void appendText(char *str); void gameOver(); Obj *getOffer(); Chr *getMonster(); -- cgit v1.2.3