#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();
}