Make Exit Conditional
This commit is contained in:
committed by
Paul Chote
parent
47c4be9191
commit
faa35946b8
@@ -89,8 +89,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var exit = dest.Info.FirstExitOrDefault(null);
|
var exit = dest.FirstExitOrDefault(null);
|
||||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
var offset = exit != null ? exit.Info.SpawnOffset : WVec.Zero;
|
||||||
|
|
||||||
if (ShouldLandAtBuilding(self, dest))
|
if (ShouldLandAtBuilding(self, dest))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -750,8 +750,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Action enter = () =>
|
Action enter = () =>
|
||||||
{
|
{
|
||||||
var exit = targetActor.Info.FirstExitOrDefault(null);
|
var exit = targetActor.FirstExitOrDefault(null);
|
||||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
var offset = exit != null ? exit.Info.SpawnOffset : WVec.Zero;
|
||||||
|
|
||||||
self.QueueActivity(new HeliFly(self, Target.FromPos(targetActor.CenterPosition + offset)));
|
self.QueueActivity(new HeliFly(self, Target.FromPos(targetActor.CenterPosition + offset)));
|
||||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Where the unit should leave the building. Multiples are allowed if IDs are added: Exit@2, ...")]
|
[Desc("Where the unit should leave the building. Multiples are allowed if IDs are added: Exit@2, ...")]
|
||||||
public class ExitInfo : TraitInfo<Exit>, Requires<IOccupySpaceInfo>
|
public class ExitInfo : ConditionalTraitInfo, Requires<IOccupySpaceInfo>
|
||||||
{
|
{
|
||||||
[Desc("Offset at which that the exiting actor is spawned relative to the center of the producing actor.")]
|
[Desc("Offset at which that the exiting actor is spawned relative to the center of the producing actor.")]
|
||||||
public readonly WVec SpawnOffset = WVec.Zero;
|
public readonly WVec SpawnOffset = WVec.Zero;
|
||||||
@@ -34,41 +34,48 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
[Desc("Number of ticks to wait before moving into the world.")]
|
[Desc("Number of ticks to wait before moving into the world.")]
|
||||||
public readonly int ExitDelay = 0;
|
public readonly int ExitDelay = 0;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new Exit(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Exit { }
|
public class Exit : ConditionalTrait<ExitInfo>
|
||||||
|
{
|
||||||
|
public Exit(ActorInitializer init, ExitInfo info)
|
||||||
|
: base(info) { }
|
||||||
|
}
|
||||||
|
|
||||||
public static class ExitExts
|
public static class ExitExts
|
||||||
{
|
{
|
||||||
public static ExitInfo FirstExitOrDefault(this ActorInfo info, string productionType = null)
|
public static Exit FirstExitOrDefault(this Actor actor, string productionType = null)
|
||||||
{
|
{
|
||||||
var all = info.TraitInfos<ExitInfo>();
|
var all = actor.TraitsImplementing<Exit>()
|
||||||
|
.Where(Exts.IsTraitEnabled);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(productionType))
|
if (string.IsNullOrEmpty(productionType))
|
||||||
return all.FirstOrDefault(e => e.ProductionTypes.Count == 0);
|
return all.FirstOrDefault(e => e.Info.ProductionTypes.Count == 0);
|
||||||
return all.FirstOrDefault(e => e.ProductionTypes.Count == 0 || e.ProductionTypes.Contains(productionType));
|
|
||||||
|
return all.FirstOrDefault(e => e.Info.ProductionTypes.Count == 0 || e.Info.ProductionTypes.Contains(productionType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<ExitInfo> Exits(this ActorInfo info, string productionType = null)
|
public static IEnumerable<Exit> Exits(this Actor actor, string productionType = null)
|
||||||
{
|
{
|
||||||
var all = info.TraitInfos<ExitInfo>();
|
var all = actor.TraitsImplementing<Exit>()
|
||||||
|
.Where(Exts.IsTraitEnabled);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(productionType))
|
if (string.IsNullOrEmpty(productionType))
|
||||||
return all.Where(e => e.ProductionTypes.Count == 0);
|
return all.Where(e => e.Info.ProductionTypes.Count == 0);
|
||||||
return all.Where(e => e.ProductionTypes.Count == 0 || e.ProductionTypes.Contains(productionType));
|
|
||||||
|
return all.Where(e => e.Info.ProductionTypes.Count == 0 || e.Info.ProductionTypes.Contains(productionType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExitInfo RandomExitOrDefault(this ActorInfo info, World world, string productionType, Func<ExitInfo, bool> p = null)
|
public static Exit RandomExitOrDefault(this Actor actor, World world, string productionType, Func<Exit, bool> p = null)
|
||||||
{
|
{
|
||||||
var allOfType = Exits(info, productionType);
|
var allOfType = Exits(actor, productionType);
|
||||||
if (!allOfType.Any())
|
if (!allOfType.Any())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var shuffled = allOfType.Shuffle(world.SharedRandom);
|
var shuffled = allOfType.Shuffle(world.SharedRandom);
|
||||||
return p != null ? shuffled.FirstOrDefault(p) : shuffled.First();
|
return p != null ? shuffled.FirstOrDefault(p) : shuffled.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExitInfo RandomExitOrDefault(this Actor self, string productionType, Func<ExitInfo, bool> p = null)
|
|
||||||
{
|
|
||||||
return RandomExitOrDefault(self.Info, self.World, productionType, p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,14 +119,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual ExitInfo SelectExit(Actor self, ActorInfo producee, string productionType, Func<ExitInfo, bool> p)
|
protected virtual Exit SelectExit(Actor self, ActorInfo producee, string productionType, Func<Exit, bool> p)
|
||||||
{
|
{
|
||||||
return self.RandomExitOrDefault(productionType, p);
|
return self.RandomExitOrDefault(self.World, productionType, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ExitInfo SelectExit(Actor self, ActorInfo producee, string productionType)
|
protected Exit SelectExit(Actor self, ActorInfo producee, string productionType)
|
||||||
{
|
{
|
||||||
return SelectExit(self, producee, productionType, e => CanUseExit(self, producee, e));
|
return SelectExit(self, producee, productionType, e => CanUseExit(self, producee, e.Info));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool Produce(Actor self, ActorInfo producee, string productionType, TypeDictionary inits)
|
public virtual bool Produce(Actor self, ActorInfo producee, string productionType, TypeDictionary inits)
|
||||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (exit != null || self.OccupiesSpace == null)
|
if (exit != null || self.OccupiesSpace == null)
|
||||||
{
|
{
|
||||||
DoProduction(self, producee, exit, productionType, inits);
|
DoProduction(self, producee, exit.Info, productionType, inits);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
// Start a fixed distance away: the width of the map.
|
// Start a fixed distance away: the width of the map.
|
||||||
// This makes the production timing independent of spawnpoint
|
// This makes the production timing independent of spawnpoint
|
||||||
var dropPos = exit != null ? self.Location + exit.ExitCell : self.Location;
|
var dropPos = exit != null ? self.Location + exit.Info.ExitCell : self.Location;
|
||||||
var startPos = dropPos + new CVec(owner.World.Map.Bounds.Width, 0);
|
var startPos = dropPos + new CVec(owner.World.Map.Bounds.Width, 0);
|
||||||
var endPos = new CPos(owner.World.Map.Bounds.Left - 5, dropPos.Y);
|
var endPos = new CPos(owner.World.Map.Bounds.Left - 5, dropPos.Y);
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
foreach (var cargo in self.TraitsImplementing<INotifyDelivery>())
|
foreach (var cargo in self.TraitsImplementing<INotifyDelivery>())
|
||||||
cargo.Delivered(self);
|
cargo.Delivered(self);
|
||||||
|
|
||||||
self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit, productionType, inits));
|
self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit.Info, productionType, inits));
|
||||||
Game.Sound.Play(SoundType.World, info.ChuteSound, self.CenterPosition);
|
Game.Sound.Play(SoundType.World, info.ChuteSound, self.CenterPosition);
|
||||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
|
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user