Skip to content

Commit 27d0465

Browse files
abcdefg30reaperrr
authored andcommitted
Remove workarounds for querying the PlayerActor in Created
1 parent 52a9fce commit 27d0465

12 files changed

+20
-78
lines changed

OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ public ResourcePurifier(Actor self, ResourcePurifierInfo info)
5252

5353
protected override void Created(Actor self)
5454
{
55-
// Special case handling is required for the Player actor.
56-
// Created is called before Player.PlayerActor is assigned,
57-
// so we must query other player traits from self, knowing that
58-
// it refers to the same actor as self.Owner.PlayerActor
59-
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
60-
playerResources = playerActor.Trait<PlayerResources>();
55+
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
6156

6257
base.Created(self);
6358
}

OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ public GrantPrerequisiteChargeDrainPower(Actor self, GrantPrerequisiteChargeDrai
5656

5757
protected override void Created(Actor self)
5858
{
59-
// Special case handling is required for the Player actor.
60-
// Created is called before Player.PlayerActor is assigned,
61-
// so we must query other player traits from self, knowing that
62-
// it refers to the same actor as self.Owner.PlayerActor
63-
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
64-
65-
techTree = playerActor.Trait<TechTree>();
59+
techTree = self.Owner.PlayerActor.Trait<TechTree>();
6660

6761
base.Created(self);
6862
}

OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,9 @@ public BaseBuilderBotModule(Actor self, BaseBuilderBotModuleInfo info)
160160

161161
protected override void Created(Actor self)
162162
{
163-
// Special case handling is required for the Player actor.
164-
// Created is called before Player.PlayerActor is assigned,
165-
// so we must query player traits from self, which refers
166-
// for bot modules always to the Player actor.
167-
playerPower = self.TraitOrDefault<PowerManager>();
168-
playerResources = self.Trait<PlayerResources>();
169-
positionsUpdatedModules = self.TraitsImplementing<IBotPositionsUpdated>().ToArray();
163+
playerPower = self.Owner.PlayerActor.TraitOrDefault<PowerManager>();
164+
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
165+
positionsUpdatedModules = self.Owner.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
170166
}
171167

172168
protected override void TraitEnabled(Actor self)

OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ public HarvesterBotModule(Actor self, HarvesterBotModuleInfo info)
7878

7979
protected override void Created(Actor self)
8080
{
81-
// Special case handling is required for the Player actor.
82-
// Created is called before Player.PlayerActor is assigned,
83-
// so we must query player traits from self, which refers
84-
// for bot modules always to the Player actor.
85-
requestUnitProduction = self.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
81+
requestUnitProduction = self.Owner.PlayerActor.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
8682
}
8783

8884
protected override void TraitEnabled(Actor self)

OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ public McvManagerBotModule(Actor self, McvManagerBotModuleInfo info)
8282

8383
protected override void Created(Actor self)
8484
{
85-
// Special case handling is required for the Player actor.
86-
// Created is called before Player.PlayerActor is assigned,
87-
// so we must query player traits from self, which refers
88-
// for bot modules always to the Player actor.
89-
notifyPositionsUpdated = self.TraitsImplementing<IBotPositionsUpdated>().ToArray();
90-
requestUnitProduction = self.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
85+
notifyPositionsUpdated = self.Owner.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
86+
requestUnitProduction = self.Owner.PlayerActor.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
9187
}
9288

9389
protected override void TraitEnabled(Actor self)

OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,8 @@ public bool IsNotHiddenUnit(Actor a)
150150

151151
protected override void Created(Actor self)
152152
{
153-
// Special case handling is required for the Player actor.
154-
// Created is called before Player.PlayerActor is assigned,
155-
// so we must query player traits from self, which refers
156-
// for bot modules always to the Player actor.
157-
notifyPositionsUpdated = self.TraitsImplementing<IBotPositionsUpdated>().ToArray();
158-
notifyIdleBaseUnits = self.TraitsImplementing<IBotNotifyIdleBaseUnits>().ToArray();
153+
notifyPositionsUpdated = self.Owner.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
154+
notifyIdleBaseUnits = self.Owner.PlayerActor.TraitsImplementing<IBotNotifyIdleBaseUnits>().ToArray();
159155
}
160156

161157
protected override void TraitEnabled(Actor self)

OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ public SupportPowerBotModule(Actor self, SupportPowerBotModuleInfo info)
5454

5555
protected override void Created(Actor self)
5656
{
57-
// Special case handling is required for the Player actor.
58-
// Created is called before Player.PlayerActor is assigned,
59-
// so we must query player traits from self, which refers
60-
// for bot modules always to the Player actor.
61-
supportPowerManager = self.Trait<SupportPowerManager>();
57+
supportPowerManager = self.Owner.PlayerActor.Trait<SupportPowerManager>();
6258
}
6359

6460
protected override void TraitEnabled(Actor self)

OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ public UnitBuilderBotModule(Actor self, UnitBuilderBotModuleInfo info)
6262

6363
protected override void Created(Actor self)
6464
{
65-
// Special case handling is required for the Player actor.
66-
// Created is called before Player.PlayerActor is assigned,
67-
// so we must query player traits from self, which refers
68-
// for bot modules always to the Player actor.
69-
requestPause = self.TraitsImplementing<IBotRequestPauseUnitProduction>().ToArray();
65+
requestPause = self.Owner.PlayerActor.TraitsImplementing<IBotRequestPauseUnitProduction>().ToArray();
7066
}
7167

7268
void IBotNotifyIdleBaseUnits.UpdatedIdleBaseUnits(List<Actor> idleUnits)

OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPlayerResources.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ public GrantConditionOnPlayerResources(GrantConditionOnPlayerResourcesInfo info)
4242

4343
void INotifyCreated.Created(Actor self)
4444
{
45-
// Special case handling is required for the Player actor.
46-
// Created is called before Player.PlayerActor is assigned,
47-
// so we must query other player traits from self, knowing that
48-
// it refers to the same actor as self.Owner.PlayerActor
49-
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
50-
playerResources = playerActor.Trait<PlayerResources>();
45+
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
5146
}
5247

5348
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)

OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,7 @@ public GrantConditionOnPrerequisite(Actor self, GrantConditionOnPrerequisiteInfo
4444

4545
void INotifyCreated.Created(Actor self)
4646
{
47-
// Special case handling is required for the Player actor.
48-
// Created is called before Player.PlayerActor is assigned,
49-
// so we must query other player traits from self, knowing that
50-
// it refers to the same actor as self.Owner.PlayerActor
51-
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
52-
53-
globalManager = playerActor.Trait<GrantConditionOnPrerequisiteManager>();
47+
globalManager = self.Owner.PlayerActor.Trait<GrantConditionOnPrerequisiteManager>();
5448
}
5549

5650
void INotifyAddedToWorld.AddedToWorld(Actor self)

OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,13 @@ public ProductionQueue(ActorInitializer init, Actor playerActor, ProductionQueue
141141

142142
void INotifyCreated.Created(Actor self)
143143
{
144-
// Special case handling is required for the Player actor.
145-
// Created is called before Player.PlayerActor is assigned,
146-
// so we must query other player traits from self, knowing that
147-
// it refers to the same actor as self.Owner.PlayerActor
148-
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
149-
150-
playerPower = playerActor.TraitOrDefault<PowerManager>();
151-
playerResources = playerActor.Trait<PlayerResources>();
152-
developerMode = playerActor.Trait<DeveloperMode>();
153-
techTree = playerActor.Trait<TechTree>();
144+
playerPower = self.Owner.PlayerActor.TraitOrDefault<PowerManager>();
145+
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
146+
developerMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
147+
techTree = self.Owner.PlayerActor.Trait<TechTree>();
154148

155149
productionTraits = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray();
156-
CacheProducibles(playerActor);
150+
CacheProducibles(self.Owner.PlayerActor);
157151
}
158152

159153
protected void ClearQueue()

OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ public IEnumerable<string> ProvidesPrerequisites
6969

7070
protected override void Created(Actor self)
7171
{
72-
// Special case handling is required for the Player actor.
73-
// Created is called before Player.PlayerActor is assigned,
74-
// so we must query other player traits from self, knowing that
75-
// it refers to the same actor as self.Owner.PlayerActor
76-
var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;
77-
78-
techTree = playerActor.Trait<TechTree>();
72+
techTree = self.Owner.PlayerActor.Trait<TechTree>();
7973

8074
Update();
8175

0 commit comments

Comments
 (0)