#include #include #include "../GameController.h" #include "../strings.h" #include "../util.h" #include "backend/Exception.h" #include "backend/print.h" #include "backend/GoldObject.h" #include "backend/Location.h" #include "backend/Dungeon.h" using namespace std; void GameController::cmd_get(string & target_name) { Player & player = this->dungeon->get_player(); Location & location = player.get_location(); auto range = location.get_visible_objects(); auto it = find_if(range.begin(), range.end(), by_name_case_insensitive(target_name)); if (!it) throw Exception("object \"%s\" niet gevonden", target_name.c_str()); auto object = unique_ptr(*it); location.remove_visible_object(object.get()); // gold objects are collected and (implicitly) destroyed GoldObject * gold = dynamic_cast(object.get()); if (gold != nullptr) { int count = gold->get_count(); player.gold += count; lprtf("Je bent %d goudstuk%s rijker.\n", count, count == 1 ? "" : "ken"); return; } // other objects go in the inventory lprtf("Je voegt %s toe aan je bezit.\n", object->get_name().c_str()); player.inventory.push_back(object.release()); }