Remove Selectable boolean from Selectable trait

Add work-around for ta/td bridge huts since they need actor Bounds to
be targetable by C4/engineer repair.
This commit is contained in:
reaperrr
2015-06-05 16:36:54 +02:00
parent 2afa3cfa3a
commit c23ee1be2e
15 changed files with 73 additions and 51 deletions

View File

@@ -310,6 +310,7 @@
<Compile Include="Traits\Crushable.cs" />
<Compile Include="Traits\CustomBuildTimeValue.cs" />
<Compile Include="Traits\CustomSellValue.cs" />
<Compile Include="Traits\CustomSelectionSize.cs" />
<Compile Include="Traits\Demolishable.cs" />
<Compile Include="Traits\DetectCloaked.cs" />
<Compile Include="Traits\EjectOnDeath.cs" />

View File

@@ -0,0 +1,36 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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 COPYING.
*/
#endregion
using System;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Special case trait for invisible, unselectable actors like bridge huts.",
"Gives actor targetable area for special cases like C4 and engineer repair.",
"This trait conflicts with AutoSelectionSize so you cannot use both, and doesn't support custom offsets.")]
public class CustomSelectionSizeInfo : ITraitInfo
{
public readonly int[] CustomBounds = null;
public object Create(ActorInitializer init) { return new CustomSelectionSize(this); }
}
public class CustomSelectionSize : IAutoSelectionSize
{
readonly CustomSelectionSizeInfo info;
public CustomSelectionSize(CustomSelectionSizeInfo info) { this.info = info; }
public int2 SelectionSize(Actor self)
{
return new int2(info.CustomBounds[0], info.CustomBounds[1]);
}
}
}

View File

@@ -1175,6 +1175,28 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
if (engineVersion < 20150604)
{
if (depth == 1 && node.Value.Nodes.Exists(n => n.Key == "Selectable"))
{
var selectable = node.Value.Nodes.FirstOrDefault(n => n.Key == "Selectable");
if (node.Key == "Selectable" && selectable.Value.Value == "false")
node.Key = "SelectableRemoveMe";
// To cover rare cases where the boolean was 'true'
if (node.Key == "Selectable" && selectable.Value.Value == "true")
node.Value.Nodes.Remove(selectable);
}
if (depth == 0 && node.Value.Nodes.Exists(n => n.Key == "SelectableRemoveMe"))
node.Value.Nodes.RemoveAll(n => n.Key == "SelectableRemoveMe");
Console.WriteLine("The 'Selectable' boolean has been removed from the Selectable trait.");
Console.WriteLine("If you just want to disable an inherited Selectable trait, use -Selectable instead.");
Console.WriteLine("For special cases like bridge huts, which need bounds to be targetable by C4 and engineers,");
Console.WriteLine("give them the CustomSelectionSize trait with CustomBounds.");
Console.WriteLine("See RA and C&C bridge huts for reference.");
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}