Applies damage to a player object, returns false if damage wasn't applied due to things like invunerability
| 804 | // Applies damage to a player object, returns false if damage wasn't applied due to things like |
| 805 | // invunerability |
| 806 | bool ApplyDamageToPlayer(object *playerobj, object *killer, int damage_type, float damage_amount, int server_says, |
| 807 | int weapon_id, bool playsound) { |
| 808 | if (!playerobj || playerobj->type != OBJ_PLAYER) { |
| 809 | // bail it's not a player (no damage should be applied to ghosts or observer's either |
| 810 | return false; |
| 811 | } |
| 812 | |
| 813 | // apply damage to the current player! |
| 814 | object *weapon_obj = NULL; |
| 815 | |
| 816 | if (killer != NULL && killer->type == OBJ_WEAPON) { |
| 817 | weapon_obj = killer; |
| 818 | killer = ObjGetUltimateParent(killer); |
| 819 | |
| 820 | if (!(Game_mode & GM_MULTI) || ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER)) |
| 821 | weapon_id = weapon_obj->id; |
| 822 | if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_CLIENT && !server_says && (Netgame.flags & NF_PEER_PEER)) |
| 823 | weapon_id = weapon_obj->id; |
| 824 | } |
| 825 | |
| 826 | if ((Players[playerobj->id].flags & PLAYER_FLAGS_DYING) || (Players[playerobj->id].flags & PLAYER_FLAGS_DEAD)) { |
| 827 | PlayPlayerDamageSound(playerobj, damage_type); |
| 828 | return false; |
| 829 | } |
| 830 | |
| 831 | if ((Players[playerobj->id].flags & PLAYER_FLAGS_INVULNERABLE) || ((Player_object->flags & OF_DESTROYABLE) == 0)) { |
| 832 | if (damage_type != PD_NONE) |
| 833 | PlayPlayerInvulnerabilitySound(playerobj); |
| 834 | |
| 835 | if (weapon_obj != NULL) { |
| 836 | Players[playerobj->id].invul_magnitude = 1; |
| 837 | Players[playerobj->id].invul_vector = weapon_obj->pos - playerobj->pos; |
| 838 | vm_NormalizeVectorFast(&Players[playerobj->id].invul_vector); |
| 839 | } |
| 840 | return false; |
| 841 | } else { |
| 842 | if (!(Game_mode & GM_MULTI)) { |
| 843 | damage_amount *= Players[playerobj->id].armor_scalar; |
| 844 | damage_amount *= Ships[Players[playerobj->id].ship_index].armor_scalar; |
| 845 | |
| 846 | DecreasePlayerShields(playerobj->id, damage_amount); |
| 847 | |
| 848 | if (damage_amount > 0 && playsound) |
| 849 | PlayPlayerDamageSound(playerobj, damage_type); |
| 850 | |
| 851 | if (Players[playerobj->id].guided_obj != NULL) |
| 852 | ReleaseGuidedMissile(playerobj->id); |
| 853 | |
| 854 | if (Players[playerobj->id].user_timeout_obj != NULL) |
| 855 | ReleaseUserTimeoutMissile(playerobj->id); |
| 856 | |
| 857 | if (weapon_id != 255) { |
| 858 | if (Weapons[weapon_id].flags & WF_MICROWAVE) |
| 859 | SetDeformDamageEffect(playerobj); |
| 860 | if (Weapons[weapon_id].flags & WF_FREEZE) |
| 861 | ApplyFreezeDamageEffect(playerobj); |
| 862 | if (Weapons[weapon_id].flags & WF_NAPALM) |
| 863 | SetNapalmDamageEffect(playerobj, killer, weapon_id); |
no test coverage detected