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

Method BattleUnit

src/Savegame/BattleUnit.cpp:50–109  ·  view source on GitHub ↗

* Initializes a BattleUnit from a Soldier * @param soldier Pointer to the Soldier. * @param faction Which faction the units belongs to. */

Source from the content-addressed store, hash-verified

48 * @param faction Which faction the units belongs to.
49 */
50BattleUnit::BattleUnit(Soldier *soldier, UnitFaction faction) : _faction(faction), _originalFaction(faction), _killedBy(faction), _id(0), _pos(Position()), _tile(0),
51 _lastPos(Position()), _direction(0), _toDirection(0), _directionTurret(0), _toDirectionTurret(0),
52 _verticalDirection(0), _status(STATUS_STANDING), _walkPhase(0), _fallPhase(0), _kneeled(false), _floating(false),
53 _dontReselect(false), _fire(0), _currentAIState(0), _visible(false), _cacheInvalid(true),
54 _expBravery(0), _expReactions(0), _expFiring(0), _expThrowing(0), _expPsiSkill(0), _expMelee(0),
55 _motionPoints(0), _kills(0), _hitByFire(false), _moraleRestored(0), _coverReserve(0), _charging(0),
56 _turnsSinceSpotted(255), _geoscapeSoldier(soldier), _unitRules(0), _rankInt(-1), _turretType(-1), _hidingForTurn(false)
57{
58 _name = soldier->getName(true);
59 _id = soldier->getId();
60 _type = "SOLDIER";
61 _rank = soldier->getRankString();
62 _stats = *soldier->getCurrentStats();
63 _standHeight = soldier->getRules()->getStandHeight();
64 _kneelHeight = soldier->getRules()->getKneelHeight();
65 _floatHeight = soldier->getRules()->getFloatHeight();
66 _deathSound = 0; // this one is hardcoded
67 _aggroSound = -1;
68 _moveSound = -1; // this one is hardcoded
69 _intelligence = 2;
70 _aggression = 1;
71 _specab = SPECAB_NONE;
72 _armor = soldier->getArmor();
73 _stats += *_armor->getStats(); // armors may modify effective stats
74 _loftempsSet = _armor->getLoftempsSet();
75 _gender = soldier->getGender();
76 _faceDirection = -1;
77
78 int rankbonus = 0;
79
80 switch (soldier->getRank())
81 {
82 case RANK_SERGEANT: rankbonus = 1; break;
83 case RANK_CAPTAIN: rankbonus = 3; break;
84 case RANK_COLONEL: rankbonus = 6; break;
85 case RANK_COMMANDER: rankbonus = 10; break;
86 default: rankbonus = 0; break;
87 }
88
89 _value = 20 + soldier->getMissions() + rankbonus;
90
91 _tu = _stats.tu;
92 _energy = _stats.stamina;
93 _health = _stats.health;
94 _morale = 100;
95 _stunlevel = 0;
96 _currentArmor[SIDE_FRONT] = _armor->getFrontArmor();
97 _currentArmor[SIDE_LEFT] = _armor->getSideArmor();
98 _currentArmor[SIDE_RIGHT] = _armor->getSideArmor();
99 _currentArmor[SIDE_REAR] = _armor->getRearArmor();
100 _currentArmor[SIDE_UNDER] = _armor->getUnderArmor();
101 for (int i = 0; i < 6; ++i)
102 _fatalWounds[i] = 0;
103 for (int i = 0; i < 5; ++i)
104 _cache[i] = 0;
105
106 _activeHand = "STR_RIGHT_HAND";
107

Callers

nothing calls this directly

Calls 15

getLoftempsSetMethod · 0.80
getMissionsMethod · 0.80
getFrontArmorMethod · 0.80
getSideArmorMethod · 0.80
getRearArmorMethod · 0.80
getUnderArmorMethod · 0.80
getRaceMethod · 0.80
PositionClass · 0.70
getNameMethod · 0.45
getIdMethod · 0.45
getRankStringMethod · 0.45
getCurrentStatsMethod · 0.45

Tested by

no test coverage detected