diff options
Diffstat (limited to 'frontend/cmd/put.cpp')
-rw-r--r-- | frontend/cmd/put.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/frontend/cmd/put.cpp b/frontend/cmd/put.cpp index 7f54c3b..acd4981 100644 --- a/frontend/cmd/put.cpp +++ b/frontend/cmd/put.cpp @@ -1,5 +1,5 @@ #include "../GameController.h" -#include "../strings.h" +#include "../util.h" #include "backend/Exception.h" #include "backend/print.h" @@ -11,15 +11,14 @@ using namespace std; void GameController::cmd_put(string & target_name) { Player & player = this->dungeon->get_player(); Location & location = player.get_location(); - for (Object * object : player.inventory) { - if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue; - lprtf("Je legt %s neer op de locatie %s.\n", object->get_displayname().c_str(), location.get_name().c_str()); - player.inventory.remove(object); - location.add_visible_object(object); - return; - } + auto it = find_if_range(player.inventory.range(), by_name_case_insensitive(target_name)); + if (!it) + throw Exception("object \"%s\" niet gevonden", target_name.c_str()); + Object & object = **it; - throw Exception("object \"%s\" niet gevonden", target_name.c_str()); + lprtf("Je legt %s neer op de locatie %s.\n", object.get_displayname().c_str(), location.get_name().c_str()); + player.inventory.remove(&object); + location.add_visible_object(&object); } |