local ids_func = Idstring
local table_contains = table.contains

local shatter_enemies = {
	ids_func("units/pd2_dlc_bex/characters/ene_swat_tazer_policia_federale/ene_swat_tazer_policia_federale"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_tazer_policia_federale/ene_swat_tazer_policia_federale_husk"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_shield_policia_federale_c45/ene_swat_shield_policia_federale_c45"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_shield_policia_federale_c45/ene_swat_shield_policia_federale_c45_husk"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_heavy_policia_federale/ene_swat_heavy_policia_federale"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_heavy_policia_federale/ene_swat_heavy_policia_federale_husk"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_heavy_policia_federale_r870/ene_swat_heavy_policia_federale_r870"),
	ids_func("units/pd2_dlc_bex/characters/ene_swat_heavy_policia_federale_r870/ene_swat_heavy_policia_federale_r870_husk")
}

--[[
local head_gear = {
  normal = {
    [ids_func("units/pd2_dlc_bex/characters/ene_swat_policia_federale/ene_swat_policia_federale"):key()] = "units/payday2/characters/ene_acc_swat_helmet/ene_acc_swat_helmet",
    [ids_func("units/pd2_dlc_bex/characters/ene_swat_policia_federale/ene_swat_policia_federale_husk"):key()] = "units/payday2/characters/ene_acc_swat_helmet/ene_acc_swat_helmet",
  },
  sm_wish = {
    [ids_func("units/pd2_dlc_bex/characters/ene_swat_policia_federale/ene_swat_policia_federale"):key()] = "units/pd2_dlc_bex/characters/ene_acc_bex_riflar/ene_acc_bex_riflar",
    [ids_func("units/pd2_dlc_bex/characters/ene_swat_policia_federale/ene_swat_policia_federale_husk"):key()] = "units/pd2_dlc_bex/characters/ene_acc_bex_riflar/ene_acc_bex_riflar",
  }
}
--]]
Hooks:PreHook( CopDamage, "_spawn_head_gadget", "smash_federales", function(self, params)
    local difficulty = Global.game_settings and Global.game_settings.difficulty or "normal"
    -- local head_gear_replacement = head_gear[difficulty] and head_gear[difficulty][self._unit:key()]

	if not self._head_gear then
		return
	end

	local my_unit = self._unit

	if not table_contains(shatter_enemies, my_unit:name()) then
		return
	end
	
	local head_obj = ids_func("Head")
	local head_object_get = my_unit:get_object(head_obj)
	
	if not head_object_get then
		return
		
	end
	--[[
	  if self._unit:name() == ids_func("units/pd2_dlc_bex/characters/ene_swat_policia_federale/ene_swat_policia_federale") then
		self._head_gear = "units/payday2/characters/ene_acc_tazer_helmet/ene_acc_tazer_helmet"
	  end
	--]]
	local world_g = World		
	local sound_ext = my_unit:sound()	
	
	world_g:effect_manager():spawn({
		effect = ids_func("effects/particles/bullet_hit/glass_breakable/bullet_hit_glass_breakable"),
		parent = head_object_get		
	})			
	
	sound_ext:play("swat_heavy_visor_shatter", nil, nil)
	sound_ext:play("swat_heavy_visor_shatter", nil, nil)
	sound_ext:play("swat_heavy_visor_shatter", nil, nil)
end)
