Remove workarounds for querying the PlayerActor in Created

This commit is contained in:
abcdefg30
2020-05-24 19:51:58 +02:00
committed by reaperrr
parent 52a9fcef3c
commit 27d0465891
12 changed files with 20 additions and 78 deletions

View File

@@ -52,12 +52,7 @@ namespace OpenRA.Mods.Cnc.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query other player traits from self, knowing that
// it refers to the same actor as self.Owner.PlayerActor
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
playerResources = playerActor.Trait<PlayerResources>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
base.Created(self);
}

View File

@@ -56,13 +56,7 @@ namespace OpenRA.Mods.Cnc.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query other player traits from self, knowing that
// it refers to the same actor as self.Owner.PlayerActor
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
techTree = playerActor.Trait<TechTree>();
techTree = self.Owner.PlayerActor.Trait<TechTree>();
base.Created(self);
}

View File

@@ -160,13 +160,9 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query player traits from self, which refers
// for bot modules always to the Player actor.
playerPower = self.TraitOrDefault<PowerManager>();
playerResources = self.Trait<PlayerResources>();
positionsUpdatedModules = self.TraitsImplementing<IBotPositionsUpdated>().ToArray();
playerPower = self.Owner.PlayerActor.TraitOrDefault<PowerManager>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
positionsUpdatedModules = self.Owner.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
}
protected override void TraitEnabled(Actor self)

View File

@@ -78,11 +78,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query player traits from self, which refers
// for bot modules always to the Player actor.
requestUnitProduction = self.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
requestUnitProduction = self.Owner.PlayerActor.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
}
protected override void TraitEnabled(Actor self)

View File

@@ -82,12 +82,8 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query player traits from self, which refers
// for bot modules always to the Player actor.
notifyPositionsUpdated = self.TraitsImplementing<IBotPositionsUpdated>().ToArray();
requestUnitProduction = self.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
notifyPositionsUpdated = self.Owner.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
requestUnitProduction = self.Owner.PlayerActor.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
}
protected override void TraitEnabled(Actor self)

View File

@@ -150,12 +150,8 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query player traits from self, which refers
// for bot modules always to the Player actor.
notifyPositionsUpdated = self.TraitsImplementing<IBotPositionsUpdated>().ToArray();
notifyIdleBaseUnits = self.TraitsImplementing<IBotNotifyIdleBaseUnits>().ToArray();
notifyPositionsUpdated = self.Owner.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
notifyIdleBaseUnits = self.Owner.PlayerActor.TraitsImplementing<IBotNotifyIdleBaseUnits>().ToArray();
}
protected override void TraitEnabled(Actor self)

View File

@@ -54,11 +54,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query player traits from self, which refers
// for bot modules always to the Player actor.
supportPowerManager = self.Trait<SupportPowerManager>();
supportPowerManager = self.Owner.PlayerActor.Trait<SupportPowerManager>();
}
protected override void TraitEnabled(Actor self)

View File

@@ -62,11 +62,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query player traits from self, which refers
// for bot modules always to the Player actor.
requestPause = self.TraitsImplementing<IBotRequestPauseUnitProduction>().ToArray();
requestPause = self.Owner.PlayerActor.TraitsImplementing<IBotRequestPauseUnitProduction>().ToArray();
}
void IBotNotifyIdleBaseUnits.UpdatedIdleBaseUnits(List<Actor> idleUnits)

View File

@@ -42,12 +42,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query other player traits from self, knowing that
// it refers to the same actor as self.Owner.PlayerActor
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
playerResources = playerActor.Trait<PlayerResources>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)

View File

@@ -44,13 +44,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query other player traits from self, knowing that
// it refers to the same actor as self.Owner.PlayerActor
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
globalManager = playerActor.Trait<GrantConditionOnPrerequisiteManager>();
globalManager = self.Owner.PlayerActor.Trait<GrantConditionOnPrerequisiteManager>();
}
void INotifyAddedToWorld.AddedToWorld(Actor self)

View File

@@ -141,19 +141,13 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query other player traits from self, knowing that
// it refers to the same actor as self.Owner.PlayerActor
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
playerPower = playerActor.TraitOrDefault<PowerManager>();
playerResources = playerActor.Trait<PlayerResources>();
developerMode = playerActor.Trait<DeveloperMode>();
techTree = playerActor.Trait<TechTree>();
playerPower = self.Owner.PlayerActor.TraitOrDefault<PowerManager>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
developerMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
techTree = self.Owner.PlayerActor.Trait<TechTree>();
productionTraits = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray();
CacheProducibles(playerActor);
CacheProducibles(self.Owner.PlayerActor);
}
protected void ClearQueue()

View File

@@ -69,13 +69,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
// Special case handling is required for the Player actor.
// Created is called before Player.PlayerActor is assigned,
// so we must query other player traits from self, knowing that
// it refers to the same actor as self.Owner.PlayerActor
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
techTree = playerActor.Trait<TechTree>();
techTree = self.Owner.PlayerActor.Trait<TechTree>();
Update();