Files
OpenRA/OpenRA.Mods.RA/SupplyTruck.cs
Paul Chote e76c746b61 Rewrite Enter and related activities.
The unit will now path to the nearest adjacent cell, drag inside, do the inner activity, then (if still alive) drag back to its original
location.

This fixes:
 - Mismatch in logic between Enter and MoveAdjacentTo,
   which causes an infinite loop.
 - Building capturing failing from certain directions.
 - Being unable to enter buildings on unpathable tiles.
 - Units being stranded inside a building if the requirements
   for the inner order aren't met.
2013-04-15 08:05:37 +12:00

85 lines
2.3 KiB
C#

#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.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
[Desc("Donate money to building if it has the AcceptSupplies: trait.")]
class SupplyTruckInfo : ITraitInfo
{
[Desc("The amount of cash the owner of the building recieves.")]
public readonly int Payload = 500;
public object Create(ActorInitializer init) { return new SupplyTruck(this); }
}
class SupplyTruck : IIssueOrder, IResolveOrder, IOrderVoice
{
SupplyTruckInfo Info;
public SupplyTruck(SupplyTruckInfo info)
{
Info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new SupplyTruckOrderTargeter(); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID == "DeliverSupplies")
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
return null;
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return "Move";
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "DeliverSupplies")
{
self.SetTargetLine(Target.FromOrder(order), Color.Yellow);
self.CancelActivity();
self.QueueActivity(new Enter(order.TargetActor, new DonateSupplies(order.TargetActor, Info.Payload)));
}
}
class SupplyTruckOrderTargeter : UnitTraitOrderTargeter<Building>
{
public SupplyTruckOrderTargeter()
: base("DeliverSupplies", 5, "enter", false, 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;
if (target.AppearsHostileTo(self)) return false;
if (!target.HasTrait<AcceptsSupplies>()) return false;
IsQueued = forceQueued;
return true;
}
}
}
}