public override Waypoint GetActiveWaypoint() { if (this.UnitClass.UnitType == GameConstants.UnitType.Mine) { return null; } if (MovementOrder != null && MovementOrder.CountWaypoints > 0) { return MovementOrder.GetActiveWaypoint(); } else if (TargetDetectedUnit != null) { if (TargetDetectedUnit.IsMarkedForDeletion) { SearchForTarget(); } if (TargetDetectedUnit != null && !TargetDetectedUnit.IsMarkedForDeletion) { Waypoint wp = new Waypoint(TargetDetectedUnit); return wp; } else { return null; } } else if (TargetPosition != null) { Waypoint wp = new Waypoint(TargetPosition); return wp; } else { SearchForTarget(); if (TargetDetectedUnit == null) { GameManager.Instance.Log.LogDebug(string.Format( "MissileUnit->ActiveWaypoint Unit {0} has no destination or target and is being deleted.", ToString())); IsMarkedForDeletion = true; //delete missile with no target HitPoints = 0; DirtySetting = TTG.NavalWar.NWComms.GameConstants.DirtyStatus.UnitChanged; return null; } else { Waypoint wp = new Waypoint(TargetDetectedUnit); return wp; } } }
public void Impact() { if (Position == null) { IsMarkedForDeletion = true; return; } if (IsMarkedForDeletion) { return; } GameManager.Instance.Log.LogDebug("MissileUnit->Impact called for unit " + Id); if (TargetDetectedUnit != null && TargetDetectedUnit.RefersToUnit != null && TargetDetectedUnit.Position != null) { if (TargetDetectedUnit.RefersToUnit.IsMarkedForDeletion) { this.IsMarkedForDeletion = true; return; } //double distanceM = MapHelper.CalculateDistance3DM(this.Position, TargetDetectedUnit.Position); double distanceM = MapHelper.CalculateDistanceM(this.Position.Coordinate, TargetDetectedUnit.Position.Coordinate); if (distanceM > GameConstants.DISTANCE_TO_TARGET_IS_HIT_M) { if (!InterceptTarget(TargetDetectedUnit)) //try again IsMarkedForDeletion = true; } else { BaseUnit unit = TargetDetectedUnit.RefersToUnit; unit.InflictDamageFromProjectileHit(this); IsMarkedForDeletion = true; } } else { if (TargetPosition != null) { var distanceM = MapHelper.CalculateDistanceM(this.Position.Coordinate, TargetPosition.Coordinate); if (distanceM <= GameConstants.DISTANCE_TO_TARGET_IS_HIT_M) { IsMarkedForDeletion = true; return; } } if (Sensors.Any()) { TargetDetectedUnit = null; SearchForTarget(); if (TargetDetectedUnit == null && TargetPosition == null && (MovementOrder == null || MovementOrder.GetActiveWaypoint() == null)) { IsMarkedForDeletion=true; } } else { IsMarkedForDeletion = true; } } }