Skip to content

Commit

Permalink
WAGE: Implement getGroundItemsList()
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 3, 2016
1 parent 07d11b4 commit d66c3a2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
34 changes: 33 additions & 1 deletion engines/wage/script.cpp
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions engines/wage/script.h
Expand Up @@ -168,6 +168,7 @@ class Script {
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();
Expand Down
12 changes: 12 additions & 0 deletions engines/wage/util.cpp
Expand Up @@ -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
1 change: 1 addition & 0 deletions engines/wage/wage.h
Expand Up @@ -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;

Expand Down

0 comments on commit d66c3a2

Please sign in to comment.