Added IRangeMultiplier
This commit is contained in:
@@ -21,15 +21,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly AttackBase attack;
|
||||
readonly IMove move;
|
||||
readonly IFacing facing;
|
||||
readonly Armament armament;
|
||||
readonly WDist minRange;
|
||||
readonly WDist maxRange;
|
||||
readonly IPositionable positionable;
|
||||
|
||||
public Attack(Actor self, Target target, Armament armament, bool allowMovement)
|
||||
{
|
||||
Target = target;
|
||||
this.minRange = armament.Weapon.MinRange;
|
||||
this.maxRange = armament.Weapon.Range;
|
||||
this.armament = armament;
|
||||
|
||||
attack = self.Trait<AttackBase>();
|
||||
facing = self.Trait<IFacing>();
|
||||
@@ -65,6 +65,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return NextActivity;
|
||||
|
||||
// Try to move within range
|
||||
var maxRange = armament.MaxRange();
|
||||
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
|
||||
return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
|
||||
|
||||
|
||||
@@ -108,7 +108,8 @@ namespace OpenRA.Mods.Common.Effects
|
||||
if (info.Inaccuracy.Length > 0)
|
||||
{
|
||||
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
|
||||
var maxOffset = inaccuracy * (target - pos).Length / args.Weapon.Range.Length;
|
||||
var range = OpenRA.Traits.Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
|
||||
var maxOffset = inaccuracy * (target - pos).Length / range;
|
||||
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
|
||||
}
|
||||
|
||||
|
||||
@@ -365,6 +365,7 @@
|
||||
<Compile Include="Traits\Multipliers\ReloadDelayMultiplier.cs" />
|
||||
<Compile Include="Traits\Multipliers\SpeedMultiplier.cs" />
|
||||
<Compile Include="Traits\Multipliers\PowerMultiplier.cs" />
|
||||
<Compile Include="Traits\Multipliers\RangeMultiplier.cs" />
|
||||
<Compile Include="Traits\PaletteEffects\CloakPaletteEffect.cs" />
|
||||
<Compile Include="Traits\PaletteEffects\GlobalLightingPaletteEffect.cs" />
|
||||
<Compile Include="Traits\PaletteEffects\FlashPaletteEffect.cs" />
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Bombs drop anywhere in range
|
||||
foreach (var a in Armaments.Where(a => a.Info.Name == info.Bombs))
|
||||
{
|
||||
if (!target.IsInRange(self.CenterPosition, a.Weapon.Range))
|
||||
if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
|
||||
continue;
|
||||
|
||||
inAttackRange = true;
|
||||
@@ -72,10 +72,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var a in Armaments.Where(a => a.Info.Name == info.Guns))
|
||||
{
|
||||
if (!target.IsInRange(self.CenterPosition, a.Weapon.Range))
|
||||
if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
|
||||
continue;
|
||||
|
||||
var t = Target.FromPos(cp - new WVec(0, a.Weapon.Range.Length / 2, cp.Z).Rotate(WRot.FromFacing(f)));
|
||||
var t = Target.FromPos(cp - new WVec(0, a.MaxRange().Length / 2, cp.Z).Rotate(WRot.FromFacing(f)));
|
||||
inAttackRange = true;
|
||||
a.CheckFire(self, facing.Value, t);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
[Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")]
|
||||
public class ArmamentInfo : UpgradableTraitInfo, Requires<AttackBaseInfo>
|
||||
public class ArmamentInfo : UpgradableTraitInfo, IRulesetLoaded, Requires<AttackBaseInfo>
|
||||
{
|
||||
public readonly string Name = "primary";
|
||||
|
||||
@@ -62,7 +62,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Use multiple muzzle images if non-zero")]
|
||||
public readonly int MuzzleSplitFacings = 0;
|
||||
|
||||
public WeaponInfo WeaponInfo { get; private set; }
|
||||
public WDist ModifiedRange { get; private set; }
|
||||
|
||||
public override object Create(ActorInitializer init) { return new Armament(init.Self, this); }
|
||||
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
WeaponInfo = rules.Weapons[Weapon.ToLowerInvariant()];
|
||||
ModifiedRange = new WDist(Util.ApplyPercentageModifiers(
|
||||
WeaponInfo.Range.Length,
|
||||
ai.TraitInfos<IRangeModifierInfo>().Select(m => m.GetRangeModifierDefault())));
|
||||
}
|
||||
}
|
||||
|
||||
public class Armament : UpgradableTrait<ArmamentInfo>, ITick, IExplodeModifier
|
||||
@@ -75,6 +86,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Lazy<BodyOrientation> coords;
|
||||
Lazy<AmmoPool> ammoPool;
|
||||
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
|
||||
Lazy<IEnumerable<int>> rangeModifiers;
|
||||
|
||||
public WDist Recoil;
|
||||
public int FireDelay { get; private set; }
|
||||
@@ -89,8 +101,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
|
||||
coords = Exts.Lazy(() => self.Trait<BodyOrientation>());
|
||||
ammoPool = Exts.Lazy(() => self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == info.AmmoPoolName));
|
||||
rangeModifiers = Exts.Lazy(() => self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier()));
|
||||
|
||||
Weapon = self.World.Map.Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
||||
Weapon = info.WeaponInfo;
|
||||
Burst = Weapon.Burst;
|
||||
|
||||
var barrels = new List<Barrel>();
|
||||
@@ -109,6 +122,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Barrels = barrels.ToArray();
|
||||
}
|
||||
|
||||
public WDist MaxRange()
|
||||
{
|
||||
return new WDist(Util.ApplyPercentageModifiers(Weapon.Range.Length, rangeModifiers.Value));
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
@@ -148,7 +166,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (ammoPool.Value != null && !ammoPool.Value.HasAmmo())
|
||||
return null;
|
||||
|
||||
if (!target.IsInRange(self.CenterPosition, Weapon.Range))
|
||||
if (!target.IsInRange(self.CenterPosition, MaxRange()))
|
||||
return null;
|
||||
|
||||
if (Weapon.MinRange != WDist.Zero && target.IsInRange(self.CenterPosition, Weapon.MinRange))
|
||||
@@ -172,6 +190,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>()
|
||||
.Select(a => a.GetInaccuracyModifier()).ToArray(),
|
||||
|
||||
RangeModifiers = self.TraitsImplementing<IRangeModifier>()
|
||||
.Select(a => a.GetRangeModifier()).ToArray(),
|
||||
|
||||
Source = muzzlePosition,
|
||||
SourceActor = self,
|
||||
PassiveTarget = target.CenterPosition,
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return WDist.Zero;
|
||||
|
||||
return Armaments.Where(a => !a.IsTraitDisabled)
|
||||
.Select(a => a.Weapon.Range)
|
||||
.Select(a => a.MaxRange())
|
||||
.Append(WDist.Zero).Max();
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
|
||||
var a = ab.ChooseArmamentForTarget(target);
|
||||
cursor = a != null && !target.IsInRange(self.CenterPosition, a.Weapon.Range)
|
||||
cursor = a != null && !target.IsInRange(self.CenterPosition, a.MaxRange())
|
||||
? ab.Info.OutsideRangeCursor
|
||||
: ab.Info.Cursor;
|
||||
|
||||
|
||||
@@ -85,8 +85,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|| (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.HasTraitInfo<IMoveInfo>());
|
||||
|
||||
// Try and sit at least one cell closer than the max range to give some leeway if the target starts moving.
|
||||
var maxRange = targetIsMobile ? new WDist(Math.Max(weapon.Weapon.MinRange.Length, weapon.Weapon.Range.Length - 1024))
|
||||
: weapon.Weapon.Range;
|
||||
var modifiedRange = weapon.MaxRange();
|
||||
var maxRange = targetIsMobile ? new WDist(Math.Max(weapon.Weapon.MinRange.Length, modifiedRange.Length - 1024))
|
||||
: modifiedRange;
|
||||
|
||||
attack.Target = target;
|
||||
|
||||
|
||||
37
OpenRA.Mods.Common/Traits/Multipliers/RangeMultiplier.cs
Normal file
37
OpenRA.Mods.Common/Traits/Multipliers/RangeMultiplier.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Range of this actor is multiplied based on upgrade level.")]
|
||||
public class RangeMultiplierInfo : UpgradeMultiplierTraitInfo, IRangeModifierInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RangeMultiplier(this, init.Self.Info.Name); }
|
||||
|
||||
public int GetRangeModifierDefault()
|
||||
{
|
||||
return BaseLevel > 0 || UpgradeTypes.Length == 0 ? 100 : Modifier[0];
|
||||
}
|
||||
}
|
||||
|
||||
public class RangeMultiplier : UpgradeMultiplierTrait, IRangeModifier
|
||||
{
|
||||
public RangeMultiplier(RangeMultiplierInfo info, string actorType)
|
||||
: base(info, "RangeMultiplier", actorType) { }
|
||||
|
||||
public int GetRangeModifier() { return GetModifier(); }
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,18 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Draw a circle indicating my weapon's range.")]
|
||||
class RenderRangeCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo, Requires<AttackBaseInfo>
|
||||
class RenderRangeCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo, IRulesetLoaded, Requires<AttackBaseInfo>
|
||||
{
|
||||
public readonly string RangeCircleType = null;
|
||||
|
||||
[Desc("Range to draw if no armaments are available")]
|
||||
public readonly WDist FallbackRange = WDist.Zero;
|
||||
|
||||
// Computed range
|
||||
WDist range;
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
var armaments = ai.TraitInfos<ArmamentInfo>()
|
||||
.Where(a => a.UpgradeMinEnabledLevel == 0);
|
||||
var range = FallbackRange;
|
||||
|
||||
if (armaments.Any())
|
||||
range = armaments.Select(a => w.Map.Rules.Weapons[a.Weapon.ToLowerInvariant()].Range).Max();
|
||||
|
||||
if (range == WDist.Zero)
|
||||
yield break;
|
||||
|
||||
@@ -52,6 +48,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new RenderRangeCircle(init.Self); }
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
var armaments = ai.TraitInfos<ArmamentInfo>().Where(a => a.UpgradeMinEnabledLevel == 0);
|
||||
|
||||
if (armaments.Any())
|
||||
range = armaments.Select(a => a.ModifiedRange).Max();
|
||||
else
|
||||
range = FallbackRange;
|
||||
}
|
||||
}
|
||||
|
||||
class RenderRangeCircle : IPostRenderSelection
|
||||
|
||||
@@ -55,6 +55,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>()
|
||||
.Select(a => a.GetInaccuracyModifier()).ToArray(),
|
||||
|
||||
RangeModifiers = self.TraitsImplementing<IRangeModifier>()
|
||||
.Select(a => a.GetRangeModifier()).ToArray(),
|
||||
|
||||
Source = self.CenterPosition,
|
||||
SourceActor = self,
|
||||
PassiveTarget = self.CenterPosition + new WVec(range, 0, 0).Rotate(rotation)
|
||||
|
||||
Reference in New Issue
Block a user