Remove producer-is-in-world assumptions from Production
D2k upgrades need to be actors that never actor the world, produced by the PlayerActor, who is also not in the world, but the Production trait expects the producer to be in the world even if it has Exit.MoveIntoWorld = False, allowing the producees to not enter the world.
This commit is contained in:
@@ -35,39 +35,50 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public ProductionInfo Info;
|
public ProductionInfo Info;
|
||||||
public string Faction { get; private set; }
|
public string Faction { get; private set; }
|
||||||
|
|
||||||
|
readonly bool occupiesSpace;
|
||||||
|
|
||||||
public Production(ActorInitializer init, ProductionInfo info)
|
public Production(ActorInitializer init, ProductionInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
|
occupiesSpace = init.Self.Info.Traits.WithInterface<IOccupySpaceInfo>().Any();
|
||||||
rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault<RallyPoint>());
|
rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault<RallyPoint>());
|
||||||
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
|
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
|
||||||
{
|
{
|
||||||
var exit = self.Location + exitinfo.ExitCell;
|
var exit = CPos.Zero;
|
||||||
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
|
var exitLocation = CPos.Zero;
|
||||||
var to = self.World.Map.CenterOfCell(exit);
|
var target = Target.Invalid;
|
||||||
|
|
||||||
var fi = producee.Traits.GetOrDefault<IFacingInfo>();
|
|
||||||
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi == null ? 0 : fi.GetInitialFacing()) : exitinfo.Facing;
|
|
||||||
|
|
||||||
var exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
|
||||||
var target = Target.FromCell(self.World, exitLocation);
|
|
||||||
|
|
||||||
var bi = producee.Traits.GetOrDefault<BuildableInfo>();
|
var bi = producee.Traits.GetOrDefault<BuildableInfo>();
|
||||||
if (bi != null && bi.ForceFaction != null)
|
if (bi != null && bi.ForceFaction != null)
|
||||||
factionVariant = bi.ForceFaction;
|
factionVariant = bi.ForceFaction;
|
||||||
|
|
||||||
|
var td = new TypeDictionary
|
||||||
|
{
|
||||||
|
new OwnerInit(self.Owner),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (occupiesSpace)
|
||||||
|
{
|
||||||
|
exit = self.Location + exitinfo.ExitCell;
|
||||||
|
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
|
||||||
|
var to = self.World.Map.CenterOfCell(exit);
|
||||||
|
|
||||||
|
var fi = producee.Traits.GetOrDefault<IFacingInfo>();
|
||||||
|
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi == null ? 0 : fi.GetInitialFacing()) : exitinfo.Facing;
|
||||||
|
|
||||||
|
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
||||||
|
target = Target.FromCell(self.World, exitLocation);
|
||||||
|
|
||||||
|
td.Add(new LocationInit(exit));
|
||||||
|
td.Add(new CenterPositionInit(spawn));
|
||||||
|
td.Add(new FacingInit(initialFacing));
|
||||||
|
}
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
var td = new TypeDictionary
|
|
||||||
{
|
|
||||||
new OwnerInit(self.Owner),
|
|
||||||
new LocationInit(exit),
|
|
||||||
new CenterPositionInit(spawn),
|
|
||||||
new FacingInit(initialFacing)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (factionVariant != null)
|
if (factionVariant != null)
|
||||||
td.Add(new FactionInit(factionVariant));
|
td.Add(new FactionInit(factionVariant));
|
||||||
|
|
||||||
@@ -107,7 +118,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Reservable.IsReserved(self))
|
if (Reservable.IsReserved(self))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// pick a spawn/exit point pair
|
if (!occupiesSpace)
|
||||||
|
{
|
||||||
|
DoProduction(self, producee, null, factionVariant);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pick a spawn/exit point pair
|
||||||
var exit = self.Info.Traits.WithInterface<ExitInfo>().Shuffle(self.World.SharedRandom)
|
var exit = self.Info.Traits.WithInterface<ExitInfo>().Shuffle(self.World.SharedRandom)
|
||||||
.FirstOrDefault(e => CanUseExit(self, producee, e));
|
.FirstOrDefault(e => CanUseExit(self, producee, e));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user