Migrate ProvidesRadar to conditions and remove JamsRadar.
This commit is contained in:
@@ -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) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user