| 2123 | } |
| 2124 | |
| 2125 | void BattleUnit::updateMorale(GameState &state, unsigned int ticks) |
| 2126 | { |
| 2127 | auto e1 = agent->getFirstItemInSlot(EquipmentSlotType::LeftHand); |
| 2128 | auto e2 = agent->getFirstItemInSlot(EquipmentSlotType::RightHand); |
| 2129 | |
| 2130 | if (moraleStateTicksRemaining > 0) |
| 2131 | { |
| 2132 | if (moraleStateTicksRemaining > ticks) |
| 2133 | { |
| 2134 | moraleStateTicksRemaining -= ticks; |
| 2135 | } |
| 2136 | else |
| 2137 | { |
| 2138 | // It seems in Apoc unit keeps panicking until reaches positive morale |
| 2139 | if (agent->modified_stats.morale >= 50) |
| 2140 | { |
| 2141 | moraleStateTicksRemaining = 0; |
| 2142 | moraleState = MoraleState::Normal; |
| 2143 | sendAgentEvent(state, GameEventType::AgentPanicOver, true); |
| 2144 | stopAttacking(); |
| 2145 | cancelMissions(state, true); |
| 2146 | aiList.reset(state, *this); |
| 2147 | } |
| 2148 | else |
| 2149 | { |
| 2150 | moraleStateTicksRemaining += TICKS_PER_LOWMORALE_STATE; |
| 2151 | moraleStateTicksRemaining -= ticks; |
| 2152 | agent->modified_stats.morale += 15; |
| 2153 | } |
| 2154 | } |
| 2155 | } |
| 2156 | else |
| 2157 | { |
| 2158 | moraleTicksAccumulated += ticks; |
| 2159 | while (moraleTicksAccumulated >= LOWMORALE_CHECK_INTERVAL) |
| 2160 | { |
| 2161 | moraleTicksAccumulated -= LOWMORALE_CHECK_INTERVAL; |
| 2162 | |
| 2163 | if (randBoundsExclusive(state.rng, 0, 100) >= 100 - 2 * agent->modified_stats.morale) |
| 2164 | { |
| 2165 | experiencePoints.bravery++; |
| 2166 | } |
| 2167 | else |
| 2168 | { |
| 2169 | moraleStateTicksRemaining = TICKS_PER_LOWMORALE_STATE; |
| 2170 | moraleState = (MoraleState)(randBoundsInclusive(state.rng, 1, 3)); |
| 2171 | agent->modified_stats.morale += 15; |
| 2172 | stopAttacking(); |
| 2173 | cancelMissions(state); |
| 2174 | aiList.reset(state, *this); |
| 2175 | // Notify |
| 2176 | switch (moraleState) |
| 2177 | { |
| 2178 | case MoraleState::PanicFreeze: |
| 2179 | sendAgentEvent(state, GameEventType::AgentFrozen, true); |
| 2180 | break; |
| 2181 | case MoraleState::PanicRun: |
| 2182 | sendAgentEvent(state, GameEventType::AgentPanicked, true); |
nothing calls this directly
no test coverage detected