#strict 2 global func GetClrModulationStack(object target) { target || FatalError("GetClrModulationStack: no target object given"); return GetEffect("ClrModulationStack", target) || AddEffect("ClrModulationStack", target, 200); } global func AddClrModulation(int color, int baseColor, int factor, int precision, object target) { baseColor = baseColor || RGB(127, 127, 127); target = target || this || FatalError("AddClrModulation: no target object given"); factor = factor || 1; precision = precision || 1; return EffectCall(target, GetClrModulationStack(target), "AddModulation", color, baseColor, factor, precision); } global func RemoveClrModulation(int id, object target) { target = target || this || FatalError("RemoveClrModulation: no target object given"); return EffectCall(target, GetClrModulationStack(target), "RemoveModulation", id); } global func FxClrModulationStackStart(object target, int effectNumber, int temp) { if(!temp) { EffectVar(1, target, effectNumber) = []; } } global func FxClrModulationStackAddModulation(object target, int effectNumber, int color, int baseColor, int factor, int precision) { EffectVar(1, target, effectNumber)[] = [++EffectVar(0, target, effectNumber), color, baseColor, factor, precision]; EffectCall(target, effectNumber, "ApplyModulation"); return EffectVar(0, target, effectNumber); } global func FxClrModulationStackRemoveModulation(object target, int effectNumber, int id) { for(var i = 0; i < GetLength(EffectVar(1, target, effectNumber)); ++i) { if(EffectVar(1, target, effectNumber)[i][0] == id) { ArrayErase(EffectVar(1, target, effectNumber), i); EffectCall(target, effectNumber, "ApplyModulation"); return true; } } return 0; } global func FxClrModulationStackApplyModulation(object target, int effectNumber) { if(GetLength(EffectVar(1, target, effectNumber)) == 0) { SetClrModulation(0, target); return 0; } var r, g, b, a; SplitRGBaValue(EffectVar(1, target, effectNumber)[0][1], r, g, b, a); a = 255 - a; for(var i = 1; i < GetLength(EffectVar(1, target, effectNumber)); ++i) { var clrPart = EffectVar(1, target, effectNumber)[i]; var mr, mg, mb, ma, br, bg, bb, ba; SplitRGBaValue(clrPart[1], mr, mg, mb, ma); SplitRGBaValue(clrPart[2], br, bg, bb, ba); ma = 255 - ma; a *= ma; a /= 0xFF; r += mr - br; r *= clrPart[3]; r /= clrPart[4]; g += mg - bg; g *= clrPart[3]; g /= clrPart[4]; b += mb - bb; b *= clrPart[3]; b /= clrPart[4]; } SetClrModulation(RGBa(BoundBy(r, 0, 255), BoundBy(g, 0, 255), BoundBy(b, 0, 255), 255 - a), target); return true; }