metaforce/Runtime/World/CPlayerEnergyDrain.cpp

41 lines
1.2 KiB
C++
Raw Normal View History

#include "Runtime/World/CPlayerEnergyDrain.hpp"
#include "Runtime/CStateManager.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
CPlayerEnergyDrain::CPlayerEnergyDrain(u32 capacity) { x0_sources.reserve(capacity); }
void CPlayerEnergyDrain::AddEnergyDrainSource(TUniqueId id, float intensity) { x0_sources.emplace_back(id, intensity); }
2018-12-08 05:30:43 +00:00
void CPlayerEnergyDrain::RemoveEnergyDrainSource(TUniqueId id) {
auto it = rstl::binary_find(x0_sources.begin(), x0_sources.end(), id,
[](const CEnergyDrainSource& item) { return item.GetEnergyDrainSourceId(); });
if (it != x0_sources.end())
x0_sources.erase(it);
}
2018-12-08 05:30:43 +00:00
float CPlayerEnergyDrain::GetEnergyDrainIntensity() const {
float intensity = 0.f;
2018-12-08 05:30:43 +00:00
for (const CEnergyDrainSource& src : x0_sources)
intensity += src.GetEnergyDrainIntensity();
2018-12-08 05:30:43 +00:00
return intensity;
}
2018-12-08 05:30:43 +00:00
void CPlayerEnergyDrain::ProcessEnergyDrain(const CStateManager& mgr, float dt) {
auto it = x0_sources.begin();
2018-12-08 05:30:43 +00:00
for (; it != x0_sources.end(); ++it) {
if (mgr.GetObjectById((*it).GetEnergyDrainSourceId()) == nullptr)
RemoveEnergyDrainSource((*it).GetEnergyDrainSourceId());
}
2018-12-08 05:30:43 +00:00
if (x0_sources.empty())
x10_energyDrainTime = 0.f;
else
x10_energyDrainTime += dt;
}
2018-12-08 05:30:43 +00:00
} // namespace urde