-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRADEngine.cpp
More file actions
42 lines (33 loc) · 1.42 KB
/
Copy pathRADEngine.cpp
File metadata and controls
42 lines (33 loc) · 1.42 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
#include "RADEEngine.h"
#include <sstream>
void RADEEngine::LoadProfile(const RADEProfile& p) {
profile = p;
}
float RADEEngine::Smooth(float current, float target, float smoothing) const {
return current + (target - current) * smoothing;
}
float RADEEngine::Clamp(float value, float min, float max) const {
if (value < min) return min;
if (value > max) return max;
return value;
}
void RADEEngine::Update(const PlayerSkill& skill, Challenge& challenge) {
for (const auto& skillEntry : profile.links) {
const std::string& skillName = skillEntry.first;
float skillValue = skill.Get(skillName);
for (const auto& challengeEntry : skillEntry.second) {
const std::string& challengeName = challengeEntry.first;
float multiplier = challengeEntry.second;
float current = challenge.Get(challengeName);
float target = current + skillValue * multiplier;
float smoothed = Smooth(current, target, profile.smoothing);
float clamped = Clamp(smoothed, profile.clampMin, profile.clampMax);
challenge.Set(challengeName, clamped);
std::ostringstream oss;
oss << "Skill '" << skillName << "' (" << skillValue
<< ") -> Challenge '" << challengeName
<< "' updated to " << clamped;
logger.Log(oss.str());
}
}
}