Merge pull request #12503 from pchote/radarjammer

Migrate ProvidesRadar from IDisable to conditions.
This commit is contained in:
Oliver Brakmann
2017-01-21 20:55:37 +01:00
committed by GitHub
15 changed files with 130 additions and 78 deletions

View File

@@ -752,7 +752,6 @@
<Compile Include="Traits\Radar\AppearsOnRadar.cs" /> <Compile Include="Traits\Radar\AppearsOnRadar.cs" />
<Compile Include="Traits\Radar\ProvidesRadar.cs" /> <Compile Include="Traits\Radar\ProvidesRadar.cs" />
<Compile Include="Traits\Radar\RadarColorFromTerrain.cs" /> <Compile Include="Traits\Radar\RadarColorFromTerrain.cs" />
<Compile Include="Traits\Radar\JamsRadar.cs" />
<Compile Include="AI\DummyAI.cs" /> <Compile Include="AI\DummyAI.cs" />
<Compile Include="UtilityCommands\ListInstallShieldContentsCommand.cs" /> <Compile Include="UtilityCommands\ListInstallShieldContentsCommand.cs" />
<Compile Include="Widgets\Logic\Installation\ModContentLogic.cs" /> <Compile Include="Widgets\Logic\Installation\ModContentLogic.cs" />
@@ -792,6 +791,7 @@
<Compile Include="UtilityCommands\OutputResolvedSequencesCommand.cs" /> <Compile Include="UtilityCommands\OutputResolvedSequencesCommand.cs" />
<Compile Include="UtilityCommands\OutputResolvedWeaponsCommand.cs" /> <Compile Include="UtilityCommands\OutputResolvedWeaponsCommand.cs" />
<Compile Include="Traits\RevealOnFire.cs" /> <Compile Include="Traits\RevealOnFire.cs" />
<Compile Include="Traits\Conditions\GrantConditionOnDisabled.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild"> <Target Name="AfterBuild">

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -15,21 +15,14 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Radar namespace OpenRA.Mods.Common.Traits.Radar
{ {
[Desc("This actor enables the radar minimap.")] [Desc("This actor enables the radar minimap.")]
public class ProvidesRadarInfo : TraitInfo<ProvidesRadar> { } public class ProvidesRadarInfo : ConditionalTraitInfo
public class ProvidesRadar : ITick
{ {
public bool IsActive { get; private set; } public override object Create(ActorInitializer init) { return new ProvidesRadar(this); }
}
public void Tick(Actor self) { IsActive = UpdateActive(self); } public class ProvidesRadar : ConditionalTrait<ProvidesRadarInfo>
{
static bool UpdateActive(Actor self) public ProvidesRadar(ProvidesRadarInfo info)
{ : base(info) { }
// 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);
}
} }
} }

View File

@@ -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); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var ticker = widget.Get<LogicTickerWidget>("RADAR_TICKER"); var ticker = widget.Get<LogicTickerWidget>("RADAR_TICKER");
ticker.OnTick = () => 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); .Any(a => a.Owner == world.LocalPlayer);
if (radarEnabled != cachedRadarEnabled) if (radarEnabled != cachedRadarEnabled)

View File

@@ -35,17 +35,6 @@ namespace OpenRA.Mods.RA.Traits
Color.FromArgb(96, Color.Black)); 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>()) foreach (var a in w.ActorsWithTrait<RenderJammerCircle>())
if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer)) if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer))
foreach (var r in a.Trait.RenderAboveShroud(a.Actor, wr)) 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(128, Color.Red),
Color.FromArgb(96, Color.Black)); 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));
}
} }
} }
} }

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA.Traits
owner.GpsAdd(self); 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; bool wasDisabled;
void ITick.Tick(Actor self) void ITick.Tick(Actor self)

View File

@@ -472,6 +472,7 @@ HQ:
Range: 10c0 Range: 10c0
Bib: Bib:
ProvidesRadar: ProvidesRadar:
RequiresCondition: !disabled
RenderDetectionCircle: RenderDetectionCircle:
DetectCloaked: DetectCloaked:
Range: 5c0 Range: 5c0
@@ -496,6 +497,8 @@ HQ:
SupportPowerChargeBar: SupportPowerChargeBar:
Power: Power:
Amount: -50 Amount: -50
GrantConditionOnDisabled@IDISABLE:
Condition: disabled
FIX: FIX:
Inherits: ^BaseBuilding Inherits: ^BaseBuilding
@@ -564,6 +567,7 @@ EYE:
Range: 10c0 Range: 10c0
Bib: Bib:
ProvidesRadar: ProvidesRadar:
RequiresCondition: !disabled
RenderDetectionCircle: RenderDetectionCircle:
DetectCloaked: DetectCloaked:
Range: 5c0 Range: 5c0
@@ -585,6 +589,8 @@ EYE:
Power: Power:
Amount: -200 Amount: -200
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
GrantConditionOnDisabled@IDISABLE:
Condition: disabled
TMPL: TMPL:
Inherits: ^BaseBuilding Inherits: ^BaseBuilding

