Merge pull request #10210 from pchote/other-enter-traits

Add enter behaviour field to Infiltrates/EngineerRepair/RepairsBridges.
This commit is contained in:
Matthias Mailänder
2016-01-01 12:01:26 +01:00
12 changed files with 64 additions and 44 deletions

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Health health;
public CaptureActor(Actor self, Actor target)
: base(self, target)
: base(self, target, EnterBehaviour.Dispose)
{
actor = target;
building = actor.TraitOrDefault<Building>();

View File

@@ -20,7 +20,6 @@ namespace OpenRA.Mods.Common.Activities
{
readonly Actor target;
readonly IDemolishable[] demolishables;
readonly EnterBehaviour enterBehaviour;
readonly int delay;
readonly int flashes;
readonly int flashesDelay;
@@ -31,11 +30,10 @@ namespace OpenRA.Mods.Common.Activities
public Demolish(Actor self, Actor target, EnterBehaviour enterBehaviour, int delay,
int flashes, int flashesDelay, int flashInterval, int flashDuration)
: base(self, target)
: base(self, target, enterBehaviour)
{
this.target = target;
demolishables = target.TraitsImplementing<IDemolishable>().ToArray();
this.enterBehaviour = enterBehaviour;
this.delay = delay;
this.flashes = flashes;
this.flashesDelay = flashesDelay;
@@ -75,11 +73,6 @@ namespace OpenRA.Mods.Common.Activities
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
demolishables.Do(d => d.Demolish(target, self));
}));
if (enterBehaviour == EnterBehaviour.Suicide)
self.Kill(self);
else if (enterBehaviour == EnterBehaviour.Dispose)
self.Dispose();
});
}
}

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
readonly int payload;
public DonateSupplies(Actor self, Actor target, int payload)
: base(self, target)
: base(self, target, EnterBehaviour.Dispose)
{
this.target = target;
this.payload = payload;
@@ -31,7 +31,6 @@ namespace OpenRA.Mods.Common.Activities
return;
target.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
self.Dispose();
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30)));

View File

@@ -24,7 +24,9 @@ namespace OpenRA.Mods.Common.Activities
readonly IMove move;
readonly int maxTries = 0;
readonly EnterBehaviour enterBehaviour;
readonly bool targetCenter;
public Target Target { get { return target; } }
Target target;
State nextState = State.ApproachingOrEntering; // Hint/starting point for next state
@@ -33,11 +35,12 @@ namespace OpenRA.Mods.Common.Activities
Activity inner;
bool firstApproach = true;
protected Enter(Actor self, Actor target, int maxTries = 1, bool targetCenter = false)
protected Enter(Actor self, Actor target, EnterBehaviour enterBehaviour, int maxTries = 1, bool targetCenter = false)
{
this.move = self.Trait<IMove>();
this.target = Target.FromActor(target);
this.maxTries = maxTries;
this.enterBehaviour = enterBehaviour;
this.targetCenter = targetCenter;
}
@@ -215,6 +218,11 @@ namespace OpenRA.Mods.Common.Activities
OnInside(self);
if (enterBehaviour == EnterBehaviour.Suicide)
self.Kill(self);
else if (enterBehaviour == EnterBehaviour.Dispose)
self.Dispose();
// Return if Abort(Actor) or Done(self) was called from OnInside.
if (nextState >= State.Exiting)
return State.Inside;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
Cargo cargo;
public EnterTransport(Actor self, Actor transport, int maxTries = 0, bool targetCenter = false)
: base(self, transport, maxTries, targetCenter)
: base(self, transport, EnterBehaviour.Exit, maxTries, targetCenter)
{
this.transport = transport;
this.maxTries = maxTries;

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Mods.Common.Activities
{
readonly BridgeHut hut;
public RepairBridge(Actor self, Actor target)
: base(self, target)
public RepairBridge(Actor self, Actor target, EnterBehaviour enterBehaviour)
: base(self, target, enterBehaviour)
{
hut = target.Trait<BridgeHut>();
}
@@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.Activities
{
if (hut.BridgeDamageState == DamageState.Undamaged || hut.Repairing || hut.Bridge.GetHut(0) == null || hut.Bridge.GetHut(1) == null)
return;
hut.Repair(self);
self.Dispose();
}
}
}

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Mods.Common.Activities
readonly Actor target;
readonly Health health;
public RepairBuilding(Actor self, Actor target)
: base(self, target)
public RepairBuilding(Actor self, Actor target, EnterBehaviour enterBehaviour)
: base(self, target, enterBehaviour)
{
this.target = target;
health = target.Trait<Health>();
@@ -34,8 +34,8 @@ namespace OpenRA.Mods.Common.Activities
{
if (health.DamageState == DamageState.Undamaged)
return;
target.InflictDamage(self, -health.MaxHP, null);
self.Dispose();
}
}
}

View File

