forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthSystem.cpp
More file actions
57 lines (50 loc) · 1.21 KB
/
HealthSystem.cpp
File metadata and controls
57 lines (50 loc) · 1.21 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
#include "HealthSystem.hpp"
HealthSystem::HealthSystem(EntitySystem& ent)
: entities_{ent}, regen_timer_{0}, regen_period_{1000.f}, // TODO: Time period in a config!
regen_{false}
{ /* DUMMY BODY */ }
void HealthSystem::update(Ogre::Real delta)
{
update_regen(delta);
for(auto& ent : entities_.get_component_container<HealthComponent>())
{
if(!ent.second.alive)
{
auto product_component = entities_.get_component<ProductComponent>(ent.first);
if(product_component)
{
auto production_component = entities_.get_component<ProductionComponent>(
product_component->producer
);
if(production_component && production_component->curr_produced > 0)
--production_component->curr_produced;
}
DestructorHelper::destroy(entities_, ent.first);
}
else if(regen_)
HealthHelper::add_health(entities_, ent.first, ent.second.regen);
}
}
void HealthSystem::update_regen(Ogre::Real delta)
{
if(regen_)
{
regen_ = false;
return;
}
if(regen_timer_ > regen_period_)
{
regen_ = true;
regen_timer_ = 0;
}
else
regen_timer_ += delta;
}
void HealthSystem::set_regen_period(Ogre::Real val)
{
regen_period_ = val;
}
Ogre::Real HealthSystem::get_regen_period() const
{
return regen_period_;
}