aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/get.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 10:18:22 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 10:18:22 +0100
commit798948dbe6f012e194f053c4e862cf697f30b793 (patch)
tree32c71420d1188f98cfb41b6f0d9536c5fa4bf5a7 /frontend/cmd/get.cpp
parentd7012045bb61f117fb7b9c51ddd03e4c54f25fe6 (diff)
more WIP (move some Player things to backend)
Diffstat (limited to 'frontend/cmd/get.cpp')
-rw-r--r--frontend/cmd/get.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp
index 359a5c5..652e989 100644
--- a/frontend/cmd/get.cpp
+++ b/frontend/cmd/get.cpp
@@ -1,4 +1,6 @@
-#include "../Player.h"
+#include <memory>
+
+#include "../GameController.h"
#include "../strings.h"
#include "backend/print.h"
@@ -7,12 +9,14 @@
using namespace std;
-FollowupAction Player::cmd_get(string & target_name) {
+FollowupAction GameController::cmd_get(string & target_name) {
+ Location & location = this->player.get_location();
unique_ptr<Object> target = nullptr;
- for (Object * object : this->location.get_visible_objects()) {
+
+ for (Object * object : location.get_visible_objects()) {
if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue;
target = unique_ptr<Object>(object);
- this->location.remove_visible_object(object);
+ location.remove_visible_object(object);
break;
}
if (target == nullptr) {
@@ -24,14 +28,14 @@ FollowupAction Player::cmd_get(string & target_name) {
GoldObject * gold = dynamic_cast<GoldObject *>(target.get());
if (gold != nullptr) {
int count = gold->get_count();
- this->gold += count;
+ this->player.gold += count;
lprtf("Je bent %d goudstuk%s rijker.\n", count, count == 1 ? "" : "ken");
return FollowupAction::NONE;
}
// other objects go in the inventory
lprtf("Je voegt %s toe aan je bezit.\n", target->get_name().c_str());
- this->inventory.push_back(std::move(target));
+ this->player.inventory.push_back(target.release());
return FollowupAction::NONE;
}