Convert UpgradeOnTerrain to conditions.
This commit is contained in:
@@ -495,7 +495,7 @@
|
|||||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||||
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
||||||
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.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\GrantConditionOnMovement.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||||
<Compile Include="Traits\Valued.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");
|
RenameNodeKey(node, "GrantConditionOnMovement");
|
||||||
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
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);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
@@ -917,9 +917,9 @@
|
|||||||
DamageInterval: 16
|
DamageInterval: 16
|
||||||
DamageTypes: BulletDeath
|
DamageTypes: BulletDeath
|
||||||
Terrain: Veins
|
Terrain: Veins
|
||||||
UpgradeOnTerrain@VEINS:
|
GrantConditionOnTerrain@VEINS:
|
||||||
TerrainTypes: Veins
|
TerrainTypes: Veins
|
||||||
Upgrades: veins
|
Condition: veins
|
||||||
WithIdleOverlay@VEINS:
|
WithIdleOverlay@VEINS:
|
||||||
Sequence: veins
|
Sequence: veins
|
||||||
RequiresCondition: veins
|
RequiresCondition: veins
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ APC:
|
|||||||
UnloadVoice: Unload
|
UnloadVoice: Unload
|
||||||
LoadingCondition: loading
|
LoadingCondition: loading
|
||||||
EjectOnDeath: true
|
EjectOnDeath: true
|
||||||
UpgradeOnTerrain:
|
GrantConditionOnTerrain:
|
||||||
Upgrades: inwater
|
Condition: inwater
|
||||||
TerrainTypes: Water
|
TerrainTypes: Water
|
||||||
WithVoxelBody:
|
WithVoxelBody:
|
||||||
RequiresCondition: !inwater
|
RequiresCondition: !inwater
|
||||||
@@ -95,7 +95,7 @@ HVR:
|
|||||||
StationaryInterval: 18
|
StationaryInterval: 18
|
||||||
MovingInterval: 6
|
MovingInterval: 6
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-UpgradeOnTerrain@VEINS:
|
-GrantConditionOnTerrain@VEINS:
|
||||||
-WithIdleOverlay@VEINS:
|
-WithIdleOverlay@VEINS:
|
||||||
|
|
||||||
SMECH:
|
SMECH:
|
||||||
@@ -137,7 +137,7 @@ SMECH:
|
|||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 20, 32, 0, -8
|
Bounds: 20, 32, 0, -8
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-UpgradeOnTerrain@VEINS:
|
-GrantConditionOnTerrain@VEINS:
|
||||||
-WithIdleOverlay@VEINS:
|
-WithIdleOverlay@VEINS:
|
||||||
|
|
||||||
MMCH:
|
MMCH:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ BGGY:
|
|||||||
AutoTarget:
|
AutoTarget:
|
||||||
WithMuzzleOverlay:
|
WithMuzzleOverlay:
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-UpgradeOnTerrain@VEINS:
|
-GrantConditionOnTerrain@VEINS:
|
||||||
-WithIdleOverlay@VEINS:
|
-WithIdleOverlay@VEINS:
|
||||||
|
|
||||||
BIKE:
|
BIKE:
|
||||||
@@ -256,7 +256,7 @@ WEED:
|
|||||||
WithVoxelUnloadBody:
|
WithVoxelUnloadBody:
|
||||||
-GainsExperience:
|
-GainsExperience:
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-UpgradeOnTerrain@VEINS:
|
-GrantConditionOnTerrain@VEINS:
|
||||||
-WithIdleOverlay@VEINS:
|
-WithIdleOverlay@VEINS:
|
||||||
|
|
||||||
SAPC:
|
SAPC:
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ HARV:
|
|||||||
gdi: harv.gdi
|
gdi: harv.gdi
|
||||||
nod: harv.nod
|
nod: harv.nod
|
||||||
-DamagedByTerrain@VEINS:
|
-DamagedByTerrain@VEINS:
|
||||||
-UpgradeOnTerrain@VEINS:
|
-GrantConditionOnTerrain@VEINS:
|
||||||
-WithIdleOverlay@VEINS:
|
-WithIdleOverlay@VEINS:
|
||||||
|
|
||||||
LPST:
|
LPST:
|
||||||
|
|||||||
Reference in New Issue
Block a user