Previously, the ClosestTo and PositionClosestTo existed to perform a simple distance based check to choose the closest location from a choice of locations to a single other location. For some functions this is sufficient, but for many functions we want to then move between the locations. If the location selected is in fact unreachable (e.g. on another island) then we would not want to consider it. We now introduce ClosestToIgnoringPath for checks where we don't care about a path existing, e.g. weapons hitting nearby targets. When we do care about paths, we introduce ClosestToWithPathFrom and ClosestToWithPathTo which will check that a path exists. The PathFrom check will make sure one of the actors from the list can make it to the single target location. The PathTo check will make sure the single actor can make it to one of the target locations. This difference allows us to specify which actor will be doing the moving. This is important as a path might exists for one actor, but not another. Consider two islands with a hovercraft on one and a tank on the other. The hovercraft can path to the tank, but the tank cannot path to the hovercraft. We also introduce WithPathFrom and WithPathTo. These will perform filtering by checking for valid paths, but won't select the closest location. By employing the new methods that filter for paths, we fix various behaviour that would cause actors to get confused. Imagine an islands map, by checking for paths we ensure logic will locate reachable locations on the island, rather than considering a location on a nearby island that is physically closer but unreachable. This fixes AI squad automation, and other automated behaviours such as rearming.
97 lines
2.9 KiB
C#
97 lines
2.9 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright (c) The OpenRA Developers and Contributors
|
|
* 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, either version 3 of
|
|
* the License, or (at your option) any later version. For more
|
|
* information, see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System.Collections.Generic;
|
|
using OpenRA.GameRules;
|
|
using OpenRA.Graphics;
|
|
using OpenRA.Mods.Cnc.Graphics;
|
|
using OpenRA.Traits;
|
|
|
|
namespace OpenRA.Mods.Cnc.Projectiles
|
|
{
|
|
[Desc("Instant-hit projectile used to create electricity-like effects.")]
|
|
public class TeslaZapInfo : IProjectileInfo
|
|
{
|
|
public readonly string Image = "litning";
|
|
|
|
[SequenceReference(nameof(Image))]
|
|
[Desc("Sprite sequence to play at the center.")]
|
|
public readonly string BrightSequence = "bright";
|
|
|
|
[SequenceReference(nameof(Image))]
|
|
[Desc("Sprite sequence to play at the borders.")]
|
|
public readonly string DimSequence = "dim";
|
|
|
|
[PaletteReference]
|
|
[Desc("The palette used to draw this electric zap.")]
|
|
public readonly string Palette = "effect";
|
|
|
|
[Desc("How many sprite sequences to play at the center.")]
|
|
public readonly int BrightZaps = 1;
|
|
|
|
[Desc("How many sprite sequences to play at the borders.")]
|
|
public readonly int DimZaps = 2;
|
|
|
|
[Desc("How long (in ticks) to play the sprite sequences.")]
|
|
public readonly int Duration = 2;
|
|
|
|
[Desc("How long (in ticks) until applying damage. Can't be longer than `" + nameof(Duration) + "`")]
|
|
public readonly int DamageDuration = 1;
|
|
|
|
[Desc("Follow the targeted actor when it moves.")]
|
|
public readonly bool TrackTarget = true;
|
|
|
|
public IProjectile Create(ProjectileArgs args) { return new TeslaZap(this, args); }
|
|
}
|
|
|
|
public class TeslaZap : IProjectile, ISync
|
|
{
|
|
readonly ProjectileArgs args;
|
|
readonly TeslaZapInfo info;
|
|
TeslaZapRenderable zap;
|
|
int ticksUntilRemove;
|
|
int damageDuration;
|
|
|
|
[Sync]
|
|
WPos target;
|
|
|
|
public TeslaZap(TeslaZapInfo info, ProjectileArgs args)
|
|
{
|
|
this.args = args;
|
|
this.info = info;
|
|
ticksUntilRemove = info.Duration;
|
|
damageDuration = info.DamageDuration > info.Duration ? info.Duration : info.DamageDuration;
|
|
target = args.PassiveTarget;
|
|
}
|
|
|
|
public void Tick(World world)
|
|
{
|
|
if (ticksUntilRemove-- <= 0)
|
|
world.AddFrameEndTask(w => w.Remove(this));
|
|
|
|
// Zap tracks target
|
|
if (info.TrackTarget && args.GuidedTarget.IsValidFor(args.SourceActor))
|
|
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.ClosestToIgnoringPath(args.Source);
|
|
|
|
if (damageDuration-- > 0)
|
|
args.Weapon.Impact(Target.FromPos(target), new WarheadArgs(args));
|
|
}
|
|
|
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
|
{
|
|
zap = new TeslaZapRenderable(args.Source, 0, target - args.Source,
|
|
info.Image, info.BrightSequence, info.BrightZaps, info.DimSequence, info.DimZaps, info.Palette);
|
|
|
|
yield return zap;
|
|
}
|
|
}
|
|
}
|