| 4654 | } |
| 4655 | |
| 4656 | void BattleUnit::die(GameState &state, StateRef<BattleUnit> attacker, bool violently) |
| 4657 | { |
| 4658 | auto attackerOrg = attacker ? attacker->agent->owner : nullptr; |
| 4659 | auto ourOrg = agent->owner; |
| 4660 | bool destroy = false; |
| 4661 | // Violent deaths (spawn stuff, blow up) |
| 4662 | if (violently) |
| 4663 | { |
| 4664 | for (auto &e : agent->equipment) |
| 4665 | { |
| 4666 | switch (e->type->type) |
| 4667 | { |
| 4668 | // Blow up |
| 4669 | case AEquipmentType::Type::Popper: |
| 4670 | state.current_battle->addExplosion(state, position, |
| 4671 | e->type->damage_type->explosionDoodad, |
| 4672 | e->type->damage_type, e->type->damage, |
| 4673 | e->type->explosion_depletion_rate, owner); |
| 4674 | destroy = true; |
| 4675 | break; |
| 4676 | case AEquipmentType::Type::Spawner: |
| 4677 | { |
| 4678 | useSpawner(state, *e->type); |
| 4679 | break; |
| 4680 | } |
| 4681 | default: |
| 4682 | break; |
| 4683 | } |
| 4684 | } |
| 4685 | } |
| 4686 | // Clear focus |
| 4687 | for (auto &u : focusedByUnits) |
| 4688 | { |
| 4689 | u->focusUnit.clear(); |
| 4690 | } |
| 4691 | focusedByUnits.clear(); |
| 4692 | // Emit sound |
| 4693 | if (agent->type->dieSfx.find(agent->gender) != agent->type->dieSfx.end() && |
| 4694 | !agent->type->dieSfx.at(agent->gender).empty()) |
| 4695 | { |
| 4696 | fw().soundBackend->playSample(pickRandom(state.rng, agent->type->dieSfx.at(agent->gender)), |
| 4697 | position); |
| 4698 | } |
| 4699 | // Morale and score |
| 4700 | auto player = state.getPlayer(); |
| 4701 | // Find next highest ranking officer |
| 4702 | state.current_battle->refreshLeadershipBonus(ourOrg); |
| 4703 | // Penalty for teamkills or bonus for eliminating a hostile |
| 4704 | if (attacker && attackerOrg == ourOrg) |
| 4705 | { |
| 4706 | // Teamkill penalty morale |
| 4707 | attacker->agent->modified_stats.loseMorale(20); |
| 4708 | attacker->combatRating -= agent->type->score; |
| 4709 | // Teamkill penalty score |
| 4710 | if (ourOrg == player) |
| 4711 | { |
| 4712 | state.current_battle->score.friendlyFire -= 10; |
| 4713 | } |
no test coverage detected