From 25d14d87e10f0257d1b9e0c44a1bcbbc5eb6ee3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 8 Jul 2015 14:18:05 +0200 Subject: [PATCH 1/2] add Effect.ChangeLighting(red, green, blue, ambient) to Lua API --- .../Scripting/Global/EffectGlobal.cs | 15 +++++++++++++++ .../GlobalLightingPaletteEffect.cs | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs index e4669aade6..b25cea7f5d 100644 --- a/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using Eluant; using OpenRA.Mods.Common.Traits; using OpenRA.Scripting; @@ -18,11 +19,13 @@ namespace OpenRA.Mods.Common.Scripting public class EffectGlobal : ScriptGlobal { readonly IEnumerable fpes; + readonly GlobalLightingPaletteEffect lighting; public EffectGlobal(ScriptContext context) : base(context) { fpes = context.World.WorldActor.TraitsImplementing(); + lighting = context.World.WorldActor.TraitOrDefault(); } [Desc("Controls the `FlashPaletteEffect` trait.")] @@ -32,5 +35,17 @@ namespace OpenRA.Mods.Common.Scripting if (fpe.Info.Type == type) fpe.Enable(ticks); } + + [Desc("Dynamically adjusts the `GlobalLightingPaletteEffect` trait.")] + public void ChangeLighting(double red, double green, double blue, double ambient) + { + if (lighting == null) + throw new LuaException("GlobalLightingPaletteEffect needs to be added to the World actor first."); + + lighting.Red = (float)red; + lighting.Green = (float)green; + lighting.Blue = (float)blue; + lighting.Ambient = (float)ambient; + } } } diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs index e59d1e106a..f48b1bd729 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs @@ -36,9 +36,19 @@ namespace OpenRA.Mods.Common.Traits { readonly GlobalLightingPaletteEffectInfo info; + public float Red; + public float Green; + public float Blue; + public float Ambient; + public GlobalLightingPaletteEffect(GlobalLightingPaletteEffectInfo info) { this.info = info; + + Red = info.Red; + Green = info.Green; + Blue = info.Blue; + Ambient = info.Ambient; } public void AdjustPalette(IReadOnlyDictionary palettes) @@ -56,9 +66,9 @@ namespace OpenRA.Mods.Common.Traits for (var x = 0; x < Palette.Size; x++) { var from = palette.GetColor(x); - var red = (int)(from.R * info.Ambient * info.Red).Clamp(0, 255); - var green = (int)(from.G * info.Ambient * info.Green).Clamp(0, 255); - var blue = (int)(from.B * info.Ambient * info.Blue).Clamp(0, 255); + var red = (int)(from.R * Ambient * Red).Clamp(0, 255); + var green = (int)(from.G * Ambient * Green).Clamp(0, 255); + var blue = (int)(from.B * Ambient * Blue).Clamp(0, 255); palette.SetColor(x, Color.FromArgb(from.A, red, green, blue)); } } From 9ec2b8aac014e3a8931d1b4d2fa3f59de967bd99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 8 Jul 2015 14:18:41 +0200 Subject: [PATCH 2/2] simulate dawn on the Dune 2000 shellmap --- mods/d2k/maps/shellmap/map.yaml | 1 + mods/d2k/maps/shellmap/shellmap.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/mods/d2k/maps/shellmap/map.yaml b/mods/d2k/maps/shellmap/map.yaml index adda1a729f..fd42ee8e29 100644 --- a/mods/d2k/maps/shellmap/map.yaml +++ b/mods/d2k/maps/shellmap/map.yaml @@ -127,6 +127,7 @@ Rules: Scripts: shellmap.lua MusicPlaylist: StartingMusic: score + GlobalLightingPaletteEffect: rockettower: Power: Amount: 100 diff --git a/mods/d2k/maps/shellmap/shellmap.lua b/mods/d2k/maps/shellmap/shellmap.lua index e69de29bb2..73d35f0252 100644 --- a/mods/d2k/maps/shellmap/shellmap.lua +++ b/mods/d2k/maps/shellmap/shellmap.lua @@ -0,0 +1,26 @@ +WorldLoaded = function() + red = 0.95 + green = 0.85 + blue = 1.25 + ambient = 0.5 +end + +Tick = function() + if (red < 1.0) then + red = red + 0.001 + end + + if (green < 1.0) then + green = green + 0.001 + end + + if (blue > 1.0) then + blue = blue - 0.001 + end + + if (ambient < 1.0) then + ambient = ambient + 0.001 + end + + Effect.ChangeLighting(red, green, blue, ambient) +end