Remove legacy Building plumbing.

This commit is contained in:
Paul Chote
2018-10-27 17:26:57 +00:00
committed by abcdefg30
parent e77aaa1a47
commit 47a470e945
6 changed files with 5 additions and 53 deletions

View File

@@ -243,12 +243,10 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public class Building : IOccupySpace, ITargetableCells, INotifySold, INotifyTransform, ISync, INotifyCreated, public class Building : IOccupySpace, ITargetableCells, INotifySold, INotifyTransform, ISync,
INotifyAddedToWorld, INotifyRemovedFromWorld INotifyAddedToWorld, INotifyRemovedFromWorld
{ {
public readonly bool SkipMakeAnimation;
public readonly BuildingInfo Info; public readonly BuildingInfo Info;
public bool BuildComplete { get; private set; }
[Sync] readonly CPos topLeft; [Sync] readonly CPos topLeft;
readonly Actor self; readonly Actor self;
@@ -257,20 +255,6 @@ namespace OpenRA.Mods.Common.Traits
Pair<CPos, SubCell>[] occupiedCells; Pair<CPos, SubCell>[] occupiedCells;
Pair<CPos, SubCell>[] targetableCells; Pair<CPos, SubCell>[] targetableCells;
// Shared activity lock: undeploy, sell, capture, etc.
[Sync] public bool Locked = true;
public bool Lock()
{
if (Locked)
return false;
Locked = true;
return true;
}
public void Unlock() { Locked = false; }
public CPos TopLeft { get { return topLeft; } } public CPos TopLeft { get { return topLeft; } }
public WPos CenterPosition { get; private set; } public WPos CenterPosition { get; private set; }
@@ -288,19 +272,12 @@ namespace OpenRA.Mods.Common.Traits
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); .Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
CenterPosition = init.World.Map.CenterOfCell(topLeft) + Info.CenterOffset(init.World); CenterPosition = init.World.Map.CenterOfCell(topLeft) + Info.CenterOffset(init.World);
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
} }
public Pair<CPos, SubCell>[] OccupiedCells() { return occupiedCells; } public Pair<CPos, SubCell>[] OccupiedCells() { return occupiedCells; }
Pair<CPos, SubCell>[] ITargetableCells.TargetableCells() { return targetableCells; } Pair<CPos, SubCell>[] ITargetableCells.TargetableCells() { return targetableCells; }
void INotifyCreated.Created(Actor self)
{
if (SkipMakeAnimation || !self.Info.HasTraitInfo<WithMakeAnimationInfo>())
NotifyBuildingComplete(self);
}
void INotifyAddedToWorld.AddedToWorld(Actor self) void INotifyAddedToWorld.AddedToWorld(Actor self)
{ {
AddedToWorld(self); AddedToWorld(self);
@@ -321,24 +298,10 @@ namespace OpenRA.Mods.Common.Traits
influence.RemoveInfluence(self, Info.Tiles(self.Location)); influence.RemoveInfluence(self, Info.Tiles(self.Location));
} }
public void NotifyBuildingComplete(Actor self)
{
if (BuildComplete)
return;
BuildComplete = true;
Unlock();
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
notify.BuildingComplete(self);
}
void INotifySold.Selling(Actor self) void INotifySold.Selling(Actor self)
{ {
if (Info.RemoveSmudgesOnSell) if (Info.RemoveSmudgesOnSell)
RemoveSmudges(); RemoveSmudges();
BuildComplete = false;
} }
void INotifySold.Sold(Actor self) { } void INotifySold.Sold(Actor self) { }

View File

@@ -106,9 +106,6 @@ namespace OpenRA.Mods.Common.Traits
var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>(); var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
foreach (var notify in notifyOthers) foreach (var notify in notifyOthers)
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType); notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType);
foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
t.BuildingComplete(newUnit);
}); });
} }

View File

@@ -102,9 +102,6 @@ namespace OpenRA.Mods.Common.Traits
var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>(); var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
foreach (var notify in notifyOthers) foreach (var notify in notifyOthers)
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType); notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType);
foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
t.BuildingComplete(newUnit);
}); });
return true; return true;

View File

@@ -158,9 +158,6 @@ namespace OpenRA.Mods.Common.Traits
var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>(); var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
foreach (var notify in notifyOthers) foreach (var notify in notifyOthers)
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType); notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType);
foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
t.BuildingComplete(newUnit);
}); });
} }
} }

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{ {
readonly WithMakeAnimationInfo info; readonly WithMakeAnimationInfo info;
readonly WithSpriteBody[] wsbs; readonly WithSpriteBody[] wsbs;
readonly bool skipMakeAnimation;
ConditionManager conditionManager; ConditionManager conditionManager;
int token = ConditionManager.InvalidConditionToken; int token = ConditionManager.InvalidConditionToken;
@@ -45,14 +46,14 @@ namespace OpenRA.Mods.Common.Traits.Render
this.info = info; this.info = info;
var self = init.Self; var self = init.Self;
wsbs = self.TraitsImplementing<WithSpriteBody>().Where(w => info.BodyNames.Contains(w.Info.Name)).ToArray(); wsbs = self.TraitsImplementing<WithSpriteBody>().Where(w => info.BodyNames.Contains(w.Info.Name)).ToArray();
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
} }
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
conditionManager = self.TraitOrDefault<ConditionManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
var building = self.TraitOrDefault<Building>(); if (!skipMakeAnimation)
if (building != null && !building.SkipMakeAnimation) Forward(self, () => { });
Forward(self, () => building.NotifyBuildingComplete(self));
} }
public void Forward(Actor self, Action onComplete) public void Forward(Actor self, Action onComplete)

View File

@@ -105,9 +105,6 @@ namespace OpenRA.Mods.Common.Traits
void PreparingAttack(Actor self, Target target, Armament a, Barrel barrel); void PreparingAttack(Actor self, Target target, Armament a, Barrel barrel);
} }
[RequireExplicitImplementation]
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
[RequireExplicitImplementation] [RequireExplicitImplementation]
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); } public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }