Made all projectile and warhead fields readonly

This came up while working on the new documentation generation and comparing the results to ORAIDE's own code parser.
This commit is contained in:
penev92
2022-04-25 03:21:36 +03:00
committed by abcdefg30
parent 2bac492a65
commit 86515610a5
2 changed files with 13 additions and 9 deletions

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Projectiles
[Desc("Scan radius for actors with projectile-blocking trait. If set to a negative value (default), it will automatically scale",
"to the blocker with the largest health shape. Only set custom values if you know what you're doing.")]
public WDist BlockerScanRadius = new WDist(-1);
public readonly WDist BlockerScanRadius = new WDist(-1);
public IProjectile Create(ProjectileArgs args) { return new InstantHit(this, args); }
}

View File

@@ -27,11 +27,13 @@ namespace OpenRA.Mods.Common.Warheads
public readonly int[] Falloff = { 100, 37, 14, 5, 0 };
[Desc("Ranges at which each Falloff step is defined. Overrides Spread.")]
public WDist[] Range = null;
public readonly WDist[] Range = null;
[Desc("Controls the way damage is calculated. Possible values are 'HitShape', 'ClosestTargetablePosition' and 'CenterPosition'.")]
public readonly DamageCalculationType DamageCalculationType = DamageCalculationType.HitShape;
WDist[] effectiveRange;
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo info)
{
if (Range != null)
@@ -42,18 +44,20 @@ namespace OpenRA.Mods.Common.Warheads
for (var i = 0; i < Range.Length - 1; i++)
if (Range[i] > Range[i + 1])
throw new YamlException("Range values must be specified in an increasing order.");
effectiveRange = Range;
}
else
Range = Exts.MakeArray(Falloff.Length, i => i * Spread);
effectiveRange = Exts.MakeArray(Falloff.Length, i => i * Spread);
}
protected override void DoImpact(WPos pos, Actor firedBy, WarheadArgs args)
{
var debugVis = firedBy.World.WorldActor.TraitOrDefault<DebugVisualizations>();
if (debugVis != null && debugVis.CombatGeometry)
firedBy.World.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Range, DebugOverlayColor);
firedBy.World.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, effectiveRange, DebugOverlayColor);
foreach (var victim in firedBy.World.FindActorsOnCircle(pos, Range[Range.Length - 1]))
foreach (var victim in firedBy.World.FindActorsOnCircle(pos, effectiveRange[effectiveRange.Length - 1]))
{
if (!IsValidAgainst(victim, firedBy))
continue;
@@ -82,7 +86,7 @@ namespace OpenRA.Mods.Common.Warheads
}
// The range to target is more than the range the warhead covers, so GetDamageFalloff() is going to give us 0 and we're going to do 0 damage anyway, so bail early.
if (falloffDistance > Range[Range.Length - 1].Length)
if (falloffDistance > effectiveRange[effectiveRange.Length - 1].Length)
continue;
var localModifiers = args.DamageModifiers.Append(GetDamageFalloff(falloffDistance));
@@ -109,10 +113,10 @@ namespace OpenRA.Mods.Common.Warheads
int GetDamageFalloff(int distance)
{
var inner = Range[0].Length;
for (var i = 1; i < Range.Length; i++)
var inner = effectiveRange[0].Length;
for (var i = 1; i < effectiveRange.Length; i++)
{
var outer = Range[i].Length;
var outer = effectiveRange[i].Length;
if (outer > distance)
return int2.Lerp(Falloff[i - 1], Falloff[i], distance - inner, outer - inner);