Add TargetableOffsets to HitShape
And remove ITargetablePositions from Building. Also, added UseFootprintOffsets to replicate the old Building behavior for easier setup of TargetablePositions for buildings.
This commit is contained in:
@@ -145,12 +145,11 @@ namespace OpenRA.Traits
|
|||||||
if (!actor.Targetables.Any(Exts.IsTraitEnabled))
|
if (!actor.Targetables.Any(Exts.IsTraitEnabled))
|
||||||
return new[] { actor.CenterPosition };
|
return new[] { actor.CenterPosition };
|
||||||
|
|
||||||
var targetablePositions = actor.TraitOrDefault<ITargetablePositions>();
|
var targetablePositions = actor.TraitsImplementing<ITargetablePositions>().Where(Exts.IsTraitEnabled);
|
||||||
if (targetablePositions != null)
|
if (targetablePositions.Any())
|
||||||
{
|
{
|
||||||
var positions = targetablePositions.TargetablePositions(actor);
|
var target = this;
|
||||||
if (positions.Any())
|
return targetablePositions.SelectMany(tp => tp.TargetablePositions(target.actor));
|
||||||
return positions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new[] { actor.CenterPosition };
|
return new[] { actor.CenterPosition };
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, ITargetablePositions
|
public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||||
{
|
{
|
||||||
public readonly BuildingInfo Info;
|
public readonly BuildingInfo Info;
|
||||||
public bool BuildComplete { get; private set; }
|
public bool BuildComplete { get; private set; }
|
||||||
@@ -143,6 +143,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
public readonly bool SkipMakeAnimation;
|
public readonly bool SkipMakeAnimation;
|
||||||
|
|
||||||
|
Pair<CPos, SubCell>[] occupiedCells;
|
||||||
|
|
||||||
// Shared activity lock: undeploy, sell, capture, etc.
|
// Shared activity lock: undeploy, sell, capture, etc.
|
||||||
[Sync] public bool Locked = true;
|
[Sync] public bool Locked = true;
|
||||||
|
|
||||||
@@ -173,14 +175,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<CPos, SubCell>[] occupiedCells;
|
|
||||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
|
||||||
|
|
||||||
public IEnumerable<WPos> TargetablePositions(Actor self)
|
|
||||||
{
|
|
||||||
return OccupiedCells().Select(c => self.World.Map.CenterOfCell(c.First));
|
|
||||||
}
|
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
if (SkipMakeAnimation || !self.Info.HasTraitInfo<WithMakeAnimationInfo>())
|
if (SkipMakeAnimation || !self.Info.HasTraitInfo<WithMakeAnimationInfo>())
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
HitShape[] shapes;
|
HitShape[] shapes;
|
||||||
IBlocksProjectiles[] allBlockers;
|
IBlocksProjectiles[] allBlockers;
|
||||||
ITargetablePositions[] targetablePositions;
|
|
||||||
|
|
||||||
public CombatDebugOverlay(Actor self)
|
public CombatDebugOverlay(Actor self)
|
||||||
{
|
{
|
||||||
@@ -51,7 +50,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
shapes = self.TraitsImplementing<HitShape>().ToArray();
|
shapes = self.TraitsImplementing<HitShape>().ToArray();
|
||||||
allBlockers = self.TraitsImplementing<IBlocksProjectiles>().ToArray();
|
allBlockers = self.TraitsImplementing<IBlocksProjectiles>().ToArray();
|
||||||
targetablePositions = self.TraitsImplementing<ITargetablePositions>().ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRenderAboveWorld.RenderAboveWorld(Actor self, WorldRenderer wr)
|
void IRenderAboveWorld.RenderAboveWorld(Actor self, WorldRenderer wr)
|
||||||
@@ -79,8 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
s.Info.Type.DrawCombatOverlay(wr, wcr, self);
|
s.Info.Type.DrawCombatOverlay(wr, wcr, self);
|
||||||
|
|
||||||
var tc = Color.Lime;
|
var tc = Color.Lime;
|
||||||
var enabledPositions = targetablePositions.Where(Exts.IsTraitEnabled);
|
var positions = activeShapes.SelectMany(tp => tp.TargetablePositions(self));
|
||||||
var positions = enabledPositions.SelectMany(tp => tp.TargetablePositions(self));
|
|
||||||
foreach (var p in positions)
|
foreach (var p in positions)
|
||||||
{
|
{
|
||||||
var center = wr.Screen3DPosition(p);
|
var center = wr.Screen3DPosition(p);
|
||||||
|
|||||||
@@ -16,9 +16,15 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Shape of actor for damage calculations.")]
|
[Desc("Shape of actor for targeting and damage calculations.")]
|
||||||
public class HitShapeInfo : ConditionalTraitInfo
|
public class HitShapeInfo : ConditionalTraitInfo, Requires<BodyOrientationInfo>
|
||||||
{
|
{
|
||||||
|
[Desc("Create a targetable position for each offset listed here (relative to CenterPosition).")]
|
||||||
|
public readonly WVec[] TargetableOffsets = { WVec.Zero };
|
||||||
|
|
||||||
|
[Desc("Create a targetable position at the center of each occupied cell. Stacks with TargetableOffsets.")]
|
||||||
|
public readonly bool UseOccupiedCellsOffsets = false;
|
||||||
|
|
||||||
[FieldLoader.LoadUsing("LoadShape")]
|
[FieldLoader.LoadUsing("LoadShape")]
|
||||||
public readonly IHitShape Type;
|
public readonly IHitShape Type;
|
||||||
|
|
||||||
@@ -51,9 +57,36 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new HitShape(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new HitShape(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HitShape : ConditionalTrait<HitShapeInfo>
|
public class HitShape : ConditionalTrait<HitShapeInfo>, ITargetablePositions
|
||||||
{
|
{
|
||||||
|
BodyOrientation orientation;
|
||||||
|
IOccupySpace occupy;
|
||||||
|
|
||||||
public HitShape(Actor self, HitShapeInfo info)
|
public HitShape(Actor self, HitShapeInfo info)
|
||||||
: base(info) { }
|
: base(info) { }
|
||||||
|
|
||||||
|
protected override void Created(Actor self)
|
||||||
|
{
|
||||||
|
orientation = self.Trait<BodyOrientation>();
|
||||||
|
occupy = self.TraitOrDefault<IOccupySpace>();
|
||||||
|
|
||||||
|
base.Created(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<WPos> TargetablePositions(Actor self)
|
||||||
|
{
|
||||||
|
if (IsTraitDisabled)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
if (Info.UseOccupiedCellsOffsets && occupy != null)
|
||||||
|
foreach (var c in occupy.OccupiedCells())
|
||||||
|
yield return self.World.Map.CenterOfCell(c.First);
|
||||||
|
|
||||||
|
foreach (var o in Info.TargetableOffsets)
|
||||||
|
{
|
||||||
|
var offset = orientation.LocalToWorld(o.Rotate(orientation.QuantizeOrientation(self, self.Orientation)));
|
||||||
|
yield return self.CenterPosition + offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -699,6 +699,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
else
|
else
|
||||||
node.Value.Nodes.Add(hitShapeNode);
|
node.Value.Nodes.Add(hitShapeNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moved ITargetablePositions from Building to HitShape
|
||||||
|
var building = node.Value.Nodes.FirstOrDefault(n => n.Key == "Building");
|
||||||
|
var hitShape = node.Value.Nodes.FirstOrDefault(n => n.Key == "HitShape");
|
||||||
|
if (building != null && hitShape == null)
|
||||||
|
{
|
||||||
|
hitShapeNode.Value.Nodes.Add(new MiniYamlNode("UseOccupiedCellsOffsets", "true"));
|
||||||
|
node.Value.Nodes.Add(hitShapeNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
@@ -565,6 +565,8 @@
|
|||||||
Priority: 3
|
Priority: 3
|
||||||
Targetable:
|
Targetable:
|
||||||
TargetTypes: Ground, C4, Structure
|
TargetTypes: Ground, C4, Structure
|
||||||
|
HitShape:
|
||||||
|
UseOccupiedCellsOffsets: true
|
||||||
Armor:
|
Armor:
|
||||||
Type: Wood
|
Type: Wood
|
||||||
Building:
|
Building:
|
||||||
@@ -878,6 +880,7 @@
|
|||||||
DamagedSounds: xplos.aud
|
DamagedSounds: xplos.aud
|
||||||
DestroyedSounds: xplobig4.aud
|
DestroyedSounds: xplobig4.aud
|
||||||
ScriptTriggers:
|
ScriptTriggers:
|
||||||
|
BodyOrientation:
|
||||||
HitShape:
|
HitShape:
|
||||||
|
|
||||||
^Crate:
|
^Crate:
|
||||||
|
|||||||
@@ -336,6 +336,8 @@
|
|||||||
VisibilityType: CenterPosition
|
VisibilityType: CenterPosition
|
||||||
Targetable:
|
Targetable:
|
||||||
TargetTypes: Ground, C4, Structure
|
TargetTypes: Ground, C4, Structure
|
||||||
|
HitShape:
|
||||||
|
UseOccupiedCellsOffsets: true
|
||||||
Building:
|
Building:
|
||||||
Dimensions: 1,1
|
Dimensions: 1,1
|
||||||
Footprint: x
|
Footprint: x
|
||||||
|
|||||||
@@ -497,6 +497,8 @@
|
|||||||
Priority: 3
|
Priority: 3
|
||||||
Targetable:
|
Targetable:
|
||||||
TargetTypes: Ground, C4, DetonateAttack, Structure
|
TargetTypes: Ground, C4, DetonateAttack, Structure
|
||||||
|
HitShape:
|
||||||
|
UseOccupiedCellsOffsets: true
|
||||||
Building:
|
Building:
|
||||||
Dimensions: 1,1
|
Dimensions: 1,1
|
||||||
Footprint: x
|
Footprint: x
|
||||||
@@ -853,6 +855,7 @@
|
|||||||
Type: Concrete
|
Type: Concrete
|
||||||
AutoTargetIgnore:
|
AutoTargetIgnore:
|
||||||
ScriptTriggers:
|
ScriptTriggers:
|
||||||
|
BodyOrientation:
|
||||||
HitShape:
|
HitShape:
|
||||||
|
|
||||||
^Rock:
|
^Rock:
|
||||||
|
|||||||
@@ -135,6 +135,8 @@
|
|||||||
Priority: 3
|
Priority: 3
|
||||||
Targetable:
|
Targetable:
|
||||||
TargetTypes: Ground, Building, C4
|
TargetTypes: Ground, Building, C4
|
||||||
|
HitShape:
|
||||||
|
UseOccupiedCellsOffsets: true
|
||||||
Building:
|
Building:
|
||||||
Dimensions: 1,1
|
Dimensions: 1,1
|
||||||
Footprint: x
|
Footprint: x
|
||||||
|
|||||||
Reference in New Issue
Block a user