aboutsummaryrefslogtreecommitdiff
path: root/backend/Enemy.cpp
blob: c4bfff2c457d0ee3e7447228af29f0580910be6e (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
#include "Enemy.h"
#include "util.h"

Enemy::Enemy(const String & name, const String & description) : name(name), description(description) { }

void Enemy::set_name(const String & name) { this->name = name; }
const String & Enemy::get_name() const { return this->name; }

void Enemy::set_description(const String & description) { this->description = description; }
const String & Enemy::get_description() const { return this->description; }

void Enemy::set_attack(float attack_chance) { this->attack_chance = attack_chance; }
float Enemy::get_attack() const { return this->attack_chance; }

void Enemy::set_damage_min(int damage_min) { this->damage_min = damage_min; }
int Enemy::get_damage_min() const { return this->damage_min; }

void Enemy::set_damage_max(int damage_max) { this->damage_max = damage_max; }
int Enemy::get_damage_max() const { return this->damage_max; }

void Enemy::set_health(unsigned health_points) { this->health_points = health_points; }
unsigned Enemy::get_health() const { return this->health_points; }
void Enemy::take_damage(unsigned int dmg) {
	dmg = min(dmg, this->health_points);
	this->health_points -= dmg;
}
bool Enemy::is_dead() const {
	return this->health_points == 0;
}

void Enemy::add_hidden_object(Object * object) {
	this->hidden_objects.push_back(object);
}
void Enemy::remove_hidden_object(Object * object) {
	this->hidden_objects.remove(object);
}
ListRange<Object *> Enemy::get_hidden_objects() {
	return this->hidden_objects.range();
}

const String & Enemy::get_displayname() const {
	static String displayname;
	displayname = String::fmt("%s%s", this->name.c_str(), this->health_points == 0 ? " [verslagen]" : "");
	return displayname;
}