aboutsummaryrefslogtreecommitdiff
path: root/backend/Location.h
blob: 6f701ade47ed1256d7c47fb97901f4cad43afa32 (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
#pragma once

#include "PtrList.h"
#include "ListIterator.h"
#include "String.h"
#include "Enemy.h"
#include "Object.h"

class Location;

enum Direction {
	NORTH = 0,
	EAST = 1,
	SOUTH = 2,
	WEST = 3,
};
static constexpr const Direction DIRECTIONS[] = { NORTH, EAST, SOUTH, WEST };
Direction operator - (const Direction &);

Direction random_direction();
Direction random_direction(const Location &);

class Location {
public:
	void set_name(const String & name);
	const String & get_name() const;

	void set_description(const String & description);
	const String & get_description() const;

	void set_exit(Direction dir, Location * location = nullptr);
	Location * get_exit(Direction dir) const;

	void add_visible_object(Object *);
	void remove_visible_object(Object *);
	ListRange<Object *> get_visible_objects();

	void add_hidden_object(Object *);
	void remove_hidden_object(Object *);
	ListRange<Object *> get_hidden_objects();

	void hide_object(Object *);
	void unhide_object(Object *);

	void add_enemy(Enemy *);
	void remove_enemy(Enemy *);
	ListRange<Enemy *> get_enemies();

private:
	friend class LocationFactory;
	Location(const String & name, const String & description);
public:
	virtual ~Location() = default;

private:
	String name;
	String description;
	PtrList<Enemy> enemies;
	PtrList<Object> hidden_objects;
	PtrList<Object> visible_objects;

	Location * edges[4] = {
		nullptr,
		nullptr,
		nullptr,
		nullptr,
	};
};