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

Method updateHourly

game/state/shared/agent.cpp:1043–1100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1041void Agent::updateDaily(GameState &state [[maybe_unused]]) { recentlyFought = false; }
1042
1043void Agent::updateHourly(GameState &state)
1044{
1045 StateRef<Base> base;
1046 if (currentBuilding == homeBuilding)
1047 {
1048 // agent is in home building
1049 base = currentBuilding->base;
1050 }
1051 else if (currentVehicle && currentVehicle->currentBuilding == homeBuilding)
1052 {
1053 // agent is in a vehicle stationed in home building
1054 base = currentVehicle->currentBuilding->base;
1055 }
1056
1057 if (!base)
1058 {
1059 // not in a base
1060 return;
1061 }
1062
1063 // Heal
1064 if (modified_stats.health < current_stats.health && !recentlyFought)
1065 {
1066 int usage = base->getUsage(state, FacilityType::Capacity::Medical);
1067 if (usage < 999)
1068 {
1069 usage = std::max(100, usage);
1070 // As per Roger Wong's guide, healing is 0.8 points an hour
1071 healingProgress += 80.0f / (float)usage;
1072 if (healingProgress > 1.0f)
1073 {
1074 healingProgress -= 1.0f;
1075 modified_stats.health++;
1076 }
1077 }
1078 }
1079 // Train
1080 if (trainingAssignment != TrainingAssignment::None)
1081 {
1082 int usage = base->getUsage(state, trainingAssignment == TrainingAssignment::Physical
1083 ? FacilityType::Capacity::Training
1084 : FacilityType::Capacity::Psi);
1085 if (usage < 999)
1086 {
1087 usage = std::max(100, usage);
1088 // As per Roger Wong's guide
1089 float mult = config().getFloat("OpenApoc.Cheat.StatGrowthMultiplier");
1090 if (trainingAssignment == TrainingAssignment::Physical)
1091 {
1092 trainPhysical(state, TICKS_PER_HOUR * 100 / usage * mult);
1093 }
1094 else
1095 {
1096 trainPsi(state, TICKS_PER_HOUR * 100 / usage * mult);
1097 }
1098 }
1099 }
1100}

Callers 1

updateEndOfHourMethod · 0.80

Calls 2

getUsageMethod · 0.80
getFloatMethod · 0.80

Tested by

no test coverage detected