Replace WithReloadingSpriteTurret with conditions
WithReloadingSpriteTurret was bound to run into conflicts with any WithTurret*Animation traits due to overriding the turret sequence constantly via ITick. Using (stacked) conditions instead avoids that.
This commit is contained in:
@@ -71,7 +71,6 @@
|
|||||||
<Compile Include="Traits\Render\WithEmbeddedTurretSpriteBody.cs" />
|
<Compile Include="Traits\Render\WithEmbeddedTurretSpriteBody.cs" />
|
||||||
<Compile Include="Traits\Render\WithCargo.cs" />
|
<Compile Include="Traits\Render\WithCargo.cs" />
|
||||||
<Compile Include="Traits\Render\WithDeliveryAnimation.cs" />
|
<Compile Include="Traits\Render\WithDeliveryAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithReloadingSpriteTurret.cs" />
|
|
||||||
<Compile Include="Traits\Render\WithRoof.cs" />
|
<Compile Include="Traits\Render\WithRoof.cs" />
|
||||||
<Compile Include="Traits\SupportPowers\IonCannonPower.cs" />
|
<Compile Include="Traits\SupportPowers\IonCannonPower.cs" />
|
||||||
<Compile Include="UtilityCommands\ImportTiberianDawnLegacyMapCommand.cs" />
|
<Compile Include="UtilityCommands\ImportTiberianDawnLegacyMapCommand.cs" />
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2018 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;
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA.Mods.Common.Traits;
|
|
||||||
using OpenRA.Mods.Common.Traits.Render;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Traits.Render
|
|
||||||
{
|
|
||||||
[Desc("Renders ammo-dependent turret graphics for units with the Turreted trait.")]
|
|
||||||
public class WithReloadingSpriteTurretInfo : WithSpriteTurretInfo, Requires<AmmoPoolInfo>, Requires<ArmamentInfo>
|
|
||||||
{
|
|
||||||
[Desc("AmmoPool to use for ammo-dependent sequences.")]
|
|
||||||
public readonly string AmmoPoolName = null;
|
|
||||||
|
|
||||||
[Desc("How many reload stages does this turret have. Defaults to AmmoPool's Ammo.",
|
|
||||||
"Adds current reload stage to Sequence as suffix when a matching AmmoPool is present.")]
|
|
||||||
public readonly int ReloadStages = -1;
|
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithReloadingSpriteTurret(init.Self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WithReloadingSpriteTurret : WithSpriteTurret
|
|
||||||
{
|
|
||||||
readonly int reloadStages;
|
|
||||||
readonly AmmoPool ammoPool;
|
|
||||||
string sequence;
|
|
||||||
string ammoSuffix;
|
|
||||||
|
|
||||||
public WithReloadingSpriteTurret(Actor self, WithReloadingSpriteTurretInfo info)
|
|
||||||
: base(self, info)
|
|
||||||
{
|
|
||||||
ammoPool = self.TraitsImplementing<AmmoPool>().FirstOrDefault(a => a.Info.Name == info.AmmoPoolName);
|
|
||||||
if (ammoPool == null)
|
|
||||||
throw new InvalidOperationException("Actor type '" + self.Info.Name + "' does not define a valid ammo pool for its reloading turret.");
|
|
||||||
|
|
||||||
sequence = Info.Sequence;
|
|
||||||
reloadStages = info.ReloadStages;
|
|
||||||
|
|
||||||
var initialAmmo = ammoPool.Info.InitialAmmo;
|
|
||||||
var ammo = ammoPool.Info.Ammo;
|
|
||||||
var initialAmmoStage = initialAmmo >= 0 && initialAmmo != ammo ? initialAmmo : ammo;
|
|
||||||
|
|
||||||
if (ammoPool != null && reloadStages < 0)
|
|
||||||
ammoSuffix = initialAmmoStage.ToString();
|
|
||||||
if (ammoPool != null && reloadStages >= 0)
|
|
||||||
ammoSuffix = (initialAmmoStage * reloadStages / ammo).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (Info.AimSequence != null)
|
|
||||||
sequence = Attack.IsAiming ? Info.AimSequence : Info.Sequence;
|
|
||||||
|
|
||||||
var currentAmmo = ammoPool.GetAmmoCount();
|
|
||||||
if (reloadStages < 0)
|
|
||||||
ammoSuffix = currentAmmo.ToString();
|
|
||||||
if (reloadStages >= 0)
|
|
||||||
ammoSuffix = (currentAmmo * reloadStages / ammoPool.Info.Ammo).ToString();
|
|
||||||
|
|
||||||
var newSequence = NormalizeSequence(self, sequence + ammoSuffix);
|
|
||||||
if (DefaultAnimation.CurrentSequence.Name != newSequence)
|
|
||||||
DefaultAnimation.ReplaceAnim(newSequence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1650,6 +1650,30 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removed WithReloadingSpriteTurret
|
||||||
|
if (engineVersion < 20180223)
|
||||||
|
{
|
||||||
|
var reloadingTurret = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("WithReloadingSpriteTurret", StringComparison.Ordinal));
|
||||||
|
if (reloadingTurret != null)
|
||||||
|
{
|
||||||
|
var ammoPool = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AmmoPool", StringComparison.Ordinal));
|
||||||
|
if (ammoPool != null)
|
||||||
|
ammoPool.Value.Nodes.Add(new MiniYamlNode("AmmoCondition", "ammo"));
|
||||||
|
|
||||||
|
RenameNodeKey(reloadingTurret, "WithSpriteTurret");
|
||||||
|
var noAmmoTurret = new MiniYamlNode("WithSpriteTurret@NoAmmo", "");
|
||||||
|
var reqAmmoCondition = new MiniYamlNode("RequiresCondition", "ammo");
|
||||||
|
var reqNoAmmoCondition = new MiniYamlNode("RequiresCondition", "!ammo");
|
||||||
|
|
||||||
|
reloadingTurret.Value.Nodes.Add(reqAmmoCondition);
|
||||||
|
noAmmoTurret.Value.Nodes.Add(reqNoAmmoCondition);
|
||||||
|
node.Value.Nodes.Add(noAmmoTurret);
|
||||||
|
|
||||||
|
Console.WriteLine("WithReloadingSpriteTurret has been removed in favor of using stacked AmmoPool.AmmoConditions.");
|
||||||
|
Console.WriteLine("Check if your affected actors need further changes.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -539,9 +539,16 @@ MLRS:
|
|||||||
AmmoPool:
|
AmmoPool:
|
||||||
Ammo: 2
|
Ammo: 2
|
||||||
PipCount: 0
|
PipCount: 0
|
||||||
|
AmmoCondition: ammo
|
||||||
AttackTurreted:
|
AttackTurreted:
|
||||||
WithReloadingSpriteTurret:
|
WithSpriteTurret:
|
||||||
AmmoPoolName: primary
|
RequiresCondition: ammo > 1
|
||||||
|
WithSpriteTurret@OneMissile:
|
||||||
|
RequiresCondition: ammo == 1
|
||||||
|
Sequence: turret1
|
||||||
|
WithSpriteTurret@NoMissiles:
|
||||||
|
RequiresCondition: !ammo
|
||||||
|
Sequence: turret0
|
||||||
AutoTarget:
|
AutoTarget:
|
||||||
InitialStanceAI: Defend
|
InitialStanceAI: Defend
|
||||||
RenderRangeCircle:
|
RenderRangeCircle:
|
||||||
|
|||||||
@@ -256,10 +256,6 @@ mlrs:
|
|||||||
Start: 32
|
Start: 32
|
||||||
Facings: 32
|
Facings: 32
|
||||||
UseClassicFacingFudge: True
|
UseClassicFacingFudge: True
|
||||||
turret2:
|
|
||||||
Start: 32
|
|
||||||
Facings: 32
|
|
||||||
UseClassicFacingFudge: True
|
|
||||||
turret1:
|
turret1:
|
||||||
Start: 64
|
Start: 64
|
||||||
Facings: 32
|
Facings: 32
|
||||||
|
|||||||
Reference in New Issue
Block a user