-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.cpp
More file actions
63 lines (55 loc) · 1.11 KB
/
Copy pathentity.cpp
File metadata and controls
63 lines (55 loc) · 1.11 KB
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
#include "entity.h"
#include "world.h"
Entity::Entity
(
World& world,
EntityType entity_type,
const std::string& name,
const std::string& description,
int health,
float damage_multiplier,
Item* key
)
: world(&world),
entity_type(entity_type),
name(name),
description(description),
starting_health(health),
health(health),
damage_multiplier(damage_multiplier),
key(key)
{
world.entities.push_back(this);
}
void Entity::Update() {}
void Entity::Inspect() const
{
std::cout << name << ":\n";
std::cout << " " << description << "\n";
}
void Entity::Damage(int damage)
{
const int final_damage = damage * damage_multiplier;
health = std::max(0, health - final_damage);
}
Entity* Entity::SearchEntity(const std::string & name) const
{
for (Entity* const entity : contains)
{
if (CaseInsensitiveCompare(entity->name, name))
{
return entity;
}
if (entity->key != nullptr)
{
// The entity is closed with a key, so we can't look inside
continue;
}
Entity* const child_entity = entity->SearchEntity(name);
if (child_entity != nullptr)
{
return child_entity;
}
}
return nullptr;
}