blob: c036c7b7b9d3e3678187640a6f624dbb8d067ce2 (
plain)
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
|
#include "RNG.h"
#include "Location.h"
#include "ListIterator.h"
#include "Enemy.h"
#include "Object.h"
#include "util.h"
Direction random_direction() {
return DIRECTIONS[RNG::get().rand_int(4)];
}
Direction random_direction(const Location & location) {
List<Direction> valid = {};
for (Direction direction : DIRECTIONS) {
if (location.get_exit(direction) == nullptr) continue;
valid.push_back(direction);
}
return valid[RNG::get().rand_int(valid.size())];
}
Location::Location(const String & name, const String & description) : name(name), description(description) { }
void Location::set_name(const String & name) { this->name = name; }
const String & Location::get_name() const { return this->name; }
void Location::set_description(const String & description) { this->description = description; }
const String & Location::get_description() const { return this->description; }
void Location::set_exit(Direction dir, Location * location) {
this->edges[dir] = location;
}
Location * Location::get_exit(Direction dir) const {
return this->edges[dir];
}
void Location::add_visible_object(Object * object) {
this->visible_objects.push_back(object);
}
void Location::remove_visible_object(Object * object) {
this->visible_objects.remove(object);
}
ListRange<Object *> Location::get_visible_objects() {
return this->visible_objects.range();
}
void Location::add_hidden_object(Object * object) {
this->hidden_objects.push_back(object);
}
void Location::remove_hidden_object(Object * object) {
this->hidden_objects.remove(object);
}
ListRange<Object *> Location::get_hidden_objects() {
return this->hidden_objects.range();
}
void Location::hide_object(Object * object) {
this->visible_objects.remove(object);
this->hidden_objects.push_back(object);
}
void Location::unhide_object(Object * object) {
this->hidden_objects.remove(object);
this->visible_objects.push_back(object);
}
void Location::add_enemy(Enemy * enemy) {
this->enemies.push_back(enemy);
}
void Location::remove_enemy(Enemy * enemy) {
this->enemies.remove(enemy);
}
ListRange<Enemy *> Location::get_enemies() {
return this->enemies.range();
}
|