Make Transform use child activities
This commit is contained in:
committed by
Paul Chote
parent
f9951f76ca
commit
f9913db5e8
@@ -12,7 +12,9 @@
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
@@ -32,11 +34,61 @@ namespace OpenRA.Mods.Common.Activities
|
||||
ToActor = toActor;
|
||||
}
|
||||
|
||||
protected override void OnFirstRun(Actor self)
|
||||
{
|
||||
if (self.Info.HasTraitInfo<IFacingInfo>())
|
||||
QueueChild(new Turn(self, Facing));
|
||||
|
||||
if (self.Info.HasTraitInfo<AircraftInfo>())
|
||||
QueueChild(new HeliLand(self, true));
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
if (ChildActivity != null)
|
||||
{
|
||||
ActivityUtils.RunActivity(self, ChildActivity);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Prevent deployment in bogus locations
|
||||
var transforms = self.TraitOrDefault<Transforms>();
|
||||
var building = self.TraitOrDefault<Building>();
|
||||
if ((transforms != null && !transforms.CanDeploy()) || (building != null && !building.Lock()))
|
||||
{
|
||||
Cancel(self, true);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
|
||||
nt.BeforeTransform(self);
|
||||
|
||||
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
||||
if (makeAnimation != null)
|
||||
{
|
||||
// Once the make animation starts the activity must not be stopped anymore.
|
||||
IsInterruptible = false;
|
||||
|
||||
// Wait forever
|
||||
QueueChild(new WaitFor(() => false));
|
||||
makeAnimation.Reverse(self, () => DoTransform(self));
|
||||
return this;
|
||||
}
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
protected override void OnLastRun(Actor self)
|
||||
{
|
||||
if (!IsCanceled)
|
||||
DoTransform(self);
|
||||
}
|
||||
|
||||
void DoTransform(Actor self)
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (self.IsDead)
|
||||
@@ -84,11 +136,10 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (selected)
|
||||
w.Selection.Add(w, a);
|
||||
|
||||
if (controlgroup.HasValue)
|
||||
w.Selection.AddToControlGroup(a, controlgroup.Value);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
Forward(self, () => building.NotifyBuildingComplete(self));
|
||||
}
|
||||
|
||||
void Forward(Actor self, Action onComplete)
|
||||
public void Forward(Actor self, Action onComplete)
|
||||
{
|
||||
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition) && token == ConditionManager.InvalidConditionToken)
|
||||
token = conditionManager.GrantCondition(self, info.Condition);
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
});
|
||||
}
|
||||
|
||||
void Reverse(Actor self, Action onComplete)
|
||||
public void Reverse(Actor self, Action onComplete)
|
||||
{
|
||||
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition) && token == ConditionManager.InvalidConditionToken)
|
||||
token = conditionManager.GrantCondition(self, info.Condition);
|
||||
|
||||
@@ -10,10 +10,8 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -73,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return (order.OrderString == "DeployTransform") ? info.Voice : null;
|
||||
}
|
||||
|
||||
bool CanDeploy()
|
||||
public bool CanDeploy()
|
||||
{
|
||||
var building = self.TraitOrDefault<Building>();
|
||||
if (building != null && building.Locked)
|
||||
@@ -113,43 +111,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!queued)
|
||||
self.CancelActivity();
|
||||
|
||||
if (self.Info.HasTraitInfo<IFacingInfo>())
|
||||
self.QueueActivity(new Turn(self, info.Facing));
|
||||
|
||||
if (self.Info.HasTraitInfo<AircraftInfo>())
|
||||
self.QueueActivity(new HeliLand(self, true));
|
||||
|
||||
self.QueueActivity(new CallFunc(() =>
|
||||
{
|
||||
// Prevent deployment in bogus locations
|
||||
var building = self.TraitOrDefault<Building>();
|
||||
if (!CanDeploy() || (building != null && !building.Lock()))
|
||||
return;
|
||||
|
||||
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
|
||||
nt.BeforeTransform(self);
|
||||
|
||||
var transform = new Transform(self, info.IntoActor)
|
||||
self.QueueActivity(new Transform(self, info.IntoActor)
|
||||
{
|
||||
Offset = info.Offset,
|
||||
Facing = info.Facing,
|
||||
Sounds = info.TransformSounds,
|
||||
Notification = info.TransformNotification,
|
||||
Faction = faction
|
||||
};
|
||||
|
||||
// Try and stop the actor from doing anything between the sanity checks above
|
||||
// and the actual transform, which we're about to queue.
|
||||
// TODO: The proper way to do this is to write all the transform code as a nested activity.
|
||||
if (self.CurrentActivity.NextInQueue != null)
|
||||
self.CurrentActivity.NextInQueue.Cancel(self);
|
||||
|
||||
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
|
||||
if (makeAnimation != null)
|
||||
makeAnimation.Reverse(self, transform);
|
||||
else
|
||||
self.QueueActivity(transform);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
|
||||
Reference in New Issue
Block a user