| 3395 | } |
| 3396 | |
| 3397 | void BattleUnit::updateAttacking(GameState &state, unsigned int ticks) |
| 3398 | { |
| 3399 | if (isAttacking()) |
| 3400 | { |
| 3401 | // Cancel acquire TU mission if attempting to attack |
| 3402 | if (!missions.empty() && missions.front()->type == BattleUnitMission::Type::AcquireTU) |
| 3403 | { |
| 3404 | cancelMissions(state); |
| 3405 | } |
| 3406 | // Prepare all needed positions |
| 3407 | static const Vec3<float> offsetTile = {0.5f, 0.5f, 0.0f}; |
| 3408 | static const Vec3<float> offsetTileGround = {0.5f, 0.5f, 10.0f / 40.0f}; |
| 3409 | Vec3<float> muzzleLocation = getMuzzleLocation(); |
| 3410 | Vec3<float> targetPosition; |
| 3411 | switch (targetingMode) |
| 3412 | { |
| 3413 | case TargetingMode::Unit: |
| 3414 | targetPosition = targetUnit->tileObject->getVoxelCentrePosition(); |
| 3415 | break; |
| 3416 | case TargetingMode::TileCenter: |
| 3417 | { |
| 3418 | // Shoot parallel to the ground |
| 3419 | float unitZ = muzzleLocation.z; |
| 3420 | unitZ -= (int)unitZ; |
| 3421 | targetPosition = |
| 3422 | (Vec3<float>)targetTile + offsetTile + Vec3<float>{0.0f, 0.0f, unitZ}; |
| 3423 | break; |
| 3424 | } |
| 3425 | case TargetingMode::TileGround: |
| 3426 | targetPosition = (Vec3<float>)targetTile + offsetTileGround; |
| 3427 | break; |
| 3428 | case TargetingMode::NoTarget: |
| 3429 | LogError("Invalid targeting mode NoTarget while targeting"); |
| 3430 | break; |
| 3431 | } |
| 3432 | |
| 3433 | // Prepare weapons we can use |
| 3434 | // We can use a weapon if we're set to fire this hand, and it's a weapon that can be fired |
| 3435 | auto weaponRight = agent->getFirstItemInSlot(EquipmentSlotType::RightHand); |
| 3436 | auto weaponLeft = agent->getFirstItemInSlot(EquipmentSlotType::LeftHand); |
| 3437 | switch (weaponStatus) |
| 3438 | { |
| 3439 | case WeaponStatus::FiringBothHands: |
| 3440 | if (weaponRight && weaponRight->needsReload()) |
| 3441 | { |
| 3442 | weaponRight->loadAmmo(state); |
| 3443 | } |
| 3444 | if (weaponRight && !weaponRight->canFire(state)) |
| 3445 | { |
| 3446 | weaponRight = nullptr; |
| 3447 | } |
| 3448 | if (weaponLeft && weaponLeft->needsReload()) |
| 3449 | { |
| 3450 | weaponLeft->loadAmmo(state); |
| 3451 | } |
| 3452 | if (weaponLeft && !weaponLeft->canFire(state)) |
| 3453 | { |
| 3454 | weaponLeft = nullptr; |
nothing calls this directly
no test coverage detected