Merge pull request #9521 from pchote/produce-support

Implement actor-producing support powers
This commit is contained in:
Oliver Brakmann
2015-10-07 21:41:36 +02:00
16 changed files with 248 additions and 41 deletions

View File

@@ -709,6 +709,7 @@
<Compile Include="Traits\ThrowsShrapnel.cs" />
<Compile Include="Traits\World\MusicPlaylist.cs" />
<Compile Include="Scripting\Global\LightingGlobal.cs" />
<Compile Include="Traits\SupportPowers\ProduceActorPower.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -46,10 +46,10 @@ namespace OpenRA.Mods.Common.Traits
this.info = info;
}
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
{
Game.Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound);
return new SelectTarget(Self.World, order, manager, this);
self.World.OrderGenerator = new SelectUpgradeTarget(Self.World, order, manager, this);
}
public override void Activate(Actor self, Order order, SupportPowerManager manager)
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
});
}
class SelectTarget : IOrderGenerator
class SelectUpgradeTarget : IOrderGenerator
{
readonly GrantUpgradePower power;
readonly int range;
@@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.Traits
readonly SupportPowerManager manager;
readonly string order;
public SelectTarget(World world, string order, SupportPowerManager manager, GrantUpgradePower power)
public SelectUpgradeTarget(World world, string order, SupportPowerManager manager, GrantUpgradePower power)
{
// Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle)

View File

@@ -0,0 +1,75 @@
#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.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Produces an actor without using the standard production queue.")]
public class ProduceActorPowerInfo : SupportPowerInfo
{
[ActorReference, FieldLoader.Require]
[Desc("Actors to produce.")]
public readonly string[] Actors = null;
[FieldLoader.Require]
[Desc("Production queue type to use")]
public readonly string Type = null;
[Desc("Notification played when production is activated.",
"The filename of the audio is defined per faction in notifications.yaml.")]
public readonly string ReadyAudio = null;
[Desc("Notification played when the exit is jammed.",
"The filename of the audio is defined per faction in notifications.yaml.")]
public readonly string BlockedAudio = null;
public override object Create(ActorInitializer init) { return new ProduceActorPower(init, this); }
}
public class ProduceActorPower : SupportPower
{
readonly string faction;
public ProduceActorPower(ActorInitializer init, ProduceActorPowerInfo info)
: base(init.Self, info)
{
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
}
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
{
self.World.IssueOrder(new Order(order, manager.Self, false));
}
public override void Activate(Actor self, Order order, SupportPowerManager manager)
{
base.Activate(self, order, manager);
var info = Info as ProduceActorPowerInfo;
var sp = self.TraitsImplementing<Production>()
.FirstOrDefault(p => p.Info.Produces.Contains(info.Type));
// TODO: The power should not reset if the production fails.
// Fixing this will require a larger rework of the support power code
var activated = false;
if (sp != null)
foreach (var name in info.Actors)
activated |= sp.Produce(self, self.World.Map.Rules.Actors[name], faction);
if (activated)
Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
else
Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.BlockedAudio, self.Owner.Faction.InternalName);
}
}
}

View File

@@ -81,6 +81,12 @@ namespace OpenRA.Mods.Common.Traits
Game.Sound.PlayToPlayer(self.Owner, Info.EndChargeSound);
}
public virtual void SelectTarget(Actor self, string order, SupportPowerManager manager)
{
Game.Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound);
self.World.OrderGenerator = new SelectGenericPowerTarget(order, manager, info.Cursor, MouseButton.Left);
}
public virtual void Activate(Actor self, Order order, SupportPowerManager manager)
{
if (Info.DisplayRadarPing && manager.RadarPings != null)
@@ -92,11 +98,5 @@ namespace OpenRA.Mods.Common.Traits
Info.RadarPingDuration);
}
}
public virtual IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
{
Game.Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound);
return new SelectGenericPowerTarget(order, manager, info.Cursor, MouseButton.Left);
}
}
}

View File

@@ -222,7 +222,11 @@ namespace OpenRA.Mods.Common.Traits
if (!Ready)
return;
manager.Self.World.OrderGenerator = Instances.First().OrderGenerator(key, manager);
var power = Instances.FirstOrDefault();
if (power == null)
return;
power.SelectTarget(power.Self, key, manager);
}
public void Activate(Order order)