Changes included: Warhead code split out of weapon code and refactored. Warhead functionality now split into several classes, each handling one effect/impact. Additional custom warheads can now be defined and called via yaml. Custom warheads inherit the abstract class Warhead, which provides target check functions. Custom warheads have to define their own impact functions, and can also define their own replacement for check functions.
87 lines
2.7 KiB
C#
87 lines
2.7 KiB
C#
#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.RA.Effects;
|
|
|
|
namespace OpenRA.Mods.RA
|
|
{
|
|
public class CreateEffectWarhead : Warhead
|
|
{
|
|
[Desc("Size of the area. An explosion animation will be created in each tile.", "Provide 2 values for a ring effect (outer/inner).")]
|
|
public readonly int[] Size = { 0, 0 };
|
|
|
|
[Desc("Explosion effect to use.")]
|
|
public readonly string Explosion = null;
|
|
|
|
[Desc("Palette to use for explosion effect.")]
|
|
public readonly string ExplosionPalette = "effect";
|
|
|
|
[Desc("Explosion effect on hitting water (usually a splash).")]
|
|
public readonly string WaterExplosion = null;
|
|
|
|
[Desc("Palette to use for effect on hitting water (usually a splash).")]
|
|
public readonly string WaterExplosionPalette = "effect";
|
|
|
|
[Desc("Sound to play on impact.")]
|
|
public readonly string ImpactSound = null;
|
|
|
|
[Desc("Sound to play on impact with water")]
|
|
public readonly string WaterImpactSound = null;
|
|
|
|
public override void DoImpact(Target target, Actor firedBy, float firepowerModifier)
|
|
{
|
|
DoImpact(target.CenterPosition, firedBy, firepowerModifier);
|
|
}
|
|
|
|
public void DoImpact(WPos pos, Actor firedBy, float firepowerModifier)
|
|
{
|
|
var world = firedBy.World;
|
|
var targetTile = world.Map.CellContaining(pos);
|
|
|
|
if (!world.Map.Contains(targetTile))
|
|
return;
|
|
|
|
var minRange = (Size.Length > 1 && Size[1] > 0) ? Size[1] : 0;
|
|
var allCells = world.Map.FindTilesInAnnulus(targetTile, minRange, Size[0]);
|
|
|
|
// Draw the effects
|
|
foreach (var currentCell in allCells)
|
|
{
|
|
var currentPos = world.Map.CenterOfCell(currentCell);
|
|
// TODO: #5937 should go in here after rebase.
|
|
var isWater = currentPos.Z <= 0 && world.Map.GetTerrainInfo(currentCell).IsWater;
|
|
var explosionType = isWater ? WaterExplosion : Explosion;
|
|
var explosionTypePalette = isWater ? WaterExplosionPalette : ExplosionPalette;
|
|
|
|
if (explosionType != null)
|
|
world.AddFrameEndTask(w => w.Add(new Explosion(w, currentPos, explosionType, explosionTypePalette)));
|
|
}
|
|
|
|
string sound = null;
|
|
|
|
var isTargetWater = pos.Z <= 0 && world.Map.GetTerrainInfo(targetTile).IsWater;
|
|
if (isTargetWater && WaterImpactSound != null)
|
|
sound = WaterImpactSound;
|
|
|
|
if (ImpactSound != null)
|
|
sound = ImpactSound;
|
|
|
|
Sound.Play(sound, pos);
|
|
}
|
|
|
|
public override float EffectivenessAgainst(ActorInfo ai) { return 1f; }
|
|
}
|
|
}
|