Migrate ProvidesRadar to conditions and remove JamsRadar.
This commit is contained in:
@@ -752,7 +752,6 @@
|
||||
<Compile Include="Traits\Radar\AppearsOnRadar.cs" />
|
||||
<Compile Include="Traits\Radar\ProvidesRadar.cs" />
|
||||
<Compile Include="Traits\Radar\RadarColorFromTerrain.cs" />
|
||||
<Compile Include="Traits\Radar\JamsRadar.cs" />
|
||||
<Compile Include="AI\DummyAI.cs" />
|
||||
<Compile Include="UtilityCommands\ListInstallShieldContentsCommand.cs" />
|
||||
<Compile Include="Widgets\Logic\Installation\ModContentLogic.cs" />
|
||||
@@ -792,6 +791,7 @@
|
||||
<Compile Include="UtilityCommands\OutputResolvedSequencesCommand.cs" />
|
||||
<Compile Include="UtilityCommands\OutputResolvedWeaponsCommand.cs" />
|
||||
<Compile Include="Traits\RevealOnFire.cs" />
|
||||
<Compile Include="Traits\Conditions\GrantConditionOnDisabled.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="AfterBuild">
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Applies a condition to the actor when it is disabled.",
|
||||
"This is a temporary shim to help migration away from the legacy IDisable code")]
|
||||
public class GrantConditionOnDisabledInfo : ITraitInfo, Requires<HealthInfo>
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[GrantedConditionReference]
|
||||
[Desc("Condition to grant.")]
|
||||
public readonly string Condition = null;
|
||||
|
||||
public object Create(ActorInitializer init) { return new GrantConditionOnDisabled(this); }
|
||||
}
|
||||
|
||||
public class GrantConditionOnDisabled : INotifyCreated, ITick
|
||||
{
|
||||
readonly GrantConditionOnDisabledInfo info;
|
||||
|
||||
ConditionManager conditionManager;
|
||||
int conditionToken = ConditionManager.InvalidConditionToken;
|
||||
|
||||
public GrantConditionOnDisabled(GrantConditionOnDisabledInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
|
||||
// Set initial disabled state
|
||||
Tick(self);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (conditionManager == null)
|
||||
return;
|
||||
|
||||
var disabled = self.IsDisabled();
|
||||
if (disabled && conditionToken == ConditionManager.InvalidConditionToken)
|
||||
conditionToken = conditionManager.GrantCondition(self, info.Condition);
|
||||
else if (!disabled && conditionToken != ConditionManager.InvalidConditionToken)
|
||||
conditionToken = conditionManager.RevokeCondition(self, conditionToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Radar
|
||||
{
|
||||
[Desc("When an actor with this trait is in range of an actor with ProvidesRadar, it will temporarily disable the radar minimap for the enemy player.")]
|
||||
public class JamsRadarInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Range for jamming.")]
|
||||
public readonly WDist Range = WDist.Zero;
|
||||
|
||||
[Desc("Which diplomatic stances are affected.")]
|
||||
public readonly Stance Stances = Stance.Enemy | Stance.Neutral;
|
||||
|
||||
public object Create(ActorInitializer init) { return new JamsRadar(this); }
|
||||
}
|
||||
|
||||
public class JamsRadar
|
||||
{
|
||||
public readonly JamsRadarInfo Info;
|
||||
|
||||
public JamsRadar(JamsRadarInfo info)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,21 +15,14 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits.Radar
|
||||
{
|
||||
[Desc("This actor enables the radar minimap.")]
|
||||
public class ProvidesRadarInfo : TraitInfo<ProvidesRadar> { }
|
||||
|
||||
public class ProvidesRadar : ITick
|
||||
public class ProvidesRadarInfo : ConditionalTraitInfo
|
||||
{
|
||||
public bool IsActive { get; private set; }
|
||||
public override object Create(ActorInitializer init) { return new ProvidesRadar(this); }
|
||||
}
|
||||
|
||||
public void Tick(Actor self) { IsActive = UpdateActive(self); }
|
||||
|
||||
static bool UpdateActive(Actor self)
|
||||
{
|
||||
// Check if powered
|
||||
if (self.IsDisabled()) return false;
|
||||
|
||||
return self.World.ActorsWithTrait<JamsRadar>().All(a => !a.Trait.Info.Stances.HasStance(a.Actor.Owner.Stances[self.Owner])
|
||||
|| (self.CenterPosition - a.Actor.CenterPosition).HorizontalLengthSquared > a.Trait.Info.Range.LengthSquared);
|
||||
}
|
||||
public class ProvidesRadar : ConditionalTrait<ProvidesRadarInfo>
|
||||
{
|
||||
public ProvidesRadar(ProvidesRadarInfo info)
|
||||
: base(info) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,6 +746,36 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
if (engineVersion < 20170121)
|
||||
{
|
||||
if (node.Key.StartsWith("ProvidesRadar", StringComparison.Ordinal))
|
||||
{
|
||||
if (node.Value.Nodes.Any(n => n.Key == "RequiresCondition"))
|
||||
Console.WriteLine("You must manually add the `disabled` condition to the ProvidesRadar RequiresCondition expression");
|
||||
else
|
||||
node.Value.Nodes.Add(new MiniYamlNode("RequiresCondition", "!disabled"));
|
||||
|
||||
if (!parent.Value.Nodes.Any(n => n.Key == "GrantConditionOnDisabled@IDISABLE"))
|
||||
addNodes.Add(new MiniYamlNode("GrantConditionOnDisabled@IDISABLE", new MiniYaml("",
|
||||
new List<MiniYamlNode>() { new MiniYamlNode("Condition", "disabled") })));
|
||||
}
|
||||
|
||||
if (node.Key.StartsWith("JamsRadar", StringComparison.Ordinal))
|
||||
{
|
||||
Console.WriteLine("JamsRadar has been replaced with trait conditions.");
|
||||
Console.WriteLine("You must manually add the `jammed` condition to the ProvidesRadar traits that you want to be affected.");
|
||||
Console.WriteLine("You must manually add a WithRangeCircle trait to render the radar jamming range.");
|
||||
RenameNodeKey(node, "ProximityExternalCondition@JAMMER");
|
||||
var stances = node.Value.Nodes.FirstOrDefault(n => n.Key == "Stances");
|
||||
if (stances != null)
|
||||
stances.Key = "ValidStances";
|
||||
else
|
||||
node.Value.Nodes.Add(new MiniYamlNode("ValidStances", "Enemy, Neutral"));
|
||||
|
||||
node.Value.Nodes.Add(new MiniYamlNode("Condition", "jammed"));
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var ticker = widget.Get<LogicTickerWidget>("RADAR_TICKER");
|
||||
ticker.OnTick = () =>
|
||||
{
|
||||
radarEnabled = devMode.DisableShroud || world.ActorsHavingTrait<ProvidesRadar>(r => r.IsActive)
|
||||
radarEnabled = devMode.DisableShroud || world.ActorsHavingTrait<ProvidesRadar>(r => !r.IsTraitDisabled)
|
||||
.Any(a => a.Owner == world.LocalPlayer);
|
||||
|
||||
if (radarEnabled != cachedRadarEnabled)
|
||||
|
||||
@@ -35,17 +35,6 @@ namespace OpenRA.Mods.RA.Traits
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
|
||||
var jamsRadar = ai.TraitInfoOrDefault<JamsRadarInfo>();
|
||||
if (jamsRadar != null)
|
||||
{
|
||||
yield return new RangeCircleRenderable(
|
||||
centerPosition,
|
||||
jamsRadar.Range,
|
||||
0,
|
||||
Color.FromArgb(128, Color.Blue),
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
|
||||
foreach (var a in w.ActorsWithTrait<RenderJammerCircle>())
|
||||
if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer))
|
||||
foreach (var r in a.Trait.RenderAboveShroud(a.Actor, wr))
|
||||
@@ -70,17 +59,6 @@ namespace OpenRA.Mods.RA.Traits
|
||||
Color.FromArgb(128, Color.Red),
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
|
||||
var jamsRadar = self.Info.TraitInfoOrDefault<JamsRadarInfo>();
|
||||
if (jamsRadar != null)
|
||||
{
|
||||
yield return new RangeCircleRenderable(
|
||||
self.CenterPosition,
|
||||
jamsRadar.Range,
|
||||
0,
|
||||
Color.FromArgb(128, Color.Blue),
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
|
||||
bool NoActiveRadar { get { return !self.World.ActorsHavingTrait<ProvidesRadar>(r => r.IsActive).Any(a => a.Owner == self.Owner); } }
|
||||
bool NoActiveRadar { get { return !self.World.ActorsHavingTrait<ProvidesRadar>(r => !r.IsTraitDisabled).Any(a => a.Owner == self.Owner); } }
|
||||
bool wasDisabled;
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
|
||||
@@ -472,6 +472,7 @@ HQ:
|
||||
Range: 10c0
|
||||
Bib:
|
||||
ProvidesRadar:
|
||||
RequiresCondition: !disabled
|
||||
RenderDetectionCircle:
|
||||
DetectCloaked:
|
||||
Range: 5c0
|
||||
@@ -496,6 +497,8 @@ HQ:
|
||||
SupportPowerChargeBar:
|
||||
Power:
|
||||
Amount: -50
|
||||
GrantConditionOnDisabled@IDISABLE:
|
||||
Condition: disabled
|
||||
|
||||
FIX:
|
||||
Inherits: ^BaseBuilding
|
||||
@@ -564,6 +567,7 @@ EYE:
|
||||
Range: 10c0
|
||||
Bib:
|
||||
ProvidesRadar:
|
||||
RequiresCondition: !disabled
|
||||
RenderDetectionCircle:
|
||||
DetectCloaked:
|
||||
Range: 5c0
|
||||
@@ -585,6 +589,8 @@ EYE:
|
||||
Power:
|
||||
Amount: -200
|
||||
ProvidesPrerequisite@buildingname:
|
||||
GrantConditionOnDisabled@IDISABLE:
|
||||
Condition: disabled
|
||||
|
||||
TMPL:
|
||||
Inherits: ^BaseBuilding
|
||||
|
||||
@@ -515,6 +515,7 @@ outpost:
|
||||
RevealsShroud:
|
||||
Range: 4c768
|
||||
ProvidesRadar:
|
||||
RequiresCondition: !disabled
|
||||
RenderSprites:
|
||||
Image: outpost.harkonnen
|
||||
FactionImages:
|
||||
@@ -528,6 +529,8 @@ outpost:
|
||||
Power:
|
||||
Amount: -125
|
||||
ProvidesPrerequisite@buildingname:
|
||||
GrantConditionOnDisabled@IDISABLE:
|
||||
Condition: disabled
|
||||
|
||||
starport:
|
||||
Inherits: ^Building
|
||||
|
||||
@@ -18,8 +18,10 @@ V01:
|
||||
|
||||
JEEP:
|
||||
Explodes:
|
||||
JamsRadar:
|
||||
ProximityExternalCondition@JAMMER:
|
||||
Range: 10c0
|
||||
ValidStances: Enemy, Neutral
|
||||
Condition: jammed
|
||||
|
||||
YAK:
|
||||
Buildable:
|
||||
|
||||
@@ -515,6 +515,9 @@ DOME:
|
||||
Range: 10c0
|
||||
Bib:
|
||||
ProvidesRadar:
|
||||
RequiresCondition: !jammed && !disabled
|
||||
ExternalConditions@JAMMED:
|
||||
Conditions: jammed
|
||||
InfiltrateForExploration:
|
||||
DetectCloaked:
|
||||
Range: 10c0
|
||||
@@ -522,6 +525,8 @@ DOME:
|
||||
Power:
|
||||
Amount: -40
|
||||
ProvidesPrerequisite@buildingname:
|
||||
GrantConditionOnDisabled@IDISABLE:
|
||||
Condition: disabled
|
||||
|
||||
PBOX:
|
||||
Inherits: ^Defense
|
||||
|
||||
@@ -540,8 +540,14 @@ MRJ:
|
||||
WithIdleOverlay@SPINNER:
|
||||
Sequence: spinner
|
||||
Offset: -256,0,256
|
||||
JamsRadar:
|
||||
ProximityExternalCondition@JAMMER:
|
||||
Range: 15c0
|
||||
ValidStances: Enemy, Neutral
|
||||
Condition: jammed
|
||||
WithRangeCircle@JAMMER:
|
||||
Type: jammer
|
||||
Range: 15c0
|
||||
Color: 0000FF80
|
||||
JamsMissiles:
|
||||
Range: 4c0
|
||||
DeflectionStances: Neutral, Enemy
|
||||
|
||||
@@ -314,6 +314,7 @@ GARADR:
|
||||
PowerupSpeech: EnablePower
|
||||
PowerdownSpeech: DisablePower
|
||||
ProvidesRadar:
|
||||
RequiresCondition: !disabled
|
||||
InfiltrateForExploration:
|
||||
DetectCloaked:
|
||||
Range: 10c0
|
||||
@@ -331,6 +332,8 @@ GARADR:
|
||||
ProvidesPrerequisite@buildingname:
|
||||
SelectionDecorations:
|
||||
VisualBounds: 96, 118, 0, -38
|
||||
GrantConditionOnDisabled@IDISABLE:
|
||||
Condition: disabled
|
||||
|
||||
GATECH:
|
||||
Inherits: ^Building
|
||||
|
||||
@@ -273,6 +273,7 @@ NARADR:
|
||||
PowerupSpeech: EnablePower
|
||||
PowerdownSpeech: DisablePower
|
||||
ProvidesRadar:
|
||||
RequiresCondition: !disabled
|
||||
InfiltrateForExploration:
|
||||
DetectCloaked:
|
||||
Range: 10c0
|
||||
@@ -290,6 +291,8 @@ NARADR:
|
||||
ProvidesPrerequisite@buildingname:
|
||||
SelectionDecorations:
|
||||
VisualBounds: 96, 72, 0, -12
|
||||
GrantConditionOnDisabled@IDISABLE:
|
||||
Condition: disabled
|
||||
|
||||
NATECH:
|
||||
Inherits: ^Building
|
||||
|
||||
Reference in New Issue
Block a user