Move some Warheads to Mods.Common
This commit is contained in:
@@ -121,7 +121,10 @@
|
||||
<Compile Include="UtilityCommands\UpgradeMapCommand.cs" />
|
||||
<Compile Include="UtilityCommands\UpgradeModCommand.cs" />
|
||||
<Compile Include="UtilityCommands\UpgradeRules.cs" />
|
||||
<Compile Include="Warheads\CreateEffectWarhead.cs" />
|
||||
<Compile Include="Warheads\HealthPercentageDamageWarhead.cs" />
|
||||
<Compile Include="Warheads\LeaveSmudgeWarhead.cs" />
|
||||
<Compile Include="Warheads\SpreadDamageWarhead.cs" />
|
||||
<Compile Include="Widgets\ConfirmationDialogs.cs" />
|
||||
<Compile Include="Widgets\HueSliderWidget.cs" />
|
||||
<Compile Include="Widgets\LabelWithTooltipWidget.cs" />
|
||||
|
||||
108
OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs
Normal file
108
OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
public class CreateEffectWarhead : Warhead
|
||||
{
|
||||
[Desc("Explosion effect to use.")]
|
||||
public readonly string Explosion = null;
|
||||
|
||||
[Desc("Palette to use for explosion effect.")]
|
||||
public readonly string ExplosionPalette = "effect";
|
||||
|
||||
[Desc("Sound to play on impact.")]
|
||||
public readonly string ImpactSound = null;
|
||||
|
||||
[Desc("What impact types should this effect apply to.")]
|
||||
public readonly ImpactType ValidImpactTypes = ImpactType.Ground | ImpactType.Water | ImpactType.Air | ImpactType.GroundHit | ImpactType.WaterHit | ImpactType.AirHit;
|
||||
|
||||
[Desc("What impact types should this effect NOT apply to.", "Overrides ValidImpactTypes.")]
|
||||
public readonly ImpactType InvalidImpactTypes = ImpactType.None;
|
||||
|
||||
public static ImpactType GetImpactType(World world, CPos cell, WPos pos)
|
||||
{
|
||||
var isAir = pos.Z > 0;
|
||||
var isWater = pos.Z <= 0 && world.Map.GetTerrainInfo(cell).IsWater;
|
||||
var isDirectHit = GetDirectHit(world, cell, pos);
|
||||
|
||||
if (isAir && !isDirectHit)
|
||||
return ImpactType.Air;
|
||||
|
||||
else if (isWater && !isDirectHit)
|
||||
return ImpactType.Water;
|
||||
|
||||
else if (isAir && isDirectHit)
|
||||
return ImpactType.AirHit;
|
||||
|
||||
else if (isWater && isDirectHit)
|
||||
return ImpactType.WaterHit;
|
||||
|
||||
else if (isDirectHit)
|
||||
return ImpactType.GroundHit;
|
||||
|
||||
return ImpactType.Ground;
|
||||
}
|
||||
|
||||
public static bool GetDirectHit(World world, CPos cell, WPos pos)
|
||||
{
|
||||
foreach (var unit in world.ActorMap.GetUnitsAt(cell))
|
||||
{
|
||||
var healthInfo = unit.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
if (healthInfo == null)
|
||||
continue;
|
||||
|
||||
// If the impact position is within any actor's health radius, we have a direct hit
|
||||
if ((unit.CenterPosition - pos).LengthSquared <= healthInfo.Radius.Range * healthInfo.Radius.Range)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
var pos = target.CenterPosition;
|
||||
var world = firedBy.World;
|
||||
var targetTile = world.Map.CellContaining(pos);
|
||||
var isValid = IsValidImpact(pos, firedBy);
|
||||
|
||||
if ((!world.Map.Contains(targetTile)) || (!isValid))
|
||||
return;
|
||||
|
||||
if (Explosion != null)
|
||||
world.AddFrameEndTask(w => w.Add(new Explosion(w, pos, Explosion, ExplosionPalette)));
|
||||
|
||||
if (ImpactSound != null)
|
||||
Sound.Play(ImpactSound, pos);
|
||||
}
|
||||
|
||||
public bool IsValidImpact(WPos pos, Actor firedBy)
|
||||
{
|
||||
var world = firedBy.World;
|
||||
var targetTile = world.Map.CellContaining(pos);
|
||||
if (!world.Map.Contains(targetTile))
|
||||
return false;
|
||||
|
||||
var impactType = GetImpactType(world, targetTile, pos);
|
||||
if (!ValidImpactTypes.HasFlag(impactType) || InvalidImpactTypes.HasFlag(impactType))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
48
OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs
Normal file
48
OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
public class HealthPercentageDamageWarhead : DamageWarhead
|
||||
{
|
||||
[Desc("Size of the area. Damage will be applied to this area.", "If two spreads are defined, the area of effect is a ring, where the second value is the inner radius.")]
|
||||
public readonly WRange[] Spread = { new WRange(43) };
|
||||
|
||||
public override void DoImpact(WPos pos, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
var world = firedBy.World;
|
||||
var range = Spread[0];
|
||||
var hitActors = world.FindActorsInCircle(pos, range);
|
||||
if (Spread.Length > 1 && Spread[1].Range > 0)
|
||||
hitActors = hitActors.Except(world.FindActorsInCircle(pos, Spread[1]));
|
||||
|
||||
foreach (var victim in hitActors)
|
||||
DoImpact(victim, firedBy, damageModifiers);
|
||||
}
|
||||
|
||||
public override void DoImpact(Actor victim, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
var healthInfo = victim.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
if (healthInfo == null)
|
||||
return;
|
||||
|
||||
// Damage is measured as a percentage of the target health
|
||||
var damage = Util.ApplyPercentageModifiers(healthInfo.HP, damageModifiers.Append(Damage, DamageVersus(victim.Info)));
|
||||
victim.InflictDamage(firedBy, damage, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
86
OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs
Normal file
86
OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
public class SpreadDamageWarhead : DamageWarhead
|
||||
{
|
||||
[Desc("Range between falloff steps.")]
|
||||
public readonly WRange Spread = new WRange(43);
|
||||
|
||||
[Desc("Ranges at which each Falloff step is defined. Overrides Spread.")]
|
||||
public WRange[] Range = null;
|
||||
|
||||
[Desc("Damage percentage at each range step")]
|
||||
public readonly int[] Falloff = { 100, 37, 14, 5, 2, 1, 0 };
|
||||
|
||||
public void InitializeRange()
|
||||
{
|
||||
if (Range != null)
|
||||
{
|
||||
if (Range.Length != 1 && Range.Length != Falloff.Length)
|
||||
throw new InvalidOperationException("Number of range values must be 1 or equal to the number of Falloff values.");
|
||||
|
||||
for (var i = 0; i < Range.Length - 1; i++)
|
||||
if (Range[i] > Range[i + 1])
|
||||
throw new InvalidOperationException("Range values must be specified in an increasing order.");
|
||||
}
|
||||
else
|
||||
Range = Exts.MakeArray(Falloff.Length, i => i * Spread);
|
||||
}
|
||||
|
||||
public override void DoImpact(WPos pos, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
if (Range == null)
|
||||
InitializeRange();
|
||||
|
||||
var world = firedBy.World;
|
||||
var hitActors = world.FindActorsInCircle(pos, Range[Range.Length - 1]);
|
||||
|
||||
foreach (var victim in hitActors)
|
||||
{
|
||||
if (!IsValidAgainst(victim, firedBy))
|
||||
continue;
|
||||
|
||||
var localModifiers = damageModifiers;
|
||||
var healthInfo = victim.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
if (healthInfo != null)
|
||||
{
|
||||
var distance = Math.Max(0, (victim.CenterPosition - pos).Length - healthInfo.Radius.Range);
|
||||
localModifiers = localModifiers.Append(GetDamageFalloff(distance));
|
||||
}
|
||||
|
||||
DoImpact(victim, firedBy, localModifiers);
|
||||
}
|
||||
}
|
||||
|
||||
int GetDamageFalloff(int distance)
|
||||
{
|
||||
var inner = Range[0].Range;
|
||||
for (var i = 1; i < Range.Length; i++)
|
||||
{
|
||||
var outer = Range[i].Range;
|
||||
if (outer > distance)
|
||||
return int2.Lerp(Falloff[i - 1], Falloff[i], distance - inner, outer - inner);
|
||||
|
||||
inner = outer;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user