#include #include "backend/ConsumableObject.h" #include "backend/Exception.h" #include "backend/print.h" #include "../GameController.h" #include "../strings.h" using namespace std; void GameController::cmd_use(string & target_name) { Player & player = this->dungeon->get_player(); Location & location = player.get_location(); auto it = find_if(player.inventory.begin(), player.inventory.end(), [target_name] (Object * object) { return str_lower(object->get_name().c_str()) == str_lower(target_name); } ); if (!it) throw Exception("object \"%s\" niet gevonden", target_name.c_str()); auto consumable = unique_ptr(dynamic_cast(*it)); if (consumable == nullptr) throw Exception("%s is niet consumeerbaar", (*it)->get_name().c_str()); lprtf("Je drinkt %s.\n", consumable->get_displayname().c_str()); player.inventory.remove(consumable.get()); consumable->consume(player); }