Replace Upgrades with Conditions in Carryable.
This commit is contained in:
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (cargo != carryall.Carryable)
|
if (cargo != carryall.Carryable)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
if (cargo.IsDead || IsCanceled)
|
if (cargo.IsDead || IsCanceled || carryable.IsTraitDisabled)
|
||||||
{
|
{
|
||||||
carryall.UnreserveCarryable(self);
|
carryall.UnreserveCarryable(self);
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|||||||
@@ -15,38 +15,41 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Can be carried by actors with the `Carryall` trait.")]
|
[Desc("Can be carried by actors with the `Carryall` trait.")]
|
||||||
public class CarryableInfo : ITraitInfo
|
public class CarryableInfo : UpgradableTraitInfo
|
||||||
{
|
{
|
||||||
[UpgradeGrantedReference]
|
[UpgradeGrantedReference]
|
||||||
[Desc("The upgrades to grant to self while waiting or being carried.")]
|
[Desc("The condition to grant to self while a carryall has been reserved.")]
|
||||||
public readonly string[] CarryableUpgrades = { };
|
public readonly string ReservedCondition = "carryall-reserved";
|
||||||
|
|
||||||
|
[UpgradeGrantedReference]
|
||||||
|
[Desc("The condition to grant to self while being carried.")]
|
||||||
|
public readonly string CarriedCondition = "carried";
|
||||||
|
|
||||||
[Desc("Carryall attachment point relative to body.")]
|
[Desc("Carryall attachment point relative to body.")]
|
||||||
public readonly WVec LocalOffset = WVec.Zero;
|
public readonly WVec LocalOffset = WVec.Zero;
|
||||||
|
|
||||||
public virtual object Create(ActorInitializer init) { return new Carryable(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new Carryable(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Carryable : INotifyCreated
|
public class Carryable : UpgradableTrait<CarryableInfo>
|
||||||
{
|
{
|
||||||
readonly CarryableInfo info;
|
|
||||||
UpgradeManager upgradeManager;
|
UpgradeManager upgradeManager;
|
||||||
|
int reservedToken = UpgradeManager.InvalidConditionToken;
|
||||||
|
int carriedToken = UpgradeManager.InvalidConditionToken;
|
||||||
|
|
||||||
public Actor Carrier { get; private set; }
|
public Actor Carrier { get; private set; }
|
||||||
public bool Reserved { get { return state != State.Free; } }
|
public bool Reserved { get { return state != State.Free; } }
|
||||||
public CPos? Destination { get; protected set; }
|
public CPos? Destination { get; protected set; }
|
||||||
public bool WantsTransport { get { return Destination != null; } }
|
public bool WantsTransport { get { return Destination != null && !IsTraitDisabled; } }
|
||||||
|
|
||||||
protected enum State { Free, Reserved, Locked }
|
protected enum State { Free, Reserved, Locked }
|
||||||
protected State state = State.Free;
|
protected State state = State.Free;
|
||||||
protected bool attached;
|
protected bool attached;
|
||||||
|
|
||||||
public Carryable(Actor self, CarryableInfo info)
|
public Carryable(Actor self, CarryableInfo info)
|
||||||
{
|
: base(info) { }
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
{
|
{
|
||||||
upgradeManager = self.Trait<UpgradeManager>();
|
upgradeManager = self.Trait<UpgradeManager>();
|
||||||
}
|
}
|
||||||
@@ -57,8 +60,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
attached = true;
|
attached = true;
|
||||||
foreach (var u in info.CarryableUpgrades)
|
|
||||||
upgradeManager.GrantUpgrade(self, u, this);
|
if (carriedToken == UpgradeManager.InvalidConditionToken)
|
||||||
|
carriedToken = upgradeManager.GrantCondition(self, Info.CarriedCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This gets called by carrier after we touched down
|
// This gets called by carrier after we touched down
|
||||||
@@ -68,17 +72,22 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
attached = false;
|
attached = false;
|
||||||
foreach (var u in info.CarryableUpgrades)
|
|
||||||
upgradeManager.RevokeUpgrade(self, u, this);
|
if (carriedToken != UpgradeManager.InvalidConditionToken)
|
||||||
|
carriedToken = upgradeManager.RevokeCondition(self, carriedToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool Reserve(Actor self, Actor carrier)
|
public virtual bool Reserve(Actor self, Actor carrier)
|
||||||
{
|
{
|
||||||
if (Reserved)
|
if (Reserved || IsTraitDisabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
state = State.Reserved;
|
state = State.Reserved;
|
||||||
Carrier = carrier;
|
Carrier = carrier;
|
||||||
|
|
||||||
|
if (reservedToken == UpgradeManager.InvalidConditionToken)
|
||||||
|
reservedToken = upgradeManager.GrantCondition(self, Info.ReservedCondition);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +95,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
state = State.Free;
|
state = State.Free;
|
||||||
Carrier = null;
|
Carrier = null;
|
||||||
|
|
||||||
|
if (reservedToken != UpgradeManager.InvalidConditionToken)
|
||||||
|
reservedToken = upgradeManager.RevokeCondition(self, reservedToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare for transport pickup
|
// Prepare for transport pickup
|
||||||
|
|||||||
@@ -283,11 +283,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (!target.AppearsFriendlyTo(self))
|
if (!target.AppearsFriendlyTo(self))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var carryable = target.TraitOrDefault<Carryable>();
|
var carryable = target.TraitOrDefault<Carryable>();
|
||||||
if (carryable == null)
|
if (carryable == null || carryable.IsTraitDisabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (carryable.Reserved && carryable.Carrier != self)
|
if (carryable.Reserved && carryable.Carrier != self)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user