1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include "../GameController.h"
#include "../strings.h"
#include "../util.h"
#include "backend/Exception.h"
#include "backend/print.h"
#include "backend/Location.h"
#include "backend/Dungeon.h"
using namespace std;
void GameController::cmd_view(string & target) {
if (target.size() == 0)
throw Exception("gebruik: Bekijk <Zelf|VIJHAND|OBJECT>");
Player & player = this->dungeon->get_player();
Location & location = player.get_location();
// view self
if (str_lower(target) == "zelf") {
lprtf("Je hebt %d levenspunten.\n", player.get_health());
lprtf("Je hebt een aanvalskans van %.0f%%.\n", player.get_attack() * 100);
if (player.weapon == nullptr)
lprtf("Je hebt geen wapen vast.\n");
else
lprtf("Je hebt het volgende wapen vast: %s.\n", player.weapon->get_displayname().c_str());
if (player.armor == nullptr)
lprtf("Je draagt geen wapenrusting.\n");
else
lprtf("Je draagt de volgende wapenrusting: %s.\n", player.armor->get_displayname().c_str());
lprtf("Je hebt %u goundstuk%s.\n", player.gold, player.gold == 1 ? "" : "ken");
size_t items = player.inventory.size();
lprtf("Je hebt %d %s%s\n", items, items == 1 ? "overig object" : "overige objecten", items > 0 ? ":" : ".");
for (auto & object : player.inventory) {
lprtf("- %s\n", object->get_displayname().c_str());
}
return;
}
// try to find visible object in location or inventory
auto object_it = find_if_range(location.get_visible_objects(), by_name_case_insensitive(target));
if (!object_it) object_it = find_if_range(player.inventory.range(), by_name_case_insensitive(target));
if (!!object_it) {
Object & object = **object_it;
lprtf("%s\n", object.get_description().c_str());
return;
}
// try to find enemy by name
auto enemy_it = find_if_range(location.get_enemies(), by_name_case_insensitive(target));
if (!!enemy_it) {
Enemy & enemy = **enemy_it;
lprtf("%s\n", enemy.get_description().c_str());
unsigned enemy_health = enemy.get_health();
lprtf("%s heeft %u levenspunten.\n", enemy.get_name().c_str(), enemy_health);
if (!enemy.is_dead())
return;
bool snatched = false;
for (Object * object : enemy.get_hidden_objects()) {
if (!snatched) lprtf("%s had de volgende voorwerpen:\n", enemy.get_displayname().c_str());
lprtf("- %s\n", object->get_displayname().c_str());
enemy.remove_hidden_object(object);
location.add_visible_object(object);
snatched = true;
}
return;
}
throw Exception("geen entiteit met naam \"%s\" gevonden", target.c_str());
}
|