Merge pull request #5134 from Mailaender/production-overlay

Fixed welding animations playing when there are no vehicles produced
This commit is contained in:
Paul Chote
2014-04-21 01:27:42 +12:00
8 changed files with 157 additions and 63 deletions

View File

@@ -83,6 +83,7 @@
<Compile Include="FogPaletteFromR8.cs" /> <Compile Include="FogPaletteFromR8.cs" />
<Compile Include="DamagedWithoutFoundation.cs" /> <Compile Include="DamagedWithoutFoundation.cs" />
<Compile Include="Render\WithBuildingPlacedOverlayInfo.cs" /> <Compile Include="Render\WithBuildingPlacedOverlayInfo.cs" />
<Compile Include="Render\WithProductionOverlay.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@@ -0,0 +1,95 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class WithProductionOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "production-overlay";
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
public object Create(ActorInitializer init) { return new WithProductionOverlay(init.self, this); }
}
public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold
{
Animation overlay;
ProductionQueue queue;
bool buildComplete;
bool IsProducing
{
get { return queue != null && queue.CurrentItem() != null && !queue.CurrentPaused; }
}
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info)
{
var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>();
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(rs.GetImage(self));
overlay.PlayRepeating(info.Sequence);
rs.anims.Add("production_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !IsProducing || !buildComplete));
}
public void Tick(Actor self)
{
// search for the queue here once so we don't rely on order of trait initialization
if (queue == null)
{
var production = self.TraitOrDefault<Production>();
var perBuildingQueues = self.TraitsImplementing<ProductionQueue>();
queue = perBuildingQueues.FirstOrDefault(q => production.Info.Produces.Contains(q.Info.Type));
if (queue == null)
{
var perPlayerQueues = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>();
queue = perPlayerQueues.FirstOrDefault(q => production.Info.Produces.Contains(q.Info.Type));
}
if (queue == null)
throw new InvalidOperationException("Can't find production queues.");
}
}
public void BuildingComplete(Actor self)
{
buildComplete = true;
}
public void Sold(Actor self) { }
public void Selling(Actor self)
{
buildComplete = false;
}
public void DamageStateChanged(Actor self, AttackInfo e)
{
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
}
}
}

View File

