Example #1
0
 public Cell(int x, int y, CellType type = CellType.Solid, CellFlag flags = CellFlag.None)
 {
     this.X     = x;
     this.Y     = y;
     this.Type  = type;
     this.Flags = flags;
 }
Example #2
0
 public void SetFlag(CellFlag flag, bool value = true)
 {
     if (value)
     {
         this.flags |= flag;
     }
     else
     {
         this.flags &= ~flag;
     }
 }
Example #3
0
 public static bool HasCellFlag(this CellFlag c, CellFlag cellFlag)
 {
     // PERF: Enum.HasFlag is slower and requires allocations.
     return((c & cellFlag) == cellFlag);
 }
Example #4
0
        bool IsBlockedBy(Actor actor, Actor otherActor, Actor ignoreActor, CPos cell, BlockedByActor check, CellFlag cellFlag)
        {
            if (otherActor == ignoreActor)
            {
                return(false);
            }

            // If the check allows: We are not blocked by units that we can force to move out of the way.
            if (check <= BlockedByActor.Immovable && cellFlag.HasCellFlag(CellFlag.HasMovableActor) &&
                actor.Owner.RelationshipWith(otherActor.Owner) == PlayerRelationship.Ally)
            {
                var mobile = otherActor.OccupiesSpace as Mobile;
                if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable)
                {
                    return(false);
                }
            }

            // If the check allows: we are not blocked by moving units.
            if (check <= BlockedByActor.Stationary && cellFlag.HasCellFlag(CellFlag.HasMovingActor) &&
                IsMoving(actor, otherActor))
            {
                return(false);
            }

            if (cellFlag.HasCellFlag(CellFlag.HasTemporaryBlocker))
            {
                // If there is a temporary blocker in our path, but we can remove it, we are not blocked.
                var temporaryBlocker = otherActor.TraitOrDefault <ITemporaryBlocker>();
                if (temporaryBlocker != null && temporaryBlocker.CanRemoveBlockage(otherActor, actor))
                {
                    return(false);
                }
            }

            if (cellFlag.HasCellFlag(CellFlag.HasTransitOnlyActor))
            {
                // Transit only tiles should not block movement
                var building = otherActor.OccupiesSpace as Building;
                if (building != null && building.TransitOnlyCells().Contains(cell))
                {
                    return(false);
                }
            }

            // If we cannot crush the other actor in our way, we are blocked.
            if (!cellFlag.HasCellFlag(CellFlag.HasCrushableActor) || Info.Crushes.IsEmpty)
            {
                return(true);
            }

            // If the other actor in our way cannot be crushed, we are blocked.
            // PERF: Avoid LINQ.
            var crushables = otherActor.TraitsImplementing <ICrushable>();

            foreach (var crushable in crushables)
            {
                if (crushable.CrushableBy(otherActor, actor, Info.Crushes))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
 public CellCache(LongBitSet <PlayerBitMask> immovable, CellFlag cellFlag, LongBitSet <PlayerBitMask> crushable = default(LongBitSet <PlayerBitMask>))
 {
     Immovable = immovable;
     Crushable = crushable;
     CellFlag  = cellFlag;
 }
Example #6
0
        bool IsBlockedBy(Actor self, Actor otherActor, Actor ignoreActor, CellConditions check, CellFlag cellFlag)
        {
            if (otherActor == ignoreActor)
            {
                return(false);
            }

            // If the check allows: we are not blocked by allied units moving in our direction.
            if (!check.HasCellCondition(CellConditions.BlockedByMovers) && cellFlag.HasCellFlag(CellFlag.HasMovingActor) &&
                self.Owner.Stances[otherActor.Owner] == Stance.Ally &&
                IsMovingInMyDirection(self, otherActor))
            {
                return(false);
            }

            if (cellFlag.HasCellFlag(CellFlag.HasTemporaryBlocker))
            {
                // If there is a temporary blocker in our path, but we can remove it, we are not blocked.
                var temporaryBlocker = otherActor.TraitOrDefault <ITemporaryBlocker>();
                if (temporaryBlocker != null && temporaryBlocker.CanRemoveBlockage(otherActor, self))
                {
                    return(false);
                }
            }

            if (!cellFlag.HasCellFlag(CellFlag.HasCrushableActor))
            {
                return(true);
            }

            // If we cannot crush the other actor in our way, we are blocked.
            if (Info.Crushes.IsEmpty)
            {
                return(true);
            }

            // If the other actor in our way cannot be crushed, we are blocked.
            // PERF: Avoid LINQ.
            var crushables = otherActor.TraitsImplementing <ICrushable>();

            foreach (var crushable in crushables)
            {
                if (crushable.CrushableBy(otherActor, self, Info.Crushes))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #7
0
 public bool HasFlag(CellFlag flag)
 {
     return((this.flags & flag) == flag);
 }
Example #8
0
 public CellCache(LongBitSet <PlayerBitMask> blocking, CellFlag cellFlag, LongBitSet <PlayerBitMask> crushable = default(LongBitSet <PlayerBitMask>))
 {
     Blocking  = blocking;
     Crushable = crushable;
     CellFlag  = cellFlag;
 }
Example #9
0
 public Cell(CellFlag cellType_p, int cellValeur_p,Color color)
 {
     m_cellType = cellType_p;
     m_cellValeur = cellValeur_p;
     m_color = color;
 }
Example #10
0
 public Cell(CellFlag cellType_p, int cellValeur_p)
 {
     m_cellType = cellType_p;
     m_cellValeur = cellValeur_p;
     m_color = System.Drawing.Color.Black;
 }
Example #11
0
        bool IsBlockedBy(Actor self, Actor otherActor, Actor ignoreActor, BlockedByActor check, CellFlag cellFlag)
        {
            if (otherActor == ignoreActor)
            {
                return(false);
            }

            // If the check allows: We are not blocked by units that we can force to move out of the way.
            if (check <= BlockedByActor.Immovable && cellFlag.HasCellFlag(CellFlag.HasMovableActor) &&
                self.Owner.Stances[otherActor.Owner] == Stance.Ally)
            {
                var mobile = otherActor.TraitOrDefault <Mobile>();
                if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable)
                {
                    return(false);
                }
            }

            // If the check allows: we are not blocked by moving units.
            if (check <= BlockedByActor.Stationary && cellFlag.HasCellFlag(CellFlag.HasMovingActor) &&
                IsMoving(self, otherActor))
            {
                return(false);
            }

            if (cellFlag.HasCellFlag(CellFlag.HasTemporaryBlocker))
            {
                // If there is a temporary blocker in our path, but we can remove it, we are not blocked.
                var temporaryBlocker = otherActor.TraitOrDefault <ITemporaryBlocker>();
                if (temporaryBlocker != null && temporaryBlocker.CanRemoveBlockage(otherActor, self))
                {
                    return(false);
                }
            }

            // If we cannot crush the other actor in our way, we are blocked.
            if (!cellFlag.HasCellFlag(CellFlag.HasCrushableActor) || Info.Crushes.IsEmpty)
            {
                return(true);
            }

            // If the other actor in our way cannot be crushed, we are blocked.
            // PERF: Avoid LINQ.
            var crushables = otherActor.TraitsImplementing <ICrushable>();

            foreach (var crushable in crushables)
            {
                if (crushable.CrushableBy(otherActor, self, Info.Crushes))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #12
0
 public Cell(CellFlag cellType_p, int cellValeur_p, int cellSolution_p)
 {
     m_cellType = cellType_p;
     m_cellValeur = cellValeur_p;
     m_cellSolution = cellSolution_p;
 }