| 3511 | } |
| 3512 | |
| 3513 | void BattleUnit::updateFiring(GameState &state, sp<AEquipment> &weaponLeft, |
| 3514 | sp<AEquipment> &weaponRight, Vec3<float> &targetPosition) |
| 3515 | { |
| 3516 | bool realTime = state.current_battle->mode == Battle::Mode::RealTime; |
| 3517 | Vec3<float> muzzleLocation = getMuzzleLocation(); |
| 3518 | |
| 3519 | // Should we start aiming? |
| 3520 | if (canHandStateChange(HandState::Aiming)) |
| 3521 | { |
| 3522 | beginHandStateChange(HandState::Aiming); |
| 3523 | } |
| 3524 | |
| 3525 | // Should we begin fire delay countdown? |
| 3526 | if (target_hand_state == HandState::Aiming) |
| 3527 | { |
| 3528 | if (weaponRight && !weaponRight->isFiring()) |
| 3529 | { |
| 3530 | weaponRight->startFiring(fire_aiming_mode, !realTime); |
| 3531 | } |
| 3532 | if (weaponLeft && !weaponLeft->isFiring()) |
| 3533 | { |
| 3534 | weaponLeft->startFiring(fire_aiming_mode, !realTime); |
| 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | // Is a gun ready to fire now? |
| 3539 | bool weaponFired = false; |
| 3540 | if (firing_animation_ticks_remaining == 0 && target_hand_state == HandState::Aiming) |
| 3541 | { |
| 3542 | sp<AEquipment> firingWeapon = nullptr; |
| 3543 | if (weaponRight && weaponRight->readyToFire) |
| 3544 | { |
| 3545 | firingWeapon = weaponRight; |
| 3546 | weaponRight = nullptr; |
| 3547 | } |
| 3548 | else if (weaponLeft && weaponLeft->readyToFire) |
| 3549 | { |
| 3550 | firingWeapon = weaponLeft; |
| 3551 | weaponLeft = nullptr; |
| 3552 | } |
| 3553 | // Weapon ready to fire: check if facing the right way |
| 3554 | if (firingWeapon) |
| 3555 | { |
| 3556 | auto targetPosAdjusted = targetPosition; |
| 3557 | // Lead the target |
| 3558 | if (targetUnit) |
| 3559 | { |
| 3560 | auto projectileVelocity = |
| 3561 | firingWeapon->getPayloadType()->speed * PROJECTILE_VELOCITY_MULTIPLIER; |
| 3562 | // Target's velocity (if falling/jumping) |
| 3563 | Vec3<float> targetVelocity = targetUnit->getVelocity(); |
| 3564 | auto distanceVoxels = |
| 3565 | glm::length((targetPosition - muzzleLocation) * VELOCITY_SCALE_BATTLE); |
| 3566 | float timeToImpact = distanceVoxels * (float)TICK_SCALE / projectileVelocity; |
| 3567 | targetPosAdjusted += Collision::getLeadingOffset(targetPosition - muzzleLocation, |
| 3568 | projectileVelocity * timeToImpact, |
| 3569 | targetVelocity * timeToImpact); |
| 3570 | } |
nothing calls this directly
no test coverage detected