Exemple #1
0
        private void SendFleet(NovaPoint position, Fleet fleet, IWaypointTask task)
        {
            Waypoint w = new Waypoint();

            w.Position    = position;
            w.Destination = position.ToString();
            w.Task        = task;

            WaypointCommand command = new WaypointCommand(CommandMode.Add, w, fleet.Key);

            command.ApplyToState(clientState.EmpireState);
            clientState.Commands.Push(command);
        }
Exemple #2
0
        /// <Summary>
        /// Left Shift Mouse: Set Waypoints.
        /// </Summary>
        /// <param name="e"></param>
        /// <param name="snapToObject"></param>
        private void LeftShiftMouse(MouseEventArgs e, bool snapToObject)
        {
            SelectionArgs args = new SelectionArgs(null);

            OnSelectionRequested(args);

            Mappable item = args.Selection;

            if (item == null || !(item is Fleet))
            {
                return;
            }

            NovaPoint       click       = new NovaPoint(e.X, e.Y);
            Fleet           fleet       = item as Fleet;
            NovaPoint       position    = DeviceToLogical(click);
            List <Mappable> nearObjects = FindNearObjects(position);
            Waypoint        waypoint    = new Waypoint();

            waypoint.Position   = position;
            waypoint.WarpFactor = 6;
            waypoint.Task       = new NoTask();

            // If there are no items near the selected position then set the
            // waypoint to just be a position in space. Otherwise, make the target
            // of the waypoint the selected Item.
            //
            // To Do: Handle multiple items at the target location

            if (nearObjects.Count == 0 || snapToObject == false)
            {
                waypoint.Destination = "Space at " + position.ToString();
                waypoint.Position    = position;
            }
            else
            {
                Mappable selected = nearObjects[0];
                waypoint.Position    = selected.Position;
                waypoint.Destination = selected.Name;
            }

            // If the new waypoint is the same as the last one then do nothing.

            int      lastIndex    = fleet.Waypoints.Count - 1;
            Waypoint lastWaypoint = fleet.Waypoints[lastIndex];

            if (waypoint.Destination == lastWaypoint.Destination)
            {
                return;
            }

            WaypointCommand command = new WaypointCommand(CommandMode.Add, waypoint, fleet.Key);

            clientState.Commands.Push(command);

            if (command.IsValid(clientState.EmpireState))
            {
                command.ApplyToState(clientState.EmpireState);
            }

            RefreshStarMap(this, EventArgs.Empty);

            if (WaypointChanged != null)
            {
                WaypointChanged(this, new EventArgs());
            }
        }