separate spy disguise and infiltrate

- add thief to classic-ra & monster tank madness
- remove crude workarounds for allies04
This commit is contained in:
Matthias Mailänder
2013-03-09 13:13:21 +01:00
parent ca6cc3fbe1
commit 49cfa21ddb
15 changed files with 190 additions and 80 deletions

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
return NextActivity;
foreach (var t in target.TraitsImplementing<IAcceptSpy>())
foreach (var t in target.TraitsImplementing<IAcceptInfiltrator>())
t.OnInfiltrate(target, self);
if (self.HasTrait<DontDestroyWhenInfiltrating>())

View File

@@ -25,16 +25,16 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new InfiltrateForCash(this); }
}
class InfiltrateForCash : IAcceptSpy
class InfiltrateForCash : IAcceptInfiltrator
{
InfiltrateForCashInfo info;
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }
public void OnInfiltrate(Actor self, Actor spy)
public void OnInfiltrate(Actor self, Actor infiltrator)
{
var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var spyResources = spy.Owner.PlayerActor.Trait<PlayerResources>();
var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>();
var toTake = (targetResources.Cash + targetResources.Ore) * info.Percentage / 100;
var toGive = Math.Max(toTake, info.Minimum);
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
Sound.PlayToPlayer(self.Owner, info.SoundToVictim);
self.World.AddFrameEndTask(w => w.Add(new CashTick(toGive, 30, 2, self.CenterLocation,
spy.Owner.ColorRamp.GetColor(0))));
infiltrator.Owner.ColorRamp.GetColor(0))));
}
}
}

View File

@@ -16,11 +16,11 @@ namespace OpenRA.Mods.RA
{
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> {}
class InfiltrateForExploration : IAcceptSpy
class InfiltrateForExploration : IAcceptInfiltrator
{
public void OnInfiltrate(Actor self, Actor spy)
public void OnInfiltrate(Actor self, Actor infiltrator)
{
spy.Owner.Shroud.MergeShroud(self.Owner.Shroud);
infiltrator.Owner.Shroud.MergeShroud(self.Owner.Shroud);
if (!self.Owner.HasFogVisibility())
self.Owner.Shroud.ResetExploration();
}

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); }
}
class InfiltrateForSupportPower : IAcceptSpy
class InfiltrateForSupportPower : IAcceptInfiltrator
{
InfiltrateForSupportPowerInfo Info;
@@ -29,11 +29,11 @@ namespace OpenRA.Mods.RA
Info = info;
}
public void OnInfiltrate(Actor self, Actor spy)
public void OnInfiltrate(Actor self, Actor infiltrator)
{
spy.World.AddFrameEndTask(w => w.CreateActor(Info.Proxy, new TypeDictionary
infiltrator.World.AddFrameEndTask(w => w.CreateActor(Info.Proxy, new TypeDictionary
{
new OwnerInit( spy.Owner )
new OwnerInit(infiltrator.Owner)
}));
}
}

View File

@@ -0,0 +1,114 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 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.Drawing;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Mods.RA.Missions;
namespace OpenRA.Mods.RA
{
class InfiltratesInfo : ITraitInfo
{
public string[] InfiltrateTypes = {"Cash", "SupportPower", "Exploration"};
public object Create(ActorInitializer init) { return new Infiltrates(this); }
}
class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice
{
public readonly InfiltratesInfo Info;
public Infiltrates(InfiltratesInfo info)
{
Info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get
{
yield return new InfiltratorOrderTargeter(target => CanInfiltrate(target));
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID == "Infiltrate")
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
return null;
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return (order.OrderString == "Infiltrate" && CanInfiltrate(order.TargetActor)) ? "Attack" : null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Infiltrate")
{
if (!CanInfiltrate(order.TargetActor))
return;
self.SetTargetLine(Target.FromOrder(order), Color.Red);
self.CancelActivity();
self.QueueActivity(new Enter(order.TargetActor));
self.QueueActivity(new Infiltrate(order.TargetActor));
}
}
bool CanInfiltrate(Actor target)
{
if (Info.InfiltrateTypes.Contains("Cash") && target.HasTrait<InfiltrateForCash>())
return true;
if (Info.InfiltrateTypes.Contains("SupportPower") && target.HasTrait<InfiltrateForSupportPower>())
return true;
if (Info.InfiltrateTypes.Contains("Exploration") && target.HasTrait<InfiltrateForExploration>())
return true;
if (Info.InfiltrateTypes.Contains("MissionObjective") && target.HasTrait<InfiltrateForMissionObjective>())
return true;
return false;
}
class InfiltratorOrderTargeter : UnitTraitOrderTargeter<IAcceptInfiltrator>
{
readonly Func<Actor, bool> useEnterCursor;
public InfiltratorOrderTargeter(Func<Actor, bool> useEnterCursor) : base("Infiltrate", 7, "enter", true, false)
{
ForceAttack=false;
this.useEnterCursor = useEnterCursor;
}
public override bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceQueued, ref string cursor)
{
if (!base.CanTargetActor(self, target, forceAttack, forceQueued, ref cursor))
return false;
if (!useEnterCursor(target))
cursor = "enter-blocked";
return true;
}
}
}
}