View File

@@ -515,6 +515,7 @@ outpost:
RevealsShroud: RevealsShroud:
Range: 4c768 Range: 4c768
ProvidesRadar: ProvidesRadar:
RequiresCondition: !disabled
RenderSprites: RenderSprites:
Image: outpost.harkonnen Image: outpost.harkonnen
FactionImages: FactionImages:
@@ -528,6 +529,8 @@ outpost:
Power: Power:
Amount: -125 Amount: -125
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
GrantConditionOnDisabled@IDISABLE:
Condition: disabled
starport: starport:
Inherits: ^Building Inherits: ^Building

View File

@@ -18,8 +18,10 @@ V01:
JEEP: JEEP:
Explodes: Explodes:
JamsRadar: ProximityExternalCondition@JAMMER:
Range: 10c0 Range: 10c0
ValidStances: Enemy, Neutral
Condition: jammed
YAK: YAK:
Buildable: Buildable:

View File

@@ -515,6 +515,9 @@ DOME:
Range: 10c0 Range: 10c0
Bib: Bib:
ProvidesRadar: ProvidesRadar:
RequiresCondition: !jammed && !disabled
ExternalConditions@JAMMED:
Conditions: jammed
InfiltrateForExploration: InfiltrateForExploration:
DetectCloaked: DetectCloaked:
Range: 10c0 Range: 10c0
@@ -522,6 +525,8 @@ DOME:
Power: Power:
Amount: -40 Amount: -40
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
GrantConditionOnDisabled@IDISABLE:
Condition: disabled
PBOX: PBOX:
Inherits: ^Defense Inherits: ^Defense

View File

@@ -505,8 +505,14 @@ MRJ:
WithIdleOverlay@SPINNER: WithIdleOverlay@SPINNER:
Sequence: spinner Sequence: spinner
Offset: -256,0,256 Offset: -256,0,256
JamsRadar: ProximityExternalCondition@JAMMER:
Range: 15c0 Range: 15c0
ValidStances: Enemy, Neutral
Condition: jammed
WithRangeCircle@JAMMER:
Type: jammer
Range: 15c0
Color: 0000FF80
JamsMissiles: JamsMissiles:
Range: 4c0 Range: 4c0
DeflectionStances: Neutral, Enemy DeflectionStances: Neutral, Enemy

View File

@@ -314,6 +314,7 @@ GARADR:
PowerupSpeech: EnablePower PowerupSpeech: EnablePower
PowerdownSpeech: DisablePower PowerdownSpeech: DisablePower
ProvidesRadar: ProvidesRadar:
RequiresCondition: !disabled
InfiltrateForExploration: InfiltrateForExploration:
DetectCloaked: DetectCloaked:
Range: 10c0 Range: 10c0
@@ -331,6 +332,8 @@ GARADR:
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
SelectionDecorations: SelectionDecorations:
VisualBounds: 96, 118, 0, -38 VisualBounds: 96, 118, 0, -38
GrantConditionOnDisabled@IDISABLE:
Condition: disabled
GATECH: GATECH:
Inherits: ^Building Inherits: ^Building

View File

@@ -273,6 +273,7 @@ NARADR:
PowerupSpeech: EnablePower PowerupSpeech: EnablePower
PowerdownSpeech: DisablePower PowerdownSpeech: DisablePower
ProvidesRadar: ProvidesRadar:
RequiresCondition: !disabled
InfiltrateForExploration: InfiltrateForExploration:
DetectCloaked: DetectCloaked:
Range: 10c0 Range: 10c0
@@ -290,6 +291,8 @@ NARADR:
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
SelectionDecorations: SelectionDecorations:
VisualBounds: 96, 72, 0, -12 VisualBounds: 96, 72, 0, -12
GrantConditionOnDisabled@IDISABLE:
Condition: disabled
NATECH: NATECH:
Inherits: ^Building Inherits: ^Building