MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / prepareNewTurn

Method prepareNewTurn

src/Savegame/BattleUnit.cpp:1415–1496  ·  view source on GitHub ↗

* Prepare for a new turn. */

Source from the content-addressed store, hash-verified

1413 * Prepare for a new turn.
1414 */
1415void BattleUnit::prepareNewTurn()
1416{
1417 // revert to original faction
1418 _faction = _originalFaction;
1419
1420 _unitsSpottedThisTurn.clear();
1421
1422 // recover TUs
1423 int TURecovery = getStats()->tu;
1424 float encumbrance = (float)getStats()->strength / (float)getCarriedWeight();
1425 if (encumbrance < 1)
1426 {
1427 TURecovery = int(encumbrance * TURecovery);
1428 }
1429 // Each fatal wound to the left or right leg reduces the soldier's TUs by 10%.
1430 TURecovery -= (TURecovery * (_fatalWounds[BODYPART_LEFTLEG]+_fatalWounds[BODYPART_RIGHTLEG] * 10))/100;
1431 setTimeUnits(TURecovery);
1432
1433 // recover energy
1434 if (!isOut())
1435 {
1436 int ENRecovery;
1437 if (_geoscapeSoldier != 0)
1438 {
1439 ENRecovery = _geoscapeSoldier->getInitStats()->tu / 3;
1440 }
1441 else
1442 {
1443 ENRecovery = _unitRules->getEnergyRecovery();
1444 }
1445 // Each fatal wound to the body reduces the soldier's energy recovery by 10%.
1446 ENRecovery -= (_energy * (_fatalWounds[BODYPART_TORSO] * 10))/100;
1447 _energy += ENRecovery;
1448 if (_energy > getStats()->stamina)
1449 _energy = getStats()->stamina;
1450 }
1451
1452 // suffer from fatal wounds
1453 _health -= getFatalWounds();
1454
1455 // suffer from fire
1456 if (!_hitByFire && _fire > 0)
1457 {
1458 _health -= _armor->getDamageModifier(DT_IN) * RNG::generate(5, 10);
1459 _fire--;
1460 }
1461
1462 if (_health < 0)
1463 _health = 0;
1464
1465 // if unit is dead, AI state should be gone
1466 if (_health == 0 && _currentAIState)
1467 {
1468 _currentAIState->exit();
1469 delete _currentAIState;
1470 _currentAIState = 0;
1471 }
1472

Callers

nothing calls this directly

Calls 6

generateFunction · 0.85
getInitStatsMethod · 0.80
getDamageModifierMethod · 0.80
clearMethod · 0.45
getEnergyRecoveryMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected