2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CPlayerEnergyDrain.hpp"
|
|
|
|
|
2020-04-02 07:41:18 +00:00
|
|
|
#include <numeric>
|
|
|
|
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2020-03-12 14:01:28 +00:00
|
|
|
CPlayerEnergyDrain::CPlayerEnergyDrain(u32 numSources) { x0_sources.reserve(numSources); }
|
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
|
|
|
|
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);
|
2016-09-25 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CPlayerEnergyDrain::GetEnergyDrainIntensity() const {
|
2020-04-02 07:41:18 +00:00
|
|
|
return std::accumulate(x0_sources.cbegin(), x0_sources.cend(), 0.0f,
|
|
|
|
[](float value, const auto& src) { return value + src.GetEnergyDrainIntensity(); });
|
2016-09-25 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CPlayerEnergyDrain::ProcessEnergyDrain(const CStateManager& mgr, float dt) {
|
|
|
|
auto it = x0_sources.begin();
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (; it != x0_sources.end(); ++it) {
|
|
|
|
if (mgr.GetObjectById((*it).GetEnergyDrainSourceId()) == nullptr)
|
|
|
|
RemoveEnergyDrainSource((*it).GetEnergyDrainSourceId());
|
|
|
|
}
|
2016-09-25 16:45:22 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x0_sources.empty())
|
|
|
|
x10_energyDrainTime = 0.f;
|
|
|
|
else
|
|
|
|
x10_energyDrainTime += dt;
|
2016-09-25 16:45:22 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|