Rework UpgradeActorsNear -> ProximityExternalCondition.
This commit is contained in:
@@ -493,7 +493,7 @@
|
|||||||
<Compile Include="Traits\Upgrades\DeployToUpgrade.cs" />
|
<Compile Include="Traits\Upgrades\DeployToUpgrade.cs" />
|
||||||
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeActorsNear.cs" />
|
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnDamageState.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnDamageState.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnMovement.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnMovement.cs" />
|
||||||
|
|||||||
@@ -9,16 +9,17 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Applies an upgrade to actors within a specified range.")]
|
[Desc("Applies an upgrade to actors within a specified range.")]
|
||||||
public class UpgradeActorsNearInfo : ITraitInfo
|
public class ProximityExternalConditionInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
[UpgradeGrantedReference, FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
[Desc("The upgrades to grant.")]
|
[Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
|
||||||
public readonly string[] Upgrades = { };
|
public readonly string Condition = null;
|
||||||
|
|
||||||
[Desc("The range to search for actors to upgrade.")]
|
[Desc("The range to search for actors to upgrade.")]
|
||||||
public readonly WDist Range = WDist.FromCells(3);
|
public readonly WDist Range = WDist.FromCells(3);
|
||||||
@@ -36,14 +37,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly string EnableSound = null;
|
public readonly string EnableSound = null;
|
||||||
public readonly string DisableSound = null;
|
public readonly string DisableSound = null;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new UpgradeActorsNear(init.Self, this); }
|
public object Create(ActorInitializer init) { return new ProximityExternalCondition(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpgradeActorsNear : ITick, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOtherProduction
|
public class ProximityExternalCondition : ITick, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOtherProduction
|
||||||
{
|
{
|
||||||
readonly UpgradeActorsNearInfo info;
|
readonly ProximityExternalConditionInfo info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
|
||||||
|
readonly Dictionary<Actor, int> tokens = new Dictionary<Actor, int>();
|
||||||
|
|
||||||
int proximityTrigger;
|
int proximityTrigger;
|
||||||
WPos cachedPosition;
|
WPos cachedPosition;
|
||||||
WDist cachedRange;
|
WDist cachedRange;
|
||||||
@@ -53,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
bool cachedDisabled = true;
|
bool cachedDisabled = true;
|
||||||
|
|
||||||
public UpgradeActorsNear(Actor self, UpgradeActorsNearInfo info)
|
public ProximityExternalCondition(Actor self, ProximityExternalConditionInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.self = self;
|
this.self = self;
|
||||||
@@ -106,9 +109,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var um = a.TraitOrDefault<UpgradeManager>();
|
var um = a.TraitOrDefault<UpgradeManager>();
|
||||||
if (um != null)
|
if (um != null && !tokens.ContainsKey(a) && um.AcceptsExternalCondition(a, info.Condition))
|
||||||
foreach (var u in info.Upgrades)
|
tokens[a] = um.GrantCondition(a, info.Condition, true);
|
||||||
um.GrantUpgrade(a, u, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
|
public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
|
||||||
@@ -129,26 +131,24 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var um = produced.TraitOrDefault<UpgradeManager>();
|
var um = produced.TraitOrDefault<UpgradeManager>();
|
||||||
if (um != null)
|
if (um != null && um.AcceptsExternalCondition(produced, info.Condition))
|
||||||
foreach (var u in info.Upgrades)
|
tokens[produced] = um.GrantCondition(produced, info.Condition, true);
|
||||||
if (um.AcknowledgesUpgrade(produced, u))
|
|
||||||
um.GrantTimedUpgrade(produced, u, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActorExited(Actor a)
|
void ActorExited(Actor a)
|
||||||
{
|
{
|
||||||
if (a == self || a.Disposed || self.Disposed)
|
if (a.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stance = self.Owner.Stances[a.Owner];
|
int token;
|
||||||
if (!info.ValidStances.HasStance(stance))
|
if (!tokens.TryGetValue(a, out token))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
tokens.Remove(a);
|
||||||
var um = a.TraitOrDefault<UpgradeManager>();
|
var um = a.TraitOrDefault<UpgradeManager>();
|
||||||
if (um != null)
|
if (um != null)
|
||||||
foreach (var u in info.Upgrades)
|
um.RevokeCondition(a, token);
|
||||||
um.RevokeUpgrade(a, u, this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,6 +567,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (engineVersion < 20161212)
|
||||||
|
{
|
||||||
|
if (node.Key.StartsWith("UpgradeActorsNear", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
RenameNodeKey(node, "ProximityExternalCondition");
|
||||||
|
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ HACKE6:
|
|||||||
CaptureTypes: building
|
CaptureTypes: building
|
||||||
Targetable:
|
Targetable:
|
||||||
RequiresCondition: !jail
|
RequiresCondition: !jail
|
||||||
|
ExternalConditions@JAIL:
|
||||||
|
Conditions: jail
|
||||||
Targetable@PRISONER:
|
Targetable@PRISONER:
|
||||||
TargetTypes: Prisoner
|
TargetTypes: Prisoner
|
||||||
RenderSprites:
|
RenderSprites:
|
||||||
@@ -42,6 +44,8 @@ HACKE6:
|
|||||||
MEDI:
|
MEDI:
|
||||||
Targetable:
|
Targetable:
|
||||||
RequiresCondition: !jail
|
RequiresCondition: !jail
|
||||||
|
ExternalConditions@JAIL:
|
||||||
|
Conditions: jail
|
||||||
Targetable@PRISONER:
|
Targetable@PRISONER:
|
||||||
TargetTypes: Prisoner
|
TargetTypes: Prisoner
|
||||||
|
|
||||||
@@ -50,8 +54,8 @@ PRISON:
|
|||||||
Type: CenterPosition
|
Type: CenterPosition
|
||||||
Immobile:
|
Immobile:
|
||||||
OccupiesSpace: false
|
OccupiesSpace: false
|
||||||
UpgradeActorsNear:
|
ProximityExternalCondition:
|
||||||
Upgrades: jail
|
Condition: jail
|
||||||
Range: 1c0
|
Range: 1c0
|
||||||
|
|
||||||
CAMERA:
|
CAMERA:
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ HACKE6:
|
|||||||
WithInfantryBody:
|
WithInfantryBody:
|
||||||
Targetable:
|
Targetable:
|
||||||
RequiresCondition: !jail
|
RequiresCondition: !jail
|
||||||
|
ExternalConditions@JAIL:
|
||||||
|
Conditions: jail
|
||||||
Targetable@PRISONER:
|
Targetable@PRISONER:
|
||||||
TargetTypes: Prisoner
|
TargetTypes: Prisoner
|
||||||
RenderSprites:
|
RenderSprites:
|
||||||
@@ -43,6 +45,8 @@ HACKE6:
|
|||||||
MEDI:
|
MEDI:
|
||||||
Targetable:
|
Targetable:
|
||||||
RequiresCondition: !jail
|
RequiresCondition: !jail
|
||||||
|
ExternalConditions@JAIL:
|
||||||
|
Conditions: jail
|
||||||
Targetable@PRISONER:
|
Targetable@PRISONER:
|
||||||
TargetTypes: Prisoner
|
TargetTypes: Prisoner
|
||||||
|
|
||||||
@@ -51,8 +55,8 @@ PRISON:
|
|||||||
Type: CenterPosition
|
Type: CenterPosition
|
||||||
Immobile:
|
Immobile:
|
||||||
OccupiesSpace: false
|
OccupiesSpace: false
|
||||||
UpgradeActorsNear:
|
ProximityExternalCondition:
|
||||||
Upgrades: jail
|
Condition: jail
|
||||||
Range: 1c0
|
Range: 1c0
|
||||||
|
|
||||||
CAMERA:
|
CAMERA:
|
||||||
|
|||||||
@@ -1263,7 +1263,7 @@ GALITE:
|
|||||||
Prerequisites: ~disabled
|
Prerequisites: ~disabled
|
||||||
SelectionDecorations:
|
SelectionDecorations:
|
||||||
VisualBounds: 25, 35, 0, -12
|
VisualBounds: 25, 35, 0, -12
|
||||||
-Cloak@CLOAKGENERATOR:
|
-Cloak@EXTERNALCLOAK:
|
||||||
|
|
||||||
TSTLAMP:
|
TSTLAMP:
|
||||||
Inherits: GALITE
|
Inherits: GALITE
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
RequiresCondition: !empdisable && !deployed && !loading
|
RequiresCondition: !empdisable && !deployed && !loading
|
||||||
|
|
||||||
^Cloakable:
|
^Cloakable:
|
||||||
Cloak@CLOAKGENERATOR:
|
Cloak@EXTERNALCLOAK:
|
||||||
RequiresCondition: cloakgenerator || crate-cloak
|
RequiresCondition: cloakgenerator || crate-cloak
|
||||||
InitialDelay: 0
|
InitialDelay: 0
|
||||||
CloakDelay: 90
|
CloakDelay: 90
|
||||||
@@ -102,6 +102,8 @@
|
|||||||
CloakSound: cloak5.aud
|
CloakSound: cloak5.aud
|
||||||
UncloakSound: cloak5.aud
|
UncloakSound: cloak5.aud
|
||||||
UncloakOn: Attack, Unload, Infiltrate, Demolish, Damage
|
UncloakOn: Attack, Unload, Infiltrate, Demolish, Damage
|
||||||
|
ExternalConditions@EXTERNALCLOAK:
|
||||||
|
Conditions: cloakgenerator, crate-cloak
|
||||||
|
|
||||||
^BasicBuilding:
|
^BasicBuilding:
|
||||||
Inherits@1: ^ExistsInWorld
|
Inherits@1: ^ExistsInWorld
|
||||||
|
|||||||
@@ -396,8 +396,8 @@ NASTLH:
|
|||||||
PowerupSpeech: EnablePower
|
PowerupSpeech: EnablePower
|
||||||
PowerdownSpeech: DisablePower
|
PowerdownSpeech: DisablePower
|
||||||
IndicatorPalette: mouse
|
IndicatorPalette: mouse
|
||||||
UpgradeActorsNear:
|
ProximityExternalCondition:
|
||||||
Upgrades: cloakgenerator
|
Condition: cloakgenerator
|
||||||
Range: 12c0
|
Range: 12c0
|
||||||
EnableSound: cloak5.aud
|
EnableSound: cloak5.aud
|
||||||
DisableSound: cloak5.aud
|
DisableSound: cloak5.aud
|
||||||
|
|||||||
Reference in New Issue
Block a user