From f8d8d7499ba4433678db2a68fb1cae74448ca31e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 31 Oct 2024 14:14:09 +0100 Subject: make ListIterator continue working on a changing list --- frontend/cmd/get.cpp | 4 ++-- frontend/cmd/search.cpp | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'frontend/cmd') diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp index 0d6d12c..359a5c5 100644 --- a/frontend/cmd/get.cpp +++ b/frontend/cmd/get.cpp @@ -12,13 +12,13 @@ FollowupAction Player::cmd_get(string & target_name) { for (Object * object : this->location.get_visible_objects()) { if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue; target = unique_ptr(object); + this->location.remove_visible_object(object); break; } if (target == nullptr) { lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str()); return FollowupAction::NONE; } - this->location.remove_visible_object(target.get()); // gold objects are collected and (implicitly) destroyed GoldObject * gold = dynamic_cast(target.get()); @@ -30,7 +30,7 @@ FollowupAction Player::cmd_get(string & target_name) { } // other objects go in the inventory - lprtf("Je voegt %s toe aan je bezit.\n", target->get_displayname().c_str()); + lprtf("Je voegt %s toe aan je bezit.\n", target->get_name().c_str()); this->inventory.push_back(std::move(target)); return FollowupAction::NONE; } diff --git a/frontend/cmd/search.cpp b/frontend/cmd/search.cpp index 16e4592..f10709a 100644 --- a/frontend/cmd/search.cpp +++ b/frontend/cmd/search.cpp @@ -7,17 +7,14 @@ using namespace std; FollowupAction Player::cmd_search(string &) { bool found = false; - List to_unhide; for (Object * object : this->location.get_hidden_objects()) { if (!found) lprtf("Je vindt:\n"); lprtf("- %s\n", object->get_displayname().c_str()); - to_unhide.push_back(object); + this->location.unhide_object(object); found = true; } if (!found) lprtf("Je hebt niks gevonden.\n"); - for (Object * object : to_unhide) - this->location.unhide_object(object); return FollowupAction::UPDATE; } -- cgit v1.2.3