aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/get.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/cmd/get.cpp')
-rw-r--r--frontend/cmd/get.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/frontend/cmd/get.cpp b/frontend/cmd/get.cpp
index 652e989..358bf1f 100644
--- a/frontend/cmd/get.cpp
+++ b/frontend/cmd/get.cpp
@@ -2,15 +2,18 @@
#include "../GameController.h"
#include "../strings.h"
+#include "../Exception.h"
#include "backend/print.h"
#include "backend/GoldObject.h"
#include "backend/Location.h"
+#include "backend/Dungeon.h"
using namespace std;
-FollowupAction GameController::cmd_get(string & target_name) {
- Location & location = this->player.get_location();
+void GameController::cmd_get(string & target_name) {
+ Player & player = this->dungeon->get_player();
+ Location & location = player.get_location();
unique_ptr<Object> target = nullptr;
for (Object * object : location.get_visible_objects()) {
@@ -19,23 +22,20 @@ FollowupAction GameController::cmd_get(string & target_name) {
location.remove_visible_object(object);
break;
}
- if (target == nullptr) {
- lprtf("Object \"%s\" niet gevonden.\n", target_name.c_str());
- return FollowupAction::NONE;
- }
+ if (target == nullptr)
+ throw Exception("Object \"%s\" niet gevonden.", target_name.c_str());
// gold objects are collected and (implicitly) destroyed
GoldObject * gold = dynamic_cast<GoldObject *>(target.get());
if (gold != nullptr) {
int count = gold->get_count();
- this->player.gold += count;
+ player.gold += count;
lprtf("Je bent %d goudstuk%s rijker.\n", count, count == 1 ? "" : "ken");
- return FollowupAction::NONE;
+ return;
}
// other objects go in the inventory
lprtf("Je voegt %s toe aan je bezit.\n", target->get_name().c_str());
- this->player.inventory.push_back(target.release());
- return FollowupAction::NONE;
+ player.inventory.push_back(target.release());
}