Play "Unable to build more" eva when the production exit is blocked. Also fixes #484.

This commit is contained in:
Paul Chote
2011-01-08 13:14:47 +13:00
parent db63724aeb
commit 8264c6c8dc
4 changed files with 29 additions and 13 deletions

View File

@@ -25,6 +25,8 @@ namespace OpenRA.Traits
public readonly string BuildingCannotPlaceAudio = "nodeply1.aud"; public readonly string BuildingCannotPlaceAudio = "nodeply1.aud";
public readonly string UnitSelectAudio = "train1.aud"; public readonly string UnitSelectAudio = "train1.aud";
public readonly string UnitReadyAudio = "unitrdy1.aud"; public readonly string UnitReadyAudio = "unitrdy1.aud";
public readonly string UnitReadyBlockedAudio = "nobuild1.aud";
public readonly string OnHoldAudio = "onhold1.aud"; public readonly string OnHoldAudio = "onhold1.aud";
public readonly string CancelledAudio = "cancld1.aud"; public readonly string CancelledAudio = "cancld1.aud";
public readonly string NewOptions = "newopt1.aud"; public readonly string NewOptions = "newopt1.aud";

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
return QueueActive ? base.BuildableItems() : None; return QueueActive ? base.BuildableItems() : None;
} }
protected override void BuildUnit( string name ) protected override bool BuildUnit( string name )
{ {
// Find a production structure to build this actor // Find a production structure to build this actor
var producers = self.World.Queries.OwnedBy[self.Owner] var producers = self.World.Queries.OwnedBy[self.Owner]
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA
if (producers.Count() == 0) if (producers.Count() == 0)
{ {
CancelProduction(name,1); CancelProduction(name,1);
return; return true;
} }
foreach (var p in producers) foreach (var p in producers)
@@ -67,9 +67,10 @@ namespace OpenRA.Mods.RA
if (p.Trait.Produce(p.Actor, Rules.Info[ name ])) if (p.Trait.Produce(p.Actor, Rules.Info[ name ]))
{ {
FinishProduction(); FinishProduction();
break; return true;
} }
} }
return false;
} }
} }
} }

View File

@@ -145,23 +145,31 @@ namespace OpenRA.Mods.RA
if (!BuildableItems().Any(b => b.Name == order.TargetString)) if (!BuildableItems().Any(b => b.Name == order.TargetString))
return; /* you can't build that!! */ return; /* you can't build that!! */
bool hasPlayedSound = false;
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;
BeginProduction(new ProductionItem(this, order.TargetString, (int)time, cost, BeginProduction(new ProductionItem(this, order.TargetString, (int)time, cost,
() => self.World.AddFrameEndTask( () => self.World.AddFrameEndTask(
_ => _ =>
{ {
var isBuilding = unit.Traits.Contains<BuildingInfo>(); var isBuilding = unit.Traits.Contains<BuildingInfo>();
if (!hasPlayedSound) var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
if (isBuilding && !hasPlayedSound)
{ {
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>(); Sound.PlayToPlayer(order.Player, eva.BuildingReadyAudio);
Sound.PlayToPlayer(order.Player, isBuilding ? eva.BuildingReadyAudio : eva.UnitReadyAudio);
hasPlayedSound = true; hasPlayedSound = true;
} }
if (!isBuilding) else if (!isBuilding)
BuildUnit(order.TargetString); {
if (BuildUnit(order.TargetString))
Sound.PlayToPlayer(order.Player, eva.UnitReadyAudio);
else if (!hasPlayedSound && time > 0)
{
Sound.PlayToPlayer(order.Player, eva.UnitReadyBlockedAudio);
hasPlayedSound = true;
}
}
}))); })));
} }
break; break;
@@ -233,18 +241,23 @@ namespace OpenRA.Mods.RA
} }
// 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)
protected virtual void BuildUnit( string name ) // Returns false if the unit can't be built
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())
{ {
CancelProduction(name, 1); CancelProduction(name, 1);
return; return true;
} }
var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault(); var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault();
if (sp != null && !IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ])) if (sp != null && !IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ]))
FinishProduction(); {
FinishProduction();
return true;
}
return false;
} }
} }

BIN
mods/cnc/bits/nobuild1.aud Normal file

Binary file not shown.