/// <summary> /// Handler when actor is moved due to game logic. /// </summary> /// <param name="sender"></param> protected void Actor_MovedHandler(object sender) { if (sender is BasicBogeyActor) { ClientActor actor = sender as ClientActor; // If this actor is the bogey we are tracking ... if (actor == TrackingBogey) { // If it off the radar scope stop tracking it. if (!actor.IsRadarScopeVisible) { actor.RadarTrackingMarkVisibility = Visibility.Hidden; TrackingBogey = null; BogeyHeading = Double.NaN; BogeyRange = Double.NaN; BogeyInterceptHeading = Double.NaN; } else { // Update the bogey tracking display IClientSprite sprite = actor.Sprite as IClientSprite; BogeyHeading = sprite.Heading; // Calculate intercept heading from pilot to bogey (by first calculating the delta distance). Vector intercept_delta = Vector.Subtract(sprite.Position, _view_translator.RadarWorldPosition); BogeyRange = intercept_delta.Length; BogeyInterceptHeading = MathHelper.headingFromVector(intercept_delta); } } } }
/// <summary> /// Handler when actor is removed due to game logic. /// </summary> /// <param name="sender"></param> protected void Actor_RemovedHandler(object sender) { if (sender is ClientActor) { ClientActor actor = sender as ClientActor; if (actor == TrackingBogey) { TrackingBogey = null; } _bogey_actors.Remove(actor); // Remove the actor from the list of bogeys the stage is tracking. RadarTargetInsertionCanvas.Children.Remove(actor); // Remove this actor from the parent stage } }
/// <summary> /// Select the next bogey for pilot radar tracking. /// </summary> private void trackNextRadarBogey() { ClientActor old_target_bogey = TrackingBogey; ClientActor target_bogey = TrackingBogey; // Create a list of radar visible bogeys List <ClientActor> radar_bogeys = new List <ClientActor>(); foreach (var actor in _bogey_actors) { if (actor.IsRadarScopeVisible) { radar_bogeys.Add(actor); } } //////////////////////////////////////// // Pick the next target bogey if (radar_bogeys.Count == 0) { target_bogey = null; // No bogeys, so null target } else if (radar_bogeys.Count == 1) { target_bogey = radar_bogeys[0]; // Only one choice. } else { // Find the next furthest based on where the current target distance. // Sort the list by distance radar_bogeys.Sort((a, b) => a.RadarDistance.CompareTo(b.RadarDistance)); if (old_target_bogey == null) { target_bogey = radar_bogeys[0]; // If we don't have a current target, use the closest. } else { // There are at least 2 qualifing bogeys, and one is likely the // old target. Find the index of the old target. int old_bogey_index = radar_bogeys.FindIndex(x => x == old_target_bogey); if (old_bogey_index == -1) { // We didnt find the current target, so pick the first. target_bogey = radar_bogeys[0]; } else { // Found the current, so move to the next in the list. int new_bogey_index = old_bogey_index + 1; // Wrap to the first if we are at the end. if (new_bogey_index == radar_bogeys.Count) { new_bogey_index = 0; } target_bogey = radar_bogeys[new_bogey_index]; } } } // Set the visibility on the old and new targets. if (target_bogey != old_target_bogey) { if (old_target_bogey != null) { old_target_bogey.RadarTrackingMarkVisibility = Visibility.Hidden; } if (target_bogey != null) { target_bogey.RadarTrackingMarkVisibility = Visibility.Visible; } } // Assign the new target to the class data member. TrackingBogey = target_bogey; }