// Retro Boss Commonalities

// A_BossDeath portion ported from 2.1.25
function A_21BossDeath(actor)
	// Stop exploding and prepare to run.
	actor.state = actor.info.xdeathstate
	if not actor.valid then return end
	
	actor.target = nil
	
	// Flee! Flee! Find a point to escape to! If none, just shoot upward!
	// scan the thinkers to find the runaway point
	for th in mobjs.iterate() do
		if th.type == MT_BOSSFLYPOINT then
			// If this one's closer then the last one, go for it
			if not actor.target or
			FixedHypot(FixedHypot(actor.x - th.x, actor.y - th.y), actor.z - th.z) <
			FixedHypot(FixedHypot(actor.x - actor.target.x, actor.y - actor.target.y), actor.z - actor.target.z) then
					actor.target = th
			end
			// Otherwise... Don't!
		end
	end
	
	actor.flags = $|MF_NOGRAVITY|MF_NOCLIP
	actor.flags = $|MF_NOCLIPHEIGHT
	
	if actor.target then
		actor.angle = R_PointToAngle2(actor.x, actor.y, actor.target.x, actor.target.y)
		actor.flags2 = $|MF2_BOSSFLEE
		actor.momz = FixedMul(FixedDiv(actor.target.z - actor.z, FixedHypot(actor.x-actor.target.x,actor.y-actor.target.y)), FixedMul(2*FRACUNIT, actor.scale))
	else
		actor.momz = FixedMul(2*FRACUNIT, actor.scale)
	end
end
