Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove discrepancy between displayed and real accuracy #1427

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Battlescape/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ void Projectile::applyAccuracy(Position origin, Position *target, double accurac
{
int xdiff = origin.x - target->x;
int ydiff = origin.y - target->y;
double realDistance = sqrt((double)(xdiff*xdiff)+(double)(ydiff*ydiff));
int zdiff = origin.z - target->z;
double realDistance = std::ceil( sqrt( (double)(xdiff*xdiff + ydiff*ydiff + zdiff*zdiff) ));
// maxRange is the maximum range a projectile shall ever travel in voxel space
double maxRange = keepRange?realDistance:16*1000; // 1000 tiles
maxRange = _action.type == BA_HIT?46:maxRange; // up to 2 tiles diagonally (as in the case of reaper v reaper)
Expand All @@ -344,6 +345,7 @@ void Projectile::applyAccuracy(Position origin, Position *target, double accurac
if (_action.type != BA_THROW && _action.type != BA_HIT)
{
double modifier = 0.0;
double tilesDistance = std::ceil(realDistance / 16);
int upperLimit = weapon->getAimRange();
int lowerLimit = weapon->getMinRange();
if (Options::battleUFOExtenderAccuracy)
Expand All @@ -357,13 +359,13 @@ void Projectile::applyAccuracy(Position origin, Position *target, double accurac
upperLimit = weapon->getSnapRange();
}
}
if (realDistance / 16 < lowerLimit)
if (tilesDistance < lowerLimit)
{
modifier = (weapon->getDropoff() * (lowerLimit - realDistance / 16)) / 100;
modifier = (weapon->getDropoff() * (lowerLimit - tilesDistance)) / 100;
}
else if (upperLimit < realDistance / 16)
else if (upperLimit < tilesDistance)
{
modifier = (weapon->getDropoff() * (realDistance / 16 - upperLimit)) / 100;
modifier = (weapon->getDropoff() * (tilesDistance - upperLimit)) / 100;
}
accuracy = std::max(0.0, accuracy - modifier);
}
Expand Down