Ejemplo n.º 1
0
 public LosWeaponFiringSolutionEventArgs(LosWeaponFiringSolution firingSolution) {
     FiringSolution = firingSolution;
 }
Ejemplo n.º 2
0
 private void OnWeaponAimed(LosWeaponFiringSolution firingSolution) {
     if (weaponAimed != null) {
         weaponAimed(this, new LosWeaponFiringSolutionEventArgs(firingSolution));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Aims this LOS Weapon using the provided firing solution.
 /// </summary>
 /// <param name="firingSolution">The firing solution.</param>
 public void AimAt(LosWeaponFiringSolution firingSolution) {
     WeaponMount.TraverseTo(firingSolution);
 }
Ejemplo n.º 4
0
 public void HandleWeaponAimed(LosWeaponFiringSolution firingSolution) {
     OnWeaponAimed(firingSolution);
 }
Ejemplo n.º 5
0
 private void HandleTraverseCompleted(LosWeaponFiringSolution firingSolution) {
     Weapon.HandleWeaponAimed(firingSolution);
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Traverses the mount to point at the target defined by the provided firing solution.
    /// </summary>
    /// <param name="firingSolution">The firing solution.</param>
    public void TraverseTo(LosWeaponFiringSolution firingSolution) {
        D.Assert(!_gameMgr.IsPaused, "Not allowed to create a Job while paused.");
        D.Assert(Weapon.IsOperational);
        D.AssertNull(_traverseJob, DebugName);

        //D.Log(ShowDebugLog, "{0} received Traverse to aim at {1}.", DebugName, firingSolution.EnemyTarget.DebugName);
        Quaternion reqdHubRotation = firingSolution.TurretRotation;
        Quaternion reqdBarrelElevation = firingSolution.TurretElevation;

        string jobName = "{0}.TraverseJob".Inject(DebugName);
        _traverseJob = _jobMgr.StartGameplayJob(ExecuteTraverse(reqdHubRotation, reqdBarrelElevation), jobName, isPausable: true, jobCompleted: (jobWasKilled) => {
            if (jobWasKilled) {
                // 12.12.16 An AssertNull(_jobRef) here can fail as the reference can refer to a new Job, created 
                // right after the old one was killed due to the 1 frame delay in execution of jobCompleted(). My attempts at allowing
                // the AssertNull to occur failed. I believe this is OK as _jobRef is nulled from KillXXXJob() and, if 
                // the reference is replaced by a new Job, then the old Job is no longer referenced which is the objective. Jobs Kill()ed
                // centrally by JobManager won't null the reference, but this only occurs during scene transitions.
            }
            else {
                _traverseJob = null;
                HandleTraverseCompleted(firingSolution);
            }
        });
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Tries to develop a firing solution from this WeaponMount to the provided target. If successful, returns <c>true</c> and provides the
    /// firing solution, otherwise <c>false</c>.
    /// </summary>
    /// <param name="enemyTarget">The enemy target.</param>
    /// <param name="firingSolution"></param>
    /// <returns></returns>
    public override bool TryGetFiringSolution(IElementAttackable enemyTarget, out WeaponFiringSolution firingSolution) {
        D.Assert(enemyTarget.IsOperational);
        D.Assert(enemyTarget.IsAttackByAllowed(Weapon.Owner));

        firingSolution = null;
        if (!ConfirmInRangeForLaunch(enemyTarget)) {
            //D.Log(ShowDebugLog, "{0}: Target {1} is out of range.", DebugName, enemyTarget.DebugName);
            return false;
        }

        Vector3 targetPosition = enemyTarget.Position;
        Quaternion reqdHubRotation, reqdBarrelElevation;
        bool canTraverseToTarget = TryCalcTraverse(targetPosition, out reqdHubRotation, out reqdBarrelElevation);
        if (!canTraverseToTarget) {
            //D.Log(ShowDebugLog, "{0}: Target {1} is out of traverse range.", DebugName, enemyTarget.DebugName);
            return false;
        }

        bool isLosClear = CheckLineOfSight(enemyTarget);
        if (!isLosClear) {
            return false;
        }
        firingSolution = new LosWeaponFiringSolution(Weapon, enemyTarget, reqdHubRotation, reqdBarrelElevation);
        return true;
    }
Ejemplo n.º 8
0
 private void HandleLosWeaponAimed(LosWeaponFiringSolution firingSolution) {
     var target = firingSolution.EnemyTarget;
     var losWeapon = firingSolution.Weapon;
     D.Assert(losWeapon.IsOperational);  // weapon should not have completed aiming if it lost operation
     if (target.IsOperational && target.IsAttackByAllowed(Owner) && losWeapon.ConfirmInRangeForLaunch(target)) {
         LaunchOrdnance(losWeapon, target);
     }
     else {
         // target moved out of range, died or changed diplomatic during aiming process
         losWeapon.HandleElementDeclinedToFire();
     }
     losWeapon.weaponAimed -= LosWeaponAimedEventHandler;
 }