/// <summary> /// Plots the course to the target and notifies the requester of the /// outcome via the onCoursePlotCompleted event. /// </summary> /// <param name="target">The target.</param> /// <param name="speed">The speed.</param> /// <param name="standoffDistance">The distance to standoff from the target. When appropriate, this is added to the radius of the target to /// determine how close the ship is allowed to approach.</param> /// <param name="isFleetMove">if set to <c>true</c> the ship will only move when the fleet is ready.</param> public void PlotCourse(INavigableTarget target, Speed speed, float standoffDistance, bool isFleetMove) { if (target is IFormationStation) { PlotCourse(target as IFormationStation, speed); } else if (target is StationaryLocation) { PlotCourse(target as StationaryLocation, speed, isFleetMove); } else if (target is ICmdTarget) { PlotCourse(target as ICmdTarget, speed, standoffDistance); } else if (target is IElementAttackableTarget) { PlotCourse(target as IElementAttackableTarget, speed, standoffDistance); } else if (target is IMortalTarget) { D.Assert(target is IPlanetoidModel); PlotCourse(target as IMortalTarget, speed, standoffDistance, isFleetMove); } else { D.Error("{0} of Type {1} not anticipated.", target.FullName, target.GetType().Name); } }
/// <summary> /// Plots the course to the target and notifies the requester of the outcome via the onCoursePlotSuccess or Failure events. /// </summary> /// <param name="target">The target.</param> /// <param name="speed">The speed.</param> /// <param name="orderSource">The source of this move order.</param> public void PlotCourse(INavigableTarget target, Speed speed, OrderSource orderSource) { D.Assert(speed != default(Speed) && speed != Speed.Stop, "{0} speed of {1} is illegal.".Inject(_ship.FullName, speed.GetValueName())); // NOTE: I know of no way to check whether a target is unreachable at this stage since many targets move, // and most have a closeEnoughDistance that makes them reachable even when enclosed in a keepoutZone if (target is IFormationStation) { D.Assert(orderSource == OrderSource.ElementCaptain); DestinationInfo = new ShipDestinationInfo(target as IFormationStation); } else if (target is SectorModel) { Vector3 destinationOffset = orderSource == OrderSource.UnitCommand ? _ship.Data.FormationStation.StationOffset : Vector3.zero; DestinationInfo = new ShipDestinationInfo(target as SectorModel, destinationOffset); } else if (target is StationaryLocation) { Vector3 destinationOffset = orderSource == OrderSource.UnitCommand ? _ship.Data.FormationStation.StationOffset : Vector3.zero; var autoPilotSpeedReference = new Reference<float>(() => _autoPilotSpeedInUnitsPerHour); DestinationInfo = new ShipDestinationInfo((StationaryLocation)target, destinationOffset, autoPilotSpeedReference); } else if (target is FleetCmdModel) { D.Assert(orderSource == OrderSource.UnitCommand); var fleetTarget = target as FleetCmdModel; bool isEnemy = _ship.Owner.IsEnemyOf(fleetTarget.Owner); DestinationInfo = new ShipDestinationInfo(fleetTarget, _ship.Data.FormationStation.StationOffset, isEnemy); } else if (target is AUnitBaseCmdModel) { D.Assert(orderSource == OrderSource.UnitCommand); var baseTarget = target as AUnitBaseCmdModel; bool isEnemy = _ship.Owner.IsEnemyOf(baseTarget.Owner); DestinationInfo = new ShipDestinationInfo(baseTarget, _ship.Data.FormationStation.StationOffset, isEnemy); } else if (target is FacilityModel) { D.Assert(orderSource == OrderSource.ElementCaptain); var facilityTarget = target as FacilityModel; bool isEnemy = _ship.Owner.IsEnemyOf(facilityTarget.Owner); DestinationInfo = new ShipDestinationInfo(facilityTarget, isEnemy); } else if (target is ShipModel) { D.Assert(orderSource == OrderSource.ElementCaptain); var shipTarget = target as ShipModel; bool isEnemy = _ship.Owner.IsEnemyOf(shipTarget.Owner); DestinationInfo = new ShipDestinationInfo(shipTarget, isEnemy); } else if (target is APlanetoidModel) { Vector3 destinationOffset = orderSource == OrderSource.UnitCommand ? _ship.Data.FormationStation.StationOffset : Vector3.zero; DestinationInfo = new ShipDestinationInfo(target as APlanetoidModel, destinationOffset); } else if (target is SystemModel) { Vector3 destinationOffset = orderSource == OrderSource.UnitCommand ? _ship.Data.FormationStation.StationOffset : Vector3.zero; DestinationInfo = new ShipDestinationInfo(target as SystemModel, destinationOffset); } else if (target is StarModel) { Vector3 destinationOffset = orderSource == OrderSource.UnitCommand ? _ship.Data.FormationStation.StationOffset : Vector3.zero; DestinationInfo = new ShipDestinationInfo(target as StarModel, destinationOffset); } else if (target is UniverseCenterModel) { Vector3 destinationOffset = orderSource == OrderSource.UnitCommand ? _ship.Data.FormationStation.StationOffset : Vector3.zero; DestinationInfo = new ShipDestinationInfo(target as UniverseCenterModel, destinationOffset); } else { D.Error("{0} of Type {1} not anticipated.", target.FullName, target.GetType().Name); return; } OrderSource = orderSource; AutoPilotSpeed = speed; RefreshNavigationalValues(); OnCoursePlotSuccess(); }