Merge pull request #7872 from Mailaender/storm-effects

Unified FlashPaletteEffect and exposed it to Lua
This commit is contained in:
Oliver Brakmann
2015-07-05 21:08:04 +02:00
26 changed files with 196 additions and 78 deletions

View File

@@ -113,6 +113,11 @@ namespace OpenRA
InternalSoundVolume * volumeModifier, true);
}
public static void StopAudio()
{
soundEngine.StopAllSounds();
}
public static ISound Play(string name) { return Play(null, name, true, WPos.Zero, 1f); }
public static ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1f); }
public static ISound Play(string name, float volumeModifier) { return Play(null, name, true, WPos.Zero, volumeModifier); }

View File

@@ -339,7 +339,11 @@ namespace OpenRA.Traits
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning, Map map); }
public interface IObjectivesPanel { string PanelName { get; } }
public interface IObjectivesPanel
{
string PanelName { get; }
int ExitDelay { get; }
}
public interface INotifyObjectivesUpdated
{

View File

@@ -387,6 +387,7 @@ namespace OpenRA
frameEndActions.Clear();
Sound.StopAudio();
Sound.StopMusic();
Sound.StopVideo();

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Effects
readonly Player firedBy;
readonly Animation anim;
readonly string weapon;
readonly string flashType;
readonly WPos ascendSource;
readonly WPos ascendTarget;
@@ -34,12 +35,13 @@ namespace OpenRA.Mods.Common.Effects
WPos pos;
int ticks;
public NukeLaunch(Player firedBy, string weapon, WPos launchPos, WPos targetPos, WRange velocity, int delay, bool skipAscent)
public NukeLaunch(Player firedBy, string weapon, WPos launchPos, WPos targetPos, WRange velocity, int delay, bool skipAscent, string flashType)
{
this.firedBy = firedBy;
this.weapon = weapon;
this.delay = delay;
this.turn = delay / 2;
this.flashType = flashType;
var offset = new WVec(WRange.Zero, WRange.Zero, velocity * turn);
ascendSource = launchPos;
@@ -84,8 +86,9 @@ namespace OpenRA.Mods.Common.Effects
weapon.Impact(Target.FromPos(pos), firedBy.PlayerActor, Enumerable.Empty<int>());
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
a.Trait.Enable();
foreach (var flash in world.WorldActor.TraitsImplementing<FlashPaletteEffect>())
if (flash.Info.Type == flashType)
flash.Enable(-1);
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)

View File

@@ -199,10 +199,7 @@
<Compile Include="Orders\UnitOrderTargeter.cs" />
<Compile Include="Pathfinder\CellInfo.cs" />
<Compile Include="PlayerExtensions.cs" />
<Compile Include="Scripting\Global\FacingGlobal.cs" />
<Compile Include="Scripting\ScriptUpgradesCache.cs" />
<Compile Include="Scripting\Global\HSLColorGlobal.cs" />
<Compile Include="Scripting\Global\UserInterfaceGlobal.cs" />
<Compile Include="Scripting\Properties\CaptureProperties.cs" />
<Compile Include="ServerTraits\ColorValidator.cs" />
<Compile Include="ServerTraits\LobbyCommands.cs" />
@@ -218,11 +215,15 @@
<Compile Include="Scripting\Global\CameraGlobal.cs" />
<Compile Include="Scripting\Global\CoordinateGlobals.cs" />
<Compile Include="Scripting\Global\DateTimeGlobal.cs" />
<Compile Include="Scripting\Global\EffectGlobal.cs" />
<Compile Include="Scripting\Global\FacingGlobal.cs" />
<Compile Include="Scripting\Global\HSLColorGlobal.cs" />
<Compile Include="Scripting\Global\MapGlobal.cs" />
<Compile Include="Scripting\Global\MediaGlobal.cs" />
<Compile Include="Scripting\Global\PlayerGlobal.cs" />
<Compile Include="Scripting\Global\ReinforcementsGlobal.cs" />
<Compile Include="Scripting\Global\TriggerGlobal.cs" />
<Compile Include="Scripting\Global\UserInterfaceGlobal.cs" />
<Compile Include="Scripting\Global\UtilsGlobal.cs" />
<Compile Include="Scripting\Properties\AirstrikeProperties.cs" />
<Compile Include="Scripting\Properties\CombatProperties.cs" />
@@ -357,9 +358,8 @@
<Compile Include="Traits\Passenger.cs" />
<Compile Include="Traits\PaletteEffects\CloakPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\GlobalLightingPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\LightPaletteRotator.cs" />
<Compile Include="Traits\PaletteEffects\FlashPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\MenuPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\NukePaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\WaterPaletteRotation.cs" />
<Compile Include="Traits\Player\ActorGroupProxy.cs" />
<Compile Include="Traits\Player\AllyRepair.cs" />

View File

@@ -0,0 +1,36 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;
namespace OpenRA.Mods.Common.Scripting
{
[ScriptGlobal("Effect")]
public class EffectGlobal : ScriptGlobal
{
readonly IEnumerable<FlashPaletteEffect> fpes;
public EffectGlobal(ScriptContext context)
: base(context)
{
fpes = context.World.WorldActor.TraitsImplementing<FlashPaletteEffect>();
}
[Desc("Controls the `FlashPaletteEffect` trait.")]
public void Flash(string type = null, int ticks = -1)
{
foreach (var fpe in fpes)
if (fpe.Info.Type == type)
fpe.Enable(ticks);
}
}
}

View File

@@ -45,6 +45,12 @@ namespace OpenRA.Mods.Common.Scripting
Sound.PlayNotification(world.Map.Rules, player, "Sounds", notification, player != null ? player.Country.Race : null);
}
[Desc("Play a sound file")]
public void PlaySound(string file)
{
Sound.Play(file);
}
MusicInfo previousMusic;
Action onComplete;
[Desc("Play track defined in music.yaml or keep it empty for a random song.")]

