Unhardcode sound and delay in PlaceBuilding.

This commit is contained in:
Taryn Hill
2015-07-08 13:39:22 -05:00
parent 54e1cf866c
commit c1abc0dfbb

View File

@@ -15,19 +15,38 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Allows to execute build orders.", " Attach this to the player actor.")]
class PlaceBuildingInfo : TraitInfo<PlaceBuilding>
[Desc("Allows the player to execute build orders.", " Attach this to the player actor.")]
public class PlaceBuildingInfo : ITraitInfo
{
[Desc("Palette to use for rendering the placement sprite.")]
public readonly string Palette = "terrain";
[Desc("Play NewOptionsNotification this many ticks after building placement.")]
public readonly int NewOptionsNotificationDelay = 10;
[Desc("Notification to play after building placement if new construction options are available.")]
public readonly string NewOptionsNotification = "NewOptions";
public object Create(ActorInitializer init) { return new PlaceBuilding(this); }
}
class PlaceBuilding : IResolveOrder
public class PlaceBuilding : IResolveOrder
{
readonly PlaceBuildingInfo info;
public PlaceBuilding(PlaceBuildingInfo info)
{
this.info = info;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "PlaceBuilding" || order.OrderString == "LineBuild" || order.OrderString == "PlacePlug")
{
var os = order.OrderString;
if (os != "PlaceBuilding" &&
os != "LineBuild" &&
os != "PlacePlug")
return;
self.World.AddFrameEndTask(w =>
{
var prevItems = GetNumBuildables(self.Owner);
@@ -50,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
if (buildableInfo != null && buildableInfo.ForceRace != null)
race = buildableInfo.ForceRace;
if (order.OrderString == "LineBuild")
if (os == "LineBuild")
{
var playSounds = true;
foreach (var t in BuildingUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo))
@@ -69,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
playSounds = false;
}
}
else if (order.OrderString == "PlacePlug")
else if (os == "PlacePlug")
{
var host = self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(order.TargetLocation);
if (host == null)
@@ -123,11 +142,10 @@ namespace OpenRA.Mods.Common.Traits
}
if (GetNumBuildables(self.Owner) > prevItems)
w.Add(new DelayedAction(10,
() => Sound.PlayNotification(self.World.Map.Rules, order.Player, "Speech", "NewOptions", order.Player.Country.Race)));
w.Add(new DelayedAction(info.NewOptionsNotificationDelay,
() => Sound.PlayNotification(self.World.Map.Rules, order.Player, "Speech", info.NewOptionsNotification, order.Player.Country.Race)));
});
}
}
static int GetNumBuildables(Player p)
{