void INotifyBecomingIdle.OnBecomingIdle(Actor self) { if (self.Location.Layer == 0) { // Make sure that units aren't left idling in a transit-only cell // HACK: activities should be making sure that this can't happen in the first place! if (!Locomotor.CanStayInCell(self.Location)) { self.QueueActivity(MoveTo(self.Location, evaluateNearestMovableCell: true)); } return; } var cml = self.World.WorldActor.TraitsImplementing <ICustomMovementLayer>() .First(l => l.Index == self.Location.Layer); if (!cml.ReturnToGroundLayerOnIdle) { return; } var moveTo = ClosestGroundCell(); if (moveTo != null) { self.QueueActivity(MoveTo(moveTo.Value, 0)); } }
public bool CanStayInCell(World world, CPos cell) { // PERF: Avoid repeated trait queries on the hot path if (locomotor == null) { locomotor = world.WorldActor.TraitsImplementing <Locomotor>() .SingleOrDefault(l => l.Info.Name == Locomotor); } if (cell.Layer == CustomMovementLayerType.Tunnel) { return(false); } return(locomotor.CanStayInCell(cell)); }