/// <summary> /// Refreshes the course. /// </summary> /// <param name="mode">The mode.</param> /// <param name="waypoint">The waypoint.</param> protected abstract void RefreshCourse(CourseRefreshMode mode, INavigableTarget waypoint = null);
private void InitiateObstacleCheckingEnrouteTo(AutoPilotDestinationProxy destProxy, CourseRefreshMode courseRefreshMode) { D.AssertNotNull(destProxy, DebugName); // 12.15.16 Got null ref in TryCheckForObstacleEnrouteTo() D.AssertNull(_apObstacleCheckJob, DebugName); _apObstacleCheckPeriod = __GenerateObstacleCheckPeriod(); AutoPilotDestinationProxy detourProxy; string jobName = "{0}.ApObstacleCheckJob".Inject(DebugName); _apObstacleCheckJob = _jobMgr.RecurringWaitForHours(new Reference<GameTimeDuration>(() => _apObstacleCheckPeriod), jobName, waitMilestone: () => { Profiler.BeginSample("Ship ApObstacleCheckJob Execution", _ship); if (TryCheckForObstacleEnrouteTo(destProxy, out detourProxy)) { KillApObstacleCheckJob(); RefreshCourse(courseRefreshMode, detourProxy); Profiler.EndSample(); ContinueCourseToTargetVia(detourProxy); return; } if (_doesApObstacleCheckPeriodNeedRefresh) { _apObstacleCheckPeriod = __GenerateObstacleCheckPeriod(); _doesApObstacleCheckPeriodNeedRefresh = false; } Profiler.EndSample(); }); }
/// <summary> /// Refreshes the course. /// </summary> /// <param name="mode">The mode.</param> /// <param name="wayPtProxy">The optional waypoint. When not null, this is always a StationaryLocation detour to avoid an obstacle.</param> /// <exception cref="System.NotImplementedException"></exception> private void RefreshCourse(CourseRefreshMode mode, AutoPilotDestinationProxy wayPtProxy = null) { //D.Log(ShowDebugLog, "{0}.RefreshCourse() called. Mode = {1}. CourseCountBefore = {2}.", DebugName, mode.GetValueName(), AutoPilotCourse.Count); switch (mode) { case CourseRefreshMode.NewCourse: D.AssertNull(wayPtProxy); ApCourse.Clear(); ApCourse.Add(_ship); IShipNavigable courseTgt; if (ApTargetProxy.IsMobile) { courseTgt = new MobileLocation(new Reference<Vector3>(() => ApTargetProxy.Position)); } else { courseTgt = new StationaryLocation(ApTargetProxy.Position); } ApCourse.Add(courseTgt); // includes fstOffset break; case CourseRefreshMode.AddWaypoint: ApCourse.Insert(ApCourse.Count - 1, new StationaryLocation(wayPtProxy.Position)); // changes Course.Count break; case CourseRefreshMode.ReplaceObstacleDetour: D.AssertEqual(3, ApCourse.Count); ApCourse.RemoveAt(ApCourse.Count - 2); // changes Course.Count ApCourse.Insert(ApCourse.Count - 1, new StationaryLocation(wayPtProxy.Position)); // changes Course.Count break; case CourseRefreshMode.RemoveWaypoint: D.AssertEqual(3, ApCourse.Count); bool isRemoved = ApCourse.Remove(new StationaryLocation(wayPtProxy.Position)); // Course.RemoveAt(Course.Count - 2); // changes Course.Count D.Assert(isRemoved); break; case CourseRefreshMode.ClearCourse: D.AssertNull(wayPtProxy); ApCourse.Clear(); break; default: throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(mode)); } //D.Log(ShowDebugLog, "CourseCountAfter = {0}.", Course.Count); HandleCourseChanged(); }
/// <summary> /// Refreshes the course. /// </summary> /// <param name="mode">The mode.</param> /// <param name="waypoint">The optional waypoint. When not null, this is always a StationaryLocation detour to avoid an obstacle.</param> /// <exception cref="System.NotImplementedException"></exception> private void RefreshApCourse(CourseRefreshMode mode, IFleetNavigable waypoint = null) { //D.Log(ShowDebugLog, "{0}.RefreshCourse() called. Mode = {1}. CourseCountBefore = {2}.", DebugName, mode.GetValueName(), ApCourse.Count); switch (mode) { case CourseRefreshMode.NewCourse: D.AssertNull(waypoint); // A fleet course is constructed by ConstructCourse D.Error("{0}: Illegal {1}.{2}.", DebugName, typeof(CourseRefreshMode).Name, mode.GetValueName()); break; case CourseRefreshMode.AddWaypoint: D.Assert(waypoint is StationaryLocation); ApCourse.Insert(_currentApCourseIndex, waypoint); // changes Course.Count break; case CourseRefreshMode.ReplaceObstacleDetour: D.Assert(waypoint is StationaryLocation); ApCourse.RemoveAt(_currentApCourseIndex); // changes Course.Count ApCourse.Insert(_currentApCourseIndex, waypoint); // changes Course.Count break; case CourseRefreshMode.RemoveWaypoint: D.Assert(waypoint is StationaryLocation); D.AssertEqual(ApCourse[_currentApCourseIndex], waypoint); bool isRemoved = ApCourse.Remove(waypoint); // changes Course.Count D.Assert(isRemoved); _currentApCourseIndex--; break; case CourseRefreshMode.ClearCourse: D.AssertNull(waypoint); ApCourse.Clear(); break; default: throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(mode)); } //D.Log(ShowDebugLog, "CourseCountAfter = {0}.", ApCourse.Count); HandleApCourseChanged(); }