View File

@@ -0,0 +1,81 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
using GUtil = OpenRA.Graphics.Util;
[Desc("Used for bursted one-colored whole screen effects. Add this to the world actor.")]
public class FlashPaletteEffectInfo : ITraitInfo
{
public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "fog", "shroud" };
[Desc("Measured in ticks.")]
public readonly int Length = 20;
public readonly Color Color = Color.White;
[Desc("Set this when using multiple independent flash effects.")]
public readonly string Type = null;
public object Create(ActorInitializer init) { return new FlashPaletteEffect(this); }
}
public class FlashPaletteEffect : IPaletteModifier, ITick
{
public readonly FlashPaletteEffectInfo Info;
public FlashPaletteEffect(FlashPaletteEffectInfo info)
{
Info = info;
}
int remainingFrames;
public void Enable(int ticks)
{
if (ticks == -1)
remainingFrames = Info.Length;
else
remainingFrames = ticks;
}
public void Tick(Actor self)
{
if (remainingFrames > 0)
remainingFrames--;
}
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
{
if (remainingFrames == 0)
return;
var frac = (float)remainingFrames / Info.Length;
foreach (var pal in palettes)
{
for (var x = 0; x < Palette.Size; x++)
{
var orig = pal.Value.GetColor(x);
var c = Info.Color;
var color = Color.FromArgb(orig.A, ((int)c.R).Clamp(0, 255), ((int)c.G).Clamp(0, 255), ((int)c.B).Clamp(0, 255));
var final = GUtil.PremultipliedColorLerp(frac, orig, GUtil.PremultiplyAlpha(Color.FromArgb(orig.A, color)));
pal.Value.SetColor(x, final);
}
}
}
}
}

View File

@@ -1,57 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
using GUtil = OpenRA.Graphics.Util;
[Desc("Apply palette full screen rotations during atom bomb explosions. Add this to the world actor.")]
class NukePaletteEffectInfo : TraitInfo<NukePaletteEffect> { }
public class NukePaletteEffect : IPaletteModifier, ITick
{
const int NukeEffectLength = 20;
int remainingFrames;
public void Enable()
{
remainingFrames = NukeEffectLength;
}
public void Tick(Actor self)
{
if (remainingFrames > 0)
remainingFrames--;
}
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
{
if (remainingFrames == 0)
return;
var frac = (float)remainingFrames / NukeEffectLength;
foreach (var pal in palettes)
{
for (var x = 0; x < Palette.Size; x++)
{
var orig = pal.Value.GetColor(x);
var final = GUtil.PremultipliedColorLerp(frac, orig, GUtil.PremultiplyAlpha(Color.FromArgb(orig.A, Color.White)));
pal.Value.SetColor(x, final);
}
}
}
}
}

View File

@@ -250,13 +250,18 @@ namespace OpenRA.Mods.Common.Traits
public class ObjectivesPanelInfo : ITraitInfo
{
public string PanelName = null;
[Desc("in ms")]
public int ExitDelay = 1400;
public object Create(ActorInitializer init) { return new ObjectivesPanel(this); }
}
public class ObjectivesPanel : IObjectivesPanel
{
ObjectivesPanelInfo info;
readonly ObjectivesPanelInfo info;
public ObjectivesPanel(ObjectivesPanelInfo info) { this.info = info; }
public string PanelName { get { return info.PanelName; } }
public int ExitDelay { get { return info.ExitDelay; } }
}
}

View File

@@ -24,10 +24,10 @@ namespace OpenRA.Mods.Common.Traits
{
public AmbientSound(Actor self, AmbientSoundInfo info)
{
if (self == self.World.WorldActor)
Sound.PlayLooped(info.SoundFile);
else
if (self.HasTrait<IOccupySpace>())
Sound.PlayLooped(info.SoundFile, self.CenterPosition);
else
Sound.PlayLooped(info.SoundFile);
}
}
}

