public bool ApplyLamp(GameObject obj, bool ambientOnly = false)
{
var lamp = this;
const double TOLERANCE = 0.001;
if (Math.Abs(lamp.LightIntensity) < TOLERANCE)
return false;
var drawLocation = obj.Tile;
double sqX = (lamp.Tile.Rx - drawLocation.Rx) * (lamp.Tile.Rx - drawLocation.Rx);
double sqY = (lamp.Tile.Ry - (drawLocation.Ry)) * (lamp.Tile.Ry - (drawLocation.Ry));
double distance = Math.Sqrt(sqX + sqY);
// checks whether we're in range
if ((0 < lamp.LightVisibility) && (distance < lamp.LightVisibility / 256)) {
double lsEffect = (lamp.LightVisibility - 256 * distance) / lamp.LightVisibility;
// we don't want to apply lamps to shared palettes, so clone first
if (obj.Palette.IsShared)
obj.Palette = obj.Palette.Clone();
obj.Palette.ApplyLamp(lamp, lsEffect, ambientOnly);
return true;
}
else
return false;
}