Cache WeaponInfo look-ups
This commit is contained in:
@@ -23,12 +23,12 @@ namespace OpenRA.Mods.Cnc.Effects
|
||||
readonly Animation anim;
|
||||
readonly Player firedBy;
|
||||
readonly string palette;
|
||||
readonly string weapon;
|
||||
readonly WeaponInfo weapon;
|
||||
|
||||
int weaponDelay;
|
||||
bool impacted = false;
|
||||
|
||||
public IonCannon(Player firedBy, string weapon, World world, CPos location, string effect, string palette, int delay)
|
||||
public IonCannon(Player firedBy, WeaponInfo weapon, World world, CPos location, string effect, string palette, int delay)
|
||||
{
|
||||
this.firedBy = firedBy;
|
||||
this.weapon = weapon;
|
||||
@@ -44,7 +44,6 @@ namespace OpenRA.Mods.Cnc.Effects
|
||||
anim.Tick();
|
||||
if (!impacted && weaponDelay-- <= 0)
|
||||
{
|
||||
var weapon = world.Map.Rules.Weapons[this.weapon.ToLowerInvariant()];
|
||||
weapon.Impact(target, firedBy.PlayerActor, Enumerable.Empty<int>());
|
||||
impacted = true;
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
class PoisonedByTiberiumInfo : UpgradableTraitInfo
|
||||
class PoisonedByTiberiumInfo : UpgradableTraitInfo, IRulesetLoaded
|
||||
{
|
||||
[WeaponReference] public readonly string Weapon = "Tiberium";
|
||||
public readonly HashSet<string> Resources = new HashSet<string> { "Tiberium", "BlueTiberium" };
|
||||
|
||||
public WeaponInfo WeaponInfo { get; private set; }
|
||||
|
||||
public override object Create(ActorInitializer init) { return new PoisonedByTiberium(this); }
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai) { WeaponInfo = rules.Weapons[Weapon.ToLowerInvariant()]; }
|
||||
}
|
||||
|
||||
class PoisonedByTiberium : UpgradableTrait<PoisonedByTiberiumInfo>, ITick, ISync
|
||||
@@ -45,10 +48,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (r == null || !Info.Resources.Contains(r.Info.Name))
|
||||
return;
|
||||
|
||||
var weapon = self.World.Map.Rules.Weapons[Info.Weapon.ToLowerInvariant()];
|
||||
|
||||
weapon.Impact(Target.FromActor(self), self.World.WorldActor, Enumerable.Empty<int>());
|
||||
poisonTicks = weapon.ReloadDelay;
|
||||
Info.WeaponInfo.Impact(Target.FromActor(self), self.World.WorldActor, Enumerable.Empty<int>());
|
||||
poisonTicks = Info.WeaponInfo.ReloadDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Cnc.Effects;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
@@ -16,7 +17,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
class IonCannonPowerInfo : SupportPowerInfo
|
||||
class IonCannonPowerInfo : SupportPowerInfo, IRulesetLoaded
|
||||
{
|
||||
[ActorReference]
|
||||
[Desc("Actor to spawn when the attack starts")]
|
||||
@@ -32,10 +33,13 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
[Desc("Which weapon to fire"), WeaponReference]
|
||||
public readonly string Weapon = "IonCannon";
|
||||
|
||||
public WeaponInfo WeaponInfo { get; private set; }
|
||||
|
||||
[Desc("Apply the weapon impact this many ticks into the effect")]
|
||||
public readonly int WeaponDelay = 7;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai) { WeaponInfo = rules.Weapons[Weapon.ToLowerInvariant()]; }
|
||||
}
|
||||
|
||||
class IonCannonPower : SupportPower
|
||||
@@ -55,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
Game.Sound.Play(Info.LaunchSound, self.World.Map.CenterOfCell(order.TargetLocation));
|
||||
w.Add(new IonCannon(self.Owner, info.Weapon, w, order.TargetLocation, info.Effect, info.EffectPalette, info.WeaponDelay));
|
||||
w.Add(new IonCannon(self.Owner, info.WeaponInfo, w, order.TargetLocation, info.Effect, info.EffectPalette, info.WeaponDelay));
|
||||
|
||||
if (info.CameraActor == null)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user