Fix botmodules querying the Player actor before it is assigned.

This commit is contained in:
matjaeck
2019-11-02 10:39:00 +01:00
committed by reaperrr
parent a74235bdbc
commit 5ac9d2c2f1
6 changed files with 55 additions and 14 deletions

View File

@@ -160,12 +160,19 @@ namespace OpenRA.Mods.Common.Traits
player = self.Owner;
}
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();
}
protected override void TraitEnabled(Actor self)
{
playerPower = player.PlayerActor.TraitOrDefault<PowerManager>();
playerResources = player.PlayerActor.Trait<PlayerResources>();
positionsUpdatedModules = player.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
var tileset = world.Map.Rules.TileSet;
resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough
foreach (var t in world.Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())