diff --git a/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs b/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs index e4d84c6d61..dd6e16b823 100644 --- a/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs +++ b/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs @@ -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 = self.Owner.PlayerActor.Trait(); base.Created(self); } diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs index 4edea38a83..de519a0bfc 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs @@ -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 = self.Owner.PlayerActor.Trait(); base.Created(self); } diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index 5934cf61a0..320f998315 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -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(); - playerResources = self.Trait(); - positionsUpdatedModules = self.TraitsImplementing().ToArray(); + playerPower = self.Owner.PlayerActor.TraitOrDefault(); + playerResources = self.Owner.PlayerActor.Trait(); + positionsUpdatedModules = self.Owner.PlayerActor.TraitsImplementing().ToArray(); } protected override void TraitEnabled(Actor self) diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index e25e5e1792..b1e9fe23f9 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -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().ToArray(); + requestUnitProduction = self.Owner.PlayerActor.TraitsImplementing().ToArray(); } protected override void TraitEnabled(Actor self) diff --git a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs index abf7dd832c..fc6a3620df 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs @@ -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().ToArray(); - requestUnitProduction = self.TraitsImplementing().ToArray(); + notifyPositionsUpdated = self.Owner.PlayerActor.TraitsImplementing().ToArray(); + requestUnitProduction = self.Owner.PlayerActor.TraitsImplementing().ToArray(); } protected override void TraitEnabled(Actor self) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index a78dd106c5..e984fee5b3 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -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().ToArray(); - notifyIdleBaseUnits = self.TraitsImplementing().ToArray(); + notifyPositionsUpdated = self.Owner.PlayerActor.TraitsImplementing().ToArray(); + notifyIdleBaseUnits = self.Owner.PlayerActor.TraitsImplementing().ToArray(); } protected override void TraitEnabled(Actor self) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs index 8ba5773a67..5f9812fe3f 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs @@ -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 = self.Owner.PlayerActor.Trait(); } protected override void TraitEnabled(Actor self) diff --git a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs index 5ae3bddb8d..010e30affd 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs @@ -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().ToArray(); + requestPause = self.Owner.PlayerActor.TraitsImplementing().ToArray(); } void IBotNotifyIdleBaseUnits.UpdatedIdleBaseUnits(List idleUnits) diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPlayerResources.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPlayerResources.cs index a1c5bf10f2..571e5fbb0c 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPlayerResources.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPlayerResources.cs @@ -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 = self.Owner.PlayerActor.Trait(); } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs index e8a32b27e1..1356bf52ca 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs @@ -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(); + globalManager = self.Owner.PlayerActor.Trait(); } void INotifyAddedToWorld.AddedToWorld(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs index 5d12c9ab40..5ace8b60d9 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs @@ -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(); - playerResources = playerActor.Trait(); - developerMode = playerActor.Trait(); - techTree = playerActor.Trait(); + playerPower = self.Owner.PlayerActor.TraitOrDefault(); + playerResources = self.Owner.PlayerActor.Trait(); + developerMode = self.Owner.PlayerActor.Trait(); + techTree = self.Owner.PlayerActor.Trait(); productionTraits = self.TraitsImplementing().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray(); - CacheProducibles(playerActor); + CacheProducibles(self.Owner.PlayerActor); } protected void ClearQueue() diff --git a/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs b/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs index e30fdb9130..75fb476790 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs @@ -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 = self.Owner.PlayerActor.Trait(); Update();