Merge pull request #11951 from pchote/hack-production-locking

Rework external capture -> production interaction
This commit is contained in:
Matthias Mailänder
2016-09-04 20:18:59 +02:00
committed by GitHub
5 changed files with 45 additions and 17 deletions

View File

@@ -27,12 +27,14 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new BaseProvider(init.Self, this); }
}
public class BaseProvider : ITick, IRenderAboveShroudWhenSelected, ISelectionBar
public class BaseProvider : ITick, INotifyCreated, IRenderAboveShroudWhenSelected, ISelectionBar
{
public readonly BaseProviderInfo Info;
readonly DeveloperMode devMode;
readonly Actor self;
Building building;
int total;
int progress;
bool allyBuildEnabled;
@@ -46,6 +48,11 @@ namespace OpenRA.Mods.Common.Traits
allyBuildEnabled = self.World.WorldActor.Trait<MapBuildRadius>().AllyBuildRadiusEnabled;
}
void INotifyCreated.Created(Actor self)
{
building = self.TraitOrDefault<Building>();
}
void ITick.Tick(Actor self)
{
if (progress > 0)
@@ -59,6 +66,9 @@ namespace OpenRA.Mods.Common.Traits
public bool Ready()
{
if (building != null && building.Locked)
return false;
return devMode.FastBuild || progress == 0;
}

View File

@@ -55,9 +55,6 @@ namespace OpenRA.Mods.Common.Traits
{
if (x.Actor.Owner == self.Owner && x.Trait.Info.Produces.Contains(Info.Type))
{
var b = x.Actor.TraitOrDefault<Building>();
if (b != null && b.Locked)
continue;
isActive = true;
break;
}

View File

@@ -28,13 +28,15 @@ namespace OpenRA.Mods.Common.Traits
public virtual object Create(ActorInitializer init) { return new Production(init, this); }
}
public class Production
public class Production : INotifyCreated
{
readonly Lazy<RallyPoint> rp;
public readonly ProductionInfo Info;
public string Faction { get; private set; }
Building building;
public Production(ActorInitializer init, ProductionInfo info)
{
Info = info;
@@ -42,6 +44,11 @@ namespace OpenRA.Mods.Common.Traits
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
}
void INotifyCreated.Created(Actor self)
{
building = self.TraitOrDefault<Building>();
}
public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
{
var exit = CPos.Zero;
@@ -122,7 +129,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual bool Produce(Actor self, ActorInfo producee, string factionVariant)
{
if (Reservable.IsReserved(self))
if (Reservable.IsReserved(self) || (building != null && building.Locked))
return false;
// Pick a spawn/exit point pair

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public object Create(ActorInitializer init) { return new WithBuildingPlacedAnimation(init.Self, this); }
}
public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete
public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete, INotifySold, INotifyTransform
{
readonly WithBuildingPlacedAnimationInfo info;
readonly WithSpriteBody wsb;
@@ -35,12 +35,26 @@ namespace OpenRA.Mods.Common.Traits.Render
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>();
}
public void BuildingComplete(Actor self)
void INotifyBuildComplete.BuildingComplete(Actor self)
{
buildComplete = true;
}
public void BuildingPlaced(Actor self)
void INotifySold.Sold(Actor self) { }
void INotifySold.Selling(Actor self)
{
buildComplete = false;
}
void INotifyTransform.BeforeTransform(Actor self)
{
buildComplete = false;
}
void INotifyTransform.OnTransform(Actor self) { }
void INotifyTransform.AfterTransform(Actor self) { }
void INotifyBuildingPlaced.BuildingPlaced(Actor self)
{
if (buildComplete)
wsb.PlayCustomAnimation(self, info.Sequence, () => wsb.CancelCustomAnimation(self));

View File

@@ -55,32 +55,32 @@ namespace OpenRA.Mods.Common.Traits.Render
rs.Add(anim, info.Palette, info.IsPlayerPalette);
}
public void BuildingComplete(Actor self)
void INotifyBuildComplete.BuildingComplete(Actor self)
{
buildComplete = true;
visible = false;
}
public void Sold(Actor self) { }
public void Selling(Actor self)
void INotifySold.Sold(Actor self) { }
void INotifySold.Selling(Actor self)
{
buildComplete = false;
}
public void BeforeTransform(Actor self)
void INotifyTransform.BeforeTransform(Actor self)
{
buildComplete = false;
}
public void OnTransform(Actor self) { }
public void AfterTransform(Actor self) { }
void INotifyTransform.OnTransform(Actor self) { }
void INotifyTransform.AfterTransform(Actor self) { }
public void DamageStateChanged(Actor self, AttackInfo e)
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
}
public void BuildingPlaced(Actor self)
void INotifyBuildingPlaced.BuildingPlaced(Actor self)
{
visible = true;
overlay.PlayThen(overlay.CurrentSequence.Name, () => visible = false);