Added IRangeMultiplier

This commit is contained in:
atlimit8
2015-06-27 13:52:00 -05:00
parent 65c1d2f5c1
commit 74a9dc6793
14 changed files with 96 additions and 23 deletions

View File

@@ -21,6 +21,7 @@ namespace OpenRA.GameRules
public WeaponInfo Weapon; public WeaponInfo Weapon;
public int[] DamageModifiers; public int[] DamageModifiers;
public int[] InaccuracyModifiers; public int[] InaccuracyModifiers;
public int[] RangeModifiers;
public int Facing; public int Facing;
public WPos Source; public WPos Source;
public Actor SourceActor; public Actor SourceActor;

View File

@@ -218,6 +218,8 @@ namespace OpenRA.Traits
public interface IFirepowerModifier { int GetFirepowerModifier(); } public interface IFirepowerModifier { int GetFirepowerModifier(); }
public interface IReloadModifier { int GetReloadModifier(); } public interface IReloadModifier { int GetReloadModifier(); }
public interface IInaccuracyModifier { int GetInaccuracyModifier(); } public interface IInaccuracyModifier { int GetInaccuracyModifier(); }
public interface IRangeModifier { int GetRangeModifier(); }
public interface IRangeModifierInfo : ITraitInfo { int GetRangeModifierDefault(); }
public interface IPowerModifier { int GetPowerModifier(); } public interface IPowerModifier { int GetPowerModifier(); }
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); } public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); } public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); }

View File

@@ -21,15 +21,15 @@ namespace OpenRA.Mods.Common.Activities
readonly AttackBase attack; readonly AttackBase attack;
readonly IMove move; readonly IMove move;
readonly IFacing facing; readonly IFacing facing;
readonly Armament armament;
readonly WDist minRange; readonly WDist minRange;
readonly WDist maxRange;
readonly IPositionable positionable; readonly IPositionable positionable;
public Attack(Actor self, Target target, Armament armament, bool allowMovement) public Attack(Actor self, Target target, Armament armament, bool allowMovement)
{ {
Target = target; Target = target;
this.minRange = armament.Weapon.MinRange; this.minRange = armament.Weapon.MinRange;
this.maxRange = armament.Weapon.Range; this.armament = armament;
attack = self.Trait<AttackBase>(); attack = self.Trait<AttackBase>();
facing = self.Trait<IFacing>(); facing = self.Trait<IFacing>();
@@ -65,6 +65,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity; return NextActivity;
// Try to move within range // Try to move within range
var maxRange = armament.MaxRange();
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange))) if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this); return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);

View File

@@ -108,7 +108,8 @@ namespace OpenRA.Mods.Common.Effects
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); 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; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
} }

View File

@@ -365,6 +365,7 @@
<Compile Include="Traits\Multipliers\ReloadDelayMultiplier.cs" /> <Compile Include="Traits\Multipliers\ReloadDelayMultiplier.cs" />
<Compile Include="Traits\Multipliers\SpeedMultiplier.cs" /> <Compile Include="Traits\Multipliers\SpeedMultiplier.cs" />
<Compile Include="Traits\Multipliers\PowerMultiplier.cs" /> <Compile Include="Traits\Multipliers\PowerMultiplier.cs" />
<Compile Include="Traits\Multipliers\RangeMultiplier.cs" />
<Compile Include="Traits\PaletteEffects\CloakPaletteEffect.cs" /> <Compile Include="Traits\PaletteEffects\CloakPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\GlobalLightingPaletteEffect.cs" /> <Compile Include="Traits\PaletteEffects\GlobalLightingPaletteEffect.cs" />
<Compile Include="Traits\PaletteEffects\FlashPaletteEffect.cs" /> <Compile Include="Traits\PaletteEffects\FlashPaletteEffect.cs" />

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
// Bombs drop anywhere in range // Bombs drop anywhere in range
foreach (var a in Armaments.Where(a => a.Info.Name == info.Bombs)) 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; continue;
inAttackRange = true; inAttackRange = true;
@@ -72,10 +72,10 @@ namespace OpenRA.Mods.Common.Traits
{ {
foreach (var a in Armaments.Where(a => a.Info.Name == info.Guns)) 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; 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; inAttackRange = true;
a.CheckFire(self, facing.Value, t); a.CheckFire(self, facing.Value, t);
} }

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
} }
[Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")] [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"; public readonly string Name = "primary";
@@ -62,7 +62,18 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Use multiple muzzle images if non-zero")] [Desc("Use multiple muzzle images if non-zero")]
public readonly int MuzzleSplitFacings = 0; 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 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 public class Armament : UpgradableTrait<ArmamentInfo>, ITick, IExplodeModifier
@@ -75,6 +86,7 @@ namespace OpenRA.Mods.Common.Traits
Lazy<BodyOrientation> coords; Lazy<BodyOrientation> coords;
Lazy<AmmoPool> ammoPool; Lazy<AmmoPool> ammoPool;
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>(); List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
Lazy<IEnumerable<int>> rangeModifiers;
public WDist Recoil; public WDist Recoil;
public int FireDelay { get; private set; } 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)); turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
coords = Exts.Lazy(() => self.Trait<BodyOrientation>()); coords = Exts.Lazy(() => self.Trait<BodyOrientation>());
ammoPool = Exts.Lazy(() => self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == info.AmmoPoolName)); 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; Burst = Weapon.Burst;
var barrels = new List<Barrel>(); var barrels = new List<Barrel>();
@@ -109,6 +122,11 @@ namespace OpenRA.Mods.Common.Traits
Barrels = barrels.ToArray(); Barrels = barrels.ToArray();
} }
public WDist MaxRange()
{
return new WDist(Util.ApplyPercentageModifiers(Weapon.Range.Length, rangeModifiers.Value));
}
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
@@ -148,7 +166,7 @@ namespace OpenRA.Mods.Common.Traits
if (ammoPool.Value != null && !ammoPool.Value.HasAmmo()) if (ammoPool.Value != null && !ammoPool.Value.HasAmmo())
return null; return null;
if (!target.IsInRange(self.CenterPosition, Weapon.Range)) if (!target.IsInRange(self.CenterPosition, MaxRange()))
return null; return null;
if (Weapon.MinRange != WDist.Zero && target.IsInRange(self.CenterPosition, Weapon.MinRange)) if (Weapon.MinRange != WDist.Zero && target.IsInRange(self.CenterPosition, Weapon.MinRange))
@@ -172,6 +190,9 @@ namespace OpenRA.Mods.Common.Traits
InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>() InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>()
.Select(a => a.GetInaccuracyModifier()).ToArray(), .Select(a => a.GetInaccuracyModifier()).ToArray(),
RangeModifiers = self.TraitsImplementing<IRangeModifier>()
.Select(a => a.GetRangeModifier()).ToArray(),
Source = muzzlePosition, Source = muzzlePosition,
SourceActor = self, SourceActor = self,
PassiveTarget = target.CenterPosition, PassiveTarget = target.CenterPosition,