View File

@@ -410,7 +410,7 @@ namespace OpenRA.Mods.RA.Missions
};
lab = actors["Lab"];
lab.AddTrait(new InfiltrateAction(OnLabInfiltrated));
lab.AddTrait(new InfiltrateForMissionObjective(OnLabInfiltrated));
lab.AddTrait(new TransformedAction(self => lab = self));
reinforcementsEntryPoint = actors["ReinforcementsEntryPoint"];
@@ -456,13 +456,17 @@ namespace OpenRA.Mods.RA.Missions
public object Create(ActorInitializer init) { return new Allies04Hijackable(init.self); }
}
class Allies04Hijackable : IAcceptSpy, INotifyPassengerExited
class Allies04Hijackable : IAcceptInfiltrator, INotifyPassengerExited
{
public Player OldOwner;
void OnTruckHijacked(Actor spy) { }
public Allies04Hijackable(Actor self)
{
OldOwner = self.Owner;
self.AddTrait(new InfiltrateForMissionObjective(OnTruckHijacked));
}
public void OnInfiltrate(Actor self, Actor spy)

View File

@@ -230,11 +230,11 @@ namespace OpenRA.Mods.RA.Missions
}
}
class InfiltrateAction : IAcceptSpy
class InfiltrateForMissionObjective : IAcceptInfiltrator
{
Action<Actor> a;
public InfiltrateAction(Action<Actor> a)
public InfiltrateForMissionObjective(Action<Actor> a)
{
this.a = a;
}

View File

@@ -329,7 +329,7 @@ namespace OpenRA.Mods.RA.Missions
world.CreateActor("camera", greece, provingGroundsCameraPoint.Location, null);
superTankDome = actors["SuperTankDome"];
superTankDome.AddTrait(new InfiltrateAction(OnSuperTankDomeInfiltrated));
superTankDome.AddTrait(new InfiltrateForMissionObjective(OnSuperTankDomeInfiltrated));
superTankDome.AddTrait(new TransformedAction(self => superTankDome = self));
Game.MoveViewport(startEntryPoint.Location.ToFloat2());

View File

@@ -409,6 +409,7 @@
<Compile Include="CloakPaletteEffect.cs" />
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
<Compile Include="FogPalette.cs" />
<Compile Include="Infiltrates.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -84,15 +84,12 @@ namespace OpenRA.Mods.RA
{
get
{
yield return new UnitTraitOrderTargeter<IAcceptSpy>( "SpyInfiltrate", 7, "enter", true, false ) { ForceAttack=false };
yield return new UnitTraitOrderTargeter<RenderInfantry>( "Disguise", 7, "ability", true, true ) { ForceAttack=false };
yield return new UnitTraitOrderTargeter<RenderInfantry>("Disguise", 7, "ability", true, true) { ForceAttack=false };
}
}
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
{
if( order.OrderID == "SpyInfiltrate" )
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
if( order.OrderID == "Disguise" )
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
return null;
@@ -100,14 +97,6 @@ namespace OpenRA.Mods.RA
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "SpyInfiltrate")
{
self.SetTargetLine(Target.FromOrder(order), Color.Red);
self.CancelActivity();
self.QueueActivity(new Enter(order.TargetActor));
self.QueueActivity(new Infiltrate(order.TargetActor));
}
if (order.OrderString == "Disguise")
{
var target = order.TargetActor == self ? null : order.TargetActor;
@@ -121,8 +110,7 @@ namespace OpenRA.Mods.RA
public string VoicePhraseForOrder(Actor self, Order order)
{
return (order.OrderString == "Disguise"
|| order.OrderString == "SpyInfiltrate") ? "Attack" : null;
return (order.OrderString == "Disguise") ? "Attack" : null;
}
public Color RadarColorOverride(Actor self)