Convert UpgradeOnTerrain to conditions.
This commit is contained in:
@@ -495,7 +495,7 @@
|
||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
||||
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
||||
<Compile Include="Traits\Upgrades\GrantConditionOnTerrain.cs" />
|
||||
<Compile Include="Traits\Upgrades\GrantConditionOnMovement.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||
<Compile Include="Traits\Valued.cs" />
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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 System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class GrantConditionOnTerrainInfo : ITraitInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[UpgradeGrantedReference]
|
||||
[Desc("Condition to grant.")]
|
||||
public readonly string Condition = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Terrain names to trigger the upgrade.")]
|
||||
public readonly string[] TerrainTypes = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new GrantConditionOnTerrain(init, this); }
|
||||
}
|
||||
|
||||
public class GrantConditionOnTerrain : INotifyCreated, ITick
|
||||
{
|
||||
readonly GrantConditionOnTerrainInfo info;
|
||||
|
||||
UpgradeManager manager;
|
||||
int conditionToken = UpgradeManager.InvalidConditionToken;
|
||||
string previousTerrain;
|
||||
|
||||
public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
manager = self.TraitOrDefault<UpgradeManager>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (manager == null)
|
||||
return;
|
||||
|
||||
var currentTerrain = self.World.Map.GetTerrainInfo(self.Location).Type;
|
||||
var wantsGranted = info.TerrainTypes.Contains(currentTerrain);
|
||||
if (currentTerrain != previousTerrain)
|
||||
{
|
||||
if (wantsGranted && conditionToken == UpgradeManager.InvalidConditionToken)
|
||||
conditionToken = manager.GrantCondition(self, info.Condition);
|
||||
else if (!wantsGranted && conditionToken != UpgradeManager.InvalidConditionToken)
|
||||
conditionToken = manager.RevokeCondition(self, conditionToken);
|
||||
}
|
||||
|
||||
previousTerrain = currentTerrain;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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 System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class UpgradeOnTerrainInfo : ITraitInfo, Requires<UpgradeManagerInfo>
|
||||
{
|
||||
[UpgradeGrantedReference]
|
||||
public readonly string[] Upgrades = { "terrain" };
|
||||
|
||||
[Desc("Terrain names to trigger the upgrade.")]
|
||||
public readonly string[] TerrainTypes = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new UpgradeOnTerrain(init, this); }
|
||||
}
|
||||
|
||||
public class UpgradeOnTerrain : ITick
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly UpgradeOnTerrainInfo info;
|
||||
readonly UpgradeManager manager;
|
||||
|
||||
bool granted;
|
||||
string previousTerrain;
|
||||
|
||||
public UpgradeOnTerrain(ActorInitializer init, UpgradeOnTerrainInfo info)
|
||||
{
|
||||
self = init.Self;
|
||||
this.info = info;
|
||||
manager = self.Trait<UpgradeManager>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var currentTerrain = self.World.Map.GetTerrainInfo(self.Location).Type;
|
||||
var wantsGranted = info.TerrainTypes.Contains(currentTerrain);
|
||||
if (currentTerrain != previousTerrain)
|
||||
{
|
||||
if (wantsGranted && !granted)
|
||||
{
|
||||
foreach (var up in info.Upgrades)
|
||||
manager.GrantUpgrade(self, up, this);
|
||||
|
||||
granted = true;
|
||||
}
|
||||
else if (!wantsGranted && granted)
|
||||
{
|
||||
foreach (var up in info.Upgrades)
|
||||
manager.RevokeUpgrade(self, up, this);
|
||||
|
||||
granted = false;
|
||||
}
|
||||
}
|
||||
|
||||
previousTerrain = currentTerrain;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -629,6 +629,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
RenameNodeKey(node, "GrantConditionOnMovement");
|
||||
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||
}
|
||||
|
||||
if (node.Key.StartsWith("UpgradeOnTerrain", StringComparison.Ordinal))
|
||||
{
|
||||
RenameNodeKey(node, "GrantConditionOnTerrain");
|
||||
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||
if (!node.Value.Nodes.Any(n => n.Key == "Condition"))
|
||||
node.Value.Nodes.Add(new MiniYamlNode("Condition", "terrain"));
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
|
||||
@@ -917,9 +917,9 @@
|
||||
DamageInterval: 16
|
||||
DamageTypes: BulletDeath
|
||||
Terrain: Veins
|
||||
UpgradeOnTerrain@VEINS:
|
||||
GrantConditionOnTerrain@VEINS:
|
||||
TerrainTypes: Veins
|
||||
Upgrades: veins
|
||||
Condition: veins
|
||||
WithIdleOverlay@VEINS:
|
||||
Sequence: veins
|
||||
RequiresCondition: veins
|
||||
|
||||
@@ -30,8 +30,8 @@ APC:
|
||||
UnloadVoice: Unload
|
||||
LoadingCondition: loading
|
||||
EjectOnDeath: true
|
||||
UpgradeOnTerrain:
|
||||
Upgrades: inwater
|
||||
GrantConditionOnTerrain:
|
||||
Condition: inwater
|
||||
TerrainTypes: Water
|
||||
WithVoxelBody:
|
||||
RequiresCondition: !inwater
|
||||
@@ -95,7 +95,7 @@ HVR:
|
||||
StationaryInterval: 18
|
||||
MovingInterval: 6
|
||||
-DamagedByTerrain@VEINS:
|
||||
-UpgradeOnTerrain@VEINS:
|
||||
-GrantConditionOnTerrain@VEINS:
|
||||
-WithIdleOverlay@VEINS:
|
||||
|
||||
SMECH:
|
||||
@@ -137,7 +137,7 @@ SMECH:
|
||||
Selectable:
|
||||
Bounds: 20, 32, 0, -8
|
||||
-DamagedByTerrain@VEINS:
|
||||
-UpgradeOnTerrain@VEINS:
|
||||
-GrantConditionOnTerrain@VEINS:
|
||||
-WithIdleOverlay@VEINS:
|
||||
|
||||
MMCH:
|
||||
|
||||
@@ -29,7 +29,7 @@ BGGY:
|
||||
AutoTarget:
|
||||
WithMuzzleOverlay:
|
||||
-DamagedByTerrain@VEINS:
|
||||
-UpgradeOnTerrain@VEINS:
|
||||
-GrantConditionOnTerrain@VEINS:
|
||||
-WithIdleOverlay@VEINS:
|
||||
|
||||
BIKE:
|
||||
@@ -256,7 +256,7 @@ WEED:
|
||||
WithVoxelUnloadBody:
|
||||
-GainsExperience:
|
||||
-DamagedByTerrain@VEINS:
|
||||
-UpgradeOnTerrain@VEINS:
|
||||
-GrantConditionOnTerrain@VEINS:
|
||||
-WithIdleOverlay@VEINS:
|
||||
|
||||
SAPC:
|
||||
|
||||
@@ -100,7 +100,7 @@ HARV:
|
||||
gdi: harv.gdi
|
||||
nod: harv.nod
|
||||
-DamagedByTerrain@VEINS:
|
||||
-UpgradeOnTerrain@VEINS:
|
||||
-GrantConditionOnTerrain@VEINS:
|
||||
-WithIdleOverlay@VEINS:
|
||||
|
||||
LPST:
|
||||
|
||||
Reference in New Issue
Block a user