View File

@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Traits
return WDist.Zero; return WDist.Zero;
return Armaments.Where(a => !a.IsTraitDisabled) return Armaments.Where(a => !a.IsTraitDisabled)
.Select(a => a.Weapon.Range) .Select(a => a.MaxRange())
.Append(WDist.Zero).Max(); .Append(WDist.Zero).Max();
} }
@@ -227,7 +227,7 @@ namespace OpenRA.Mods.Common.Traits
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
var a = ab.ChooseArmamentForTarget(target); 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.OutsideRangeCursor
: ab.Info.Cursor; : ab.Info.Cursor;

View File

@@ -85,8 +85,9 @@ namespace OpenRA.Mods.Common.Traits
|| (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.HasTraitInfo<IMoveInfo>()); || (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. // 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)) var modifiedRange = weapon.MaxRange();
: weapon.Weapon.Range; var maxRange = targetIsMobile ? new WDist(Math.Max(weapon.Weapon.MinRange.Length, modifiedRange.Length - 1024))
: modifiedRange;
attack.Target = target; attack.Target = target;

View 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(); }
}
}

View File

@@ -18,22 +18,18 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Draw a circle indicating my weapon's range.")] [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; public readonly string RangeCircleType = null;
[Desc("Range to draw if no armaments are available")] [Desc("Range to draw if no armaments are available")]
public readonly WDist FallbackRange = WDist.Zero; public readonly WDist FallbackRange = WDist.Zero;
// Computed range
WDist range;
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) 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) if (range == WDist.Zero)
yield break; yield break;
@@ -52,6 +48,15 @@ namespace OpenRA.Mods.Common.Traits
} }
public object Create(ActorInitializer init) { return new RenderRangeCircle(init.Self); } 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 class RenderRangeCircle : IPostRenderSelection

View File

@@ -55,6 +55,9 @@ namespace OpenRA.Mods.Common.Traits
InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>() InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>()
.Select(a => a.GetInaccuracyModifier()).ToArray(), .Select(a => a.GetInaccuracyModifier()).ToArray(),
RangeModifiers = self.TraitsImplementing<IRangeModifier>()
.Select(a => a.GetRangeModifier()).ToArray(),
Source = self.CenterPosition, Source = self.CenterPosition,
SourceActor = self, SourceActor = self,
PassiveTarget = self.CenterPosition + new WVec(range, 0, 0).Rotate(rotation) PassiveTarget = self.CenterPosition + new WVec(range, 0, 0).Rotate(rotation)

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.D2k.Traits
if (a == null) if (a == null)
return; return;
if (!target.IsInRange(self.CenterPosition, a.Weapon.Range)) if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
return; return;
self.CancelActivity(); self.CancelActivity();

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Traits
if (a == null) if (a == null)
return; return;
if (!target.IsInRange(self.CenterPosition, a.Weapon.Range)) if (!target.IsInRange(self.CenterPosition, a.MaxRange()))
return; return;
self.CancelActivity(); self.CancelActivity();