Tweak capturing traits

This commit is contained in:
Paul Chote
2011-04-10 12:34:54 +12:00
parent a31ef3d8e2
commit 362170ee67
7 changed files with 109 additions and 76 deletions

View File

@@ -14,11 +14,11 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class CaptureBuilding : CancelableActivity
class CaptureActor : CancelableActivity
{
Actor target;
public CaptureBuilding(Actor target) { this.target = target; }
public CaptureActor(Actor target) { this.target = target; }
public override IActivity Tick(Actor self)
{

View File

@@ -16,7 +16,10 @@ namespace OpenRA.Mods.RA
{
public class CapturableInfo : TraitInfo<Capturable>
{
public readonly string[] CaptureClasses = {"Building"};
public readonly string Type = "building";
public readonly bool AllowAllies = false;
public readonly bool AllowNeutral = false;
public readonly bool AllowEnemies = true;
}
public class Capturable {}

View File

@@ -0,0 +1,99 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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.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;
namespace OpenRA.Mods.RA
{
class CapturesInfo : ITraitInfo
{
public string[] CaptureTypes = {"building"};
public object Create(ActorInitializer init) { return new Captures(this); }
}
class Captures : IIssueOrder, IResolveOrder, IOrderVoice
{
public readonly CapturesInfo Info;
public Captures(CapturesInfo info)
{
Info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get
{
yield return new CaptureOrderTargeter(Info.CaptureTypes);
}
}
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
{
if( order.OrderID == "CaptureActor" )
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
return null;
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return (order.OrderString == "CaptureActor") ? "Attack" : null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "CaptureActor")
{
self.SetTargetLine(Target.FromOrder(order), Color.Red);
self.CancelActivity();
self.QueueActivity(new Enter(order.TargetActor));
self.QueueActivity(new CaptureActor(order.TargetActor));
}
}
}
class CaptureOrderTargeter : UnitTraitOrderTargeter<Capturable>
{
readonly string[] captureTypes;
public CaptureOrderTargeter(string[] captureTypes)
: base( "CaptureActor", 6, "enter", true, true )
{
this.captureTypes = captureTypes;
}
public override bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
{
if( !base.CanTargetActor( self, target, forceAttack, forceMove, forceQueued, ref cursor ) ) return false;
var ci = target.Info.Traits.Get<CapturableInfo>();
var playerRelationship = self.Owner.Stances[ target.Owner ];
if( playerRelationship == Stance.Ally && !ci.AllowAllies ) return false;
if( playerRelationship == Stance.Enemy && !ci.AllowEnemies ) return false;
if( playerRelationship == Stance.Neutral && !ci.AllowNeutral ) return false;
IsQueued = forceQueued;
if (captureTypes.Contains(ci.Type))
{
cursor = "enter";
return true;
}
return false;
}
}
}

View File

@@ -1,69 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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.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;
namespace OpenRA.Mods.RA
{
class EngineerCaptureInfo : ITraitInfo
{
public string[] CaptureClasses = {"Building"};
public object Create(ActorInitializer init) { return new EngineerCapture(this); }
}
class EngineerCapture : IIssueOrder, IResolveOrder, IOrderVoice
{
public readonly EngineerCaptureInfo Info;
public EngineerCapture(EngineerCaptureInfo info)
{
Info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get
{
yield return new EnterOrderTargeter<Capturable>( "CaptureBuilding", 5, true, false,
_ => true, target => target.Info.Traits.Get<CapturableInfo>().CaptureClasses.Intersect(Info.CaptureClasses).Any() );
}
}
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
{
if( order.OrderID == "CaptureBuilding" )
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
return null;
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return (order.OrderString == "CaptureBuilding") ? "Attack" : null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "CaptureBuilding")
{
self.SetTargetLine(Target.FromOrder(order), Color.Red);
self.CancelActivity();
self.QueueActivity(new Enter(order.TargetActor));
self.QueueActivity(new CaptureBuilding(order.TargetActor));
}
}
}
}

View File

@@ -55,7 +55,6 @@
<Compile Include="AcceptsSupplies.cs" />
<Compile Include="Activities\Attack.cs" />
<Compile Include="Activities\CallFunc.cs" />
<Compile Include="Activities\CaptureBuilding.cs" />
<Compile Include="Activities\DonateSupplies.cs" />
<Compile Include="Activities\QueuedActivity.cs" />
<Compile Include="Activities\DeliverOre.cs" />
@@ -207,7 +206,6 @@
<Compile Include="Effects\InvulnEffect.cs" />
<Compile Include="Effects\Parachute.cs" />
<Compile Include="Effects\SatelliteLaunch.cs" />
<Compile Include="EngineerCapture.cs" />
<Compile Include="SupportPowers\GpsPower.cs" />
<Compile Include="InfiltrateForSupportPower.cs" />
<Compile Include="IronCurtainable.cs" />
@@ -342,6 +340,8 @@
<Compile Include="Activities\MakeAnimation.cs" />
<Compile Include="Activities\Sell.cs" />
<Compile Include="Sellable.cs" />
<Compile Include="Captures.cs" />
<Compile Include="Activities\CaptureActor.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -144,7 +144,7 @@ E6:
Passenger:
PipType: Yellow
EngineerRepair:
EngineerCapture:
Captures:
-AutoTarget:
AttackMove:
JustMove: true

View File

@@ -155,7 +155,7 @@ E6:
Passenger:
PipType: Yellow
EngineerRepair:
EngineerCapture:
Captures:
TakeCover:
-AutoTarget:
AttackMove: