--Sp-人车合体
function c87593017.initial_effect(c)
	--counter
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_COUNTER)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1,87593017+EFFECT_COUNT_CODE_DUEL)
	e1:SetTarget(c87593017.target)
	e1:SetOperation(c87593017.operation)
	c:RegisterEffect(e1)
end
function c87593017.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetLP(tp)>=1000 end
	Duel.SetOperationInfo(0,CATEGORY_COUNTER,nil,1,nil,nil)
end
function c87593017.operation(e,tp,eg,ep,ev,re,r,rp)
	local c=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil,87593200):GetFirst()
	if c:GetControler()==tp then cou=0x871 else cou=0x872 end
	c:AddCounter(cou,math.floor(Duel.GetLP(tp)/1000))
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e3:SetProperty(EFFECT_FLAG_DELAY)
	e3:SetCode(EVENT_REMOVE_COUNTER+cou)
	e3:SetOperation(c87593017.ctop)
	Duel.RegisterEffect(e3,tp)
end
function c87593017.ctop(e,tp,eg,ep,ev,re,r,rp)
	local c=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil,87593200):GetFirst()
	if c:GetControler()==tp then cou=0x871 else cou=0x872 end
	if c:GetCounter(cou)==0 then Duel.SetLP(tp,0) end
end