MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / processExperience

Method processExperience

game/state/battle/battleunit.cpp:4106–4186  ·  view source on GitHub ↗

FIXME: Ensure correct For now, using X-Com 1/2 system of primary/secondary stats, except psi which assumes it's same 3x limit that is applied when using psi gym

Source from the content-addressed store, hash-verified

4104// For now, using X-Com 1/2 system of primary/secondary stats,
4105// except psi which assumes it's same 3x limit that is applied when using psi gym
4106void BattleUnit::processExperience(GameState &state)
4107{
4108 int secondaryXP = experiencePoints.accuracy + experiencePoints.bravery +
4109 experiencePoints.psi_attack + experiencePoints.psi_energy +
4110 experiencePoints.reactions;
4111 if (agent->current_stats.accuracy < 100)
4112 {
4113 agent->current_stats.accuracy += rollForPrimaryStat(
4114 state, experiencePoints.accuracy * agent->type->improvementPercentagePhysical / 100);
4115 }
4116 if (agent->current_stats.psi_attack < 100 &&
4117 agent->current_stats.psi_attack < agent->initial_stats.psi_attack * 3)
4118 {
4119 agent->current_stats.psi_attack += rollForPrimaryStat(
4120 state, experiencePoints.psi_attack * agent->type->improvementPercentagePsi / 100);
4121 }
4122 if (agent->current_stats.psi_energy < 100 &&
4123 agent->current_stats.psi_energy < agent->initial_stats.psi_energy * 3)
4124 {
4125 agent->current_stats.psi_energy += rollForPrimaryStat(
4126 state, experiencePoints.psi_energy * agent->type->improvementPercentagePsi / 100);
4127 }
4128 if (agent->current_stats.reactions < 100)
4129 {
4130 if (state.current_battle->mode == Battle::Mode::TurnBased)
4131 {
4132 agent->current_stats.reactions +=
4133 rollForPrimaryStat(state, experiencePoints.reactions *
4134 agent->type->improvementPercentagePhysical / 100);
4135 }
4136 else
4137 {
4138 agent->current_stats.reactions += rollForPrimaryStat(
4139 state, std::min(3, secondaryXP * agent->type->improvementPercentagePhysical / 100));
4140 }
4141 }
4142 if (agent->current_stats.bravery < 100)
4143 {
4144 agent->current_stats.bravery +=
4145 10 * randBoundsExclusive(state.rng, 0, 99) <
4146 experiencePoints.bravery * 9 * agent->type->improvementPercentagePhysical / 100;
4147 }
4148 // Units with slower improvement rates need to gain more xp to have a chance to improve
4149 // >= 100% improvement rate need just 1 xp
4150 // 50% improvement rate needs 2 xp
4151 // 10% improvement rate needs 10 xp
4152 // ---
4153 // Percentile increase also affected (units with 100% improvement gain 10% of their missing
4154 // stat, units with 50% gain 5% etc)
4155 if (agent->type->improvementPercentagePhysical > 0 &&
4156 secondaryXP > 100 / agent->type->improvementPercentagePhysical)
4157 {
4158 if (agent->current_stats.health < 100)
4159 {
4160 int healthBoost = randBoundsInclusive(state.rng, 0, 2) +
4161 (100 - agent->current_stats.health) / 10 *
4162 agent->type->improvementPercentagePhysical / 100;
4163 agent->current_stats.health += healthBoost;

Callers 1

finishBattleMethod · 0.80

Calls 3

randBoundsExclusiveFunction · 0.85
randBoundsInclusiveFunction · 0.85
updateModifiedStatsMethod · 0.80

Tested by

no test coverage detected