protected void SetShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor, int start, int end)
{
var currentPalette = roomData.Palettes[_curPalIndex];
// This is an implementation based on the original games code.
//
// The four known rooms where setShadowPalette is used in atlantis are:
//
// 1) FOA Room 53: subway departing Knossos for Atlantis.
// 2) FOA Room 48: subway crashing into the Atlantis entrance area
// 3) FOA Room 82: boat/sub shadows while diving near Thera
// 4) FOA Room 23: the big machine room inside Atlantis
//
// There seems to be no explanation for why this function is called
// from within Room 23 (the big machine), as it has no shadow effects
// and thus doesn't result in any visual differences.
if (Game.GameId == Scumm.IO.GameId.SamNMax)
{
for (var i = 0; i < 256; i++)
_shadowPalette[i] = (byte)i;
}
for (var i = start; i < end; i++)
{
var r = ((currentPalette.Colors[i].R >> 2) * redScale) >> 8;
var g = ((currentPalette.Colors[i].G >> 2) * greenScale) >> 8;
var b = ((currentPalette.Colors[i].B >> 2) * blueScale) >> 8;
var bestitem = 0;
uint bestsum = 32000;
for (var j = startColor; j <= endColor; j++)
{
int ar = currentPalette.Colors[j].R >> 2;
int ag = currentPalette.Colors[j].G >> 2;
int ab = currentPalette.Colors[j].B >> 2;
uint sum = (uint)(Math.Abs(ar - r) + Math.Abs(ag - g) + Math.Abs(ab - b));
if (sum < bestsum)
{
bestsum = sum;
bestitem = j;
}
}
_shadowPalette[i] = (byte)bestitem;
}
}