Example #1
0
        public void ApplyMove(Move move)
        {
            // TODO: проверки на валидность
            var movePt        = new Point(move.X, move.Y);
            var moveVecNorm   = movePt.Normalized();
            var moveVecLength = movePt.Length;

            switch (move.Action)
            {
            case ActionType.ClearAndSelect:
                foreach (var unit in MyVehicles)
                {
                    if (move.Group != 0)
                    {
                        unit.IsSelected = unit.HasGroup(move.Group);
                    }
                    else
                    {
                        unit.IsSelected = Geom.Between(move.Left, move.Right, unit.X) &&
                                          Geom.Between(move.Top, move.Bottom, unit.Y) &&
                                          (move.VehicleType == null || move.VehicleType == unit.Type);
                    }
                }
                break;

            case ActionType.AddToSelection:
                foreach (var unit in MyVehicles)
                {
                    if (move.Group != 0)
                    {
                        unit.IsSelected = unit.HasGroup(move.Group);
                    }
                    else
                    {
                        unit.IsSelected |= Geom.Between(move.Left, move.Right, unit.X) &&
                                           Geom.Between(move.Top, move.Bottom, unit.Y) &&
                                           (move.VehicleType == null || move.VehicleType == unit.Type);
                    }
                }
                break;

            case ActionType.Deselect:
                foreach (var unit in MyVehicles)
                {
                    if (!unit.IsSelected)
                    {
                        continue;
                    }

                    if (move.Group != 0)
                    {
                        if (unit.HasGroup(move.Group))
                        {
                            unit.IsSelected = false;
                        }
                    }
                    else
                    {
                        if (Geom.Between(move.Left, move.Right, unit.X) &&
                            Geom.Between(move.Top, move.Bottom, unit.Y) &&
                            (move.VehicleType == null || move.VehicleType == unit.Type))
                        {
                            unit.IsSelected = false;
                        }
                    }
                }
                break;

            case ActionType.Assign:
                foreach (var unit in Vehicles)
                {
                    if (!unit.IsMy)
                    {
                        continue;
                    }

                    unit.AddGroup(move.Group);
                }
                break;

            case ActionType.Move:
                foreach (var unit in Vehicles)
                {
                    if (!unit.IsSelected)
                    {
                        continue;
                    }
                    unit.Action = AVehicle.MoveType.Move;
                    unit.MoveSpeedOrAngularSpeed    = move.MaxSpeed;
                    unit.MoveVectorOrRotationCenter = moveVecNorm;
                    unit.MoveLengthOrRotationAngle  = moveVecLength;
                }
                break;

            case ActionType.Rotate:
                foreach (var unit in Vehicles)
                {
                    if (!unit.IsSelected)
                    {
                        continue;
                    }
                    unit.Action = AVehicle.MoveType.Rotate;
                    unit.MoveSpeedOrAngularSpeed    = move.MaxAngularSpeed;
                    unit.MoveLengthOrRotationAngle  = move.Angle;
                    unit.MoveVectorOrRotationCenter = movePt;
                }
                break;

            case ActionType.Scale:
                foreach (var unit in Vehicles)
                {
                    if (!unit.IsSelected)
                    {
                        continue;
                    }
                    unit.Action = AVehicle.MoveType.Scale;
                    unit.MoveSpeedOrAngularSpeed = move.MaxSpeed;

                    var vec = (unit - movePt) * move.Factor + movePt - unit;
                    unit.MoveVectorOrRotationCenter = vec.Normalized();
                    unit.MoveLengthOrRotationAngle  = vec.Length;
                }
                break;
            }
        }
Example #2
0
 public static bool IsInRange(this double value, Range range) =>
 Geom.Between(range.MinLimit, range.MaxLimit, value);
Example #3
0
 public static bool IsInRange2(this AbsolutePosition position, Range2 range) =>
 Geom.Between(range.XMin, range.XMax, position.X) && Geom.Between(range.YMin, range.YMax, position.Y);
Example #4
0
 public static bool IsInRange(this double value, double minLimit, double maxLimit) =>
 Geom.Between(minLimit, maxLimit, value);