aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/put.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/cmd/put.cpp')
-rw-r--r--frontend/cmd/put.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/frontend/cmd/put.cpp b/frontend/cmd/put.cpp
index 5460b02..dabac19 100644
--- a/frontend/cmd/put.cpp
+++ b/frontend/cmd/put.cpp
@@ -1,6 +1,4 @@
-#include <algorithm>
-
-#include "../Player.h"
+#include "../GameController.h"
#include "../strings.h"
#include "backend/print.h"
@@ -8,18 +6,17 @@
using namespace std;
-FollowupAction Player::cmd_put(string & target_name) {
- auto el = find_if(this->inventory.begin(), this->inventory.end(), [target_name](const auto & object) -> bool {
- return str_lower(object->get_name().c_str()) == str_lower(target_name);
- });
- if (el == this->inventory.end()) {
- lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str());
+FollowupAction GameController::cmd_put(string & target_name) {
+ Location & location = this->player.get_location();
+ for (Object * object : this->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());
+ this->player.inventory.remove(object);
+ location.add_visible_object(object);
return FollowupAction::NONE;
}
-
- lprtf("Je legt %s neer op de locatie %s.\n", (*el)->get_displayname().c_str(), this->location.get_name().c_str());
- this->location.add_visible_object((*el).release());
- this->inventory.erase(el);
+ lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str());
return FollowupAction::NONE;
}