protected override void Created(Actor self)
 {
     transforms = self.TraitsImplementing <Transforms>().ToArray();
     locomotor  = self.World.WorldActor.TraitsImplementing <Locomotor>()
                  .Single(l => l.Info.Name == Info.Locomotor);
     base.Created(self);
 }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
            public HarvesterTraitWrapper(Actor actor)
            {
                Actor        = actor;
                Harvester    = actor.Trait <Harvester>();
                Parachutable = actor.TraitOrDefault <Parachutable>();
                var mobile = actor.Trait <Mobile>();

                Locomotor = mobile.Locomotor;
            }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Note: If the target <paramref name="cell"/> has any free subcell, the value of <paramref name="subCell"/> is ignored.
        /// </summary>
        public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
        {
            // PERF: Avoid repeated trait queries on the hot path
            if (locomotor == null)
            {
                locomotor = world.WorldActor.TraitsImplementing <Locomotor>()
                            .SingleOrDefault(l => l.Info.Name == Locomotor);
            }

            if (locomotor.MovementCostForCell(cell) == PathGraph.MovementCostForUnreachableCell)
            {
                return(false);
            }

            return(locomotor.CanMoveFreelyInto(self, cell, subCell, check, ignoreActor));
        }
Ejemplo n.º 6
0
        public bool IsPassable(CPos p1, CPos p2, Locomotor locomotor)
        {
            // HACK: Work around units in other movement layers from being blocked
            // when the point in the main layer is not pathable
            if (p1.Layer != 0 || p2.Layer != 0)
            {
                return(true);
            }

            if (locomotor.Info.DisableDomainPassabilityCheck)
            {
                return(true);
            }

            return(domainIndexes[locomotor.MovementClass].IsPassable(p1, p2));
        }
Ejemplo n.º 7
0
        public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
        {
            // PERF: Avoid repeated trait queries on the hot path
            if (locomotor == null)
            {
                locomotor = world.WorldActor.TraitsImplementing <Locomotor>()
                            .SingleOrDefault(l => l.Info.Name == Locomotor);
            }

            if (locomotor.MovementCostForCell(cell) == short.MaxValue)
            {
                return(false);
            }

            var check = checkTransientActors ? CellConditions.All : CellConditions.BlockedByMovers;

            return(locomotor.CanMoveFreelyInto(self, cell, ignoreActor, check));
        }
Ejemplo n.º 8
0
 public bool CanExistInCell(CPos cell)
 {
     return(Locomotor.MovementCostForCell(cell) != short.MaxValue);
 }
Ejemplo n.º 9
0
        public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
        {
            var cellConditions = checkTransientActors ? CellConditions.All : CellConditions.None;

            return(Locomotor.GetAvailableSubCell(self, a, preferredSubCell, ignoreActor, cellConditions));
        }
Ejemplo n.º 10
0
 public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
 {
     return(Locomotor.GetAvailableSubCell(self, a, check, preferredSubCell, ignoreActor));
 }