Make Cargo and Carryall conditional.
This commit is contained in:
committed by
Gustas
parent
a14cc8cc4d
commit
98896f9a75
@@ -21,7 +21,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("This actor can transport Passenger actors.")]
|
||||
public class CargoInfo : TraitInfo, Requires<IOccupySpaceInfo>
|
||||
public class CargoInfo : ConditionalTraitInfo, Requires<IOccupySpaceInfo>
|
||||
{
|
||||
[Desc("The maximum sum of Passenger.Weight that this actor can support.")]
|
||||
public readonly int MaxWeight = 0;
|
||||
@@ -88,11 +88,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new Cargo(init, this); }
|
||||
}
|
||||
|
||||
public class Cargo : IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
||||
public class Cargo : ConditionalTrait<CargoInfo>, IIssueOrder, IResolveOrder, IOrderVoice,
|
||||
INotifyOwnerChanged, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
|
||||
ITransformActorInitModifier
|
||||
INotifyCreated, INotifyKilled, ITransformActorInitModifier
|
||||
{
|
||||
public readonly CargoInfo Info;
|
||||
readonly Actor self;
|
||||
readonly List<Actor> cargo = new();
|
||||
readonly HashSet<Actor> reserves = new();
|
||||
@@ -119,9 +118,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
State state = State.Free;
|
||||
|
||||
public Cargo(ActorInitializer init, CargoInfo info)
|
||||
: base(info)
|
||||
{
|
||||
self = init.Self;
|
||||
Info = info;
|
||||
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
|
||||
|
||||
currentAdjacentCells = new CachedTransform<CPos, IEnumerable<CPos>>(loc =>
|
||||
@@ -162,8 +161,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
facing = Exts.Lazy(self.TraitOrDefault<IFacing>);
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
base.Created(self);
|
||||
aircraft = self.TraitOrDefault<Aircraft>();
|
||||
|
||||
if (cargo.Count > 0)
|
||||
@@ -200,6 +200,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
yield break;
|
||||
|
||||
yield return new DeployOrderTargeter("Unload", 10,
|
||||
() => CanUnload() ? Info.UnloadCursor : Info.UnloadBlockedCursor);
|
||||
}
|
||||
@@ -233,6 +236,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanUnload(BlockedByActor check = BlockedByActor.None)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return false;
|
||||
|
||||
if (checkTerrainType)
|
||||
{
|
||||
var terrainType = self.World.Map.GetTerrainInfo(self.Location).Type;
|
||||
@@ -247,7 +253,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanLoad(Actor a)
|
||||
{
|
||||
return reserves.Contains(a) || HasSpace(GetWeight(a));
|
||||
return !IsTraitDisabled && (reserves.Contains(a) || HasSpace(GetWeight(a)));
|
||||
}
|
||||
|
||||
internal bool ReserveSpace(Actor a)
|
||||
|
||||
Reference in New Issue
Block a user