Actor *PlayerAI::chooseFromInventory(Actor *me, string filter) { static const int INV_WIDTH = 50; static const int INV_HEIGHT = 28; static TCODConsole con(INV_WIDTH, INV_HEIGHT); string title = ""; // determine title of menu based on filter type. defaults to "inventory" if (filter == "") title = "inventory"; else title = filter; con.setDefaultForeground(TCODColor(200, 180, 50)); con.printFrame(0, 0, INV_WIDTH, INV_HEIGHT, true, TCOD_BKGND_DEFAULT, title.c_str()); con.setDefaultForeground(TCODColor::white); int shortcut = 'a'; int y = 1; TCODList<Actor *> inventory = me->getContainer()->getInventory(); Actor *item; for (Actor **iter = inventory.begin(); iter != inventory.end(); iter++) { item = *iter; if (item == NULL) continue; // apply necessary filters if (filter == "equipment") { if (!item->isEquipment()) continue; } else if (filter == "equipped") { if (!me->getEquipment()->isEquipped(me, item)) continue; } string itemName = item->getName(); if (me->getEquipment()->isEquipped(me, item)) itemName += " [equipped]"; con.print(2, y, "(%c) - %s", shortcut, itemName.c_str()); y++; shortcut++; } TCODConsole::blit(&con, 0, 0, INV_WIDTH, INV_HEIGHT, TCODConsole::root, engine.getScreenWidth() / 2 - INV_WIDTH / 2, engine.getScreenHeight() / 2 - INV_HEIGHT / 2); TCODConsole::flush(); TCOD_key_t key; TCODSystem::waitForEvent(TCOD_EVENT_KEY_PRESS, &key, NULL, true); if (key.vk == TCODK_CHAR) { int itemIndex = key.c - 'a'; if (itemIndex >= 0 && itemIndex < inventory.size()) return inventory.get(itemIndex); } return NULL; }
bool TCODBsp::traverseLevelOrder(ITCODBspCallback *listener, void *userData) { TCODList<TCODBsp *> stack; stack.push(this); while ( ! stack.isEmpty() ) { TCODBsp *node=stack.get(0); stack.remove(node); if ( node->getLeft() ) stack.push(node->getLeft()); if ( node->getRight() ) stack.push(node->getRight()); if (!listener->visitNode(node,userData)) return false; } return true; }