Hey everyone,
I'm attempting to write a seemingly simple routine that filters character experience by an intelligence-like character state. The state value will be a scaler ranging from 0 to 1. When experience is earned, the scaler represents how much of that experience is granted to the character, and the remaining experience goes toward repairing the state (scaled by a hardcoded value). Here's some quick code to demonstrate:
// some defines
real REPAIR_SCALER = xxxx;
// some known values
real input_experience = ?;
real char_state = 0 to 1;
// the (incorrect) code
real earned_experience = input_experience * char_state;
real repair_experience = input_experience - earned_experience;
char_state = min( 1.0, char_state + repair_experience * REPAIR_SCALER );
AddCharExperience( earned_experience );
SetCharState( char_state );
The problem with this approach is that there will be a significant difference between earning a bunch of small amounts of experience versus earning a single large amount of experience. Since the state that scales the experience is increasing each time its earned, each epsilon(?) of the experience is changing the amount of experience earned. I could mostly mitigate this issue by iterating through a loop and applying small amounts of experience per iteration, but I was hoping there is a more elegant solution. I've been playing around with pow() and exp(), but math isn't my strongest skill, and I'm having trouble coming up with anything.
If anyone has any advice, it will be greatly appreciated. Thank you.