Cache WeaponInfo look-ups

This commit is contained in:
atlimit8
2015-10-03 22:29:40 -05:00
parent f2f2fd8871
commit 49d7604bd9
12 changed files with 82 additions and 53 deletions

View File

@@ -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;
}

View File

@@ -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;
}
}
}

View File

@@ -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;