Fix botmodules querying the Player actor before it is assigned.
This commit is contained in:
@@ -160,12 +160,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
player = self.Owner;
|
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)
|
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;
|
var tileset = world.Map.Rules.TileSet;
|
||||||
resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough
|
resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length); // Big enough
|
||||||
foreach (var t in world.Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())
|
foreach (var t in world.Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())
|
||||||
|
|||||||
@@ -76,9 +76,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
unitCannotBeOrdered = a => a.Owner != self.Owner || a.IsDead || !a.IsInWorld;
|
unitCannotBeOrdered = a => a.Owner != self.Owner || a.IsDead || !a.IsInWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
{
|
{
|
||||||
requestUnitProduction = player.PlayerActor.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
|
|
||||||
pathfinder = world.WorldActor.Trait<IPathFinder>();
|
pathfinder = world.WorldActor.Trait<IPathFinder>();
|
||||||
domainIndex = world.WorldActor.Trait<DomainIndex>();
|
domainIndex = world.WorldActor.Trait<DomainIndex>();
|
||||||
resLayer = world.WorldActor.TraitOrDefault<ResourceLayer>();
|
resLayer = world.WorldActor.TraitOrDefault<ResourceLayer>();
|
||||||
|
|||||||
@@ -80,11 +80,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
unitCannotBeOrdered = a => a.Owner != player || a.IsDead || !a.IsInWorld;
|
unitCannotBeOrdered = a => a.Owner != player || a.IsDead || !a.IsInWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
{
|
{
|
||||||
notifyPositionsUpdated = player.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
|
|
||||||
requestUnitProduction = player.PlayerActor.TraitsImplementing<IBotRequestUnitProduction>().ToArray();
|
|
||||||
|
|
||||||
// Avoid all AIs reevaluating assignments on the same tick, randomize their initial evaluation delay.
|
// Avoid all AIs reevaluating assignments on the same tick, randomize their initial evaluation delay.
|
||||||
scanInterval = world.LocalRandom.Next(Info.ScanForNewMcvInterval, Info.ScanForNewMcvInterval * 2);
|
scanInterval = world.LocalRandom.Next(Info.ScanForNewMcvInterval, Info.ScanForNewMcvInterval * 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,11 +126,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
&& !a.GetEnabledTargetTypes().IsEmpty;
|
&& !a.GetEnabledTargetTypes().IsEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
{
|
{
|
||||||
notifyPositionsUpdated = Player.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
|
|
||||||
notifyIdleBaseUnits = Player.PlayerActor.TraitsImplementing<IBotNotifyIdleBaseUnits>().ToArray();
|
|
||||||
|
|
||||||
// Avoid all AIs trying to rush in the same tick, randomize their initial rush a little.
|
// Avoid all AIs trying to rush in the same tick, randomize their initial rush a little.
|
||||||
var smallFractionOfRushInterval = Info.RushInterval / 20;
|
var smallFractionOfRushInterval = Info.RushInterval / 20;
|
||||||
rushTicks = World.LocalRandom.Next(Info.RushInterval - smallFractionOfRushInterval, Info.RushInterval + smallFractionOfRushInterval);
|
rushTicks = World.LocalRandom.Next(Info.RushInterval - smallFractionOfRushInterval, Info.RushInterval + smallFractionOfRushInterval);
|
||||||
|
|||||||
@@ -52,9 +52,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
player = self.Owner;
|
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.
|
||||||
|
supportPowerManager = self.Trait<SupportPowerManager>();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
{
|
{
|
||||||
supportPowerManager = player.PlayerActor.Trait<SupportPowerManager>();
|
|
||||||
foreach (var decision in Info.Decisions)
|
foreach (var decision in Info.Decisions)
|
||||||
powerDecisions.Add(decision.OrderName, decision);
|
powerDecisions.Add(decision.OrderName, decision);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,9 +60,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
player = self.Owner;
|
player = self.Owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void Created(Actor self)
|
||||||
{
|
{
|
||||||
requestPause = player.PlayerActor.TraitsImplementing<IBotRequestPauseUnitProduction>().ToArray();
|
// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IBotNotifyIdleBaseUnits.UpdatedIdleBaseUnits(List<Actor> idleUnits)
|
void IBotNotifyIdleBaseUnits.UpdatedIdleBaseUnits(List<Actor> idleUnits)
|
||||||
|
|||||||
Reference in New Issue
Block a user