Merge repair and rearm anim traits into WithResupplyAnimation
This is the safest approach to avoid conflicts/visual glitches when the host is responsible for both resupply types. The new trait will simply play a looping animation as long as the actor is resupplying in any form.
This commit is contained in:
@@ -13,16 +13,20 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class Rearm : Activity
|
||||
{
|
||||
readonly Target host;
|
||||
readonly WDist closeEnough;
|
||||
readonly AmmoPool[] ammoPools;
|
||||
|
||||
public Rearm(Actor self)
|
||||
public Rearm(Actor self, Actor host, WDist closeEnough)
|
||||
{
|
||||
this.host = Target.FromActor(host);
|
||||
this.closeEnough = closeEnough;
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>().Where(p => !p.AutoReloads).ToArray();
|
||||
}
|
||||
|
||||
@@ -33,6 +37,28 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// HACK: this really shouldn't be managed from here
|
||||
foreach (var pool in ammoPools)
|
||||
pool.RemainingTicks = pool.Info.ReloadDelay;
|
||||
|
||||
if (host.Type == TargetType.Invalid)
|
||||
return;
|
||||
|
||||
foreach (var notify in host.Actor.TraitsImplementing<INotifyRearm>())
|
||||
notify.RearmingStarted(host.Actor, self);
|
||||
}
|
||||
|
||||
protected override void OnLastRun(Actor self)
|
||||
{
|
||||
if (host.Type == TargetType.Invalid)
|
||||
return;
|
||||
|
||||
foreach (var notify in host.Actor.TraitsImplementing<INotifyRearm>())
|
||||
notify.RearmingFinished(host.Actor, self);
|
||||
}
|
||||
|
||||
protected override void OnActorDispose(Actor self)
|
||||
{
|
||||
// If the actor died (or will be disposed directly) this tick, Activity.TickOuter won't be ticked again,
|
||||
// so we need to run OnLastRun directly (otherwise it would be skipped completely).
|
||||
OnLastRun(self);
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -40,11 +66,10 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
// HACK: check if we are on the helipad/airfield/etc.
|
||||
var hostBuilding = self.World.ActorMap.GetActorsAt(self.Location)
|
||||
.FirstOrDefault(a => a.Info.HasTraitInfo<BuildingInfo>());
|
||||
if (host.Type == TargetType.Invalid)
|
||||
return NextActivity;
|
||||
|
||||
if (hostBuilding == null || !hostBuilding.IsInWorld)
|
||||
if (closeEnough.LengthSquared > 0 && !host.IsInRange(self.CenterPosition, closeEnough))
|
||||
return NextActivity;
|
||||
|
||||
var complete = true;
|
||||
@@ -52,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
if (!pool.FullAmmo())
|
||||
{
|
||||
Reload(self, hostBuilding, pool);
|
||||
Reload(self, host.Actor, pool);
|
||||
complete = false;
|
||||
}
|
||||
}
|
||||
@@ -60,12 +85,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return complete ? NextActivity : this;
|
||||
}
|
||||
|
||||
void Reload(Actor self, Actor hostBuilding, AmmoPool ammoPool)
|
||||
void Reload(Actor self, Actor host, AmmoPool ammoPool)
|
||||
{
|
||||
if (--ammoPool.RemainingTicks <= 0)
|
||||
{
|
||||
foreach (var host in hostBuilding.TraitsImplementing<INotifyRearm>())
|
||||
host.Rearming(hostBuilding, self);
|
||||
foreach (var notify in host.TraitsImplementing<INotifyRearm>())
|
||||
notify.Rearming(host, self);
|
||||
|
||||
ammoPool.RemainingTicks = ammoPool.Info.ReloadDelay;
|
||||
if (!string.IsNullOrEmpty(ammoPool.Info.RearmSound))
|
||||
|
||||
@@ -137,5 +137,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
foreach (var depot in host.Actor.TraitsImplementing<INotifyRepair>())
|
||||
depot.AfterRepair(host.Actor, self);
|
||||
}
|
||||
|
||||
protected override void OnActorDispose(Actor self)
|
||||
{
|
||||
// If the actor died (or will be disposed directly) this tick, Activity.TickOuter won't be ticked again,
|
||||
// so we need to run OnLastRun directly (otherwise it would be skipped completely).
|
||||
OnLastRun(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user