local player_x, player_y = EntityGetTransform(EntityGetWithTag("player_unit")[1])
local hellhound_x, hellhound_y = EntityGetTransform(GetUpdatedEntityID())

if math.abs(player_y - hellhound_y) + math.abs(player_x - hellhound_x) > 500 then
	EntityLoad("data/entities/particles/teleportation_source.xml", hellhound_x, hellhound_y)
	EntityLoad("data/entities/particles/teleportation_source.xml", player_x, player_y)
	EntitySetTransform(GetUpdatedEntityID(), player_x, player_y)
end

local hellhound = GetUpdatedEntityID()

-- 0 is "player" herd_id
if ComponentGetValue2(EntityGetFirstComponent(hellhound, "GenomeDataComponent"), "herd_id") == 0 then
	SetRandomSeed(hellhound_x, hellhound_y)

	if Random(1, 50) == 1 then
		-- charm is needed so hellhound follows player instead of just standing somewhere
		local h_children = EntityGetAllChildren(hellhound)

		for i, ch in ipairs(h_children) do
			if ComponentGetValue2(EntityGetFirstComponent(ch, "GameEffectComponent"), "effect") == "CHARM" then
				EntityKill(ch)
			end
		end

		ComponentSetValue2(EntityGetFirstComponent(hellhound, "GenomeDataComponent"), "herd_id", StringToHerdId("wolf"))
		ComponentSetValue2(EntityGetFirstComponent(hellhound, "AnimalAIComponent"), "attack_melee_damage_min", 0)
		ComponentSetValue2(EntityGetFirstComponent(hellhound, "AnimalAIComponent"), "attack_melee_damage_max", 0)
		GamePrintImportant("hellhound is horny!", "Prepare your ass", "mods/lewd_noita/files/sex_logic/ui_msg.png")
		GamePlaySound("data/audio/Desktop/event_cues.bank", "event_cues/heartbeat/create", player_x, player_y)
	end
end