Remove unused stance code
This commit is contained in:
@@ -64,8 +64,6 @@
|
|||||||
<Compile Include="Strategic\StrategicVictoryConditions.cs" />
|
<Compile Include="Strategic\StrategicVictoryConditions.cs" />
|
||||||
<Compile Include="Strategic\StrategicPoint.cs" />
|
<Compile Include="Strategic\StrategicPoint.cs" />
|
||||||
<Compile Include="ProximityCapturable.cs" />
|
<Compile Include="ProximityCapturable.cs" />
|
||||||
<Compile Include="UnitStances\UnitStanceDefensive.cs" />
|
|
||||||
<Compile Include="UnitStances\UnitStanceAggressive.cs" />
|
|
||||||
<Compile Include="Air\Fly.cs" />
|
<Compile Include="Air\Fly.cs" />
|
||||||
<Compile Include="Air\FlyAttack.cs" />
|
<Compile Include="Air\FlyAttack.cs" />
|
||||||
<Compile Include="Air\FlyTimed.cs" />
|
<Compile Include="Air\FlyTimed.cs" />
|
||||||
@@ -87,7 +85,6 @@
|
|||||||
<Compile Include="Activities\Turn.cs" />
|
<Compile Include="Activities\Turn.cs" />
|
||||||
<Compile Include="Activities\UnloadCargo.cs" />
|
<Compile Include="Activities\UnloadCargo.cs" />
|
||||||
<Compile Include="Activities\Wait.cs" />
|
<Compile Include="Activities\Wait.cs" />
|
||||||
<Compile Include="UnitStances\UnitStance.cs" />
|
|
||||||
<Compile Include="AttackBase.cs" />
|
<Compile Include="AttackBase.cs" />
|
||||||
<Compile Include="AttackMove.cs" />
|
<Compile Include="AttackMove.cs" />
|
||||||
<Compile Include="BaseBuilding.cs" />
|
<Compile Include="BaseBuilding.cs" />
|
||||||
@@ -102,10 +99,6 @@
|
|||||||
<Compile Include="Buildings\Sell.cs" />
|
<Compile Include="Buildings\Sell.cs" />
|
||||||
<Compile Include="Buildings\TechTree.cs" />
|
<Compile Include="Buildings\TechTree.cs" />
|
||||||
<Compile Include="Buildings\Util.cs" />
|
<Compile Include="Buildings\Util.cs" />
|
||||||
<Compile Include="UnitStances\AssignUnitStance.cs" />
|
|
||||||
<Compile Include="UnitStances\UnitStanceHoldFire.cs" />
|
|
||||||
<Compile Include="UnitStances\UnitStanceReturnFire.cs" />
|
|
||||||
<Compile Include="UnitStances\UnitStanceHoldGround.cs" />
|
|
||||||
<Compile Include="ProximityCaptor.cs" />
|
<Compile Include="ProximityCaptor.cs" />
|
||||||
<Compile Include="Valued.cs" />
|
<Compile Include="Valued.cs" />
|
||||||
<Compile Include="Combat.cs" />
|
<Compile Include="Combat.cs" />
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.UnitStances
|
|
||||||
{
|
|
||||||
public class AssignUnitStanceInfo : TraitInfo<AssignUnitStance>
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AssignUnitStance : INotifyProduction
|
|
||||||
{
|
|
||||||
public void UnitProduced(Actor self, Actor other, int2 exit)
|
|
||||||
{
|
|
||||||
var stance = UnitStance.GetActive(self);
|
|
||||||
if (stance == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var target = other.TraitsImplementing<UnitStance>().Where(t => t.GetType() == stance.GetType()).FirstOrDefault();
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
target.Activate(other);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,313 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
|
|
||||||
public class UnitStanceInfo : ITraitInfo, ITraitPrerequisite<AttackBaseInfo>
|
|
||||||
{
|
|
||||||
public readonly bool Default = false;
|
|
||||||
public readonly int ScanDelayMin = 12;
|
|
||||||
public readonly int ScanDelayMax = 24;
|
|
||||||
#region ITraitInfo Members
|
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init)
|
|
||||||
{
|
|
||||||
throw new Exception("UnitStanceInfo: Override me!");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class UnitStance : ITick, IResolveOrder, ISelectionColorModifier, IPostRenderSelection, ISync
|
|
||||||
{
|
|
||||||
[Sync]
|
|
||||||
public int NextScanTime;
|
|
||||||
|
|
||||||
public UnitStanceInfo Info { get; protected set; }
|
|
||||||
public abstract Color SelectionColor { get; }
|
|
||||||
|
|
||||||
[Sync]
|
|
||||||
public bool AllowMultiTrigger { get; protected set; }
|
|
||||||
|
|
||||||
#region ITick Members
|
|
||||||
|
|
||||||
protected UnitStance(Actor self, UnitStanceInfo info)
|
|
||||||
{
|
|
||||||
Info = info;
|
|
||||||
Active = Info.Default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (!Active) return;
|
|
||||||
|
|
||||||
TickScan(self);
|
|
||||||
|
|
||||||
OnTick(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnTick(Actor self)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TickScan(Actor self)
|
|
||||||
{
|
|
||||||
NextScanTime--;
|
|
||||||
|
|
||||||
if (NextScanTime <= 0)
|
|
||||||
{
|
|
||||||
NextScanTime = GetNextScanTime(self);
|
|
||||||
OnScan(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetNextScanTime(Actor self)
|
|
||||||
{
|
|
||||||
return self.World.SharedRandom.Next(Info.ScanDelayMin, Info.ScanDelayMax+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IUnitStance Members
|
|
||||||
|
|
||||||
public bool Active { get; set; }
|
|
||||||
|
|
||||||
public virtual bool IsDefault
|
|
||||||
{
|
|
||||||
get { return Info.Default; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Activate(Actor self)
|
|
||||||
{
|
|
||||||
if (Active && !AllowMultiTrigger) return;
|
|
||||||
|
|
||||||
Active = true;
|
|
||||||
NextScanTime = 0;
|
|
||||||
DeactivateOthers(self);
|
|
||||||
OnActivate(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Deactivate(Actor self)
|
|
||||||
{
|
|
||||||
if (Active)
|
|
||||||
{
|
|
||||||
Active = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public virtual void DeactivateOthers(Actor self)
|
|
||||||
{
|
|
||||||
DeactivateOthers(self, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsActive<T>(Actor self) where T : UnitStance
|
|
||||||
{
|
|
||||||
var stance = self.TraitOrDefault<T>();
|
|
||||||
|
|
||||||
return stance != null && stance.Active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DeactivateOthers(Actor self, UnitStance stance)
|
|
||||||
{
|
|
||||||
self.TraitsImplementing<UnitStance>().Where(t => t != stance).Do(t => t.Deactivate(self));
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract string OrderString { get; }
|
|
||||||
|
|
||||||
public static bool ReturnFire(Actor self, AttackInfo e, bool allowActivity, bool allowTargetSwitch, bool holdStill)
|
|
||||||
{
|
|
||||||
if (!self.IsIdle && !allowActivity) return false;
|
|
||||||
if (e.Attacker.Destroyed) return false;
|
|
||||||
|
|
||||||
var attack = self.TraitOrDefault<AttackBase>();
|
|
||||||
|
|
||||||
// this unit cannot fight back at all (no guns)
|
|
||||||
if (attack == null) return false;
|
|
||||||
|
|
||||||
// if attacking already and force was used, return (ie to respond to attacks while moving around)
|
|
||||||
if (attack.IsAttacking && (!allowTargetSwitch)) return false;
|
|
||||||
|
|
||||||
// don't fight back if we dont have the guns to do so
|
|
||||||
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker))) return false;
|
|
||||||
|
|
||||||
// don't retaliate against allies
|
|
||||||
if (self.Owner.Stances[e.Attacker.Owner] == Stance.Ally) return false;
|
|
||||||
|
|
||||||
// don't retaliate against healers
|
|
||||||
if (e.Damage < 0) return false;
|
|
||||||
|
|
||||||
// perform the attack
|
|
||||||
AttackTarget(self, e.Attacker, holdStill);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ReturnFire(Actor self, AttackInfo e, bool allowActivity, bool allowTargetSwitch)
|
|
||||||
{
|
|
||||||
return ReturnFire(self, e, allowActivity, allowTargetSwitch, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ReturnFire(Actor self, AttackInfo e, bool allowActivity)
|
|
||||||
{
|
|
||||||
return ReturnFire(self, e, allowActivity, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UnitStance GetActive(Actor self)
|
|
||||||
{
|
|
||||||
return self.TraitsImplementing<UnitStance>().Where(t => t.Active).FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AttackTarget(Actor self, Actor target, bool holdStill)
|
|
||||||
{
|
|
||||||
if (target != null)
|
|
||||||
self.Trait<AttackBase>().AttackTarget(Target.FromActor(target), false, !holdStill);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void StopAttack(Actor self)
|
|
||||||
{
|
|
||||||
if (self.GetCurrentActivity() is Activities.Attack)
|
|
||||||
self.GetCurrentActivity().Cancel(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when on the first tick after the stance has been activated
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
protected virtual void OnScan(Actor self)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when on the first tick after the stance has been activated
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="self"></param>
|
|
||||||
protected virtual void OnActivate(Actor self)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Actor ScanForTarget(Actor self)
|
|
||||||
{
|
|
||||||
return self.Trait<AttackBase>().ScanForTarget(self, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
if (order.OrderString == OrderString)
|
|
||||||
{
|
|
||||||
// Its our order, activate the stance
|
|
||||||
Activate(self);
|
|
||||||
return; // Do not call OnOrder on our own stance order
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Active) return;
|
|
||||||
|
|
||||||
OnOrder(self, order);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OrderStance(Actor self, UnitStance stance)
|
|
||||||
{
|
|
||||||
self.World.IssueOrder(new Order(stance.OrderString, self, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color GetSelectionColorModifier(Actor self, Color defaultColor)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] != Stance.Ally)
|
|
||||||
return defaultColor;
|
|
||||||
|
|
||||||
return Active ? SelectionColor : defaultColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RenderAfterWorld(WorldRenderer wr, Actor self)
|
|
||||||
{
|
|
||||||
if (!Active) return;
|
|
||||||
if (!self.IsInWorld) return;
|
|
||||||
if (self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] != Stance.Ally)
|
|
||||||
return;
|
|
||||||
|
|
||||||
RenderStance(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual string Shape
|
|
||||||
{
|
|
||||||
get { return "xxxx\nx x\nx x\nxxxx"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RenderStance(Actor self)
|
|
||||||
{
|
|
||||||
var bounds = self.GetBounds(false);
|
|
||||||
var loc = new float2(bounds.Left, bounds.Top) + new float2(0, 1);
|
|
||||||
var max = Math.Max(bounds.Height, bounds.Width);
|
|
||||||
|
|
||||||
var shape = Shape;
|
|
||||||
|
|
||||||
// 'Resize' for large actors
|
|
||||||
if (max >= Game.CellSize)
|
|
||||||
{
|
|
||||||
shape = shape.Replace(" ", " ");
|
|
||||||
shape = shape.Replace("x", "xx");
|
|
||||||
}
|
|
||||||
var color = Color.FromArgb(125, Color.Black);
|
|
||||||
|
|
||||||
|
|
||||||
int y = 0;
|
|
||||||
var shapeLines = shape.Split('\n');
|
|
||||||
|
|
||||||
foreach (var shapeLine in shapeLines)
|
|
||||||
{
|
|
||||||
for (int yt = 0; yt < ((max >= Game.CellSize) ? 2 : 1); yt++)
|
|
||||||
{
|
|
||||||
int x = 0;
|
|
||||||
|
|
||||||
foreach (var shapeKey in shapeLine)
|
|
||||||
{
|
|
||||||
if (shapeKey == 'x')
|
|
||||||
{
|
|
||||||
Game.Renderer.LineRenderer.DrawLine(loc + new float2(x, y), loc + new float2(x + 1f, y), color, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
y = 0;
|
|
||||||
shapeLines = shape.Split('\n');
|
|
||||||
|
|
||||||
color = SelectionColor;
|
|
||||||
foreach (var shapeLine in shapeLines)
|
|
||||||
{
|
|
||||||
for (int yt = 0; yt < ((max >= Game.CellSize) ? 2 : 1); yt++)
|
|
||||||
{
|
|
||||||
int x = 0;
|
|
||||||
|
|
||||||
foreach (var shapeKey in shapeLine)
|
|
||||||
{
|
|
||||||
if (shapeKey == 'x')
|
|
||||||
{
|
|
||||||
Game.Renderer.LineRenderer.DrawLine(loc + new float2(x + 1, y + 1), loc + new float2(x + 1 + 1f, y + 1), color, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
public class UnitStanceAggressiveInfo : UnitStanceInfo
|
|
||||||
{
|
|
||||||
public override object Create(ActorInitializer init) { return new UnitStanceAggressive(init.self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Inherits the Return Fire damage handler!
|
|
||||||
/// </summary>
|
|
||||||
public class UnitStanceAggressive : UnitStance, INotifyDamage
|
|
||||||
{
|
|
||||||
public UnitStanceAggressive(Actor self, UnitStanceAggressiveInfo info)
|
|
||||||
: base(self, info)
|
|
||||||
{
|
|
||||||
RankAnim = new Animation("rank");
|
|
||||||
RankAnim.PlayFetchIndex("rank", () => 3 - 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Animation RankAnim { get; set; }
|
|
||||||
|
|
||||||
public override string OrderString
|
|
||||||
{
|
|
||||||
get { return "StanceAggressive"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnScan(Actor self)
|
|
||||||
{
|
|
||||||
if (!self.IsIdle) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
var target = ScanForTarget(self);
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttackTarget(self, target, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnActivate(Actor self)
|
|
||||||
{
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
if (self.Trait<AttackBase>().IsAttacking)
|
|
||||||
StopAttack(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void Damaged(Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
if (!Active) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
ReturnFire(self, e, false); // only triggers when standing still
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Color SelectionColor
|
|
||||||
{
|
|
||||||
get { return Color.Red; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Shape
|
|
||||||
{
|
|
||||||
get { return "x x\n xx \n xx \nx x"; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Mods.RA.Move;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
public class UnitStanceDefensiveInfo : UnitStanceInfo
|
|
||||||
{
|
|
||||||
public override object Create(ActorInitializer init) { return new UnitStanceDefensive(init.self, this); }
|
|
||||||
public readonly int MaxDistance = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Return Fire
|
|
||||||
///
|
|
||||||
/// Will fire only when fired upon
|
|
||||||
/// </summary>
|
|
||||||
public class UnitStanceDefensive : UnitStance, INotifyDamage, ISync
|
|
||||||
{
|
|
||||||
public enum ETargetType
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Location,
|
|
||||||
Actor
|
|
||||||
}
|
|
||||||
|
|
||||||
[Sync] public int MaxDistance;
|
|
||||||
public Target DefendTarget = Target.None;
|
|
||||||
public ETargetType TargetType = ETargetType.None;
|
|
||||||
public bool WaitingForIdle = false;
|
|
||||||
[Sync]
|
|
||||||
public bool IsReturning { get; protected set; }
|
|
||||||
|
|
||||||
public UnitStanceDefensive(Actor self, UnitStanceDefensiveInfo info)
|
|
||||||
: base(self, info)
|
|
||||||
{
|
|
||||||
MaxDistance = info.MaxDistance;
|
|
||||||
|
|
||||||
base.AllowMultiTrigger = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnActivate(Actor self)
|
|
||||||
{
|
|
||||||
DefendThis(self.CenterLocation);
|
|
||||||
|
|
||||||
if (!self.IsIdle)
|
|
||||||
WaitForIdle();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void DefendThis(int2 target)
|
|
||||||
{
|
|
||||||
DefendTarget = Target.FromPos(target);
|
|
||||||
TargetType = ETargetType.Location;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void DefendThis(Actor target)
|
|
||||||
{
|
|
||||||
DefendTarget = Target.FromActor(target);
|
|
||||||
TargetType = ETargetType.Actor;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnScan(Actor self)
|
|
||||||
{
|
|
||||||
if (TargetType == ETargetType.None) return;
|
|
||||||
if (IsReturning) return;
|
|
||||||
if (!self.IsIdle) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
var target = ScanForTarget(self);
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttackTarget(self, target, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnTick(Actor self)
|
|
||||||
{
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
// when the unit is doing nothing or the target actor is gone, tell him to defend the current location
|
|
||||||
if ((WaitingForIdle && self.IsIdle) || (self.IsIdle && (TargetType == ETargetType.Actor && !DefendTarget.IsValid)))
|
|
||||||
{
|
|
||||||
IsReturning = false;
|
|
||||||
WaitingForIdle = false;
|
|
||||||
DefendThis(self.CenterLocation);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (IsReturning && self.IsIdle)
|
|
||||||
{
|
|
||||||
IsReturning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TargetType != ETargetType.None)
|
|
||||||
{
|
|
||||||
if ((self.CenterLocation - DefendTarget.CenterLocation).Length > MaxDistance * Game.CellSize)
|
|
||||||
{
|
|
||||||
Return(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnOrder(Actor self, Order order)
|
|
||||||
{
|
|
||||||
WaitForIdle();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WaitForIdle()
|
|
||||||
{
|
|
||||||
// could be an attack or move order ... => 'disable' the stance for now (invalidate the target)
|
|
||||||
DefendTarget = Target.None;
|
|
||||||
TargetType = ETargetType.None;
|
|
||||||
WaitingForIdle = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
if (!Active) return;
|
|
||||||
if (TargetType == ETargetType.None) return;
|
|
||||||
if (IsReturning) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
ReturnFire(self, e, false); // only triggers when standing still
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string OrderString
|
|
||||||
{
|
|
||||||
get { return "StanceDefensive"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Color SelectionColor
|
|
||||||
{
|
|
||||||
get { return Color.LightGoldenrodYellow; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Shape
|
|
||||||
{
|
|
||||||
get { return "xxxx\nxxxx"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Return(Actor self)
|
|
||||||
{
|
|
||||||
if ((TargetType == ETargetType.None) || (!DefendTarget.IsValid && (TargetType == ETargetType.Actor && !DefendTarget.IsValid))) return;
|
|
||||||
IsReturning = true;
|
|
||||||
|
|
||||||
var attackBase = self.TraitOrDefault<AttackBase>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Reset the attack target => otherwise it will not pick up enemies anymore!
|
|
||||||
|
|
||||||
// This should result in unsetting the target (could do it directly, this seems more 'valid')
|
|
||||||
self.World.AddFrameEndTask(w =>
|
|
||||||
{
|
|
||||||
self.CancelActivity();
|
|
||||||
attackBase.ResolveOrder(self, new Order("Stop", self, false));
|
|
||||||
self.QueueActivity(self.Trait<Mobile>().MoveWithinRange(DefendTarget, 1));
|
|
||||||
WaitForIdle();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
public class UnitStanceHoldFireInfo : UnitStanceInfo
|
|
||||||
{
|
|
||||||
public override object Create(ActorInitializer init) { return new UnitStanceHoldFire(init.self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Hold Fire
|
|
||||||
///
|
|
||||||
/// Will not perform any attacks automaticly
|
|
||||||
/// </summary>
|
|
||||||
public class UnitStanceHoldFire : UnitStance, ISelectionColorModifier
|
|
||||||
{
|
|
||||||
public UnitStanceHoldFire(Actor self, UnitStanceHoldFireInfo info)
|
|
||||||
: base(self, info)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string OrderString
|
|
||||||
{
|
|
||||||
get { return "StanceHoldFire"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnActivate(Actor self)
|
|
||||||
{
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
if (self.Trait<AttackBase>().IsAttacking)
|
|
||||||
StopAttack(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Color SelectionColor
|
|
||||||
{
|
|
||||||
get { return Color.SpringGreen; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Shape
|
|
||||||
{
|
|
||||||
get { return " xx \nxxxx\n xx "; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Mods.RA.Move;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
public class UnitStanceHoldGroundInfo : UnitStanceInfo
|
|
||||||
{
|
|
||||||
public override object Create(ActorInitializer init) { return new UnitStanceHoldGround(init.self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UnitStanceHoldGround : UnitStance, INotifyDamage
|
|
||||||
{
|
|
||||||
public UnitStanceHoldGround(Actor self, UnitStanceHoldGroundInfo info)
|
|
||||||
: base(self, info)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override string OrderString
|
|
||||||
{
|
|
||||||
get { return "StanceHoldGround"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnScan(Actor self)
|
|
||||||
{
|
|
||||||
if (!self.IsIdle) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
var target = ScanForTarget(self);
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AttackTarget(self, target, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnActivate(Actor self)
|
|
||||||
{
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
if (self.Trait<AttackBase>().IsAttacking)
|
|
||||||
StopAttack(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
if (!Active) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
ReturnFire(self, e, false, false, true); // only triggers when standing still
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Color SelectionColor
|
|
||||||
{
|
|
||||||
get { return Color.Yellow; }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Shape
|
|
||||||
{
|
|
||||||
get { return "xxx\nx x\nx x\nxxx"; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
|
||||||
{
|
|
||||||
public class UnitStanceReturnFireInfo : UnitStanceInfo
|
|
||||||
{
|
|
||||||
public override object Create(ActorInitializer init) { return new UnitStanceReturnFire(init.self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Return Fire
|
|
||||||
///
|
|
||||||
/// Will fire only when fired upon
|
|
||||||
/// </summary>
|
|
||||||
public class UnitStanceReturnFire : UnitStance, INotifyDamage, ISelectionColorModifier
|
|
||||||
{
|
|
||||||
public UnitStanceReturnFire(Actor self, UnitStanceReturnFireInfo info)
|
|
||||||
: base(self, info)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
if (!Active) return;
|
|
||||||
if (!self.HasTrait<AttackBase>()) return;
|
|
||||||
|
|
||||||
ReturnFire(self, e, false); // only triggers when standing still
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string OrderString
|
|
||||||
{
|
|
||||||
get { return "StanceReturnFire"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Color SelectionColor
|
|
||||||
{
|
|
||||||
get { return Color.Orange; }
|
|
||||||
}
|
|
||||||
protected override string Shape
|
|
||||||
{
|
|
||||||
get { return "xxx\nxxx\nxxx\n x \n x \n\nxxx \nxxx "; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,11 +14,6 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
public char AttackMoveKey = 'a';
|
public char AttackMoveKey = 'a';
|
||||||
public char StopKey = 's';
|
public char StopKey = 's';
|
||||||
public char HoldGroundKey = 'g'; // Hold (G)round
|
|
||||||
public char DefensiveKey = 'd'; // (D)efensive
|
|
||||||
public char AggressiveKey = 'a'; // (A)ggressive
|
|
||||||
public char ReturnFireKey = 'r'; // (R)eturn Fire
|
|
||||||
public char HoldFireKey = 'h'; // (h)old fire
|
|
||||||
public readonly OrderManager OrderManager;
|
public readonly OrderManager OrderManager;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
@@ -52,56 +47,10 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
if (e.KeyChar == StopKey)
|
if (e.KeyChar == StopKey)
|
||||||
return PerformStop();
|
return PerformStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* // command: GuardStance
|
|
||||||
if (e.KeyChar == HoldGroundKey && (e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
{
|
|
||||||
return EnableStance<UnitStanceHoldGround>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// command: AggressiveStance
|
|
||||||
if (e.KeyChar == AggressiveKey && (e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
{
|
|
||||||
return EnableStance<UnitStanceAggressive>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// stance: Return Fire
|
|
||||||
// description: Fires only when fired upon, stops firing if no longer under attack
|
|
||||||
if (e.KeyChar == ReturnFireKey && (e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
{
|
|
||||||
return EnableStance<UnitStanceReturnFire>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// stance: Hold Fire
|
|
||||||
// description: Prevents attacking (ie no autotarget is being done)
|
|
||||||
if (e.KeyChar == HoldFireKey && (e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
{
|
|
||||||
return EnableStance<UnitStanceHoldFire>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// stance: Defensive
|
|
||||||
if (e.KeyChar == DefensiveKey && (e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
{
|
|
||||||
return EnableStance<UnitStanceDefensive>();
|
|
||||||
} */
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool EnableStance<T>() where T : UnitStance
|
|
||||||
//{
|
|
||||||
// if (World.Selection.Actors.Count() == 0)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
// var traits =
|
|
||||||
// World.Selection.Actors.Where(a => !a.Destroyed && a.Owner == World.LocalPlayer && a.TraitOrDefault<T>() != null && !UnitStance.IsActive<T>(a)).
|
|
||||||
// Select(a => new Pair<Actor, T>(a, a.TraitOrDefault<T>()) );
|
|
||||||
|
|
||||||
// World.AddFrameEndTask(w => traits.Do(p => UnitStance.OrderStance(p.First, p.Second)));
|
|
||||||
|
|
||||||
// return traits.Any();
|
|
||||||
//}
|
|
||||||
|
|
||||||
bool PerformAttackMove()
|
bool PerformAttackMove()
|
||||||
{
|
{
|
||||||
World.OrderGenerator = new GenericSelectTarget(World.Selection.Actors, "AttackMove",
|
World.OrderGenerator = new GenericSelectTarget(World.Selection.Actors, "AttackMove",
|
||||||
|
|||||||
Reference in New Issue
Block a user