@@ -21,6 +21,10 @@ namespace OpenRA.Mods.Common.Traits
{
[VoiceReference] public readonly string Voice = "Action";
[Desc("Behaviour when entering the structure.",
"Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose;
public object Create(ActorInitializer init) { return new EngineerRepair(init, this); }
}
@@ -91,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
self.CancelActivity();
self.SetTargetLine(target, Color.Yellow);
self.QueueActivity(new RepairBuilding(self, target.Actor));
self.QueueActivity(new RepairBuilding(self, target.Actor, info.EnterBehaviour));
}
class EngineerRepairOrderTargeter : UnitOrderTargeter

View File

@@ -21,6 +21,10 @@ namespace OpenRA.Mods.Common.Traits
{
[VoiceReference] public readonly string Voice = "Action";
[Desc("Behaviour when entering the structure.",
"Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose;
public object Create(ActorInitializer init) { return new RepairsBridges(this); }
}
@@ -72,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(Target.FromOrder(self.World, order), Color.Yellow);
self.CancelActivity();
self.QueueActivity(new RepairBridge(self, order.TargetActor));
self.QueueActivity(new RepairBridge(self, order.TargetActor, info.EnterBehaviour));
}
}

View File

@@ -18,19 +18,17 @@ namespace OpenRA.Mods.RA.Activities
class Infiltrate : Enter
{
readonly Actor target;
readonly Stance validStances;
readonly Cloak cloak;
readonly string notification;
readonly Infiltrates infiltrates;
public Infiltrate(Actor self, Actor target)
: base(self, target)
public Infiltrate(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances, string notification)
: base(self, target, enterBehaviour)
{
this.target = target;
this.validStances = validStances;
this.notification = notification;
cloak = self.TraitOrDefault<Cloak>();
infiltrates = self.TraitOrDefault<Infiltrates>();
}
protected override void OnInside(Actor self)
@@ -39,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
return;
var stance = self.Owner.Stances[target.Owner];
if (!infiltrates.Info.ValidStances.HasStance(stance))
if (!validStances.HasStance(stance))
return;
if (cloak != null && cloak.Info.UncloakOnInfiltrate)
@@ -48,10 +46,9 @@ namespace OpenRA.Mods.RA.Activities
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
t.Infiltrated(target, self);
self.Dispose();
if (target.Info.HasTraitInfo<BuildingInfo>())
Game.Sound.PlayToPlayer(self.Owner, "bldginf1.aud");
if (!string.IsNullOrEmpty(notification))
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
notification, self.Owner.Faction.InternalName);
}
}
}

View File

@@ -8,22 +8,29 @@
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Traits;
using OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Ability")]
public class InfiltrateProperties : ScriptActorProperties
public class InfiltrateProperties : ScriptActorProperties, Requires<InfiltratesInfo>
{
readonly InfiltratesInfo info;
public InfiltrateProperties(ScriptContext context, Actor self)
: base(context, self)
{ }
{
info = Self.Info.TraitInfo<InfiltratesInfo>();
}
[Desc("Infiltrate the target actor.")]
public void Infiltrate(Actor target)
{
Self.QueueActivity(new Infiltrate(Self, target));
Self.QueueActivity(new Infiltrate(Self, target, info.EnterBehaviour, info.ValidStances, info.Notification));
}
}
}

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
@@ -27,21 +28,28 @@ namespace OpenRA.Mods.RA.Traits
[Desc("What diplomatic stances can be infiltrated by this actor.")]
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
[Desc("Behaviour when entering the structure.",
"Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose;
[Desc("Notification to play when a building is infiltrated.")]
public readonly string Notification = "BuildingInfiltrated";
public object Create(ActorInitializer init) { return new Infiltrates(this); }
}
class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice
{
public readonly InfiltratesInfo Info;
readonly InfiltratesInfo info;
public Infiltrates(InfiltratesInfo info)
{
Info = info;
this.info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new InfiltrationOrderTargeter(Info); }
get { yield return new InfiltrationOrderTargeter(info); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
@@ -79,13 +87,13 @@ namespace OpenRA.Mods.RA.Traits
else
targetTypes = order.TargetActor.GetEnabledTargetTypes();
return Info.Types.Overlaps(targetTypes);
return info.Types.Overlaps(targetTypes);
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return order.OrderString == "Infiltrate" && IsValidOrder(self, order)
? Info.Voice : null;
? info.Voice : null;
}
public void ResolveOrder(Actor self, Order order)
@@ -95,14 +103,14 @@ namespace OpenRA.Mods.RA.Traits
var target = self.ResolveFrozenActorOrder(order, Color.Red);
if (target.Type != TargetType.Actor
|| !Info.Types.Overlaps(target.Actor.GetAllTargetTypes()))
|| !info.Types.Overlaps(target.Actor.GetAllTargetTypes()))
return;
if (!order.Queued)
self.CancelActivity();
self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Infiltrate(self, target.Actor));
self.QueueActivity(new Infiltrate(self, target.Actor, info.EnterBehaviour, info.ValidStances, info.Notification));
}
}