2016-09-25 16:45:22 +00:00
|
|
|
#include "CPlayerEnergyDrain.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-12-19 18:27:58 +00:00
|
|
|
CPlayerEnergyDrain::CPlayerEnergyDrain(u32 capacity) { x0_sources.reserve(capacity); }
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2016-12-19 18:27:58 +00:00
|
|
|
void CPlayerEnergyDrain::AddEnergyDrainSource(TUniqueId id, float intensity) { x0_sources.emplace_back(id, intensity); }
|
2016-09-25 16:45:22 +00:00
|
|
|
|
|
|
|
void CPlayerEnergyDrain::RemoveEnergyDrainSource(TUniqueId id)
|
|
|
|
{
|
|
|
|
auto it = std::lower_bound(x0_sources.begin(), x0_sources.end(), CEnergyDrainSource(id, 0.f));
|
|
|
|
if (it != x0_sources.end())
|
|
|
|
x0_sources.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
float CPlayerEnergyDrain::GetEnergyDrainIntensity() const
|
|
|
|
{
|
|
|
|
float intensity = 0.f;
|
|
|
|
|
|
|
|
for (const CEnergyDrainSource& src : x0_sources)
|
|
|
|
intensity += src.GetEnergyDrainIntensity();
|
|
|
|
|
|
|
|
return intensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerEnergyDrain::ProcessEnergyDrain(const CStateManager& mgr, float dt)
|
|
|
|
{
|
|
|
|
auto it = x0_sources.begin();
|
|
|
|
|
|
|
|
for (; it != x0_sources.end(); ++it)
|
|
|
|
{
|
|
|
|
if (mgr.GetObjectById((*it).GetEnergyDrainSourceId()) == nullptr)
|
|
|
|
RemoveEnergyDrainSource((*it).GetEnergyDrainSourceId());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x0_sources.empty())
|
|
|
|
x10_energyDrainTime = 0.f;
|
|
|
|
else
|
|
|
|
x10_energyDrainTime += dt;
|
|
|
|
}
|
|
|
|
}
|