Remove cargo initialization from Tick
This commit is contained in:
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
||||||
INotifyOwnerChanged, ITick, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
|
INotifyOwnerChanged, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
|
||||||
ITransformActorInitModifier
|
ITransformActorInitModifier
|
||||||
{
|
{
|
||||||
public readonly CargoInfo Info;
|
public readonly CargoInfo Info;
|
||||||
@@ -161,6 +161,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
totalWeight = cargo.Sum(c => GetWeight(c));
|
totalWeight = cargo.Sum(c => GetWeight(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var c in cargo)
|
||||||
|
{
|
||||||
|
c.Trait<Passenger>().Transport = self;
|
||||||
|
|
||||||
|
foreach (var nec in c.TraitsImplementing<INotifyEnteredCargo>())
|
||||||
|
nec.OnEnteredCargo(c, self);
|
||||||
|
|
||||||
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
|
npe.OnPassengerEntered(self, c);
|
||||||
|
}
|
||||||
|
|
||||||
facing = Exts.Lazy(self.TraitOrDefault<IFacing>);
|
facing = Exts.Lazy(self.TraitOrDefault<IFacing>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,15 +419,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
loadingToken = conditionManager.RevokeCondition(self, loadingToken);
|
loadingToken = conditionManager.RevokeCondition(self, loadingToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not initialized then this will be notified in the first tick
|
foreach (var nec in a.TraitsImplementing<INotifyEnteredCargo>())
|
||||||
if (initialized)
|
nec.OnEnteredCargo(a, self);
|
||||||
{
|
|
||||||
foreach (var nec in a.TraitsImplementing<INotifyEnteredCargo>())
|
|
||||||
nec.OnEnteredCargo(a, self);
|
|
||||||
|
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
npe.OnPassengerEntered(self, a);
|
npe.OnPassengerEntered(self, a);
|
||||||
}
|
|
||||||
|
|
||||||
var p = a.Trait<Passenger>();
|
var p = a.Trait<Passenger>();
|
||||||
p.Transport = self;
|
p.Transport = self;
|
||||||
@@ -495,27 +502,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
p.ChangeOwner(newOwner);
|
p.ChangeOwner(newOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialized;
|
|
||||||
void ITick.Tick(Actor self)
|
|
||||||
{
|
|
||||||
// Notify initial cargo load
|
|
||||||
if (!initialized)
|
|
||||||
{
|
|
||||||
foreach (var c in cargo)
|
|
||||||
{
|
|
||||||
c.Trait<Passenger>().Transport = self;
|
|
||||||
|
|
||||||
foreach (var nec in c.TraitsImplementing<INotifyEnteredCargo>())
|
|
||||||
nec.OnEnteredCargo(c, self);
|
|
||||||
|
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
|
||||||
npe.OnPassengerEntered(self, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init)
|
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init)
|
||||||
{
|
{
|
||||||
init.Add(new RuntimeCargoInit(Passengers.ToArray()));
|
init.Add(new RuntimeCargoInit(Passengers.ToArray()));
|
||||||
|
|||||||
Reference in New Issue
Block a user