Exemple #1
0
 /// <summary>
 /// Internal control that changes the speed the ship is currently traveling at. 
 /// This version does not disengage the autopilot.
 /// </summary>
 /// <param name="newSpeed">The new speed.</param>
 /// <param name="moveMode">The move mode.</param>
 private void ChangeSpeed_Internal(Speed newSpeed, bool isFleetSpeed) {
     float newSpeedValue = isFleetSpeed ? newSpeed.GetUnitsPerHour(_ship.Command.Data) : newSpeed.GetUnitsPerHour(_ship.Data);
     _engineRoom.ChangeSpeed(newSpeed, newSpeedValue);
     if (IsPilotEngaged) {
         _isApCurrentSpeedFleetwide = isFleetSpeed;
     }
 }
Exemple #2
0
    IEnumerator ExecuteAssumeStationOrder_EnterState() {
        LogEvent();

        TryBreakOrbit();
        _helm.ChangeSpeed(Speed.Stop);

        if (IsHQ) {
            D.Assert(FormationStation.IsOnStation);
            if (CurrentOrder.ToNotifyCmd) {
                Command.HandleOrderOutcome(CurrentOrder.Directive, this, isSuccess: true);
            }
            CurrentState = ShipState.Idling;
            yield return null;
        }

        _apMoveSpeed = Speed.Standard;

        if (ShowDebugLog) {
            string speedMsg = "{0}({1:0.##}) units/hr".Inject(_apMoveSpeed.GetValueName(), _apMoveSpeed.GetUnitsPerHour(Data));
            D.Log("{0} is initiating repositioning to FormationStation at speed {1}. DistanceToStation: {2:0.##}.",
                DebugName, speedMsg, FormationStation.DistanceToStation);
        }

        Call(ShipState.Moving);
        yield return null;  // required so Return()s here

        if (_orderFailureCause != UnitItemOrderFailureCause.None) {
            if (CurrentOrder.ToNotifyCmd) {
                Command.HandleOrderOutcome(CurrentOrder.Directive, this, isSuccess: false, failCause: _orderFailureCause);
            }
            switch (_orderFailureCause) {
                case UnitItemOrderFailureCause.UnitItemNeedsRepair:
                    InitiateRepair(retainSuperiorsOrderOnRepairCompletion: false);
                    break;
                case UnitItemOrderFailureCause.UnitItemDeath:
                    // Dead state will follow
                    break;
                case UnitItemOrderFailureCause.TgtUncatchable:
                case UnitItemOrderFailureCause.TgtDeath:
                case UnitItemOrderFailureCause.TgtRelationship:
                case UnitItemOrderFailureCause.TgtUnreachable:
                default:
                    throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(_orderFailureCause));
            }
            yield return null;
        }
        if (FormationStation.IsOnStation) {
            D.Log(ShowDebugLog, "{0} has reached its formation station.", DebugName);
        }
        else {
            D.Warn("{0} has exited 'Moving' to its formation station without being on station.", DebugName);
        }

        // If there was a failure generated by Moving, resulting new Orders or Dead state should keep this point from being reached
        D.AssertDefault((int)_orderFailureCause, _orderFailureCause.GetValueName());

        // No need to wait for HQ to stop turning as we are aligning with its intended facing
        Vector3 hqIntendedHeading = Command.HQElement.Data.IntendedHeading;
        _helm.ChangeHeading(hqIntendedHeading, headingConfirmed: () => {
            Speed hqSpeed = Command.HQElement.CurrentSpeedSetting;
            _helm.ChangeSpeed(hqSpeed);  // UNCLEAR always align speed with HQ?
                                         //D.Log(ShowDebugLog, "{0} has aligned heading and speed {1} with HQ {2}.", DebugName, hqSpeed.GetValueName(), Command.HQElement.DebugName);
            if (CurrentOrder.ToNotifyCmd) {
                Command.HandleOrderOutcome(CurrentOrder.Directive, this, isSuccess: true);
            }
            CurrentState = ShipState.Idling;
        });
    }
Exemple #3
0
 /// <summary>
 /// Changes the speed of the ship.
 /// </summary>
 /// <param name="newSpeed">The new speed request.</param>
 /// <returns><c>true</c> if the speed change was accepted.</returns>
 public bool ChangeSpeed(Speed newSpeed) {
     if (DebugSettings.Instance.StopShipMovement) {
         DisengageAutoPilot();
         return false;
     }
     return _engineRoom.ChangeSpeed(newSpeed.GetUnitsPerHour(_ship.Command.Data, _ship.Data));
 }