attack if in range of any cell of a building
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
@@ -31,6 +32,11 @@ namespace OpenRA.Traits
|
||||
public virtual string[] TargetTypes
|
||||
{
|
||||
get { return Info.TargetTypes;}
|
||||
}
|
||||
|
||||
public virtual IEnumerable<int2> TargetableSquares( Actor self )
|
||||
{
|
||||
yield return self.Location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var targetCell = Util.CellContaining(Target.CenterLocation);
|
||||
|
||||
if ((targetCell - self.Location).LengthSquared >= Range * Range)
|
||||
if (!Combat.IsInRange( self.CenterLocation, Range, Util.CenterOfCell(targetCell)))
|
||||
return Util.SequenceActivities( mobile.MoveTo( Target, Range ), this );
|
||||
|
||||
var desiredFacing = Util.GetFacing((targetCell - self.Location).ToFloat2(), 0);
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace OpenRA.Mods.RA
|
||||
if (IsLeaping) return;
|
||||
|
||||
var weapon = self.Trait<AttackBase>().Weapons[0].Info;
|
||||
if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize
|
||||
< (target.CenterLocation - self.CenterLocation).LengthSquared) return;
|
||||
if( !Combat.IsInRange( self.CenterLocation, weapon.Range, target.Actor ) ) return;
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Leap(self, target));
|
||||
|
||||
@@ -219,5 +219,20 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f);
|
||||
}
|
||||
|
||||
public static bool IsInRange( float2 attackOrigin, float range, Actor target )
|
||||
{
|
||||
var rsq = range * range * Game.CellSize * Game.CellSize;
|
||||
foreach( var cell in target.Trait<Targetable>().TargetableSquares( target ) )
|
||||
if( ( attackOrigin - cell * Game.CellSize ).LengthSquared < rsq )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsInRange( float2 attackOrigin, float range, float2 targetLocation )
|
||||
{
|
||||
var rsq = range * range * Game.CellSize * Game.CellSize;
|
||||
return ( attackOrigin - targetLocation ).LengthSquared < rsq;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,7 @@
|
||||
<Compile Include="SupportPowers\SupportPower.cs" />
|
||||
<Compile Include="TakeCover.cs" />
|
||||
<Compile Include="TargetableAircraft.cs" />
|
||||
<Compile Include="TargetableBuilding.cs" />
|
||||
<Compile Include="TeslaInstantKills.cs" />
|
||||
<Compile Include="Crates\ResetRadarCrateAction.cs" />
|
||||
<Compile Include="ThrowsParticles.cs" />
|
||||
|
||||
26
OpenRA.Mods.RA/TargetableBuilding.cs
Executable file
26
OpenRA.Mods.RA/TargetableBuilding.cs
Executable file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class TargetableBuildingInfo : TargetableInfo, ITraitPrerequisite<BuildingInfo>
|
||||
{
|
||||
public override object Create( ActorInitializer init ) { return new TargetableBuilding( this ); }
|
||||
}
|
||||
|
||||
class TargetableBuilding : Targetable
|
||||
{
|
||||
public TargetableBuilding( TargetableBuildingInfo info )
|
||||
: base( info )
|
||||
{
|
||||
}
|
||||
|
||||
public override IEnumerable<int2> TargetableSquares( Actor self )
|
||||
{
|
||||
return self.Trait<Building>().OccupiedCells();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,8 +102,10 @@ namespace OpenRA.Mods.RA
|
||||
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
|
||||
return;
|
||||
|
||||
if (Info.Range * Info.Range * Game.CellSize * Game.CellSize
|
||||
< (target.CenterLocation - self.CenterLocation).LengthSquared) return;
|
||||
if( target.IsActor && !Combat.IsInRange( self.CenterLocation, Info.Range, target.Actor ) )
|
||||
return;
|
||||
else if( !target.IsActor && !Combat.IsInRange( self.CenterLocation, Info.Range, target.CenterLocation ) )
|
||||
return;
|
||||
|
||||
if (Info.MinRange * Info.MinRange * Game.CellSize * Game.CellSize >
|
||||
(target.CenterLocation - self.CenterLocation).LengthSquared) return;
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
AppearsOnRadar:
|
||||
Selectable:
|
||||
Priority: 3
|
||||
Targetable:
|
||||
TargetableBuilding:
|
||||
TargetTypes: Ground
|
||||
Building:
|
||||
Dimensions: 1,1
|
||||
|
||||
Reference in New Issue
Block a user