WAGE: Implement getGroundItemsList()

This commit is contained in:
Eugene Sandulenko 2016-01-03 20:23:39 +01:00
parent 07d11b4af6
commit d66c3a21f1
4 changed files with 47 additions and 1 deletions

View File

@ -941,10 +941,42 @@ void Script::handleLookCommand() {
}
Common::String *Script::getGroundItemsList(Scene *scene) {
warning("STUB: getGroundItemsList");
Common::Array<Obj *> objs;
for (Common::List<Obj *>::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, Common::Array<Obj *> &objs) {
for (int 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() {
warning("STUB: handleInventoryCommand");

View File

@ -168,6 +168,7 @@ private:
void handleMoveCommand(Scene::Directions dir, const char *dirName);
void handleLookCommand();
Common::String *getGroundItemsList(Scene *scene);
void appendObjNames(Common::String &str, Common::Array<Obj *> &objs);
void handleInventoryCommand();
void handleStatusCommand();
void handleRestCommand();

View File

@ -87,4 +87,16 @@ Common::Rect *readRect(Common::SeekableReadStream *in) {
return new Common::Rect(x1, y1, x2, y2);
}
const char *getIndefiniteArticle(String &word) {
switch (word[0]) {
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return "an ";
}
return "a ";
}
} // End of namespace Wage

View File

@ -98,6 +98,7 @@ enum {
Common::String readPascalString(Common::SeekableReadStream *in);
Common::Rect *readRect(Common::SeekableReadStream *in);
const char *getIndefiniteArticle(String &word);
typedef Common::Array<byte *> Patterns;