Files
Gleb Mazovetskiy 999f44cf07 Point: Safer operator-
1. Require both operands to have the same signedness to avoid surprises.
2. Only allow unary negation on signed points.

Fixes #6409
Also fixes a potential bug in the sound position calculation.
2023-08-11 22:58:44 +01:00

27 lines
620 B
C++

#include "engine/sound_position.hpp"
#include "engine/sound_defs.hpp"
#include "player.h"
namespace devilution {
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan)
{
const Point playerPosition { MyPlayer->position.tile };
const Displacement delta = soundPosition - playerPosition;
const int pan = (delta.deltaX - delta.deltaY) * 256;
*plPan = clamp(pan, PAN_MIN, PAN_MAX);
const int volume = playerPosition.ApproxDistance(soundPosition) * -64;
if (volume <= ATTENUATION_MIN)
return false;
*plVolume = volume;
return true;
}
} // namespace devilution