unify handling of order expose + issue for plane/heli; was identical
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#region Copyright & License Information
|
||||
#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
|
||||
@@ -11,9 +11,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Air
|
||||
{
|
||||
@@ -76,7 +78,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
public virtual object Create( ActorInitializer init ) { return new Aircraft( init , this ); }
|
||||
}
|
||||
|
||||
public class Aircraft : IMove, IFacing, IOccupySpace, ISync, INotifyKilled
|
||||
public class Aircraft : IMove, IFacing, IOccupySpace, ISync, INotifyKilled, IIssueOrder, IOrderVoice
|
||||
{
|
||||
public IDisposable reservation;
|
||||
|
||||
@@ -183,5 +185,51 @@ namespace OpenRA.Mods.RA.Air
|
||||
if (Info.RepairBuildings.Contains(name))
|
||||
self.QueueActivity(new Repair(a));
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterOrderTargeter<Building>("Enter", 5, false, true,
|
||||
target => AircraftCanEnter(target), target => !Reservable.IsReserved(target));
|
||||
|
||||
yield return new AircraftMoveOrderTargeter();
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID == "Enter")
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
|
||||
if (order.OrderID == "Move")
|
||||
return new Order(order.OrderID, self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) };
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return (order.OrderString == "Move" || order.OrderString == "Enter") ? "Move" : null;
|
||||
}
|
||||
}
|
||||
|
||||
class AircraftMoveOrderTargeter : IOrderTargeter
|
||||
{
|
||||
public string OrderID { get { return "Move"; } }
|
||||
public int OrderPriority { get { return 4; } }
|
||||
|
||||
public bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
|
||||
{
|
||||
IsQueued = forceQueued;
|
||||
cursor = self.World.Map.IsInMap(location) ? "move" : "move-blocked";
|
||||
return true;
|
||||
}
|
||||
public bool IsQueued { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,11 @@
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Air
|
||||
@@ -28,7 +23,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
public override object Create( ActorInitializer init ) { return new Helicopter( init, this); }
|
||||
}
|
||||
|
||||
class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder, IOrderVoice
|
||||
class Helicopter : Aircraft, ITick, IResolveOrder
|
||||
{
|
||||
HelicopterInfo Info;
|
||||
bool firstTick = true;
|
||||
@@ -38,33 +33,6 @@ namespace OpenRA.Mods.RA.Air
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterOrderTargeter<Building>( "Enter", 5, false, true,
|
||||
target => AircraftCanEnter( target ), target => !Reservable.IsReserved( target ) );
|
||||
|
||||
yield return new AircraftMoveOrderTargeter();
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
|
||||
{
|
||||
if( order.OrderID == "Enter" )
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
|
||||
if( order.OrderID == "Move" )
|
||||
return new Order(order.OrderID, self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) };
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return (order.OrderString == "Move" || order.OrderString == "Enter") ? "Move" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (reservation != null)
|
||||
|
||||
@@ -8,12 +8,8 @@
|
||||
*/
|
||||
#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.Air
|
||||
@@ -23,7 +19,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
public override object Create( ActorInitializer init ) { return new Plane( init, this ); }
|
||||
}
|
||||
|
||||
public class Plane : Aircraft, IIssueOrder, IResolveOrder, IOrderVoice, ITick, ISync
|
||||
public class Plane : Aircraft, IResolveOrder, ITick, ISync
|
||||
{
|
||||
[Sync]
|
||||
public int2 RTBPathHash;
|
||||
@@ -52,33 +48,6 @@ namespace OpenRA.Mods.RA.Air
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterOrderTargeter<Building>( "Enter", 5, false, true,
|
||||
target => AircraftCanEnter( target ), target => !Reservable.IsReserved( target ) );
|
||||
|
||||
yield return new AircraftMoveOrderTargeter();
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
|
||||
{
|
||||
if( order.OrderID == "Enter" )
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
|
||||
if( order.OrderID == "Move" )
|
||||
return new Order( order.OrderID, self, queued ) { TargetLocation = Util.CellContaining( target.CenterLocation ) };
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return (order.OrderString == "Move" || order.OrderString == "Enter") ? "Move" : null;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Move")
|
||||
@@ -101,8 +70,8 @@ namespace OpenRA.Mods.RA.Air
|
||||
self.SetTargetLine(Target.FromOrder(order), Color.Green);
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
||||
|
||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
||||
|
||||
QueueResupplyActivities(order.TargetActor);
|
||||
}
|
||||
else if (order.OrderString == "Stop")
|
||||
@@ -117,23 +86,4 @@ namespace OpenRA.Mods.RA.Air
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AircraftMoveOrderTargeter : IOrderTargeter
|
||||
{
|
||||
public string OrderID { get { return "Move"; } }
|
||||
public int OrderPriority { get { return 4; } }
|
||||
|
||||
public bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor)
|
||||
{
|
||||
IsQueued = forceQueued;
|
||||
cursor = self.World.Map.IsInMap(location) ? "move" : "move-blocked";
|
||||
return true;
|
||||
}
|
||||
public bool IsQueued { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user