@@ -203,9 +203,9 @@ namespace OpenRA.Mods.RA
Queue[ 0 ].Tick(playerResources); Queue[ 0 ].Tick(playerResources);
} }
public void ResolveOrder( Actor self, Order order ) public void ResolveOrder(Actor self, Order order)
{ {
switch( order.OrderString ) switch(order.OrderString)
{ {
case "StartProduction": case "StartProduction":
{ {
@@ -225,45 +225,43 @@ namespace OpenRA.Mods.RA
{ {
var inQueue = Queue.Count(pi => pi.Item == order.TargetString); var inQueue = Queue.Count(pi => pi.Item == order.TargetString);
var owned = self.Owner.World.ActorsWithTrait<Buildable>().Count(a => a.Actor.Info.Name == order.TargetString && a.Actor.Owner == self.Owner); var owned = self.Owner.World.ActorsWithTrait<Buildable>().Count(a => a.Actor.Info.Name == order.TargetString && a.Actor.Owner == self.Owner);
if (inQueue + owned >= bi.BuildLimit) if (inQueue + owned >= bi.BuildLimit)
return; return;
} }
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
{ {
bool hasPlayedSound = false; bool hasPlayedSound = false;
BeginProduction(new ProductionItem(this, order.TargetString, cost, PlayerPower, BeginProduction(new ProductionItem(this, order.TargetString, cost, PlayerPower,
() => self.World.AddFrameEndTask( () => self.World.AddFrameEndTask(_ =>
_ => {
var isBuilding = unit.Traits.Contains<BuildingInfo>();
if (isBuilding && !hasPlayedSound)
{ {
var isBuilding = unit.Traits.Contains<BuildingInfo>(); hasPlayedSound = Sound.PlayNotification(self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
}
if (isBuilding && !hasPlayedSound) else if (!isBuilding)
{
if (BuildUnit(order.TargetString))
Sound.PlayNotification(self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
else if (!hasPlayedSound && time > 0)
{ {
hasPlayedSound = Sound.PlayNotification(self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race); hasPlayedSound = Sound.PlayNotification(self.Owner, "Speech", Info.BlockedAudio, self.Owner.Country.Race);
} }
else if (!isBuilding) }
{ })));
if (BuildUnit(order.TargetString))
Sound.PlayNotification(self.Owner, "Speech", Info.ReadyAudio, self.Owner.Country.Race);
else if (!hasPlayedSound && time > 0)
{
hasPlayedSound = Sound.PlayNotification(self.Owner, "Speech", Info.BlockedAudio, self.Owner.Country.Race);
}
}
})));
} }
break; break;
} }
case "PauseProduction": case "PauseProduction":
{ {
if( Queue.Count > 0 && Queue[0].Item == order.TargetString ) if (Queue.Count > 0 && Queue[0].Item == order.TargetString)
Queue[0].Paused = ( order.TargetLocation.X != 0 ); Queue[0].Paused = ( order.TargetLocation.X != 0 );
break; break;
} }
case "CancelProduction": case "CancelProduction":
{ {
CancelProduction(order.TargetString,order.TargetLocation.X); CancelProduction(order.TargetString, order.TargetLocation.X);
break; break;
} }
} }
@@ -309,14 +307,14 @@ namespace OpenRA.Mods.RA
Queue.RemoveAt(0); Queue.RemoveAt(0);
} }
protected void BeginProduction( ProductionItem item ) protected void BeginProduction(ProductionItem item)
{ {
Queue.Add(item); Queue.Add(item);
} }
// Builds a unit from the actor that holds this queue (1 queue per building) // Builds a unit from the actor that holds this queue (1 queue per building)
// Returns false if the unit can't be built // Returns false if the unit can't be built
protected virtual bool BuildUnit( string name ) protected virtual bool BuildUnit(string name)
{ {
// Cannot produce if i'm dead // Cannot produce if i'm dead
if (!self.IsInWorld || self.IsDead()) if (!self.IsInWorld || self.IsDead())
@@ -326,7 +324,7 @@ namespace OpenRA.Mods.RA
} }
var sp = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type)); var sp = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type));
if (sp != null && !self.IsDisabled() && sp.Produce(self, Rules.Info[ name ])) if (sp != null && !self.IsDisabled() && sp.Produce(self, Rules.Info[name]))
{ {
FinishProduction(); FinishProduction();
return true; return true;

View File

@@ -260,8 +260,8 @@ CONCRETEB:
ProductionBar: ProductionBar:
ProvidesCustomPrerequisite: ProvidesCustomPrerequisite:
Prerequisite: Light Prerequisite: Light
WithIdleOverlay@WELDING: WithProductionOverlay@WELDING:
Sequence: idle-welding Sequence: production-welding
^HEAVY: ^HEAVY:
Inherits: ^Building Inherits: ^Building
@@ -300,8 +300,8 @@ CONCRETEB:
ProductionBar: ProductionBar:
ProvidesCustomPrerequisite: ProvidesCustomPrerequisite:
Prerequisite: Heavy Prerequisite: Heavy
WithIdleOverlay@WELDING: WithProductionOverlay@WELDING:
Sequence: idle-welding Sequence: production-welding
^RADAR: ^RADAR:
Inherits: ^Building Inherits: ^Building
@@ -603,8 +603,8 @@ WALL:
Range: 4c0 Range: 4c0
ProvidesCustomPrerequisite: ProvidesCustomPrerequisite:
Prerequisite: Hitech Prerequisite: Hitech
WithIdleOverlay@WELDING: # WithProductionOverlay@WELDING:
Sequence: idle-welding # Sequence: production-welding
^RESEARCH: ^RESEARCH:
Inherits: ^Building Inherits: ^Building

View File

@@ -514,7 +514,7 @@ hightecha:
damaged-idle: DATA damaged-idle: DATA
Start: 2565 Start: 2565
Offset: -48,80 Offset: -48,80
idle-welding: DATA production-welding: DATA
Start: 4614 Start: 4614
Length: 30 Length: 30
Offset: -48,80 Offset: -48,80
@@ -690,7 +690,7 @@ lighta:
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 2675 Start: 2675
Offset: -48,64 Offset: -48,64
idle-welding: DATA production-welding: DATA
Start: 4644 Start: 4644
Length: 30 Length: 30
Offset: -48,64 Offset: -48,64
@@ -739,7 +739,7 @@ heavya:
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 2520 Start: 2520
Offset: -48,80 Offset: -48,80
idle-welding: DATA production-welding: DATA
Start: 4674 Start: 4674
Length: 47 Length: 47
Offset: -48,80 Offset: -48,80
@@ -1005,7 +1005,7 @@ hightechh:
damaged-idle: DATA damaged-idle: DATA
Start: 2725 Start: 2725
Offset: -48,80 Offset: -48,80
idle-welding: DATA production-welding: DATA
Start: 4614 Start: 4614
Length: 30 Length: 30
Offset: -48,80 Offset: -48,80
@@ -1090,7 +1090,7 @@ lighth:
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 2835 Start: 2835
Offset: -48,64 Offset: -48,64
idle-welding: DATA production-welding: DATA
Start: 4644 Start: 4644
Length: 30 Length: 30
Offset: -48,64 Offset: -48,64
@@ -1139,7 +1139,7 @@ heavyh:
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 2680 Start: 2680
Offset: -48,80 Offset: -48,80
idle-welding: DATA production-welding: DATA
Start: 4674 Start: 4674
Length: 47 Length: 47
Offset: -48,80 Offset: -48,80
@@ -1406,7 +1406,7 @@ hightecho:
damaged-idle: DATA damaged-idle: DATA
Start: 2885 Start: 2885
Offset: -48,80 Offset: -48,80
idle-welding: DATA production-welding: DATA
Start: 4614 Start: 4614
Length: 30 Length: 30
Offset: -48,80 Offset: -48,80
@@ -1483,7 +1483,7 @@ lighto:
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 2995 Start: 2995
Offset: -48,64 Offset: -48,64
idle-welding: DATA production-welding: DATA
Start: 4644 Start: 4644
Length: 30 Length: 30
Offset: -48,64 Offset: -48,64
@@ -1532,7 +1532,7 @@ heavyo:
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 2840 Start: 2840
Offset: -48,80 Offset: -48,80
idle-welding: DATA production-welding: DATA
Start: 4674 Start: 4674
Length: 47 Length: 47
Offset: -48,80 Offset: -48,80
@@ -1647,7 +1647,7 @@ heavyc: # TODO: unused
damaged-idle-top: DATA damaged-idle-top: DATA
Start: 3003 Start: 3003
Offset: -48,64 Offset: -48,64
idle-welding: DATA production-welding: DATA
Start: 4674 Start: 4674
Length: 47 Length: 47
Offset: -48,80 Offset: -48,80

View File

@@ -90,8 +90,8 @@ Chrome:
mods/ts/chrome.yaml mods/ts/chrome.yaml
Assemblies: Assemblies:
mods/ra/OpenRA.Mods.RA.dll
mods/d2k/OpenRA.Mods.D2k.dll mods/d2k/OpenRA.Mods.D2k.dll
mods/ra/OpenRA.Mods.RA.dll
mods/ts/OpenRA.Mods.TS.dll mods/ts/OpenRA.Mods.TS.dll
ChromeLayout: ChromeLayout:

View File

@@ -104,8 +104,8 @@ GAPILE:
PrimaryBuilding: PrimaryBuilding:
IronCurtainable: IronCurtainable:
ProductionBar: ProductionBar:
WithIdleOverlay@LIGHTS: WithProductionOverlay@LIGHTS:
Sequence: idle-lights Sequence: production-lights
WithIdleOverlay@LIGHT: WithIdleOverlay@LIGHT:
Sequence: idle-light Sequence: idle-light
WithIdleOverlay@FLAG: WithIdleOverlay@FLAG:
@@ -142,10 +142,10 @@ GAWEAP:
Production: Production:
Produces: Vehicle Produces: Vehicle
ProductionBar: ProductionBar:
WithIdleOverlay@LIGHTS1: WithProductionOverlay@WHITELIGHTS:
Sequence: idle-lights1 Sequence: production-lights-white
WithIdleOverlay@LIGHTS2: WithProductionOverlay@REDLIGHTS:
Sequence: idle-lights2 Sequence: production-lights-red
WithIdleOverlay@TURBINES: WithIdleOverlay@TURBINES:
Sequence: idle-turbines Sequence: idle-turbines
@@ -211,8 +211,8 @@ NAHAND:
ProductionBar: ProductionBar:
WithIdleOverlay@LIGHTS: WithIdleOverlay@LIGHTS:
Sequence: idle-lights Sequence: idle-lights
WithIdleOverlay@LIGHT: WithProductionOverlay@LIGHT:
Sequence: idle-light Sequence: production-light
NAWEAP: NAWEAP:
Inherits: ^Building Inherits: ^Building
@@ -245,8 +245,8 @@ NAWEAP:
Production: Production:
Produces: Vehicle Produces: Vehicle
ProductionBar: ProductionBar:
WithIdleOverlay@LIGHTS: WithProductionOverlay@LIGHTS:
Sequence: idle-lights Sequence: production-lights
GASAND: GASAND:
Inherits: ^Wall Inherits: ^Wall

View File

@@ -103,11 +103,11 @@ gapile:
critical-idle: gtpile critical-idle: gtpile
Start: 2 Start: 2
ShadowStart: 5 ShadowStart: 5
idle-lights: gtpile_a production-lights: gtpile_a
Start: 0 Start: 0
Length: 7 Length: 7
Tick: 200 Tick: 200
damaged-idle-lights: gtpile_a damaged-production-lights: gtpile_a
Start:7 Start:7
Length: 7 Length: 7
Tick: 200 Tick: 200
@@ -142,22 +142,22 @@ gaweap:
dead: gtweap dead: gtweap
Start: 2 Start: 2
ShadowStart: 5 ShadowStart: 5
idle-lights1: gtweap_a production-lights-white: gtweap_a
Start: 0 Start: 0
Length: 8 Length: 8
Tick: 100 Tick: 100
ZOffset: 2048 ZOffset: 2048
damaged-idle-lights1: gtweap_a damaged-production-lights-white: gtweap_a
Start: 8 Start: 8
Length: 8 Length: 8
Tick: 100 Tick: 100
ZOffset: 2048 ZOffset: 2048
idle-lights2: gtweap_b production-lights-red: gtweap_b
Start: 0 Start: 0
Length: 4 Length: 4
Tick: 120 Tick: 120
ZOffset: 2048 ZOffset: 2048
damaged-idle-lights2: gtweap_b damaged-production-lights-red: gtweap_b
Start: 4 Start: 4
Length: 4 Length: 4
Tick: 120 Tick: 120
@@ -232,11 +232,11 @@ nahand:
critical-idle: nthand critical-idle: nthand
Start: 2 Start: 2
ShadowStart: 5 ShadowStart: 5
idle-light: nthand_a production-light: nthand_a
Start: 0 Start: 0
Length: 5 Length: 5
Tick: 100 Tick: 100
damaged-idle-light: nthand_a damaged-production-light: nthand_a
Start: 5 Start: 5
Length: 5 Length: 5
Tick: 100 Tick: 100
@@ -265,12 +265,12 @@ naweap:
dead: ntweap dead: ntweap
Start: 2 Start: 2
ShadowStart: 5 ShadowStart: 5
idle-lights: ntweap_a production-lights: ntweap_a
Start: 0 Start: 0
Length: 16 Length: 16
Tick: 100 Tick: 100
ZOffset: 2048 ZOffset: 2048
damaged-idle-lights: ntweap_a damaged-production-lights: ntweap_a
Start: 16 Start: 16
Length: 16 Length: 16
Tick: 100 Tick: 100