aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/put.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 13:18:50 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 13:18:50 +0100
commit5a675c5e6833e98b92b55396594bc0d607b98903 (patch)
treeb252fafe921e7734a13d796b950e5ab817a22a1f /frontend/cmd/put.cpp
parent671a25463419691bc6c8d11bd57d932bdea9632b (diff)
clean up code + implement teleport consumable
Diffstat (limited to 'frontend/cmd/put.cpp')
-rw-r--r--frontend/cmd/put.cpp17
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);
}