use new orders system in various traits
This commit is contained in:
39
OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs
Executable file
39
OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs
Executable file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
class DeployOrderTargeter : IOrderTargeter
|
||||
{
|
||||
readonly Func<bool> useDeployCursor;
|
||||
|
||||
public DeployOrderTargeter( string order, int priority )
|
||||
: this( order, priority, () => true )
|
||||
{
|
||||
}
|
||||
|
||||
public DeployOrderTargeter( string order, int priority, Func<bool> useDeployCursor )
|
||||
{
|
||||
this.OrderID = order;
|
||||
this.OrderPriority = priority;
|
||||
this.useDeployCursor = useDeployCursor;
|
||||
}
|
||||
|
||||
public string OrderID { get; private set; }
|
||||
public int OrderPriority { get; private set; }
|
||||
|
||||
public bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
cursor = useDeployCursor() ? "deploy" : "deploy-blocked";
|
||||
return self == target;
|
||||
}
|
||||
|
||||
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
OpenRA.Mods.RA/Orders/EnterBuildingOrderTargeter.cs
Executable file
27
OpenRA.Mods.RA/Orders/EnterBuildingOrderTargeter.cs
Executable file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
class EnterBuildingOrderTargeter<T> : UnitTraitOrderTargeter<T>
|
||||
{
|
||||
readonly Func<Actor, bool> useEnterCursor;
|
||||
|
||||
public EnterBuildingOrderTargeter( string order, int priority, bool targetEnemy, bool targetAlly, Func<Actor, bool> useEnterCursor )
|
||||
: base( order, priority, "enter", targetEnemy, targetAlly )
|
||||
{
|
||||
this.useEnterCursor = useEnterCursor;
|
||||
}
|
||||
|
||||
public override bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
if( !base.CanTargetUnit( self, target, forceAttack, forceMove, ref cursor ) ) return false;
|
||||
|
||||
cursor = useEnterCursor( target ) ? "enter" : "enter-blocked";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
70
OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs
Executable file
70
OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs
Executable file
@@ -0,0 +1,70 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
class UnitOrderTargeter : IOrderTargeter
|
||||
{
|
||||
readonly string cursor;
|
||||
readonly bool targetEnemyUnits, targetAllyUnits;
|
||||
|
||||
public UnitOrderTargeter( string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits )
|
||||
{
|
||||
this.OrderID = order;
|
||||
this.OrderPriority = priority;
|
||||
this.cursor = cursor;
|
||||
this.targetEnemyUnits = targetEnemyUnits;
|
||||
this.targetAllyUnits = targetAllyUnits;
|
||||
}
|
||||
|
||||
public string OrderID { get; private set; }
|
||||
public int OrderPriority { get; private set; }
|
||||
|
||||
public virtual bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
if( self == null ) throw new ArgumentNullException( "self" );
|
||||
if( target == null ) throw new ArgumentNullException( "target" );
|
||||
|
||||
cursor = this.cursor;
|
||||
|
||||
var playerRelationship = self.Owner.Stances[ target.Owner ];
|
||||
|
||||
if( !forceAttack && playerRelationship == Stance.Ally && !targetAllyUnits ) return false;
|
||||
if( !forceAttack && playerRelationship == Stance.Enemy && !targetEnemyUnits ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class UnitTraitOrderTargeter<T> : UnitOrderTargeter
|
||||
{
|
||||
public UnitTraitOrderTargeter( string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits )
|
||||
: base( order, priority, cursor, targetEnemyUnits, targetAllyUnits )
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
if( !base.CanTargetUnit( self, target, forceAttack, forceMove, ref cursor ) ) return false;
|
||||
if( !target.HasTrait<T>() ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user