View File

@@ -45,6 +45,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Amount of time after detonation to remove the camera")]
public readonly int CameraRemoveDelay = 25;
public readonly string FlashType = null;
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
}
@@ -76,7 +78,8 @@ namespace OpenRA.Mods.Common.Traits
var missile = new NukeLaunch(self.Owner, info.MissileWeapon,
self.CenterPosition + body.LocalToWorld(info.SpawnOffset),
targetPosition,
info.FlightVelocity, info.FlightDelay, info.SkipAscent);
info.FlightVelocity, info.FlightDelay, info.SkipAscent,
info.FlashType);
self.World.AddFrameEndTask(w => w.Add(missile));

View File

@@ -1353,6 +1353,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
// Generalized the flash palette trait
if (engineVersion < 20150627)
{
if (node.Key == "NukePaletteEffect")
node.Key = "FlashPaletteEffect";
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}

View File

@@ -9,8 +9,10 @@
#endregion
using System;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
@@ -41,7 +43,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
resumeDisabled = true;
var exitDelay = 1200;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
var exitDelay = iop != null ? iop.ExitDelay : 0;
if (mpe != null)
{
Game.RunAfterDelay(exitDelay, () => mpe.Fade(MenuPaletteEffect.EffectType.Black));

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Widgets
Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave",
world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race);
var exitDelay = 1200;
var exitDelay = iop != null ? iop.ExitDelay : 0;
if (mpe != null)
{
Game.RunAfterDelay(exitDelay, () => mpe.Fade(MenuPaletteEffect.EffectType.Black));

View File

@@ -103,6 +103,7 @@
<Compile Include="Traits\Mine.cs" />
<Compile Include="Traits\Minelayer.cs" />
<Compile Include="Traits\PaletteEffects\ChronoshiftPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\LightPaletteRotator.cs" />
<Compile Include="Traits\PortableChrono.cs" />
<Compile Include="Traits\Render\RenderJammerCircle.cs" />
<Compile Include="Traits\Render\WithLandingCraftAnimation.cs" />

View File

@@ -13,7 +13,7 @@ using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
namespace OpenRA.Mods.RA.Traits
{
[Desc("Palette effect used for blinking \"animations\" on actors.")]
class LightPaletteRotatorInfo : ITraitInfo

View File

@@ -70,7 +70,7 @@
MenuPaletteEffect:
MenuEffect: Desaturated
CloakPaletteEffect:
NukePaletteEffect:
FlashPaletteEffect:
WaterPaletteRotation:
ExcludePalettes: effect

View File

@@ -54,7 +54,6 @@ World:
PlayerCommands:
HelpCommand:
ScreenShaker:
NukePaletteEffect:
BuildingInfluence:
BridgeLayer:
Bridges: bridge1, bridge2, bridge3, bridge4

View File

@@ -86,5 +86,5 @@
Alpha: 0.68
Premultiply: false
PlayerHighlightPalette:
NukePaletteEffect:
FlashPaletteEffect:

BIN
mods/ra/bits/rain.aud Normal file

Binary file not shown.

BIN
mods/ra/bits/thunder.aud Normal file

Binary file not shown.

View File

@@ -147,6 +147,16 @@ SovietsRetreating = function()
end)
end
Tick = function()
if (Utils.RandomInteger(1, 200) == 10) then
local delay = Utils.RandomInteger(1, 10)
Effect.Flash("LightningStrike", delay)
Trigger.AfterDelay(delay, function()
Media.PlaySound("thunder.aud")
end)
end
end
WorldLoaded = function()
soviets = Player.GetPlayer("Soviets")
players = { }

View File

@@ -501,6 +501,15 @@ Rules:
CrateActors: fortcrate
-SpawnMPUnits:
-MPStartLocations:
GlobalLightingPaletteEffect:
Red: 0.75
Green: 0.85
Blue: 1.5
Ambient: 0.35
AmbientSound:
SoundFile: rain.aud
FlashPaletteEffect@LIGHTNINGSTRIKE:
Type: LightningStrike
LuaScript:
Scripts: fort-lonestar.lua
ScriptUpgradesCache:

View File

@@ -70,5 +70,6 @@
LightPaletteRotator:
ExcludePalettes: terrain, effect
ChronoshiftPaletteEffect:
NukePaletteEffect:
FlashPaletteEffect@NUKE:
Type: Nuke

View File

@@ -38,6 +38,7 @@ MSLO:
DisplayRadarPing: True
BeaconPoster: atomicon
CameraActor: camera
FlashType: Nuke
CanPowerDown:
RequiresPower:
DisabledOverlay: