Add BridgeHut and repair activities.
This commit is contained in:
37
OpenRA.Mods.RA/Activities/RepairBridge.cs
Normal file
37
OpenRA.Mods.RA/Activities/RepairBridge.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
#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.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class RepairBridge : Activity
|
||||
{
|
||||
Target target;
|
||||
|
||||
public RepairBridge(Actor target) { this.target = Target.FromActor(target); }
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled || !target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
var hut = target.Actor.Trait<BridgeHut>();
|
||||
if (hut.BridgeDamageState == DamageState.Undamaged)
|
||||
return NextActivity;
|
||||
|
||||
hut.Repair(self);
|
||||
self.Destroy();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
OpenRA.Mods.RA/BridgeHut.cs
Normal file
41
OpenRA.Mods.RA/BridgeHut.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#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.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class BridgeHutInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new BridgeHut(init); }
|
||||
}
|
||||
|
||||
class BridgeHut
|
||||
{
|
||||
public Bridge bridge;
|
||||
|
||||
public BridgeHut(ActorInitializer init)
|
||||
{
|
||||
bridge = init.Get<ParentActorInit>().value.Trait<Bridge>();
|
||||
}
|
||||
|
||||
public void Repair(Actor repairer)
|
||||
{
|
||||
bridge.Repair(repairer, true, true);
|
||||
}
|
||||
|
||||
public DamageState BridgeDamageState { get { return bridge.AggregateDamageState(); } }
|
||||
}
|
||||
}
|
||||
@@ -423,6 +423,9 @@
|
||||
<Compile Include="Buildings\BaseProvider.cs" />
|
||||
<Compile Include="Render\WithSpinner.cs" />
|
||||
<Compile Include="Widgets\Logic\ObserverShroudSelectorLogic.cs" />
|
||||
<Compile Include="RepairsBridges.cs" />
|
||||
<Compile Include="Activities\RepairBridge.cs" />
|
||||
<Compile Include="BridgeHut.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
96
OpenRA.Mods.RA/RepairsBridges.cs
Normal file
96
OpenRA.Mods.RA/RepairsBridges.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#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 OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class RepairsBridgesInfo : TraitInfo<RepairsBridges> {}
|
||||
|
||||
class RepairsBridges : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
{
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get { yield return new RepairBridgeOrderTargeter(); }
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID == "RepairBridge")
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString != "RepairBridge")
|
||||
return null;
|
||||
|
||||
var bridge = order.TargetActor.TraitOrDefault<BridgeHut>();
|
||||
if (bridge == null)
|
||||
return null;
|
||||
|
||||
return bridge.BridgeDamageState > DamageState.Undamaged ? "Attack" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "RepairBridge")
|
||||
{
|
||||
var bridge = order.TargetActor.TraitOrDefault<BridgeHut>();
|
||||
if (bridge == null)
|
||||
return;
|
||||
|
||||
if (bridge.BridgeDamageState == DamageState.Undamaged)
|
||||
return;
|
||||
|
||||
self.SetTargetLine(Target.FromOrder(order), Color.Yellow);
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Enter(order.TargetActor, new RepairBridge(order.TargetActor)));
|
||||
}
|
||||
}
|
||||
|
||||
class RepairBridgeOrderTargeter : UnitOrderTargeter
|
||||
{
|
||||
public RepairBridgeOrderTargeter()
|
||||
: base("RepairBridge", 6, "goldwrench", true, true) { }
|
||||
|
||||
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;
|
||||
|
||||
var bridge = target.TraitOrDefault<BridgeHut>();
|
||||
if (bridge == null)
|
||||
return false;
|
||||
|
||||
// Require force attack to heal partially damaged bridges to avoid unnecessary cursor noise
|
||||
var damage = bridge.BridgeDamageState;
|
||||
if (!forceAttack && damage != DamageState.Dead)
|
||||
return false;
|
||||
|
||||
IsQueued = forceQueued;
|
||||
|
||||
// Can't repair an undamaged bridge
|
||||
if (damage == DamageState.Undamaged)
|
||||
cursor = "goldwrench-blocked";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user