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

Method getFiringAccuracy

src/Savegame/BattleUnit.cpp:1287–1321  ·  view source on GitHub ↗

* Calculate firing accuracy. * Formula = accuracyStat * weaponAccuracy * kneelingbonus(1.15) * one-handPenalty(0.8) * woundsPenalty(% health) * critWoundsPenalty (-10%/wound) * @param actionType * @param item * @return firing Accuracy */

Source from the content-addressed store, hash-verified

1285 * @return firing Accuracy
1286 */
1287int BattleUnit::getFiringAccuracy(BattleActionType actionType, BattleItem *item)
1288{
1289
1290 int weaponAcc = item->getRules()->getAccuracySnap();
1291 if (actionType == BA_AIMEDSHOT || actionType == BA_LAUNCH)
1292 weaponAcc = item->getRules()->getAccuracyAimed();
1293 else if (actionType == BA_AUTOSHOT)
1294 weaponAcc = item->getRules()->getAccuracyAuto();
1295 else if (actionType == BA_HIT || actionType == BA_STUN)
1296 {
1297 if (item->getRules()->isSkillApplied())
1298 {
1299 return (getStats()->melee * item->getRules()->getAccuracyMelee() / 100) * getAccuracyModifier(item) / 100;
1300 }
1301 return item->getRules()->getAccuracyMelee() * getAccuracyModifier(item) / 100;
1302 }
1303
1304 int result = getStats()->firing * weaponAcc / 100;
1305
1306 if (_kneeled)
1307 {
1308 result = result * 115 / 100;
1309 }
1310
1311 if (item->getRules()->isTwoHanded())
1312 {
1313 // two handed weapon, means one hand should be empty
1314 if (getItem("STR_RIGHT_HAND") != 0 && getItem("STR_LEFT_HAND") != 0)
1315 {
1316 result = result * 80 / 100;
1317 }
1318 }
1319
1320 return result * getAccuracyModifier(item) / 100;
1321}
1322
1323/**
1324 * To calculate firing accuracy. Takes health and fatal wounds into account.

Callers 5

addItemMethod · 0.80
drawTerrainMethod · 0.80
createNewProjectileMethod · 0.80
thinkMethod · 0.80
explodeMethod · 0.80

Calls 7

getAccuracySnapMethod · 0.80
getAccuracyAimedMethod · 0.80
getAccuracyAutoMethod · 0.80
isSkillAppliedMethod · 0.80
getAccuracyMeleeMethod · 0.80
isTwoHandedMethod · 0.80
getRulesMethod · 0.45

Tested by

no test coverage detected