Add dedicated TDGunboat traits

And get rid of Mobile.OnRails hack.
This commit is contained in:
reaperrr
2017-07-14 02:28:01 +02:00
committed by Oliver Brakmann
parent 3bdd35fd2d
commit 94fa24088b
8 changed files with 323 additions and 29 deletions

View File

@@ -63,7 +63,6 @@ namespace OpenRA.Mods.Common.Traits
readonly IMove move;
readonly Target target;
readonly bool forceAttack;
readonly bool onRailsHack;
bool hasTicked;
public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack)
@@ -71,14 +70,6 @@ namespace OpenRA.Mods.Common.Traits
attack = self.Trait<AttackFollow>();
move = allowMove ? self.TraitOrDefault<IMove>() : null;
// HACK: Mobile.OnRails is horrible. Blergh.
var mobile = move as Mobile;
if (mobile != null && mobile.Info.OnRails)
{
move = null;
onRailsHack = true;
}
this.target = target;
this.forceAttack = forceAttack;
}
@@ -112,14 +103,12 @@ namespace OpenRA.Mods.Common.Traits
if (move != null)
return ActivityUtils.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
if (!onRailsHack &&
target.IsInRange(self.CenterPosition, weapon.MaxRange()) &&
if (target.IsInRange(self.CenterPosition, weapon.MaxRange()) &&
!target.IsInRange(self.CenterPosition, weapon.Weapon.MinRange))
return this;
}
if (!onRailsHack)
attack.Target = Target.Invalid;
attack.Target = Target.Invalid;
return NextActivity;
}

View File

@@ -70,8 +70,6 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Speed = 1;
public readonly bool OnRails = false;
[Desc("Allow multiple (infantry) units in one cell.")]
public readonly bool SharesCell = false;
@@ -583,12 +581,7 @@ namespace OpenRA.Mods.Common.Traits
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order is MoveOrderTargeter)
{
if (Info.OnRails)
return null;
return new Order("Move", self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) };
}
return null;
}

View File

@@ -845,6 +845,38 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
// Replace Mobile.OnRails hack with dedicated TDGunboat traits in Mods.Cnc
if (engineVersion < 20170715)
{
var mobile = node.Value.Nodes.FirstOrDefault(n => n.Key == "Mobile");
if (mobile != null)
{
var onRailsNode = mobile.Value.Nodes.FirstOrDefault(n => n.Key == "OnRails");
var onRails = onRailsNode != null ? FieldLoader.GetValue<bool>("OnRails", onRailsNode.Value.Value) : false;
if (onRails)
{
var speed = mobile.Value.Nodes.FirstOrDefault(n => n.Key == "Speed");
var initFacing = mobile.Value.Nodes.FirstOrDefault(n => n.Key == "InitialFacing");
var previewFacing = mobile.Value.Nodes.FirstOrDefault(n => n.Key == "PreviewFacing");
var tdGunboat = new MiniYamlNode("TDGunboat", "");
if (speed != null)
tdGunboat.Value.Nodes.Add(speed);
if (initFacing != null)
tdGunboat.Value.Nodes.Add(initFacing);
if (previewFacing != null)
tdGunboat.Value.Nodes.Add(previewFacing);
node.Value.Nodes.Add(tdGunboat);
var attackTurreted = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AttackTurreted", StringComparison.Ordinal));
if (attackTurreted != null)
RenameNodeKey(attackTurreted, "AttackTDGunboatTurreted");
node.Value.Nodes.Remove(mobile);
}
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}